Skip to content

Commit dfa172f

Browse files
author
android-build-team Robot
committed
release-request-d11808fb-f5d0-48e4-95ae-f963ed01948b-for-ub-testdpc-oc-release-4086426 snap-temp-L92900000072707625
Change-Id: I61cdbabfe54a612fa7eb0f3c32caacee625bc94b
2 parents f46e5db + 9e8ce04 commit dfa172f

18 files changed

+368
-76
lines changed

app/build.gradle

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ext {
99
// exactly 1 digit
1010
versionMinor = 0
1111
// exactly 2 digits
12-
versionBuild = 03
12+
versionBuild = 04
1313
}
1414

1515
android {
@@ -22,9 +22,6 @@ android {
2222
targetSdkVersion 26
2323
versionCode versionMajor * 1000 + versionMinor * 100 + versionBuild
2424
versionName "${versionMajor}.${versionMinor}.${versionBuild}"
25-
jackOptions {
26-
enabled true
27-
}
2825
}
2926

3027
buildTypes {
@@ -34,16 +31,6 @@ android {
3431
}
3532
}
3633

37-
productFlavors {
38-
target25 {
39-
targetSdkVersion 25
40-
}
41-
42-
targetO {
43-
targetSdkVersion 'O'
44-
}
45-
}
46-
4734
lintOptions {
4835
check 'NewApi'
4936
abortOnError true
@@ -68,12 +55,20 @@ android {
6855
dirs 'libs'
6956
}
7057
}
58+
59+
// Enable lint checking in all build variants.
60+
applicationVariants.all { variant ->
61+
variant.outputs.each { output ->
62+
def lintTask = tasks["lint${variant.name.capitalize()}"]
63+
output.assemble.dependsOn lintTask
64+
}
65+
}
7166
}
7267

7368
dependencies {
74-
compile 'com.android.support:preference-v14:26.+'
75-
compile 'com.android.support:recyclerview-v7:26.+'
76-
compile 'com.android.support:support-v13:26.+'
69+
compile 'com.android.support:preference-v14:26.0.0-SNAPSHOT'
70+
compile 'com.android.support:recyclerview-v7:26.0.0-SNAPSHOT'
71+
compile 'com.android.support:support-v13:26.0.0-SNAPSHOT'
7772
compile 'com.google.android.gms:play-services-safetynet:+'
7873
compile(name:'setup-wizard-lib-platform-release', ext:'aar')
7974
}

app/src/main/AndroidManifest.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,23 @@
167167

168168
<service
169169
android:name=".comp.ProfileOwnerService"
170-
android:exported="false"/>
170+
android:exported="true"
171+
android:permission="android.permission.BIND_DEVICE_ADMIN"/>
171172

172173
<service
173174
android:name=".comp.DeviceOwnerService"
174-
android:exported="false"/>
175+
android:exported="true"
176+
android:permission="android.permission.BIND_DEVICE_ADMIN"/>
177+
178+
<service
179+
android:name=".DeviceAdminService"
180+
android:enabled="@bool/is_o_or_later"
181+
android:exported="true"
182+
android:permission="android.permission.BIND_DEVICE_ADMIN">
183+
<intent-filter>
184+
<action android:name="android.app.action.DEVICE_ADMIN_SERVICE" />
185+
</intent-filter>
186+
</service>
175187

176188
</application>
177189

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.afwsamples.testdpc;
1818

19-
import static com.afwsamples.testdpc.policy.PolicyManagementFragment.OVERRIDE_KEY_SELECTION_KEY;
20-
2119
import android.annotation.TargetApi;
2220
import android.app.Notification;
2321
import android.app.NotificationManager;
@@ -35,10 +33,12 @@
3533
import android.os.UserHandle;
3634
import android.os.UserManager;
3735
import android.preference.PreferenceManager;
36+
import android.support.v7.app.NotificationCompat;
3837
import android.text.TextUtils;
3938
import android.util.Log;
4039
import android.widget.Toast;
4140

41+
import com.afwsamples.testdpc.common.NotificationUtil;
4242
import com.afwsamples.testdpc.common.Util;
4343
import com.afwsamples.testdpc.provision.PostProvisioningTask;
4444

@@ -59,6 +59,8 @@
5959
import java.util.Date;
6060
import java.util.List;
6161

