Loading packages/SystemUI/src/com/android/systemui/qs/QSFooter.java +39 −28 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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(); Loading @@ -154,32 +154,43 @@ 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; } } private final Runnable mUpdateDisplayState = new Runnable() { @Override Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java +2 −0 Original line number Diff line number Diff line Loading @@ -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); Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java +66 −17 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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) { Loading @@ -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 Loading @@ -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 Loading @@ -115,9 +121,38 @@ public class SecurityControllerImpl implements SecurityController { return null; } @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 Loading @@ -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(); Loading @@ -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() { Loading @@ -182,5 +232,4 @@ public class SecurityControllerImpl implements SecurityController { fireCallbacks(); }; }; } packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java +10 −0 Original line number Diff line number Diff line Loading @@ -314,6 +314,16 @@ public class QsTuner extends Fragment implements Callback { return false; } @Override public String getPrimaryVpnName() { return null; } @Override public String getProfileVpnName() { return null; } @Override public void onUserSwitched(int newUserId) { } Loading services/core/java/com/android/server/ConnectivityService.java +16 −3 Original line number Diff line number Diff line Loading @@ -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; } } } Loading @@ -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); } } } Loading Loading @@ -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; } } } Loading Loading
packages/SystemUI/src/com/android/systemui/qs/QSFooter.java +39 −28 Original line number Diff line number Diff line Loading @@ -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); } Loading @@ -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(); Loading @@ -154,32 +154,43 @@ 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; } } private final Runnable mUpdateDisplayState = new Runnable() { @Override Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java +2 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java +66 −17 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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) { Loading @@ -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 Loading @@ -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 Loading @@ -115,9 +121,38 @@ public class SecurityControllerImpl implements SecurityController { return null; } @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 Loading @@ -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(); Loading @@ -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() { Loading @@ -182,5 +232,4 @@ public class SecurityControllerImpl implements SecurityController { fireCallbacks(); }; }; }
packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java +10 −0 Original line number Diff line number Diff line Loading @@ -314,6 +314,16 @@ public class QsTuner extends Fragment implements Callback { return false; } @Override public String getPrimaryVpnName() { return null; } @Override public String getProfileVpnName() { return null; } @Override public void onUserSwitched(int newUserId) { } Loading
services/core/java/com/android/server/ConnectivityService.java +16 −3 Original line number Diff line number Diff line Loading @@ -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; } } } Loading @@ -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); } } } Loading Loading @@ -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; } } } Loading