summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Lee <rgl@google.com>2015-06-09 23:13:35 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-09 23:13:38 +0000
commit63cc6458ace9da6a064f254323fe493618a6c518 (patch)
tree3b4566ce5a021fd85b91962aff6c931589f6bf57
parent2bad67b16fbfbfa56081bfbd6a43c0b1793ce8a3 (diff)
parent472834518e2d23172189ee34e98c51f868628a90 (diff)
downloadframeworks_base-63cc6458ace9da6a064f254323fe493618a6c518.zip
frameworks_base-63cc6458ace9da6a064f254323fe493618a6c518.tar.gz
frameworks_base-63cc6458ace9da6a064f254323fe493618a6c518.tar.bz2
Merge "Switch over to updated VPN warning strings" into mnc-dev
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QSFooter.java67
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java83
-rw-r--r--packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java10
-rw-r--r--services/core/java/com/android/server/ConnectivityService.java19
5 files changed, 133 insertions, 48 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java
index f59e864..ca38528 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java
@@ -110,15 +110,13 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
}
private void handleRefreshState() {
- boolean hasDeviceOwner = mSecurityController.hasDeviceOwner();
- boolean hasVpn = mSecurityController.isVpnEnabled();
-
- mIsVisible = (hasVpn || hasDeviceOwner);
- mIsIconVisible = hasVpn;
- if (hasDeviceOwner) {
+ mIsIconVisible = mSecurityController.isVpnEnabled();
+ if (mSecurityController.hasDeviceOwner()) {
mFooterTextId = R.string.device_owned_footer;
+ mIsVisible = true;
} else {
mFooterTextId = R.string.vpn_footer;
+ mIsVisible = mIsIconVisible;
}
mMainHandler.post(mUpdateDisplayState);
}
@@ -132,15 +130,17 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
}
private void createDialog() {
- boolean hasDeviceOwner = mSecurityController.hasDeviceOwner();
- boolean hasProfile = mSecurityController.hasProfileOwner();
- boolean hasVpn = mSecurityController.isVpnEnabled();
+ String deviceOwner = mSecurityController.getDeviceOwnerName();
+ String profileOwner = mSecurityController.getProfileOwnerName();
+ String primaryVpn = mSecurityController.getPrimaryVpnName();
+ String profileVpn = mSecurityController.getProfileVpnName();
+ boolean managed = mSecurityController.hasProfileOwner();
mDialog = new SystemUIDialog(mContext);
- mDialog.setTitle(getTitle(hasDeviceOwner, hasProfile));
- mDialog.setMessage(getMessage(hasDeviceOwner, hasProfile, hasVpn));
+ mDialog.setTitle(getTitle(deviceOwner));
+ mDialog.setMessage(getMessage(deviceOwner, profileOwner, primaryVpn, profileVpn, managed));
mDialog.setButton(DialogInterface.BUTTON_POSITIVE, getPositiveButton(), this);
- if (hasVpn) {
+ if (mSecurityController.isVpnEnabled()) {
mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getNegativeButton(), this);
}
mDialog.show();
@@ -154,31 +154,42 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
return mContext.getString(R.string.quick_settings_done);
}
- private String getMessage(boolean hasDeviceOwner, boolean hasProfile, boolean hasVpn) {
- if (hasDeviceOwner) {
- if (hasVpn) {
- return mContext.getString(R.string.monitoring_description_vpn_device_owned,
- mSecurityController.getDeviceOwnerName());
+ private String getMessage(String deviceOwner, String profileOwner, String primaryVpn,
+ String profileVpn, boolean primaryUserIsManaged) {
+ if (deviceOwner != null) {
+ if (primaryVpn != null) {
+ return mContext.getString(R.string.monitoring_description_vpn_app_device_owned,
+ deviceOwner, primaryVpn);
} else {
return mContext.getString(R.string.monitoring_description_device_owned,
- mSecurityController.getDeviceOwnerName());
+ deviceOwner);
+ }
+ } else if (primaryVpn != null) {
+ if (profileVpn != null) {
+ return mContext.getString(R.string.monitoring_description_app_personal_work,
+ profileOwner, profileVpn, primaryVpn);
+ } else {
+ return mContext.getString(R.string.monitoring_description_app_personal,
+ primaryVpn);
}
- } else if (hasProfile) {
- return mContext.getString(
- R.string.monitoring_description_vpn_profile_owned,
- mSecurityController.getProfileOwnerName());
+ } else if (profileVpn != null) {
+ return mContext.getString(R.string.monitoring_description_app_work,
+ profileOwner, profileVpn);
+ } else if (profileOwner != null && primaryUserIsManaged) {
+ return mContext.getString(R.string.monitoring_description_device_owned,
+ profileOwner);
} else {
- return mContext.getString(R.string.monitoring_description_vpn);
+ // No device owner, no personal VPN, no work VPN, no user owner. Why are we here?
+ return null;
}
}
- private int getTitle(boolean hasDeviceOwner, boolean hasProfile) {
- if (hasDeviceOwner) {
+ private int getTitle(String deviceOwner) {
+ if (deviceOwner != null) {
return R.string.monitoring_title_device_owned;
- } else if (hasProfile) {
- return R.string.monitoring_title_profile_owned;
+ } else {
+ return R.string.monitoring_title;
}
- return R.string.monitoring_title;
}
private final Runnable mUpdateDisplayState = new Runnable() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java
index e1e022d..40984d4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java
@@ -22,6 +22,8 @@ public interface SecurityController {
String getDeviceOwnerName();
String getProfileOwnerName();
boolean isVpnEnabled();
+ String getPrimaryVpnName();
+ String getProfileVpnName();
void onUserSwitched(int newUserId);
void addCallback(SecurityControllerCallback callback);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java
index 4f47cc6..962000a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java
@@ -36,6 +36,7 @@ import android.util.SparseArray;
import com.android.internal.net.VpnConfig;
import com.android.internal.net.VpnInfo;
+import com.android.systemui.R;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -61,7 +62,7 @@ public class SecurityControllerImpl implements SecurityController {
private final ArrayList<SecurityControllerCallback> mCallbacks
= new ArrayList<SecurityControllerCallback>();
- private SparseArray<Boolean> mCurrentVpnUsers = new SparseArray<>();
+ private SparseArray<VpnConfig> mCurrentVpns = new SparseArray<>();
private int mCurrentUserId;
public SecurityControllerImpl(Context context) {
@@ -82,7 +83,16 @@ public class SecurityControllerImpl implements SecurityController {
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("SecurityController state:");
- pw.print(" mCurrentVpnUsers=" + mCurrentVpnUsers);
+ pw.print(" mCurrentVpns={");
+ for (int i = 0 ; i < mCurrentVpns.size(); i++) {
+ if (i > 0) {
+ pw.print(", ");
+ }
+ pw.print(mCurrentVpns.keyAt(i));
+ pw.print('=');
+ pw.print(mCurrentVpns.valueAt(i).user);
+ }
+ pw.println("}");
}
@Override
@@ -97,11 +107,7 @@ public class SecurityControllerImpl implements SecurityController {
@Override
public boolean hasProfileOwner() {
- boolean result = false;
- for (UserInfo profile : mUserManager.getProfiles(mCurrentUserId)) {
- result |= (mDevicePolicyManager.getProfileOwnerAsUser(profile.id) != null);
- }
- return result;
+ return mDevicePolicyManager.getProfileOwnerAsUser(mCurrentUserId) != null;
}
@Override
@@ -116,8 +122,37 @@ public class SecurityControllerImpl implements SecurityController {
}
@Override
+ public String getPrimaryVpnName() {
+ VpnConfig cfg = mCurrentVpns.get(mCurrentUserId);
+ if (cfg != null) {
+ return getNameForVpnConfig(cfg, new UserHandle(mCurrentUserId));
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String getProfileVpnName() {
+ for (UserInfo profile : mUserManager.getProfiles(mCurrentUserId)) {
+ if (profile.id == mCurrentUserId) {
+ continue;
+ }
+ VpnConfig cfg = mCurrentVpns.get(profile.id);
+ if (cfg != null) {
+ return getNameForVpnConfig(cfg, profile.getUserHandle());
+ }
+ }
+ return null;
+ }
+
+ @Override
public boolean isVpnEnabled() {
- return mCurrentVpnUsers.get(mCurrentUserId) != null;
+ for (UserInfo profile : mUserManager.getProfiles(mCurrentUserId)) {
+ if (mCurrentVpns.get(profile.id) != null) {
+ return true;
+ }
+ }
+ return false;
}
@Override
@@ -140,6 +175,22 @@ public class SecurityControllerImpl implements SecurityController {
fireCallbacks();
}
+ private String getNameForVpnConfig(VpnConfig cfg, UserHandle user) {
+ if (cfg.legacy) {
+ return mContext.getString(R.string.legacy_vpn_name);
+ }
+ // The package name for an active VPN is stored in the 'user' field of its VpnConfig
+ final String vpnPackage = cfg.user;
+ try {
+ Context userContext = mContext.createPackageContextAsUser(mContext.getPackageName(),
+ 0 /* flags */, user);
+ return VpnConfig.getVpnLabel(userContext, vpnPackage).toString();
+ } catch (NameNotFoundException nnfe) {
+ Log.e(TAG, "Package " + vpnPackage + " is not present", nnfe);
+ return null;
+ }
+ }
+
private void fireCallbacks() {
for (SecurityControllerCallback callback : mCallbacks) {
callback.onStateChanged();
@@ -148,21 +199,20 @@ public class SecurityControllerImpl implements SecurityController {
private void updateState() {
// Find all users with an active VPN
- SparseArray<Boolean> vpnUsers = new SparseArray<>();
+ SparseArray<VpnConfig> vpns = new SparseArray<>();
try {
- for (VpnInfo vpn : mConnectivityManagerService.getAllVpnInfo()) {
- UserInfo user = mUserManager.getUserInfo(UserHandle.getUserId(vpn.ownerUid));
- int groupId = (user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID ?
- user.profileGroupId : user.id);
-
- vpnUsers.put(groupId, Boolean.TRUE);
+ for (UserInfo user : mUserManager.getUsers()) {
+ VpnConfig cfg = mConnectivityManagerService.getVpnConfig(user.id);
+ if (cfg != null) {
+ vpns.put(user.id, cfg);
+ }
}
} catch (RemoteException rme) {
// Roll back to previous state
Log.e(TAG, "Unable to list active VPNs", rme);
return;
}
- mCurrentVpnUsers = vpnUsers;
+ mCurrentVpns = vpns;
}
private final NetworkCallback mNetworkCallback = new NetworkCallback() {
@@ -182,5 +232,4 @@ public class SecurityControllerImpl implements SecurityController {
fireCallbacks();
};
};
-
}
diff --git a/packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java b/packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java
index 7472af9..2b76c31 100644
--- a/packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java
+++ b/packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java
@@ -315,6 +315,16 @@ public class QsTuner extends Fragment implements Callback {
}
@Override
+ public String getPrimaryVpnName() {
+ return null;
+ }
+
+ @Override
+ public String getProfileVpnName() {
+ return null;
+ }
+
+ @Override
public void onUserSwitched(int newUserId) {
}
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 99c4eda..68e8307 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -2994,7 +2994,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
throwIfLockdownEnabled();
synchronized(mVpns) {
- return mVpns.get(userId).prepare(oldPackage, newPackage);
+ Vpn vpn = mVpns.get(userId);
+ if (vpn != null) {
+ return vpn.prepare(oldPackage, newPackage);
+ } else {
+ return false;
+ }
}
}
@@ -3016,7 +3021,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
enforceCrossUserPermission(userId);
synchronized(mVpns) {
- mVpns.get(userId).setPackageAuthorization(packageName, authorized);
+ Vpn vpn = mVpns.get(userId);
+ if (vpn != null) {
+ vpn.setPackageAuthorization(packageName, authorized);
+ }
}
}
@@ -3127,7 +3135,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
public VpnConfig getVpnConfig(int userId) {
enforceCrossUserPermission(userId);
synchronized(mVpns) {
- return mVpns.get(userId).getVpnConfig();
+ Vpn vpn = mVpns.get(userId);
+ if (vpn != null) {
+ return vpn.getVpnConfig();
+ } else {
+ return null;
+ }
}
}