Do not include disabled activity in Default Browser.
- query the intent activites with flags 0, so that only enabled activities will be returned. Change-Id: I6ec4e3f3fdff850228a723bcb2d2bdc5721b41eb Fixes: 111796304 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -111,7 +111,7 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont
|
||||
final List<ResolveInfo> candidates = new ArrayList<>();
|
||||
// Resolve that intent and check that the handleAllWebDataURI boolean is set
|
||||
final List<ResolveInfo> list = packageManager.queryIntentActivitiesAsUser(
|
||||
BROWSE_PROBE, PackageManager.MATCH_ALL, userId);
|
||||
BROWSE_PROBE, 0 /* flags */, userId);
|
||||
if (list != null) {
|
||||
final Set<String> addedPackages = new ArraySet<>();
|
||||
for (ResolveInfo info : list) {
|
||||
@@ -181,13 +181,12 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont
|
||||
* Whether or not the pkg is the default browser
|
||||
*/
|
||||
public boolean isBrowserDefault(String pkg, int userId) {
|
||||
String defaultPackage = mPackageManager.getDefaultBrowserPackageNameAsUser(userId);
|
||||
final String defaultPackage = mPackageManager.getDefaultBrowserPackageNameAsUser(userId);
|
||||
if (defaultPackage != null) {
|
||||
return defaultPackage.equals(pkg);
|
||||
}
|
||||
|
||||
final List<ResolveInfo> list = mPackageManager.queryIntentActivitiesAsUser(BROWSE_PROBE,
|
||||
PackageManager.MATCH_ALL, userId);
|
||||
final List<ResolveInfo> list = getCandidates(mPackageManager, userId);
|
||||
// There is only 1 app, it must be the default browser.
|
||||
return list != null && list.size() == 1;
|
||||
}
|
||||
|
@@ -18,9 +18,9 @@ package com.android.settings.applications.defaultapps;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -133,8 +133,11 @@ public class DefaultBrowserPreferenceControllerTest {
|
||||
@Test
|
||||
public void isBrowserDefault_onlyApp_shouldReturnTrue() {
|
||||
when(mPackageManager.getDefaultBrowserPackageNameAsUser(anyInt())).thenReturn(null);
|
||||
final List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
final String PACKAGE_ONE = "pkg";
|
||||
resolveInfos.add(createResolveInfo(PACKAGE_ONE));
|
||||
when(mPackageManager.queryIntentActivitiesAsUser(any(Intent.class), anyInt(), anyInt()))
|
||||
.thenReturn(Collections.singletonList(new ResolveInfo()));
|
||||
.thenReturn(resolveInfos);
|
||||
|
||||
assertThat(mController.isBrowserDefault("pkg", 0)).isTrue();
|
||||
}
|
||||
@@ -161,6 +164,15 @@ public class DefaultBrowserPreferenceControllerTest {
|
||||
assertThat(defaultBrowserInfo.size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCandidates_shouldQueryActivityWithFlagsEquals0() {
|
||||
|
||||
mController.getCandidates(mPackageManager, 0 /* userId */);
|
||||
|
||||
verify(mPackageManager).queryIntentActivitiesAsUser(
|
||||
any(Intent.class), eq(0) /* flags */, eq(0) /* userId */);
|
||||
}
|
||||
|
||||
private ResolveInfo createResolveInfo(String packageName) {
|
||||
final ResolveInfo info = new ResolveInfo();
|
||||
info.handleAllWebDataURI = true;
|
||||
|
Reference in New Issue
Block a user