OSDN Git Service

Fix issue 7198767, 7198366, 7189824.
authorDianne Hackborn <hackbod@google.com>
Fri, 21 Sep 2012 23:40:21 +0000 (16:40 -0700)
committerDianne Hackborn <hackbod@google.com>
Sat, 22 Sep 2012 00:02:22 +0000 (17:02 -0700)
Bug #7198767: Crash on choosing App info from the Recent apps tab
Bug #7198366: Settings UI should not show other Users' apps
Bug #7189824: Settings crashes on trying to access Battery usage summary

Also fix running services to be able to show user bitmap when in
secondary users, crash in running services if a service is running
whose app is not installed for the current user.

Change-Id: Ief24810c9ddce1ec3f8641ce08af79e1bc18f221

res/values/strings.xml
src/com/android/settings/applications/ApplicationsState.java
src/com/android/settings/applications/InstalledAppDetails.java
src/com/android/settings/applications/RunningState.java
src/com/android/settings/fuelgauge/PowerUsageDetail.java
src/com/android/settings/fuelgauge/PowerUsageSummary.java

index 97c0726..a2c7e22 100644 (file)
     <string name="service_process_name"><xliff:g id="process">%1$s</xliff:g></string>
     <!-- [CHAR LIMIT=NONE] Label of a running process that represents another user -->
     <string name="running_process_item_user_label">User: <xliff:g id="user_name">%1$s</xliff:g></string>
+    <!-- [CHAR LIMIT=NONE] Label of a running process that represents a removed -->
+    <string name="running_process_item_removed_user_label">Removed user</string>
     <!-- Descriptive text of a running process: singular process, singular service. -->
     <string name="running_processes_item_description_s_s"><xliff:g id="numprocess">%1$d</xliff:g>
         process and <xliff:g id="numservices">%2$d</xliff:g> service</string>
index 2ce6779..e87d7cf 100644 (file)
@@ -18,6 +18,7 @@ import android.os.Looper;
 import android.os.Message;
 import android.os.Process;
 import android.os.SystemClock;
+import android.os.UserHandle;
 import android.text.format.Formatter;
 import android.util.Log;
 
