Loading src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java +5 −56 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import android.view.View; import com.android.settings.R; import com.android.settings.vpn2.VpnUtils; import com.android.settingslib.utils.WorkPolicyUtils; import java.util.Date; import java.util.List; Loading @@ -54,6 +55,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe private final ConnectivityManager mCm; private final VpnManager mVm; private final Resources mResources; private final WorkPolicyUtils mWorkPolicyUtils; private static final int MY_USER_ID = UserHandle.myUserId(); Loading @@ -67,6 +69,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe mCm = cm; mVm = vm; mResources = resources; mWorkPolicyUtils = new WorkPolicyUtils(mContext, mPm, mUm, mDpm); } @Override Loading Loading @@ -228,25 +231,12 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe @Override public boolean hasWorkPolicyInfo() { return (getWorkPolicyInfoIntentDO() != null) || (getWorkPolicyInfoIntentPO() != null); return mWorkPolicyUtils.hasWorkPolicy(); } @Override public boolean showWorkPolicyInfo(Context activityContext) { Intent intent = getWorkPolicyInfoIntentDO(); if (intent != null) { activityContext.startActivity(intent); return true; } intent = getWorkPolicyInfoIntentPO(); final UserInfo userInfo = getManagedProfileUserInfo(); if (intent != null && userInfo != null) { activityContext.startActivityAsUser(intent, userInfo.getUserHandle()); return true; } return false; return mWorkPolicyUtils.showWorkPolicyInfo(activityContext); } @Override Loading Loading @@ -301,47 +291,6 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe return UserHandle.USER_NULL; } private Intent getWorkPolicyInfoIntentDO() { final ComponentName ownerComponent = getDeviceOwnerComponent(); if (ownerComponent == null) { return null; } // Only search for the required action in the Device Owner's package final Intent intent = new Intent(Settings.ACTION_SHOW_WORK_POLICY_INFO) .setPackage(ownerComponent.getPackageName()); final List<ResolveInfo> activities = mPm.queryIntentActivities(intent, 0); if (activities.size() != 0) { return intent; } return null; } private Intent getWorkPolicyInfoIntentPO() { final int userId = getManagedProfileUserId(); if (userId == UserHandle.USER_NULL) { return null; } final ComponentName ownerComponent = mDpm.getProfileOwnerAsUser(userId); if (ownerComponent == null) { return null; } // Only search for the required action in the Profile Owner's package final Intent intent = new Intent(Settings.ACTION_SHOW_WORK_POLICY_INFO) .setPackage(ownerComponent.getPackageName()); final List<ResolveInfo> activities = mPm.queryIntentActivitiesAsUser(intent, 0, userId); if (activities.size() != 0) { return intent; } return null; } protected static class EnterprisePrivacySpan extends ClickableSpan { private final Context mContext; Loading tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java +16 −4 Original line number Diff line number Diff line Loading @@ -377,10 +377,22 @@ public class EnterprisePrivacyFeatureProviderImplTest { } @Test public void workPolicyInfo_profileOwner_shouldResolveIntent() { public void workPolicyInfo_profileOwner_shouldResolveIntent() throws PackageManager.NameNotFoundException { when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null); mProfiles.add(new UserInfo(mManagedProfileUserId, "", "", UserInfo.FLAG_MANAGED_PROFILE)); when(mDevicePolicyManager.getProfileOwnerAsUser(mManagedProfileUserId)).thenReturn(mOwner); List<UserHandle> mAllProfiles = new ArrayList<>(); mAllProfiles.add(new UserHandle(mManagedProfileUserId)); when(mUserManager.getAllProfiles()).thenReturn(mAllProfiles); when(mUserManager.isManagedProfile(mManagedProfileUserId)).thenReturn(true); when(mContext.getPackageName()).thenReturn("somePackageName"); when(mContext.createPackageContextAsUser( eq(mContext.getPackageName()), anyInt(), any(UserHandle.class)) ).thenReturn(mContext); when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE)) .thenReturn(mDevicePolicyManager); when(mDevicePolicyManager.getProfileOwner()).thenReturn(mOwner); // If the intent is not resolved, then there's no info to show for PO assertThat(mProvider.hasWorkPolicyInfo()).isFalse(); Loading Loading @@ -441,7 +453,7 @@ public class EnterprisePrivacyFeatureProviderImplTest { } if (profileOwner) { when(mPackageManager.queryIntentActivitiesAsUser( intentEquals(intent), anyInt(), eq(mManagedProfileUserId))) intentEquals(intent), anyInt(), eq(UserHandle.of(mManagedProfileUserId)))) .thenReturn(activities); } Loading Loading
src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java +5 −56 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import android.view.View; import com.android.settings.R; import com.android.settings.vpn2.VpnUtils; import com.android.settingslib.utils.WorkPolicyUtils; import java.util.Date; import java.util.List; Loading @@ -54,6 +55,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe private final ConnectivityManager mCm; private final VpnManager mVm; private final Resources mResources; private final WorkPolicyUtils mWorkPolicyUtils; private static final int MY_USER_ID = UserHandle.myUserId(); Loading @@ -67,6 +69,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe mCm = cm; mVm = vm; mResources = resources; mWorkPolicyUtils = new WorkPolicyUtils(mContext, mPm, mUm, mDpm); } @Override Loading Loading @@ -228,25 +231,12 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe @Override public boolean hasWorkPolicyInfo() { return (getWorkPolicyInfoIntentDO() != null) || (getWorkPolicyInfoIntentPO() != null); return mWorkPolicyUtils.hasWorkPolicy(); } @Override public boolean showWorkPolicyInfo(Context activityContext) { Intent intent = getWorkPolicyInfoIntentDO(); if (intent != null) { activityContext.startActivity(intent); return true; } intent = getWorkPolicyInfoIntentPO(); final UserInfo userInfo = getManagedProfileUserInfo(); if (intent != null && userInfo != null) { activityContext.startActivityAsUser(intent, userInfo.getUserHandle()); return true; } return false; return mWorkPolicyUtils.showWorkPolicyInfo(activityContext); } @Override Loading Loading @@ -301,47 +291,6 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe return UserHandle.USER_NULL; } private Intent getWorkPolicyInfoIntentDO() { final ComponentName ownerComponent = getDeviceOwnerComponent(); if (ownerComponent == null) { return null; } // Only search for the required action in the Device Owner's package final Intent intent = new Intent(Settings.ACTION_SHOW_WORK_POLICY_INFO) .setPackage(ownerComponent.getPackageName()); final List<ResolveInfo> activities = mPm.queryIntentActivities(intent, 0); if (activities.size() != 0) { return intent; } return null; } private Intent getWorkPolicyInfoIntentPO() { final int userId = getManagedProfileUserId(); if (userId == UserHandle.USER_NULL) { return null; } final ComponentName ownerComponent = mDpm.getProfileOwnerAsUser(userId); if (ownerComponent == null) { return null; } // Only search for the required action in the Profile Owner's package final Intent intent = new Intent(Settings.ACTION_SHOW_WORK_POLICY_INFO) .setPackage(ownerComponent.getPackageName()); final List<ResolveInfo> activities = mPm.queryIntentActivitiesAsUser(intent, 0, userId); if (activities.size() != 0) { return intent; } return null; } protected static class EnterprisePrivacySpan extends ClickableSpan { private final Context mContext; Loading
tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java +16 −4 Original line number Diff line number Diff line Loading @@ -377,10 +377,22 @@ public class EnterprisePrivacyFeatureProviderImplTest { } @Test public void workPolicyInfo_profileOwner_shouldResolveIntent() { public void workPolicyInfo_profileOwner_shouldResolveIntent() throws PackageManager.NameNotFoundException { when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null); mProfiles.add(new UserInfo(mManagedProfileUserId, "", "", UserInfo.FLAG_MANAGED_PROFILE)); when(mDevicePolicyManager.getProfileOwnerAsUser(mManagedProfileUserId)).thenReturn(mOwner); List<UserHandle> mAllProfiles = new ArrayList<>(); mAllProfiles.add(new UserHandle(mManagedProfileUserId)); when(mUserManager.getAllProfiles()).thenReturn(mAllProfiles); when(mUserManager.isManagedProfile(mManagedProfileUserId)).thenReturn(true); when(mContext.getPackageName()).thenReturn("somePackageName"); when(mContext.createPackageContextAsUser( eq(mContext.getPackageName()), anyInt(), any(UserHandle.class)) ).thenReturn(mContext); when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE)) .thenReturn(mDevicePolicyManager); when(mDevicePolicyManager.getProfileOwner()).thenReturn(mOwner); // If the intent is not resolved, then there's no info to show for PO assertThat(mProvider.hasWorkPolicyInfo()).isFalse(); Loading Loading @@ -441,7 +453,7 @@ public class EnterprisePrivacyFeatureProviderImplTest { } if (profileOwner) { when(mPackageManager.queryIntentActivitiesAsUser( intentEquals(intent), anyInt(), eq(mManagedProfileUserId))) intentEquals(intent), anyInt(), eq(UserHandle.of(mManagedProfileUserId)))) .thenReturn(activities); } Loading