62+
import static com.afwsamples.testdpc.policy.PolicyManagementFragment.OVERRIDE_KEY_SELECTION_KEY;
63+
6264
/**
6365
* Handles events related to the managed profile.
6466
*/
@@ -189,9 +191,9 @@ public void onProfileProvisioningComplete(Context context, Intent intent) {
189191
@Override
190192
public void onBugreportSharingDeclined(Context context, Intent intent) {
191193
Log.i(TAG, "Bugreport sharing declined");
192-
Util.showNotification(context, R.string.bugreport_title,
194+
NotificationUtil.showNotification(context, R.string.bugreport_title,
193195
context.getString(R.string.bugreport_sharing_declined),
194-
Util.BUGREPORT_NOTIFICATION_ID);
196+
NotificationUtil.BUGREPORT_NOTIFICATION_ID);
195197
}
196198

197199
@TargetApi(Build.VERSION_CODES.N)
@@ -234,8 +236,8 @@ protected String doInBackground(Void... params) {
234236

235237
@Override
236238
protected void onPostExecute(String message) {
237-
Util.showNotification(context, R.string.bugreport_title,
238-
message, Util.BUGREPORT_NOTIFICATION_ID);
239+
NotificationUtil.showNotification(context, R.string.bugreport_title,
240+
message, NotificationUtil.BUGREPORT_NOTIFICATION_ID);
239241
result.finish();
240242
}
241243

@@ -258,9 +260,9 @@ public void onBugreportFailed(Context context, Intent intent, int failureCode) {
258260
R.string.bugreport_failure_failed_completing);
259261
}
260262
Log.i(TAG, "Bugreport failed: " + failureReason);
261-
Util.showNotification(context, R.string.bugreport_title,
263+
NotificationUtil.showNotification(context, R.string.bugreport_title,
262264
context.getString(R.string.bugreport_failure_message, failureReason),
263-
Util.BUGREPORT_NOTIFICATION_ID);
265+
NotificationUtil.BUGREPORT_NOTIFICATION_ID);
264266
}
265267

266268

@@ -271,9 +273,9 @@ public void onUserAdded(Context context, Intent intent, UserHandle newUser) {
271273
String message = context.getString(R.string.on_user_added_message,
272274
userManager.getSerialNumberForUser(newUser));
273275
Log.i(TAG, message);
274-
Util.showNotification(context, R.string.on_user_added_title,
276+
NotificationUtil.showNotification(context, R.string.on_user_added_title,
275277
message,
276-
Util.USER_ADDED_NOTIFICATION_ID);
278+
NotificationUtil.USER_ADDED_NOTIFICATION_ID);
277279
}
278280

279281
@TargetApi(Build.VERSION_CODES.O)
@@ -283,8 +285,8 @@ public void onUserRemoved(Context context, Intent intent, UserHandle removedUser
283285
String message = context.getString(R.string.on_user_removed_message,
284286
userManager.getSerialNumberForUser(removedUser));
285287
Log.i(TAG, message);
286-
Util.showNotification(context, R.string.on_user_removed_title, message,
287-
Util.USER_REMOVED_NOTIFICATION_ID);
288+
NotificationUtil.showNotification(context, R.string.on_user_removed_title, message,
289+
NotificationUtil.USER_REMOVED_NOTIFICATION_ID);
288290
}
289291

290292
@TargetApi(Build.VERSION_CODES.M)
@@ -349,11 +351,11 @@ public void onPasswordExpiring(Context context, Intent intent, UserHandle user)
349351
devicePolicyManager.getPasswordExpiration(getComponentName(context));
350352
final boolean expiredBySelf = (timeNow >= timeAdminExpires && timeAdminExpires != 0);
351353

352-
Util.showNotification(context, R.string.password_expired_title,
354+
NotificationUtil.showNotification(context, R.string.password_expired_title,
353355
context.getString(expiredBySelf
354356
? R.string.password_expired_by_self
355357
: R.string.password_expired_by_others),
356-
Util.PASSWORD_EXPIRATION_NOTIFICATION_ID);
358+
NotificationUtil.PASSWORD_EXPIRATION_NOTIFICATION_ID);
357359
}
358360

359361
@Deprecated
@@ -397,15 +399,15 @@ public void onPasswordFailed(Context context, Intent intent, UserHandle user) {
397399
: context.getResources().getQuantityString(
398400
R.plurals.password_failed_attempts_content, maxAttempts, maxAttempts);
399401

400-
Notification.Builder warn = new Notification.Builder(context)
401-
.setSmallIcon(R.drawable.ic_launcher)
402+
NotificationCompat.Builder warn = NotificationUtil.getNotificationBuilder(context);
403+
warn.setSmallIcon(R.drawable.ic_launcher)
402404
.setTicker(title)
403405
.setContentTitle(title)
404406
.setContentText(content)
405407
.setContentIntent(PendingIntent.getActivity(context, /* requestCode */ -1,
406408
new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD), /* flags */ 0));
407409

408-
Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
410+
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
409411
inboxStyle.setBigContentTitle(title);
410412

411413
final DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance();
@@ -416,7 +418,7 @@ public void onPasswordFailed(Context context, Intent intent, UserHandle user) {
416418

417419
NotificationManager nm = (NotificationManager)
418420
context.getSystemService(Context.NOTIFICATION_SERVICE);
419-
nm.notify(PASSWORD_FAILED_NOTIFICATION_ID, warn.getNotification());
421+
nm.notify(PASSWORD_FAILED_NOTIFICATION_ID, warn.build());
420422
}
421423

