Skip to content

Commit 460ba27

Browse files
committed
Small refactor to standardise on VERSION_CODES.X.
This is ahead of further tidying to remove isAtLeastX calls and make api gates clearer. Test: no functional changes. Confirmed build with ./gradlew assemble Change-Id: If0c9e5a8358c1051575e8731c51afe3d34bb2346
1 parent 26c2527 commit 460ba27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+236
-286
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@
1616

1717
package com.afwsamples.testdpc;
1818

19+
import static com.afwsamples.testdpc.policy.PolicyManagementFragment.OVERRIDE_KEY_SELECTION_KEY;
20+
1921
import android.annotation.TargetApi;
2022
import android.app.admin.DevicePolicyManager;
2123
import android.app.admin.NetworkEvent;
2224
import android.content.ComponentName;
2325
import android.content.Context;
2426
import android.os.AsyncTask;
25-
import android.os.Build;
27+
import android.os.Build.VERSION_CODES;
2628
import android.os.Process;
2729
import android.preference.PreferenceManager;
2830
import android.support.v4.os.BuildCompat;
2931
import android.text.TextUtils;
3032
import android.util.Log;
3133
import android.widget.Toast;
32-
3334
import java.io.File;
3435
import java.io.FileOutputStream;
3536
import java.io.IOException;
@@ -38,8 +39,6 @@
3839
import java.util.Date;
3940
import java.util.List;
4041

41-
import static com.afwsamples.testdpc.policy.PolicyManagementFragment.OVERRIDE_KEY_SELECTION_KEY;
42-
4342
/**
4443
* A class that implements common logic to handle direct and delegated admin callbacks
4544
* from DeviceAdminReceiver and DelegatedAdminReceiver.
@@ -65,7 +64,7 @@ public static String onChoosePrivateKeyAlias(Context context, int uid) {
6564
}
6665
}
6766

68-
@TargetApi(Build.VERSION_CODES.O)
67+
@TargetApi(VERSION_CODES.O)
6968
public static void onNetworkLogsAvailable(Context context, ComponentName admin, long batchToken,
7069
int networkLogsCount) {
7170
Log.i(TAG, "onNetworkLogsAvailable(), batchToken: " + batchToken

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import android.content.Context;
2121
import android.content.Intent;
2222
import android.net.Uri;
23-
import android.os.Build;
23+
import android.os.Build.VERSION_CODES;
2424

25-
@TargetApi(Build.VERSION_CODES.Q)
25+
@TargetApi(VERSION_CODES.Q)
2626
public class DelegatedAdminReceiver extends android.app.admin.DelegatedAdminReceiver {
2727

2828
@Override

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import android.net.Uri;
2727
import android.os.AsyncTask;
2828
import android.os.Binder;
29-
import android.os.Build;
29+
import android.os.Build.VERSION_CODES;
3030
import android.os.ParcelFileDescriptor;
3131
import android.os.PersistableBundle;
3232
import android.os.Process;
@@ -92,7 +92,7 @@ public void onReceive(Context context, Intent intent) {
9292
}
9393
}
9494

95-
@TargetApi(Build.VERSION_CODES.N)
95+
@TargetApi(VERSION_CODES.N)
9696
@Override
9797
public void onSecurityLogsAvailable(Context context, Intent intent) {
9898
Log.i(TAG, "onSecurityLogsAvailable() called");
@@ -107,7 +107,7 @@ public void onSecurityLogsAvailable(Context context, Intent intent) {
107107
* TODO: reconsider how to store and present the logs in the future, e.g. save the file into
108108
* internal memory and show the content in a ListView
109109
*/
110-
@TargetApi(Build.VERSION_CODES.O)
110+
@TargetApi(VERSION_CODES.O)
111111
@Override
112112
public void onNetworkLogsAvailable(Context context, Intent intent, long batchToken,
113113
int networkLogsCount) {
@@ -133,7 +133,7 @@ public void onProfileProvisioningComplete(Context context, Intent intent) {
133133
}
134134
}
135135

136-
@TargetApi(Build.VERSION_CODES.N)
136+
@TargetApi(VERSION_CODES.N)
137137
@Override
138138
public void onBugreportSharingDeclined(Context context, Intent intent) {
139139
Log.i(TAG, "Bugreport sharing declined");
@@ -142,7 +142,7 @@ public void onBugreportSharingDeclined(Context context, Intent intent) {
142142
NotificationUtil.BUGREPORT_NOTIFICATION_ID);
143143
}
144144

