Home default setting should not shown in managed profile settings

Each default preference needs to have its corresponding
PreferenceAvailabilityProvider to provide us the availability of it.
If no corresponding provider is found, it is considered to be not
available. So it encourages other developers who will add new default app
preference later to consider the availability of it.

Bug:27143673
Change-Id: I073b7122dddc579504f397c5de2bdd4df3826269
This commit is contained in:
Tony Mak
2016-02-17 17:08:02 +00:00
parent 6b00d3fe40
commit 0e19d2420b
9 changed files with 171 additions and 68 deletions

View File

@@ -32,6 +32,7 @@ import android.util.ArraySet;
import android.util.AttributeSet;
import com.android.settings.AppListPreference;
import com.android.settings.PreferenceAvailabilityProvider;
import com.android.settings.Utils;
import java.util.List;
@@ -51,10 +52,7 @@ public class DefaultEmergencyPreference extends AppListPreference {
public DefaultEmergencyPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mContentResolver = context.getContentResolver();
if (isAvailable(context)) {
load();
}
load();
}
@Override
@@ -135,13 +133,7 @@ public class DefaultEmergencyPreference extends AppListPreference {
return packages;
}
public static boolean isAvailable(Context context) {
return isCapable(context)
&& context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null
&& !Utils.isManagedProfile(UserManager.get(context)) ;
}
public static boolean isCapable(Context context) {
private static boolean isCapable(Context context) {
return TelephonyManager.EMERGENCY_ASSISTANCE_ENABLED
&& context.getResources().getBoolean(
com.android.internal.R.bool.config_voice_capable);
@@ -151,4 +143,13 @@ public class DefaultEmergencyPreference extends AppListPreference {
return info.applicationInfo != null
&& (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
}
public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
@Override
public boolean isAvailable(Context context) {
return isCapable(context)
&& context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null
&& !Utils.isManagedProfile(UserManager.get(context));
}
}
}