422424
@Deprecated
@@ -520,8 +522,8 @@ private static void updatePasswordQualityNotification(Context context) {
520522
context.getSystemService(Context.NOTIFICATION_SERVICE);
521523

522524
if (!devicePolicyManager.isActivePasswordSufficient()) {
523-
Notification.Builder warn = new Notification.Builder(context)
524-
.setOngoing(true)
525+
NotificationCompat.Builder warn = NotificationUtil.getNotificationBuilder(context);
526+
warn.setOngoing(true)
525527
.setSmallIcon(R.drawable.ic_launcher)
526528
.setTicker(context.getText(R.string.password_not_compliant_title))
527529
.setContentTitle(context.getText(R.string.password_not_compliant_title))
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.afwsamples.testdpc;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Intent;
5+
import android.content.IntentFilter;
6+
import android.os.Build;
7+
import android.support.annotation.RequiresApi;
8+
9+
/**
10+
* To allow DPC process to be persistent and foreground.
11+
*
12+
* @see {@link android.app.admin.DeviceAdminService}
13+
*/
14+
@RequiresApi(api = Build.VERSION_CODES.O)
15+
public class DeviceAdminService extends android.app.admin.DeviceAdminService {
16+
17+
private BroadcastReceiver mPackageChangedReceiver;
18+
19+
@Override
20+
public void onCreate() {
21+
super.onCreate();
22+
registerPackageChangesReceiver();
23+
}
24+
25+
@Override
26+
public void onDestroy() {
27+
super.onDestroy();
28+
unregisterPackageChangesReceiver();
29+
}
30+
31+
private void registerPackageChangesReceiver() {
32+
IntentFilter intentFilter = new IntentFilter();
33+
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
34+
intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
35+
intentFilter.addDataScheme("package");
36+
mPackageChangedReceiver = new PackageMonitorReceiver();
37+
getApplicationContext().registerReceiver(mPackageChangedReceiver, intentFilter);
38+
}
39+
40+
private void unregisterPackageChangesReceiver() {
41+
if (mPackageChangedReceiver != null) {
42+
getApplicationContext().unregisterReceiver(mPackageChangedReceiver);
43+
mPackageChangedReceiver = null;
44+
}
45+
}
46+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.afwsamples.testdpc;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.text.TextUtils;
7+
8+
import com.afwsamples.testdpc.common.NotificationUtil;
9+
10+
public class PackageMonitorReceiver extends BroadcastReceiver {
11+
private static final String TAG = "PackageMonitorReceiver";
12+
private static final int PACKAGE_CHANGED_NOTIIFICATION_ID = 34857;
13+
14+
@Override
15+
public void onReceive(Context context, Intent intent) {
16+
String action = intent.getAction();
17+
if (!Intent.ACTION_PACKAGE_ADDED.equals(action)
18+
&& !Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
19+
return;
20+
}
21+
String packageName = getPackageNameFromIntent(intent);
22+
if (TextUtils.isEmpty(packageName)) {
23+
return;
24+
}
25+
boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
26+
if (replacing) {
27+
return;
28+
}
29+
String notificationBody = buildNotificationText(context, packageName, action);
30+
NotificationUtil.showNotification(context,
31+
R.string.package_changed_notification_title,
32+
notificationBody,
33+
PACKAGE_CHANGED_NOTIIFICATION_ID);
34+
}
35+
36+
private String getPackageNameFromIntent(Intent intent) {
37+
if (intent.getData() == null) {
38+
return null;
39+
}
40+
return intent.getData().getSchemeSpecificPart();
41+
}
42+
43+
private String buildNotificationText(Context context, String pkgName, String action) {
44+
int res = Intent.ACTION_PACKAGE_ADDED.equals(action)
45+
? R.string.package_added_notification_text
46+
: R.string.package_removed_notification_text;
47+
return context.getString(res, pkgName);
48+
}
49+
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@
5050
import com.afwsamples.testdpc.common.Util;
5151
import com.android.setupwizardlib.SetupWizardLayout;
5252
import com.android.setupwizardlib.view.NavigationBar;
53+
5354
import java.security.SecureRandom;
5455
import java.util.Arrays;
55-
import java.util.List;
56+
import java.util.Collections;
57+
import java.util.Set;
5658

5759
import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE;
5860
import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE;
@@ -292,14 +294,14 @@ private void passAffiliationIds(Intent intent, PersistableBundle adminExtras) {
292294
ComponentName admin = DeviceAdminReceiver.getComponentName(getActivity());
293295
DevicePolicyManager dpm = (DevicePolicyManager)
294296
getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
295-
List<String> ids = dpm.getAffiliationIds(admin);
297+
Set<String> ids = dpm.getAffiliationIds(admin);
296298
String affiliationId = null;
297299
if (ids.size() == 0) {
298300
SecureRandom randomGenerator = new SecureRandom();
299301
affiliationId = Integer.toString(randomGenerator.nextInt(1000000));
300-
dpm.setAffiliationIds(admin, Arrays.asList(affiliationId));
302+
dpm.setAffiliationIds(admin, Collections.singleton(affiliationId));
301303
} else {
302-
affiliationId = ids.get(0);
304+
affiliationId = ids.iterator().next();
303305
}
304306
adminExtras.putString(LaunchIntentUtil.EXTRA_AFFILIATION_ID, affiliationId);
305307
}

0 commit comments

Comments
 (0)