am 0e1aaa0c: am d888b543: Revert "Update Location Settings for Enterprise" due to build breakage.

* commit '0e1aaa0cc8a95d014314220c2453c6606f13428b':
  Revert "Update Location Settings for Enterprise" due to build breakage.
This commit is contained in:
Amith Yamasani
2014-07-17 20:58:49 +00:00
committed by Android Git Automerger

View File

@@ -16,18 +16,15 @@
package com.android.settings.location; package com.android.settings.location;
import android.app.AppGlobals; import android.app.ActivityManager;
import android.app.AppOpsManager; import android.app.AppOpsManager;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.IPackageManager;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Process; import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager;
import android.preference.Preference; import android.preference.Preference;
import android.util.Log; import android.util.Log;
@@ -92,37 +89,33 @@ 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() { public List<Preference> getAppList() {
// Retrieve a location usage list from AppOps // Retrieve a location usage list from AppOps
AppOpsManager aoManager = AppOpsManager aoManager =
(AppOpsManager) mActivity.getSystemService(Context.APP_OPS_SERVICE); (AppOpsManager) mActivity.getSystemService(Context.APP_OPS_SERVICE);
List<AppOpsManager.PackageOps> appOps = aoManager.getPackagesForOps(new int[] { List<AppOpsManager.PackageOps> appOps = aoManager.getPackagesForOps(
AppOpsManager.OP_MONITOR_LOCATION, AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION, }); new int[] {
AppOpsManager.OP_MONITOR_LOCATION,
AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION,
});
// Process the AppOps list and generate a preference list. // Process the AppOps list and generate a preference list.
ArrayList<Preference> prefs = new ArrayList<Preference>(); ArrayList<Preference> prefs = new ArrayList<Preference>();
final long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
final UserManager um = (UserManager) mActivity.getSystemService(Context.USER_SERVICE); for (AppOpsManager.PackageOps ops : appOps) {
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. // 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 except managed users. // Also don't show apps belonging to background users.
String packageName = ops.getPackageName();
int uid = ops.getUid(); int uid = ops.getUid();
int userId = UserHandle.getUserId(uid); boolean isAndroidOs = (uid == Process.SYSTEM_UID)
boolean isAndroidOs = && ANDROID_SYSTEM_PACKAGE_NAME.equals(ops.getPackageName());
(uid == Process.SYSTEM_UID) && ANDROID_SYSTEM_PACKAGE_NAME.equals(packageName); if (!isAndroidOs && ActivityManager.getCurrentUser() == UserHandle.getUserId(uid)) {
if (isAndroidOs || !profiles.contains(UserHandle.fromUserId(userId))) { Preference pref = getPreferenceFromOps(now, ops);
continue; if (pref != null) {
} prefs.add(pref);
Preference preference = getPreferenceFromOps(um, now, ops); }
if (preference != null) {
prefs.add(preference);
} }
} }
@@ -137,8 +130,7 @@ public class RecentLocationApps {
* When the PackageOps is fresh enough, this method returns a Preference pointing to the App * When the PackageOps is fresh enough, this method returns a Preference pointing to the App
* Info page for that package. * Info page for that package.
*/ */
private Preference getPreferenceFromOps(final UserManager um, long now, private Preference getPreferenceFromOps(long now, AppOpsManager.PackageOps ops) {
AppOpsManager.PackageOps ops) {
String packageName = ops.getPackageName(); String packageName = ops.getPackageName();
List<AppOpsManager.OpEntry> entries = ops.getOps(); List<AppOpsManager.OpEntry> entries = ops.getOps();
boolean highBattery = false; boolean highBattery = false;
@@ -169,24 +161,30 @@ public class RecentLocationApps {
// The package is fresh enough, continue. // The package is fresh enough, continue.
int uid = ops.getUid(); Preference pref = null;
int userId = UserHandle.getUserId(uid);
Preference preference = null;
try { try {
IPackageManager ipm = AppGlobals.getPackageManager(); ApplicationInfo appInfo = mPackageManager.getApplicationInfo(
ApplicationInfo appInfo = packageName, PackageManager.GET_META_DATA);
ipm.getApplicationInfo(packageName, PackageManager.GET_META_DATA, userId); // Multiple users can install the same package. Each user gets a different Uid for
// the same package.
Drawable icon = um.getBadgedDrawableForUser( //
mPackageManager.getApplicationIcon(appInfo), UserHandle.fromUserId(userId)); // Here we retrieve the Uid with package name, that will be the Uid for that package
preference = createRecentLocationEntry(icon, // associated with the current active user. If the Uid differs from the Uid in ops,
mPackageManager.getApplicationLabel(appInfo), highBattery, // that means this entry belongs to another inactive user and we should ignore that.
new PackageEntryClickedListener(packageName)); if (appInfo.uid == ops.getUid()) {
} catch (RemoteException e) { pref = createRecentLocationEntry(
Log.w(TAG, "Error while retrieving application info", e); 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);
} }
return preference; return pref;
} }
} }