summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/vpn2/AppPreference.java
diff options
context:
space:
mode:
authorRobin Lee <rgl@google.com>2015-05-01 17:42:30 +0100
committerRobin Lee <rgl@google.com>2015-05-05 10:54:24 +0000
commitab6a65c03b2505ed2cce0226e11ef2d566699cf4 (patch)
tree78c73cce1cd945c843044b80c14df41339c389eb /src/com/android/settings/vpn2/AppPreference.java
parentf09497a2a702484a78b9462fc6d10eb3dc5c430d (diff)
downloadpackages_apps_Settings-ab6a65c03b2505ed2cce0226e11ef2d566699cf4.zip
packages_apps_Settings-ab6a65c03b2505ed2cce0226e11ef2d566699cf4.tar.gz
packages_apps_Settings-ab6a65c03b2505ed2cce0226e11ef2d566699cf4.tar.bz2
VPN: Convert current-context IPCs to user context
These fetch info for the wrong user, which may be either wrong or worse wholly nonexistent. Bug: 20747154 Change-Id: Ibd5f2e5d3c5dfd252a032ebdfe204de7166fa3a5
Diffstat (limited to 'src/com/android/settings/vpn2/AppPreference.java')
-rw-r--r--src/com/android/settings/vpn2/AppPreference.java49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/com/android/settings/vpn2/AppPreference.java b/src/com/android/settings/vpn2/AppPreference.java
index 1935dd8..599c45b 100644
--- a/src/com/android/settings/vpn2/AppPreference.java
+++ b/src/com/android/settings/vpn2/AppPreference.java
@@ -18,7 +18,6 @@ package com.android.settings.vpn2;
import android.app.AppGlobals;
import android.content.Context;
-import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
@@ -55,13 +54,17 @@ public class AppPreference extends ManageablePreference {
public PackageInfo getPackageInfo() {
UserHandle user = new UserHandle(UserHandle.getUserId(mUid));
try {
- IPackageManager ipm = AppGlobals.getPackageManager();
- return ipm.getPackageInfo(mPackageName, 0 /* flags */, user.getIdentifier());
- } catch (RemoteException rme) {
+ PackageManager pm = getUserContext().getPackageManager();
+ return pm.getPackageInfo(mPackageName, 0 /* flags */);
+ } catch (PackageManager.NameNotFoundException nnfe) {
return null;
}
}
+ public String getLabel() {
+ return mName;
+ }
+
public String getPackageName() {
return mPackageName;
}
@@ -85,24 +88,28 @@ public class AppPreference extends ManageablePreference {
mName = mPackageName;
Drawable icon = null;
+
try {
// Make all calls to the package manager as the appropriate user.
- int userId = UserHandle.getUserId(mUid);
- Context userContext = getContext().createPackageContextAsUser(
- getContext().getPackageName(), 0 /* flags */, new UserHandle(userId));
+ Context userContext = getUserContext();
PackageManager pm = userContext.getPackageManager();
-
- // Fetch icon and VPN label
- PackageInfo pkgInfo = pm.getPackageInfo(mPackageName, 0 /* flags */);
- if (pkgInfo != null) {
- icon = pkgInfo.applicationInfo.loadIcon(pm);
- mName = VpnConfig.getVpnLabel(userContext, mPackageName).toString();
+ // Fetch icon and VPN label- the nested catch block is for the case that the app doesn't
+ // exist, in which case we can fall back to the default activity icon for an activity in
+ // that user.
+ try {
+ PackageInfo pkgInfo = pm.getPackageInfo(mPackageName, 0 /* flags */);
+ if (pkgInfo != null) {
+ icon = pkgInfo.applicationInfo.loadIcon(pm);
+ mName = VpnConfig.getVpnLabel(userContext, mPackageName).toString();
+ }
+ } catch (PackageManager.NameNotFoundException pkgNotFound) {
+ // Use default app label and icon as fallback
}
- } catch (PackageManager.NameNotFoundException nnfe) {
- // Failed - use default app label and icon as fallback
- }
- if (icon == null) {
- icon = getContext().getPackageManager().getDefaultActivityIcon();
+ if (icon == null) {
+ icon = pm.getDefaultActivityIcon();
+ }
+ } catch (PackageManager.NameNotFoundException userNotFound) {
+ // No user, no useful information to obtain. Quietly fail.
}
setTitle(mName);
setIcon(icon);
@@ -110,6 +117,12 @@ public class AppPreference extends ManageablePreference {
notifyHierarchyChanged();
}
+ private Context getUserContext() throws PackageManager.NameNotFoundException {
+ UserHandle user = new UserHandle(UserHandle.getUserId(mUid));
+ return getContext().createPackageContextAsUser(
+ getContext().getPackageName(), 0 /* flags */, user);
+ }
+
public int compareTo(Preference preference) {
if (preference instanceof AppPreference) {
AppPreference another = (AppPreference) preference;