Skip to content

Commit db12e19

Browse files
author
Rubin Xu
committed
Replace hardcoded strings with Q SDK APIs
Also fix a bug where DO-only delegations are not showing up in the list on TestDPC replica when it's a delegated app. Bug: 122460462 Test: manual Change-Id: Id2626420bbf2dc135610f79cd37ac1afa9a73ab9
1 parent 574933b commit db12e19

File tree

3 files changed

+17
-36
lines changed

3 files changed

+17
-36
lines changed

app/src/main/java/com/afwsamples/testdpc/DelegatedAdminReceiver.java

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,25 @@
1616

1717
package com.afwsamples.testdpc;
1818

19-
import android.content.BroadcastReceiver;
19+
import android.annotation.TargetApi;
2020
import android.content.Context;
2121
import android.content.Intent;
2222
import android.net.Uri;
23-
import android.util.Log;
23+
import android.os.Build;
2424

25-
//TODO(b/122460462) Revert to android.app.admin.DelegatedAdminReceiver once we have a new SDK drop.
26-
public class DelegatedAdminReceiver extends BroadcastReceiver {
25+
@TargetApi(Build.VERSION_CODES.Q)
26+
public class DelegatedAdminReceiver extends android.app.admin.DelegatedAdminReceiver {
2727

28-
//@Override
28+
@Override
2929
public String onChoosePrivateKeyAlias(Context context, Intent intent, int uid, Uri uri,
3030
String alias) {
3131
return CommonReceiverOperations.onChoosePrivateKeyAlias(context, uid);
3232
}
3333

34-
//@Override
34+
@Override
3535
public void onNetworkLogsAvailable(Context context, Intent intent, long batchToken,
3636
int networkLogsCount) {
3737
CommonReceiverOperations.onNetworkLogsAvailable(context, null, batchToken,
3838
networkLogsCount);
3939
}
40-
41-
@Override
42-
public void onReceive(Context context, Intent intent) {
43-
String action = intent.getAction();
44-
45-
if ("android.app.action.CHOOSE_PRIVATE_KEY_ALIAS".equals(action)) {
46-
int uid = intent.getIntExtra("android.app.extra.CHOOSE_PRIVATE_KEY_SENDER_UID", -1);
47-
Uri uri = intent.getParcelableExtra("android.app.extra.CHOOSE_PRIVATE_KEY_URI");
48-
String alias = intent.getStringExtra("android.app.extra.CHOOSE_PRIVATE_KEY_ALIAS");
49-
String chosenAlias = onChoosePrivateKeyAlias(context, intent, uid, uri, alias);
50-
setResultData(chosenAlias);
51-
} else if ("android.app.action.NETWORK_LOGS_AVAILABLE".equals(action)) {
52-
long batchToken = intent.getLongExtra("android.app.extra.EXTRA_NETWORK_LOGS_TOKEN", -1);
53-
int networkLogsCount = intent.getIntExtra("android.app.extra.EXTRA_NETWORK_LOGS_COUNT",
54-
0);
55-
onNetworkLogsAvailable(context, intent, batchToken, networkLogsCount);
56-
} else {
57-
Log.w("DelegatedReceiver", "Unhandled broadcast: " + action);
58-
}
59-
60-
}
6140
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public void onCreate(Bundle savedInstanceState) {
6363
final boolean isProfileOwner = mDpm.isProfileOwnerApp(mPackageName);
6464
mIsDeviceOrProfileOwner = isDeviceOwner || isProfileOwner;
6565

66-
mDelegations = DelegationScope.defaultDelegationScopes(isDeviceOwner);
66+
// Show DO-only delegations if we are DO or delegated app i.e. we are not PO, ignoring the
67+
// case where we are neither PO or DO (in which case this fragment is not accessible at all)
68+
mDelegations = DelegationScope.defaultDelegationScopes(!isProfileOwner);
6769

6870
getActivity().getActionBar().setTitle(R.string.generic_delegation);
6971
}
@@ -194,7 +196,7 @@ static class DelegationScope {
194196
}
195197

196198
@TargetApi(Build.VERSION_CODES.O)
197-
static List<DelegationScope> defaultDelegationScopes(boolean isDeviceOwner) {
199+
static List<DelegationScope> defaultDelegationScopes(boolean showDoOnlyDelegations) {
198200
List<DelegationScope> defaultDelegations = new ArrayList<>();
199201
defaultDelegations.add(
200202
new DelegationScope(DevicePolicyManager.DELEGATION_CERT_INSTALL));
@@ -209,12 +211,12 @@ static List<DelegationScope> defaultDelegationScopes(boolean isDeviceOwner) {
209211
defaultDelegations.add(
210212
new DelegationScope(DevicePolicyManager.DELEGATION_ENABLE_SYSTEM_APP));
211213
defaultDelegations.add(
212-
new DelegationScope("delegation-cert-selection")); //TODO: b/122460462
213-
if (isDeviceOwner) {
214+
new DelegationScope(DevicePolicyManager.DELEGATION_CERT_SELECTION));
215+
if (showDoOnlyDelegations) {
214216
defaultDelegations.add(
215-
new DelegationScope("delegation-network-logging")); //TODO: b/122460462
217+
new DelegationScope(DevicePolicyManager.DELEGATION_NETWORK_LOGGING));
216218
defaultDelegations.add(
217-
new DelegationScope("delegation-package-installation")); //TODO: b/122460462
219+
new DelegationScope(DevicePolicyManager.DELEGATION_PACKAGE_INSTALLATION));
218220
}
219221
return defaultDelegations;
220222
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ public View getView(int position, View convertView, ViewGroup parent) {
5959
case DevicePolicyManager.DELEGATION_ENABLE_SYSTEM_APP:
6060
viewHolder.setText(R.string.delegation_scope_enable_system_app);
6161
break;
62-
case "delegation-network-logging": //TODO: b/122460462
62+
case DevicePolicyManager.DELEGATION_NETWORK_LOGGING:
6363
viewHolder.setText(R.string.delegation_scope_network_logging);
6464
break;
65-
case "delegation-cert-selection": //TODO: b/122460462
65+
case DevicePolicyManager.DELEGATION_CERT_SELECTION:
6666
viewHolder.setText(R.string.delegation_scope_cert_selection);
6767
break;
68-
case "delegation-package-installation": //TODO: b/122460462
68+
case DevicePolicyManager.DELEGATION_PACKAGE_INSTALLATION:
6969
viewHolder.setText(R.string.delegation_scope_package_installation);
7070
break;
7171

0 commit comments

Comments
 (0)