Only add entry with unique package name to default browser list.

When we query the package manager for activities that can handle the
web data uri, different capable activities within the same package will
be returned as separate entries. However, when we show the default
browser apps to the user, the entries are simply base on package name.
So, if there are multiple activities within the same package that can
handle the web data, they will be shown as duplicate entries.

When we process the resolved activities, check the corresponding package
name for duplicate entries before adding it to the default browser list.

Change-Id: I70c88866eb3d5fe6466554749e23c85f429dd30c
Fixes: 84207432
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2018-06-05 15:28:27 -07:00
parent 0614f76677
commit 1503b0273b
2 changed files with 58 additions and 1 deletions

View File

@@ -16,6 +16,8 @@
package com.android.settings.applications.defaultapps;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
@@ -23,10 +25,20 @@ import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.os.UserManager;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.applications.DefaultAppInfo;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
@@ -53,6 +65,7 @@ public class DefaultBrowserPickerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest();
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
mPicker = new DefaultBrowserPicker();
@@ -72,4 +85,39 @@ public class DefaultBrowserPickerTest {
mPicker.getDefaultKey();
verify(mPackageManager).getDefaultBrowserPackageNameAsUser(anyInt());
}
@Test
public void getCandidates_shouldNotIncludeDuplicatePackageName() throws NameNotFoundException {
final List<ResolveInfo> resolveInfos = new ArrayList<>();
final String PACKAGE_ONE = "com.first.package";
final String PACKAGE_TWO = "com.second.package";
resolveInfos.add(createResolveInfo(PACKAGE_ONE));
resolveInfos.add(createResolveInfo(PACKAGE_TWO));
resolveInfos.add(createResolveInfo(PACKAGE_ONE));
resolveInfos.add(createResolveInfo(PACKAGE_TWO));
when(mPackageManager.queryIntentActivitiesAsUser(any(Intent.class), anyInt(), anyInt()))
.thenReturn(resolveInfos);
when(mPackageManager.getApplicationInfoAsUser(eq(PACKAGE_ONE), anyInt(), anyInt()))
.thenReturn(createApplicationInfo(PACKAGE_ONE));
when(mPackageManager.getApplicationInfoAsUser(eq(PACKAGE_TWO), anyInt(), anyInt()))
.thenReturn(createApplicationInfo(PACKAGE_TWO));
final List<DefaultAppInfo> defaultBrowserInfo = mPicker.getCandidates();
assertThat(defaultBrowserInfo.size()).isEqualTo(2);
}
private ResolveInfo createResolveInfo(String packageName) {
final ResolveInfo info = new ResolveInfo();
info.handleAllWebDataURI = true;
info.activityInfo = new ActivityInfo();
info.activityInfo.packageName = packageName;
return info;
}
private ApplicationInfo createApplicationInfo(String packageName) {
final ApplicationInfo info = new ApplicationInfo();
info.packageName = packageName;
return info;
}
}