145-
@TargetApi(Build.VERSION_CODES.N)
145+
@TargetApi(VERSION_CODES.N)
146146
@Override
147147
public void onBugreportShared(final Context context, Intent intent,
148148
final String bugreportFileHash) {
@@ -190,7 +190,7 @@ protected void onPostExecute(String message) {
190190
}.execute();
191191
}
192192

193-
@TargetApi(Build.VERSION_CODES.N)
193+
@TargetApi(VERSION_CODES.N)
194194
@Override
195195
public void onBugreportFailed(Context context, Intent intent, int failureCode) {
196196
String failureReason;
@@ -212,42 +212,42 @@ public void onBugreportFailed(Context context, Intent intent, int failureCode) {
212212
}
213213

214214

215-
@TargetApi(Build.VERSION_CODES.O)
215+
@TargetApi(VERSION_CODES.O)
216216
@Override
217217
public void onUserAdded(Context context, Intent intent, UserHandle newUser) {
218218
handleUserAction(context, newUser, R.string.on_user_added_title,
219219
R.string.on_user_added_message, NotificationUtil.USER_ADDED_NOTIFICATION_ID);
220220
}
221221

222-
@TargetApi(Build.VERSION_CODES.O)
222+
@TargetApi(VERSION_CODES.O)
223223
@Override
224224
public void onUserRemoved(Context context, Intent intent, UserHandle removedUser) {
225225
handleUserAction(context, removedUser, R.string.on_user_removed_title,
226226
R.string.on_user_removed_message, NotificationUtil.USER_REMOVED_NOTIFICATION_ID);
227227
}
228228

229-
@TargetApi(Build.VERSION_CODES.P)
229+
@TargetApi(VERSION_CODES.P)
230230
@Override
231231
public void onUserStarted(Context context, Intent intent, UserHandle startedUser) {
232232
handleUserAction(context, startedUser, R.string.on_user_started_title,
233233
R.string.on_user_started_message, NotificationUtil.USER_STARTED_NOTIFICATION_ID);
234234
}
235235

236-
@TargetApi(Build.VERSION_CODES.P)
236+
@TargetApi(VERSION_CODES.P)
237237
@Override
238238
public void onUserStopped(Context context, Intent intent, UserHandle stoppedUser) {
239239
handleUserAction(context, stoppedUser, R.string.on_user_stopped_title,
240240
R.string.on_user_stopped_message, NotificationUtil.USER_STOPPED_NOTIFICATION_ID);
241241
}
242242

243-
@TargetApi(Build.VERSION_CODES.P)
243+
@TargetApi(VERSION_CODES.P)
244244
@Override
245245
public void onUserSwitched(Context context, Intent intent, UserHandle switchedUser) {
246246
handleUserAction(context, switchedUser, R.string.on_user_switched_title,
247247
R.string.on_user_switched_message, NotificationUtil.USER_SWITCHED_NOTIFICATION_ID);
248248
}
249249

250-
@TargetApi(Build.VERSION_CODES.M)
250+
@TargetApi(VERSION_CODES.M)
251251
@Override
252252
public void onSystemUpdatePending(Context context, Intent intent, long receivedTime) {
253253
if (receivedTime != -1) {
@@ -260,7 +260,7 @@ public void onSystemUpdatePending(Context context, Intent intent, long receivedT
260260
}
261261
}
262262

263-
@TargetApi(Build.VERSION_CODES.M)
263+
@TargetApi(VERSION_CODES.M)
264264
@Override
265265
public String onChoosePrivateKeyAlias(Context context, Intent intent, int uid, Uri uri,
266266
String alias) {
@@ -281,7 +281,7 @@ public void onPasswordExpiring(Context context, Intent intent) {
281281
onPasswordExpiring(context, intent, Process.myUserHandle());
282282
}
283283

284-
@TargetApi(Build.VERSION_CODES.O)
284+
@TargetApi(VERSION_CODES.O)
285285
// @Override
286286
public void onPasswordExpiring(Context context, Intent intent, UserHandle user) {
287287
if (!Process.myUserHandle().equals(user)) {
@@ -309,7 +309,7 @@ public void onPasswordFailed(Context context, Intent intent) {
309309
onPasswordFailed(context, intent, Process.myUserHandle());
310310
}
311311

312-
@TargetApi(Build.VERSION_CODES.O)
312+
@TargetApi(VERSION_CODES.O)
313313
// @Override
314314
public void onPasswordFailed(Context context, Intent intent, UserHandle user) {
315315
if (!Process.myUserHandle().equals(user)) {
@@ -372,7 +372,7 @@ public void onPasswordSucceeded(Context context, Intent intent) {
372372
onPasswordSucceeded(context, intent, Process.myUserHandle());
373373
}
374374

375-
@TargetApi(Build.VERSION_CODES.O)
375+
@TargetApi(VERSION_CODES.O)
376376
// @Override
377377
public void onPasswordSucceeded(Context context, Intent intent, UserHandle user) {
378378
if (Process.myUserHandle().equals(user)) {
@@ -386,7 +386,7 @@ public void onPasswordChanged(Context context, Intent intent) {
386386
onPasswordChanged(context, intent, Process.myUserHandle());
387387
}
388388

389-
@TargetApi(Build.VERSION_CODES.O)
389+
@TargetApi(VERSION_CODES.O)
390390
// @Override
391391
public void onPasswordChanged(Context context, Intent intent, UserHandle user) {
392392
if (Process.myUserHandle().equals(user)) {
@@ -546,7 +546,7 @@ private void onDeviceOwnerChanged(Context context) {
546546
NotificationUtil.DEVICE_OWNER_CHANGED_ID);
547547
}
548548

549-
@TargetApi(Build.VERSION_CODES.P)
549+
@TargetApi(VERSION_CODES.P)
550550
public void onTransferOwnershipComplete(Context context, PersistableBundle bundle) {
551551
Log.i(TAG, "onTransferOwnershipComplete");
552552
NotificationUtil.showNotification(context,
@@ -556,7 +556,7 @@ public void onTransferOwnershipComplete(Context context, PersistableBundle bundl
556556
NotificationUtil.TRANSFER_OWNERSHIP_COMPLETE_ID);
557557
}
558558

559-
@TargetApi(Build.VERSION_CODES.P)
559+
@TargetApi(VERSION_CODES.P)
560560
public void onTransferAffiliatedProfileOwnershipComplete(Context context, UserHandle user) {
561561
Log.i(TAG, "onTransferAffiliatedProfileOwnershipComplete");
562562
NotificationUtil.showNotification(context,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import android.content.Intent;
55
import android.content.IntentFilter;
66
import android.os.Build;
7+
import android.os.Build.VERSION_CODES;
78
import android.support.annotation.RequiresApi;
89

910
/**
1011
* To allow DPC process to be persistent and foreground.
1112
*
1213
* @see {@link android.app.admin.DeviceAdminService}
1314
*/
14-
@RequiresApi(api = Build.VERSION_CODES.O)
15+
@RequiresApi(api = VERSION_CODES.O)
1516
public class DeviceAdminService extends android.app.admin.DeviceAdminService {
1617

1718
private BroadcastReceiver mPackageChangedReceiver;

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616

1717
package com.afwsamples.testdpc;
1818

19+
import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE;
20+
import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE;
21+
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE;
22+
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE;
23+
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME;
24+
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME;
25+
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LOGO_URI;
26+
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_MAIN_COLOR;
27+
1928
import android.accounts.Account;
2029
import android.annotation.TargetApi;
2130
import android.app.Activity;
@@ -29,10 +38,10 @@
2938
import android.content.res.ColorStateList;
3039
import android.net.Uri;
3140
import android.os.Build;
41+
import android.os.Build.VERSION_CODES;
3242
import android.os.Bundle;
3343
import android.os.PersistableBundle;
3444
import android.support.v4.os.BuildCompat;
35-
import android.view.ContextThemeWrapper;
3645
import android.view.LayoutInflater;
3746
import android.view.View;
3847
import android.view.ViewGroup;
@@ -43,27 +52,15 @@
4352
import android.widget.RadioGroup;
4453
import android.widget.TextView;
4554
import android.widget.Toast;
46-
4755
import com.afwsamples.testdpc.common.ColorPicker;
4856
import com.afwsamples.testdpc.common.LaunchIntentUtil;
4957
import com.afwsamples.testdpc.common.ProvisioningStateUtil;
5058
import com.afwsamples.testdpc.common.Util;
5159
import com.android.setupwizardlib.GlifLayout;
52-
import com.android.setupwizardlib.view.NavigationBar;
53-
5460
import java.security.SecureRandom;
5561
import java.util.Collections;
5662
import java.util.Set;
5763

58-
import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE;
59-
import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE;
60-
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE;
61-
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE;
62-
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME;
63-
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME;
64-
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_LOGO_URI;
65-
import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_MAIN_COLOR;
66-
6764
/**
6865
* This {@link Fragment} shows the UI that allows the user to start the setup of a managed profile
6966
* or configuration of a device-owner if the device is in an appropriate state.
@@ -216,7 +213,7 @@ private void maybeLaunchProvisioning(String intentAction, int requestCode) {
216213
Activity activity = getActivity();
217214

218215
Intent intent = new Intent(intentAction);
219-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
216+
if (Build.VERSION.SDK_INT >= VERSION_CODES.M) {
220217
intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
221218
DeviceAdminReceiver.getComponentName(getActivity()));
222219
} else {
@@ -259,7 +256,7 @@ private void maybeSpecifySyncAuthExtras(Intent intent, PersistableBundle adminEx
259256
Account accountToMigrate = LaunchIntentUtil.getAddedAccount(launchIntent);
260257
if (accountToMigrate != null) {
261258
// EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE only supported in API 22+.
262-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
259+
if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP_MR1) {
263260
// Configure the account to migrate into the managed profile if setup
264261
// completes.
265262
intent.putExtra(EXTRA_PROVISIONING_ACCOUNT_TO_MIGRATE, accountToMigrate);
@@ -281,7 +278,7 @@ private void maybePassAffiliationIds(Intent intent, PersistableBundle adminExtra
281278
}
282279
}
283280

284-
@TargetApi(Build.VERSION_CODES.O)
281+
@TargetApi(VERSION_CODES.O)
285282
private void passAffiliationIds(Intent intent, PersistableBundle adminExtras) {
286283
ComponentName admin = DeviceAdminReceiver.getComponentName(getActivity());
287284
DevicePolicyManager dpm = (DevicePolicyManager)

app/src/main/java/com/afwsamples/testdpc/common/BundleUtil.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
package com.afwsamples.testdpc.common;
1818

1919
import android.annotation.TargetApi;
20-
import android.os.Build;
20+
import android.os.Build.VERSION_CODES;
2121
import android.os.Bundle;
2222
import android.os.PersistableBundle;
23-
2423
import java.util.Set;
2524

2625
public class BundleUtil {
2726

28-
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
27+
@TargetApi(VERSION_CODES.LOLLIPOP_MR1)
2928
public static PersistableBundle bundleToPersistableBundle(Bundle bundle) {
3029
Set<String> keySet = bundle.keySet();
3130
PersistableBundle persistableBundle = new PersistableBundle();
@@ -47,7 +46,7 @@ public static PersistableBundle bundleToPersistableBundle(Bundle bundle) {
4746
return persistableBundle;
4847
}
4948

50-
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
49+
@TargetApi(VERSION_CODES.LOLLIPOP_MR1)
5150
public static Bundle persistableBundleToBundle(PersistableBundle persistableBundle) {
5251
Set<String> keySet = persistableBundle.keySet();
5352
Bundle bundle = new Bundle();

app/src/main/java/com/afwsamples/testdpc/common/NotificationUtil.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
import android.app.NotificationChannel;
55
import android.app.NotificationManager;
66
import android.content.Context;
7-
import android.os.Build;
7+
import android.os.Build.VERSION_CODES;
88
import android.support.annotation.RequiresApi;
99
import android.support.annotation.StringRes;
10-
import android.support.v4.os.BuildCompat;
1110
import android.support.v4.app.NotificationCompat;
12-
11+
import android.support.v4.os.BuildCompat;
1312
import com.afwsamples.testdpc.R;
1413

1514
public class NotificationUtil {
@@ -49,7 +48,7 @@ public static NotificationCompat.Builder getNotificationBuilder(Context context)
4948
return builder;
5049
}
5150

52-
@RequiresApi(Build.VERSION_CODES.O)
51+
@RequiresApi(VERSION_CODES.O)
5352
private static void createDefaultNotificationChannel(Context context) {
5453
NotificationManager notificationManager =
5554
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

0 commit comments

Comments
 (0)