Check VPN status when adding/removing restricted profiles

Restricted profiles are tied to a VPN of the parent user. addVpnUserLocked/
removeVpnUserLocked should not be called for restricted profiles when VPN
is not active, because they will throw an exception.

Bug: 27296721
Change-Id: Ifcfaa85c12fbca1bbad81217c2f0d07a79347547
This commit is contained in:
Fyodor Kupolov
2016-03-04 13:41:58 -08:00
parent c9f0a1103e
commit 49d5a01e9b

View File

@@ -718,7 +718,8 @@ public class Vpn {
public void onUserAdded(int userHandle) {
// If the user is restricted tie them to the parent user's VPN
UserInfo user = UserManager.get(mContext).getUserInfo(userHandle);
if (user.isRestricted() && user.restrictedProfileParentId == mUserHandle) {
if (user.isRestricted() && user.restrictedProfileParentId == mUserHandle
&& mVpnUsers != null) {
synchronized(Vpn.this) {
try {
addVpnUserLocked(userHandle);
@@ -736,7 +737,8 @@ public class Vpn {
public void onUserRemoved(int userHandle) {
// clean up if restricted
UserInfo user = UserManager.get(mContext).getUserInfo(userHandle);
if (user.isRestricted() && user.restrictedProfileParentId == mUserHandle) {
if (user.isRestricted() && user.restrictedProfileParentId == mUserHandle
&& mVpnUsers != null) {
synchronized(Vpn.this) {
try {
removeVpnUserLocked(userHandle);