Address UI change request for injected services

- Remove icons from injected items
- Create a separate section for work profile

Bug: 129948280
Test: build, flash, and test manually
Change-Id: Ia64af349c8dd1575d629debd574cdb3ae6eb650d
This commit is contained in:
Lifu Tang
2019-04-05 13:47:21 -07:00
parent f1cea95f3e
commit e531bd01fd
4 changed files with 60 additions and 42 deletions

View File

@@ -34,6 +34,7 @@ import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
import java.util.List;
import java.util.Map;
public class LocationServicePreferenceController extends LocationBasePreferenceController
implements LifecycleObserver, OnResume, OnPause {
@@ -41,14 +42,17 @@ public class LocationServicePreferenceController extends LocationBasePreferenceC
private static final String TAG = "LocationServicePrefCtrl";
/** Key for preference category "Location services" */
private static final String KEY_LOCATION_SERVICES = "location_services";
/** Key for preference category "Location services for work" */
private static final String KEY_LOCATION_SERVICES_MANAGED = "location_services_managed_profile";
@VisibleForTesting
static final IntentFilter INTENT_FILTER_INJECTED_SETTING_CHANGED =
new IntentFilter(SettingInjectorService.ACTION_INJECTED_SETTING_CHANGED);
private PreferenceCategory mCategoryLocationServices;
private PreferenceCategory mCategoryLocationServicesManaged;
private final LocationSettings mFragment;
private final AppSettingsInjector mInjector;
/** Receives UPDATE_INTENT */
/** Receives UPDATE_INTENT */
@VisibleForTesting
BroadcastReceiver mInjectedSettingsReceiver;
@@ -73,30 +77,37 @@ public class LocationServicePreferenceController extends LocationBasePreferenceC
return KEY_LOCATION_SERVICES;
}
@Override
public boolean isAvailable() {
// If managed profile has lock-down on location access then its injected location services
// must not be shown.
return mInjector.hasInjectedSettings(mLocationEnabler.isManagedProfileRestrictedByBase()
? UserHandle.myUserId() : UserHandle.USER_CURRENT);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mCategoryLocationServices = screen.findPreference(KEY_LOCATION_SERVICES);
mCategoryLocationServicesManaged = screen.findPreference(KEY_LOCATION_SERVICES_MANAGED);
}
@Override
public void updateState(Preference preference) {
mCategoryLocationServices.removeAll();
final List<Preference> prefs = getLocationServices();
for (Preference pref : prefs) {
if (pref instanceof RestrictedAppPreference) {
((RestrictedAppPreference) pref).checkRestrictionAndSetDisabled();
mCategoryLocationServicesManaged.removeAll();
final Map<Integer, List<Preference>> prefs = getLocationServices();
boolean showPrimary = false;
boolean showManaged = false;
for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) {
for (Preference pref : entry.getValue()) {
if (pref instanceof RestrictedAppPreference) {
((RestrictedAppPreference) pref).checkRestrictionAndSetDisabled();
}
}
if (entry.getKey() == UserHandle.myUserId()) {
LocationSettings.addPreferencesSorted(entry.getValue(), mCategoryLocationServices);
showPrimary = true;
} else {
LocationSettings.addPreferencesSorted(entry.getValue(),
mCategoryLocationServicesManaged);
showManaged = true;
}
}
LocationSettings.addPreferencesSorted(prefs, mCategoryLocationServices);
mCategoryLocationServices.setVisible(showPrimary);
mCategoryLocationServicesManaged.setVisible(showManaged);
}
@Override
@@ -128,7 +139,7 @@ public class LocationServicePreferenceController extends LocationBasePreferenceC
mContext.unregisterReceiver(mInjectedSettingsReceiver);
}
private List<Preference> getLocationServices() {
private Map<Integer, List<Preference>> getLocationServices() {
// If location access is locked down by device policy then we only show injected settings
// for the primary profile.
final int profileUserId = Utils.getManagedProfileId(mUserManager, UserHandle.myUserId());