summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings
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
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')
-rw-r--r--src/com/android/settings/vpn2/AppDialog.java16
-rw-r--r--src/com/android/settings/vpn2/AppDialogFragment.java17
-rw-r--r--src/com/android/settings/vpn2/AppPreference.java49
-rw-r--r--src/com/android/settings/vpn2/VpnSettings.java7
4 files changed, 47 insertions, 42 deletions
diff --git a/src/com/android/settings/vpn2/AppDialog.java b/src/com/android/settings/vpn2/AppDialog.java
index 2145297..cd6a16c 100644
--- a/src/com/android/settings/vpn2/AppDialog.java
+++ b/src/com/android/settings/vpn2/AppDialog.java
@@ -40,15 +40,18 @@ import com.android.settings.R;
* {@see ConfigDialog}
*/
class AppDialog extends AlertDialog implements DialogInterface.OnClickListener {
- private final PackageInfo mPkgInfo;
private final Listener mListener;
+ private final PackageInfo mPkgInfo;
+ private final String mLabel;
private final boolean mConnected;
- AppDialog(Context context, Listener listener, PackageInfo pkgInfo, boolean connected) {
+ AppDialog(Context context, Listener listener, PackageInfo pkgInfo, String label,
+ boolean connected) {
super(context);
mListener = listener;
mPkgInfo = pkgInfo;
+ mLabel = label;
mConnected = connected;
}
@@ -58,14 +61,7 @@ class AppDialog extends AlertDialog implements DialogInterface.OnClickListener {
@Override
protected void onCreate(Bundle savedState) {
- CharSequence vpnName;
- try {
- vpnName = VpnConfig.getVpnLabel(getContext(), mPkgInfo.packageName);
- } catch (PackageManager.NameNotFoundException ex) {
- vpnName = mPkgInfo.packageName;
- }
-
- setTitle(vpnName);
+ setTitle(mLabel);
setMessage(getContext().getString(R.string.vpn_version, mPkgInfo.versionName));
createButtons();
diff --git a/src/com/android/settings/vpn2/AppDialogFragment.java b/src/com/android/settings/vpn2/AppDialogFragment.java
index fc8d9e3..6ac4fb5 100644
--- a/src/com/android/settings/vpn2/AppDialogFragment.java
+++ b/src/com/android/settings/vpn2/AppDialogFragment.java
@@ -40,18 +40,20 @@ public class AppDialogFragment extends DialogFragment implements AppDialog.Liste
private static final String TAG = "AppDialogFragment";
private static final String ARG_MANAGING = "managing";
+ private static final String ARG_LABEL = "label";
private static final String ARG_PACKAGE = "package";
private static final String ARG_CONNECTED = "connected";
private final IConnectivityManager mService = IConnectivityManager.Stub.asInterface(
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
- public static void show(VpnSettings parent, PackageInfo pkgInfo, boolean managing,
+ public static void show(VpnSettings parent, PackageInfo pkgInfo, String label, boolean managing,
boolean connected) {
if (!parent.isAdded()) return;
Bundle args = new Bundle();
args.putParcelable(ARG_PACKAGE, pkgInfo);
+ args.putString(ARG_LABEL, label);
args.putBoolean(ARG_MANAGING, managing);
args.putBoolean(ARG_CONNECTED, connected);
@@ -65,23 +67,16 @@ public class AppDialogFragment extends DialogFragment implements AppDialog.Liste
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle args = getArguments();
PackageInfo pkgInfo = (PackageInfo) args.getParcelable(ARG_PACKAGE);
+ String label = args.getString(ARG_LABEL);
boolean managing = args.getBoolean(ARG_MANAGING);
boolean connected = args.getBoolean(ARG_CONNECTED);
if (managing) {
- return new AppDialog(getActivity(), this, pkgInfo, connected);
+ return new AppDialog(getActivity(), this, pkgInfo, label, connected);
} else {
// Build an AlertDialog with an option to disconnect.
-
- CharSequence vpnName;
- try {
- vpnName = VpnConfig.getVpnLabel(getActivity(), pkgInfo.packageName);
- } catch (PackageManager.NameNotFoundException ex) {
- vpnName = pkgInfo.packageName;
- }
-
AlertDialog.Builder dlog = new AlertDialog.Builder(getActivity())
- .setTitle(vpnName)
+ .setTitle(label)
.setMessage(getActivity().getString(R.string.vpn_disconnect_confirm))
.setNegativeButton(getActivity().getString(R.string.vpn_cancel), null);
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;
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index a333de9..e60a262 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -251,7 +251,7 @@ public class VpnSettings extends SettingsPreferenceFragment implements
// Already onnected or no launch intent available - show an info dialog
PackageInfo pkgInfo = pref.getPackageInfo();
- AppDialogFragment.show(this, pkgInfo, false /* editing */, connected);
+ AppDialogFragment.show(this, pkgInfo, pref.getLabel(), false /* editing */, connected);
return true;
}
return false;
@@ -268,8 +268,9 @@ public class VpnSettings extends SettingsPreferenceFragment implements
true /* exists */);
} else if (tag instanceof AppPreference) {
AppPreference pref = (AppPreference) tag;
- AppDialogFragment.show(VpnSettings.this, pref.getPackageInfo(), true /* editing */,
- (pref.getState() == AppPreference.STATE_CONNECTED) /* connected */);
+ boolean connected = (pref.getState() == AppPreference.STATE_CONNECTED);
+ AppDialogFragment.show(VpnSettings.this, pref.getPackageInfo(), pref.getLabel(),
+ true /* editing */, connected);
}
}
};