Correctly report whether the current app is default home.
Change-Id: I79c374228e82c91667d7b5a0dcc19fa1216e57c4 Fix: 38065524 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
import android.Manifest.permission;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
@@ -116,6 +114,8 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
/**
|
||||
* Activity to display application information from Settings. This activity presents
|
||||
* extended information associated with a package like code, data, total size, permissions
|
||||
@@ -1200,7 +1200,8 @@ public class InstalledAppDetails extends AppInfoBase
|
||||
Preference pref = findPreference("default_home");
|
||||
|
||||
if (pref != null) {
|
||||
pref.setSummary(DefaultHomePreferenceController.isHomeDefault(mPackageName, context)
|
||||
pref.setSummary(DefaultHomePreferenceController.isHomeDefault(mPackageName,
|
||||
new PackageManagerWrapperImpl(context.getPackageManager()))
|
||||
? R.string.yes : R.string.no);
|
||||
}
|
||||
pref = findPreference("default_browser");
|
||||
|
@@ -26,6 +26,8 @@ import android.content.pm.ResolveInfo;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -106,11 +108,10 @@ public class DefaultHomePreferenceController extends DefaultAppPreferenceControl
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isHomeDefault(String pkg, Context context) {
|
||||
ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
PackageManager pm = context.getPackageManager();
|
||||
public static boolean isHomeDefault(String pkg, PackageManagerWrapper pm) {
|
||||
final ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
ComponentName def = pm.getHomeActivities(homeActivities);
|
||||
|
||||
return def != null && def.getPackageName().equals(pkg);
|
||||
return def == null || def.getPackageName().equals(pkg);
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
@@ -84,4 +85,33 @@ public class DefaultHomePreferenceControllerTest {
|
||||
|
||||
verify(mPackageManager).getHomeActivities(anyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsHomeDefault_noDefaultSet_shouldReturnTrue() {
|
||||
when(mPackageManager.getHomeActivities(anyList())).thenReturn(null);
|
||||
assertThat(DefaultHomePreferenceController.isHomeDefault("test.pkg", mPackageManager))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsHomeDefault_defaultSetToPkg_shouldReturnTrue() {
|
||||
final String pkgName = "test.pkg";
|
||||
final ComponentName defaultHome = new ComponentName(pkgName, "class");
|
||||
|
||||
when(mPackageManager.getHomeActivities(anyList())).thenReturn(defaultHome);
|
||||
|
||||
assertThat(DefaultHomePreferenceController.isHomeDefault(pkgName, mPackageManager))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsHomeDefault_defaultSetToOtherPkg_shouldReturnFalse() {
|
||||
final String pkgName = "test.pkg";
|
||||
final ComponentName defaultHome = new ComponentName("not" + pkgName, "class");
|
||||
|
||||
when(mPackageManager.getHomeActivities(anyList())).thenReturn(defaultHome);
|
||||
|
||||
assertThat(DefaultHomePreferenceController.isHomeDefault(pkgName, mPackageManager))
|
||||
.isFalse();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user