diff options
author | 2019-04-10 16:46:15 +0000 | |
---|---|---|
committer | 2019-04-10 16:46:15 +0000 | |
commit | f746b4b4850eeb45cb64910e72fe45e37534c944 (patch) | |
tree | 85a9a79b61cda61962cd99ce3636bc9c710b6b87 | |
parent | bef3d76b16d5b5a5e8ba2c6dc48fa55dcb8b55ea (diff) | |
parent | 0f27213d83b1c83ea84e8a0a85c83994c603513c (diff) |
Merge "Address UI change request for injected services" into qt-dev
-rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/location/SettingsInjector.java | 54 |
1 files changed, 10 insertions, 44 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/location/SettingsInjector.java b/packages/SettingsLib/src/com/android/settingslib/location/SettingsInjector.java index 74057be8434b..ff40d8e00603 100644 --- a/packages/SettingsLib/src/com/android/settingslib/location/SettingsInjector.java +++ b/packages/SettingsLib/src/com/android/settingslib/location/SettingsInjector.java @@ -20,14 +20,12 @@ import android.app.ActivityManager; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; -import android.content.pm.PackageItemInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; -import android.graphics.drawable.Drawable; import android.location.SettingInjectorService; import android.os.Bundle; import android.os.Handler; @@ -37,9 +35,9 @@ import android.os.Messenger; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserManager; +import android.util.ArrayMap; import android.util.ArraySet; import android.util.AttributeSet; -import android.util.IconDrawableFactory; import android.util.Log; import android.util.Xml; @@ -56,8 +54,8 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; import java.util.HashSet; -import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -157,22 +155,8 @@ public class SettingsInjector { * Adds the InjectedSetting information to a Preference object */ private void populatePreference(Preference preference, InjectedSetting setting) { - final PackageManager pm = mContext.getPackageManager(); - Drawable appIcon = null; - try { - final PackageItemInfo itemInfo = new PackageItemInfo(); - itemInfo.icon = setting.iconId; - itemInfo.packageName = setting.packageName; - final ApplicationInfo appInfo = pm.getApplicationInfo(setting.packageName, - PackageManager.GET_META_DATA); - appIcon = IconDrawableFactory.newInstance(mContext) - .getBadgedIcon(itemInfo, appInfo, setting.mUserHandle.getIdentifier()); - } catch (PackageManager.NameNotFoundException e) { - Log.e(TAG, "Can't get ApplicationInfo for " + setting.packageName, e); - } preference.setTitle(setting.title); preference.setSummary(R.string.loading_injected_setting_summary); - preference.setIcon(appIcon); preference.setOnPreferenceClickListener(new ServiceSettingClickedListener(setting)); } @@ -182,13 +166,15 @@ public class SettingsInjector { * @param profileId Identifier of the user/profile to obtain the injected settings for or * UserHandle.USER_CURRENT for all profiles associated with current user. */ - public List<Preference> getInjectedSettings(Context prefContext, final int profileId) { + public Map<Integer, List<Preference>> getInjectedSettings(Context prefContext, + final int profileId) { final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); final List<UserHandle> profiles = um.getUserProfiles(); - ArrayList<Preference> prefs = new ArrayList<>(); + final ArrayMap<Integer, List<Preference>> result = new ArrayMap<>(); mSettings.clear(); for (UserHandle userHandle : profiles) { if (profileId == UserHandle.USER_CURRENT || profileId == userHandle.getIdentifier()) { + final List<Preference> prefs = new ArrayList<>(); Iterable<InjectedSetting> settings = getSettings(userHandle); for (InjectedSetting setting : settings) { Preference preference = createPreference(prefContext, setting); @@ -196,12 +182,14 @@ public class SettingsInjector { prefs.add(preference); mSettings.add(new Setting(setting, preference)); } + if (!prefs.isEmpty()) { + result.put(userHandle.getIdentifier(), prefs); + } } } reloadStatusMessages(); - - return prefs; + return result; } /** @@ -303,28 +291,6 @@ public class SettingsInjector { } /** - * Checks wheteher there is any preference that other apps have injected. - * - * @param profileId Identifier of the user/profile to obtain the injected settings for or - * UserHandle.USER_CURRENT for all profiles associated with current user. - */ - public boolean hasInjectedSettings(final int profileId) { - final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); - final List<UserHandle> profiles = um.getUserProfiles(); - final int profileCount = profiles.size(); - for (int i = 0; i < profileCount; ++i) { - final UserHandle userHandle = profiles.get(i); - if (profileId == UserHandle.USER_CURRENT || profileId == userHandle.getIdentifier()) { - Iterable<InjectedSetting> settings = getSettings(userHandle); - for (InjectedSetting setting : settings) { - return true; - } - } - } - return false; - } - - /** * Reloads the status messages for all the preference items. */ public void reloadStatusMessages() { |