Skip to content

Commit 6aae82b

Browse files
author
Alex Johnston
committed
TestDPC replica show all delegations
If the TestDPC replica app is the delegated app, show all delegations. Do not call isManagedProfile(admin) as the admin is null for the delegated app. Manual testing - Set TestDPC as the device owner - Delegate security logging to TestDPC replica - Select 'Generic delegation' in TestDPC replica - Verify an exception is not thrown - Verify all delegations are shown and security logging is selected. Bug: 188174397 Test: manual testing Change-Id: I15a47dff2acadae8960fc382016f9b6541a65ccc
1 parent 9370510 commit 6aae82b

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

app/src/main/java/com/afwsamples/testdpc/profilepolicy/delegation/DelegationFragment.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,26 @@ public class DelegationFragment extends ManageAppFragment {
5454
List<DelegationScope> mDelegations;
5555
private String mPackageName;
5656
private boolean mIsDeviceOrProfileOwner;
57-
private ComponentName mAdminName;
5857

5958
@Override
6059
public void onCreate(Bundle savedInstanceState) {
6160
super.onCreate(savedInstanceState);
62-
mAdminName = DeviceAdminReceiver.getComponentName(getActivity());
6361
mDpm = (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
6462
mPackageName = getActivity().getPackageName();
65-
final boolean isDeviceOwner = mDpm.isDeviceOwnerApp(mPackageName);
66-
final boolean isProfileOwner = mDpm.isProfileOwnerApp(mPackageName);
67-
final boolean isManagedProfile = mDpm.isManagedProfile(mAdminName);
68-
mIsDeviceOrProfileOwner = isDeviceOwner || isProfileOwner;
69-
70-
// Show DO or managed PO only delegations if we are DO, delegated app or managed PO.
71-
mDelegations = DelegationScope
72-
.defaultDelegationScopes(isDeviceOwner || (isManagedProfile && isProfileOwner));
63+
if (isDelegatedApp(mPackageName)) {
64+
// Show all delegations if we are delegated app.
65+
mDelegations = DelegationScope.defaultDelegationScopes(true);
66+
} else {
67+
ComponentName mAdminName = DeviceAdminReceiver.getComponentName(getActivity());
68+
final boolean isDeviceOwner = mDpm.isDeviceOwnerApp(mPackageName);
69+
final boolean isProfileOwner = mDpm.isProfileOwnerApp(mPackageName);
70+
final boolean isManagedProfile = mDpm.isManagedProfile(mAdminName);
71+
mIsDeviceOrProfileOwner = isDeviceOwner || isProfileOwner;
72+
73+
// Show DO or managed PO only delegations if we are DO or managed PO.
74+
mDelegations = DelegationScope
75+
.defaultDelegationScopes(isDeviceOwner || (isManagedProfile && isProfileOwner));
76+
}
7377

7478
getActivity().getActionBar().setTitle(R.string.generic_delegation);
7579
}
@@ -231,4 +235,9 @@ static List<DelegationScope> defaultDelegationScopes(boolean showDoOnlyDelegatio
231235
return defaultDelegations;
232236
}
233237
}
238+
239+
@TargetApi(VERSION_CODES.O)
240+
private boolean isDelegatedApp(String packageName) {
241+
return !mDpm.getDelegatedScopes(null, packageName).isEmpty();
242+
}
234243
}

0 commit comments

Comments
 (0)