diff options
author | Zoltan Szatmary-Ban <szatmz@google.com> | 2014-06-16 13:08:24 +0100 |
---|---|---|
committer | Zoltan Szatmary-Ban <szatmz@google.com> | 2014-07-17 21:11:48 +0100 |
commit | 925560e9a2437e3cb6139a4421a6a5cd4b355fc5 (patch) | |
tree | b8cb371d31c6e2975c259bd945105689f2850227 /src/com/android | |
parent | 5427b9a7990d408df1f2231ec649501f848f7d3d (diff) | |
download | packages_apps_Settings-925560e9a2437e3cb6139a4421a6a5cd4b355fc5.tar.gz packages_apps_Settings-925560e9a2437e3cb6139a4421a6a5cd4b355fc5.tar.bz2 packages_apps_Settings-925560e9a2437e3cb6139a4421a6a5cd4b355fc5.zip |
Update Location Settings for Enterprise
Find packages of the corporate user and show them
with badged icon on the "Recent location requests" list.
Bug: 15467321
Change-Id: Ic52ed3d01a0816288d4818190e82befa5235f28b
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/settings/location/RecentLocationApps.java | 84 |
1 files changed, 43 insertions, 41 deletions
diff --git a/src/com/android/settings/location/RecentLocationApps.java b/src/com/android/settings/location/RecentLocationApps.java index 164f4e71e..8e1ec0520 100644 --- a/src/com/android/settings/location/RecentLocationApps.java +++ b/src/com/android/settings/location/RecentLocationApps.java @@ -16,15 +16,18 @@ package com.android.settings.location; -import android.app.ActivityManager; +import android.app.AppGlobals; import android.app.AppOpsManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.content.pm.IPackageManager; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Process; +import android.os.RemoteException; import android.os.UserHandle; +import android.os.UserManager; import android.preference.Preference; import android.util.Log; @@ -89,33 +92,37 @@ public class RecentLocationApps { } /** - * Fills a list of applications which queried location recently within - * specified time. + * Fills a list of applications which queried location recently within specified time. */ public List<Preference> getAppList() { // Retrieve a location usage list from AppOps AppOpsManager aoManager = (AppOpsManager) mActivity.getSystemService(Context.APP_OPS_SERVICE); - List<AppOpsManager.PackageOps> appOps = aoManager.getPackagesForOps( - new int[] { - AppOpsManager.OP_MONITOR_LOCATION, - AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION, - }); + List<AppOpsManager.PackageOps> appOps = aoManager.getPackagesForOps(new int[] { + AppOpsManager.OP_MONITOR_LOCATION, AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION, }); // Process the AppOps list and generate a preference list. ArrayList<Preference> prefs = new ArrayList<Preference>(); - long now = System.currentTimeMillis(); - for (AppOpsManager.PackageOps ops : appOps) { + final long now = System.currentTimeMillis(); + final UserManager um = (UserManager) mActivity.getSystemService(Context.USER_SERVICE); + final List<UserHandle> profiles = um.getUserProfiles(); + + final int appOpsN = appOps.size(); + for (int i = 0; i < appOpsN; ++i) { + AppOpsManager.PackageOps ops = appOps.get(i); // Don't show the Android System in the list - it's not actionable for the user. - // Also don't show apps belonging to background users. + // Also don't show apps belonging to background users except managed users. + String packageName = ops.getPackageName(); int uid = ops.getUid(); - boolean isAndroidOs = (uid == Process.SYSTEM_UID) - && ANDROID_SYSTEM_PACKAGE_NAME.equals(ops.getPackageName()); - if (!isAndroidOs && ActivityManager.getCurrentUser() == UserHandle.getUserId(uid)) { - Preference pref = getPreferenceFromOps(now, ops); - if (pref != null) { - prefs.add(pref); - } + int userId = UserHandle.getUserId(uid); + boolean isAndroidOs = + (uid == Process.SYSTEM_UID) && ANDROID_SYSTEM_PACKAGE_NAME.equals(packageName); + if (isAndroidOs || !profiles.contains(new UserHandle(userId))) { + continue; + } + Preference preference = getPreferenceFromOps(um, now, ops); + if (preference != null) { + prefs.add(preference); } } @@ -130,7 +137,8 @@ public class RecentLocationApps { * When the PackageOps is fresh enough, this method returns a Preference pointing to the App * Info page for that package. */ - private Preference getPreferenceFromOps(long now, AppOpsManager.PackageOps ops) { + private Preference getPreferenceFromOps(final UserManager um, long now, + AppOpsManager.PackageOps ops) { String packageName = ops.getPackageName(); List<AppOpsManager.OpEntry> entries = ops.getOps(); boolean highBattery = false; @@ -161,30 +169,24 @@ public class RecentLocationApps { // The package is fresh enough, continue. - Preference pref = null; + int uid = ops.getUid(); + int userId = UserHandle.getUserId(uid); + + Preference preference = null; try { - ApplicationInfo appInfo = mPackageManager.getApplicationInfo( - packageName, PackageManager.GET_META_DATA); - // Multiple users can install the same package. Each user gets a different Uid for - // the same package. - // - // Here we retrieve the Uid with package name, that will be the Uid for that package - // associated with the current active user. If the Uid differs from the Uid in ops, - // that means this entry belongs to another inactive user and we should ignore that. - if (appInfo.uid == ops.getUid()) { - pref = createRecentLocationEntry( - mPackageManager.getApplicationIcon(appInfo), - mPackageManager.getApplicationLabel(appInfo), - highBattery, - new PackageEntryClickedListener(packageName)); - } else if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.v(TAG, "package " + packageName + " with Uid " + ops.getUid() + - " belongs to another inactive account, ignored."); - } - } catch (PackageManager.NameNotFoundException e) { - Log.wtf(TAG, "Package not found: " + packageName, e); + IPackageManager ipm = AppGlobals.getPackageManager(); + ApplicationInfo appInfo = + ipm.getApplicationInfo(packageName, PackageManager.GET_META_DATA, userId); + + Drawable icon = um.getBadgedDrawableForUser( + mPackageManager.getApplicationIcon(appInfo), new UserHandle(userId)); + preference = createRecentLocationEntry(icon, + mPackageManager.getApplicationLabel(appInfo), highBattery, + new PackageEntryClickedListener(packageName)); + } catch (RemoteException e) { + Log.w(TAG, "Error while retrieving application info", e); } - return pref; + return preference; } } |