@@ -238,6 +239,7 @@ public class ApplicationsState {
 
     final Context mContext;
     final PackageManager mPm;
+    final int mRetrieveFlags;
     PackageIntentReceiver mPackageIntentReceiver;
 
     boolean mResumed;
@@ -401,7 +403,15 @@ public class ApplicationsState {
                 Process.THREAD_PRIORITY_BACKGROUND);
         mThread.start();
         mBackgroundHandler = new BackgroundHandler(mThread.getLooper());
-        
+
+        // Only the owner can see all apps.
+        if (UserHandle.myUserId() == 0) {
+            mRetrieveFlags = PackageManager.GET_UNINSTALLED_PACKAGES |
+                    PackageManager.GET_DISABLED_COMPONENTS;
+        } else {
+            mRetrieveFlags = PackageManager.GET_DISABLED_COMPONENTS;
+        }
+
         /**
          * This is a trick to prevent the foreground thread from being delayed.
          * The problem is that Dalvik monitors are initially spin locks, to keep
@@ -591,9 +601,7 @@ public class ApplicationsState {
             mPackageIntentReceiver = new PackageIntentReceiver();
             mPackageIntentReceiver.registerReceiver();
         }
-        mApplications = mPm.getInstalledApplications(
-                PackageManager.GET_UNINSTALLED_PACKAGES |
-                PackageManager.GET_DISABLED_COMPONENTS);
+        mApplications = mPm.getInstalledApplications(mRetrieveFlags);
         if (mApplications == null) {
             mApplications = new ArrayList<ApplicationInfo>();
         }
@@ -723,9 +731,7 @@ public class ApplicationsState {
                     if (DEBUG_LOCKING) Log.v(TAG, "addPackage release lock: already exists");
                     return;
                 }
-                ApplicationInfo info = mPm.getApplicationInfo(pkgName,
-                        PackageManager.GET_UNINSTALLED_PACKAGES |
-                        PackageManager.GET_DISABLED_COMPONENTS);
+                ApplicationInfo info = mPm.getApplicationInfo(pkgName, mRetrieveFlags);
                 mApplications.add(info);
                 if (!mBackgroundHandler.hasMessages(BackgroundHandler.MSG_LOAD_ENTRIES)) {
                     mBackgroundHandler.sendEmptyMessage(BackgroundHandler.MSG_LOAD_ENTRIES);
index 97d7b75..7588c1a 100644 (file)
@@ -340,7 +340,8 @@ public class InstalledAppDetails extends Fragment
                 }
             } else if ((mPackageInfo.applicationInfo.flags
                     & ApplicationInfo.FLAG_INSTALLED) == 0) {
-                mUninstallButton.setText(R.string.install_text);
+                mUninstallButton.setText(R.string.uninstall_text);
+                enabled = false;
             } else {
                 mUninstallButton.setText(R.string.uninstall_text);
             }
@@ -392,6 +393,9 @@ public class InstalledAppDetails extends Fragment
 
         mCanBeOnSdCardChecker = new CanBeOnSdCardChecker();
 
+        // Need to make sure we have loaded applications at this point.
+        mSession.resume();
+
         retrieveAppEntry();
 
         setHasOptionsMenu(true);
@@ -1134,6 +1138,7 @@ public class InstalledAppDetails extends Fragment
                     Uri.fromParts("package", mAppEntry.info.packageName, null));
             intent.putExtra(Intent.EXTRA_PACKAGES, new String[] { mAppEntry.info.packageName });
             intent.putExtra(Intent.EXTRA_UID, mAppEntry.info.uid);
+            intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(mAppEntry.info.uid));
             getActivity().sendOrderedBroadcast(intent, null, mCheckKillProcessesReceiver, null,
                     Activity.RESULT_CANCELED, null, null);
         }
index 838e4fe..e4d34f7 100644 (file)
@@ -17,6 +17,7 @@
 package com.android.settings.applications;
 
 import com.android.settings.R;
+import com.android.settings.users.UserUtils;
 
 import android.app.ActivityManager;
 import android.app.ActivityManagerNative;
@@ -377,7 +378,8 @@ public class RunningState {
             }
             
             try {
-                ApplicationInfo ai = pm.getApplicationInfo(mProcessName, 0);
+                ApplicationInfo ai = pm.getApplicationInfo(mProcessName,
+                        PackageManager.GET_UNINSTALLED_PACKAGES);
                 if (ai.uid == mUid) {
                     mDisplayLabel = ai.loadLabel(pm);
                     mLabel = mDisplayLabel.toString();
@@ -394,7 +396,8 @@ public class RunningState {
             // If there is one package with this uid, that is what we want.
             if (pkgs.length == 1) {
                 try {
-                    ApplicationInfo ai = pm.getApplicationInfo(pkgs[0], 0);
+                    ApplicationInfo ai = pm.getApplicationInfo(pkgs[0],
+                            PackageManager.GET_UNINSTALLED_PACKAGES);
                     mDisplayLabel = ai.loadLabel(pm);
                     mLabel = mDisplayLabel.toString();
                     mPackageInfo = ai;
@@ -435,7 +438,8 @@ public class RunningState {
             
             // Finally... whatever, just pick the first package's name.
             try {
-                ApplicationInfo ai = pm.getApplicationInfo(pkgs[0], 0);
+                ApplicationInfo ai = pm.getApplicationInfo(pkgs[0],
+                        PackageManager.GET_UNINSTALLED_PACKAGES);
                 mDisplayLabel = ai.loadLabel(pm);
                 mLabel = mDisplayLabel.toString();
                 mPackageInfo = ai;
@@ -455,7 +459,8 @@ public class RunningState {
                 si = new ServiceItem(mUserId);
                 si.mRunningService = service;
                 try {
-                    si.mServiceInfo = pm.getServiceInfo(service.service, 0);
+                    si.mServiceInfo = pm.getServiceInfo(service.service,
+                            PackageManager.GET_UNINSTALLED_PACKAGES);
                 } catch (PackageManager.NameNotFoundException e) {
                 }
                 si.mDisplayLabel = makeLabel(pm,
@@ -818,12 +823,9 @@ public class RunningState {
                 userItem.mUser = new UserState();
                 UserInfo info = mUm.getUserInfo(newItem.mUserId);
                 userItem.mUser.mInfo = info;
-                if (info != null && info.iconPath != null) {
-                    try {
-                        userItem.mUser.mIcon = Drawable.createFromPath(info.iconPath);
-                    } catch (Exception e) {
-                        Log.w(TAG, "Failure loading user picture " + info.iconPath, e);
-                    }
+                if (info != null) {
+                    userItem.mUser.mIcon = UserUtils.getUserIcon(mUm, info,
+                            context.getResources());
                 }
                 String name = info != null ? info.name : null;
                 if (name == null) {
index bb96ca9..0cc58be 100644 (file)
@@ -34,6 +34,7 @@ import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Process;
+import android.os.UserHandle;
 import android.preference.PreferenceActivity;
 import android.provider.Settings;
 import android.text.TextUtils;
@@ -455,6 +456,7 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener
                 Uri.fromParts("package", mPackages[0], null));
         intent.putExtra(Intent.EXTRA_PACKAGES, mPackages);
         intent.putExtra(Intent.EXTRA_UID, mUid);
+        intent.putExtra(Intent.EXTRA_USER_HANDLE, mUid);
         getActivity().sendOrderedBroadcast(intent, null, mCheckKillProcessesReceiver, null,
                 Activity.RESULT_CANCELED, null, null);
     }
index 5704163..4a79d9d 100644 (file)
@@ -767,15 +767,23 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
             final int userId = mUserSippers.keyAt(i);
             final List<BatterySipper> sippers = mUserSippers.valueAt(i);
             UserInfo info = mUm.getUserInfo(userId);
-            Drawable icon = UserUtils.getUserIcon(mUm, info, getResources());
-            String name = info != null ? info.name : null;
-            if (name == null) {
-                name = Integer.toString(info.id);
+            Drawable icon;
+            String name;
+            if (info != null) {
+                icon = UserUtils.getUserIcon(mUm, info, getResources());
+                name = info != null ? info.name : null;
+                if (name == null) {
+                    name = Integer.toString(info.id);
+                }
+                name = getActivity().getResources().getString(
+                        R.string.running_process_item_user_label, name);
+            } else {
+                icon = null;
+                name = getActivity().getResources().getString(
+                        R.string.running_process_item_removed_user_label);
             }
             double power = mUserPower.get(userId);
-            String label = getActivity().getResources().getString(
-                    R.string.running_process_item_user_label, name);
-            BatterySipper bs = addEntry(label, DrainType.USER, 0, 0, power);
+            BatterySipper bs = addEntry(name, DrainType.USER, 0, 0, power);
             bs.icon = icon;
             aggregateSippers(bs, sippers, "User");
         }