Skip to content

Commit 18cea73

Browse files
committed
Merge /usr/local/google/home/ascull/ub-testdpc-oc-release/vendor/unbundled_google/packages/TestDPC into new-version
2 parents 5e5a8ae + 6b1e816 commit 18cea73

File tree

4 files changed

+64
-11
lines changed

4 files changed

+64
-11
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ext {
77
// exactly 1 digit
88
versionMinor = 0
99
// exactly 2 digits
10-
versionBuild = 04
10+
versionBuild = 05
1111
}
1212

1313
android {

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<intent-filter>
5454
<action android:name="android.intent.action.MAIN"/>
5555
<category android:name="android.intent.category.LAUNCHER"/>
56+
<category android:name="android.intent.category.INFO"/>
5657
</intent-filter>
5758
</activity-alias>
5859

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.afwsamples.testdpc;
22

3+
import android.app.Notification;
4+
import android.app.NotificationManager;
35
import android.content.BroadcastReceiver;
46
import android.content.Context;
57
import android.content.Intent;
8+
import android.support.v7.app.NotificationCompat;
9+
import android.support.v7.app.NotificationCompat.Builder;
610
import android.text.TextUtils;
711

812
import com.afwsamples.testdpc.common.NotificationUtil;
@@ -27,10 +31,16 @@ public void onReceive(Context context, Intent intent) {
2731
return;
2832
}
2933
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+
Notification notification = NotificationUtil.getNotificationBuilder(context)
35+
.setSmallIcon(R.drawable.ic_launcher)
36+
.setContentTitle(context.getString(R.string.package_changed_notification_title))
37+
.setContentText(notificationBody)
38+
.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBody))
39+
.setDefaults(Notification.DEFAULT_LIGHTS)
40+
.build();
41+
NotificationManager notificationManager =
42+
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
43+
notificationManager.notify(PACKAGE_CHANGED_NOTIIFICATION_ID, notification);
3444
}
3545

3646
private String getPackageNameFromIntent(Intent intent) {

app/src/main/java/com/afwsamples/testdpc/policy/locktask/KioskModeActivity.java

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import android.content.pm.PackageManager;
3636
import android.os.Build;
3737
import android.os.Bundle;
38+
import android.support.v4.os.BuildCompat;
39+
import android.util.ArrayMap;
3840
import android.util.Log;
3941
import android.view.LayoutInflater;
4042
import android.view.View;
@@ -75,6 +77,13 @@ public class KioskModeActivity extends Activity {
7577
public static final String LOCKED_APP_PACKAGE_LIST
7678
= "com.afwsamples.testdpc.policy.locktask.LOCKED_APP_PACKAGE_LIST";
7779

80+
private static final String[] KIOSK_USER_RESTRICTIONS = {
81+
DISALLOW_SAFE_BOOT,
82+
DISALLOW_FACTORY_RESET,
83+
DISALLOW_ADD_USER,
84+
DISALLOW_MOUNT_PHYSICAL_MEDIA,
85+
DISALLOW_ADJUST_VOLUME };
86+
7887
private ComponentName mAdminComponentName;
7988
private ArrayList<String> mKioskPackages;
8089
private DevicePolicyManager mDevicePolicyManager;
@@ -98,6 +107,7 @@ protected void onCreate(Bundle savedInstanceState) {
98107
}
99108
mKioskPackages.remove(getPackageName());
100109
mKioskPackages.add(getPackageName());
110+
101111
setDefaultKioskPolicies(true);
102112
} else {
103113
// after a reboot there is no need to set the policies again
@@ -164,12 +174,17 @@ private void setUserRestriction(String restriction, boolean disallow) {
164174
}
165175

166176
private void setDefaultKioskPolicies(boolean active) {
167-
// set user restrictions
168-
setUserRestriction(DISALLOW_SAFE_BOOT, active);
169-
setUserRestriction(DISALLOW_FACTORY_RESET, active);
170-
setUserRestriction(DISALLOW_ADD_USER, active);
171-
setUserRestriction(DISALLOW_MOUNT_PHYSICAL_MEDIA, active);
172-
setUserRestriction(DISALLOW_ADJUST_VOLUME, active);
177+
// restore or save previous configuration
178+
if (active) {
179+
saveCurrentConfiguration();
180+
setUserRestriction(DISALLOW_SAFE_BOOT, active);
181+
setUserRestriction(DISALLOW_FACTORY_RESET, active);
182+
setUserRestriction(DISALLOW_ADD_USER, active);
183+
setUserRestriction(DISALLOW_MOUNT_PHYSICAL_MEDIA, active);
184+
setUserRestriction(DISALLOW_ADJUST_VOLUME, active);
185+
} else {
186+
restorePreviousConfiguration();
187+
}
173188

174189
// disable keyguard and status bar
175190
mDevicePolicyManager.setKeyguardDisabled(mAdminComponentName, active);
@@ -198,6 +213,33 @@ private void setDefaultKioskPolicies(boolean active) {
198213
editor.commit();
199214
}
200215

216+
@TargetApi(Build.VERSION_CODES.N)
217+
private void saveCurrentConfiguration() {
218+
if (BuildCompat.isAtLeastN()) {
219+
Bundle settingsBundle = mDevicePolicyManager.getUserRestrictions(mAdminComponentName);
220+
SharedPreferences.Editor editor = getSharedPreferences(KIOSK_PREFERENCE_FILE,
221+
MODE_PRIVATE).edit();
222+
223+
for (String userRestriction : KIOSK_USER_RESTRICTIONS) {
224+
boolean currentSettingValue = settingsBundle.getBoolean(userRestriction);
225+
editor.putBoolean(userRestriction, currentSettingValue);
226+
}
227+
editor.commit();
228+
}
229+
}
230+
231+
private void restorePreviousConfiguration() {
232+
if (BuildCompat.isAtLeastN()) {
233+
SharedPreferences sharedPreferences = getSharedPreferences(KIOSK_PREFERENCE_FILE,
234+
MODE_PRIVATE);
235+
236+
for (String userRestriction : KIOSK_USER_RESTRICTIONS) {
237+
boolean prevSettingValue = sharedPreferences.getBoolean(userRestriction, false);
238+
setUserRestriction(userRestriction, prevSettingValue);
239+
}
240+
}
241+
}
242+
201243
private class KioskAppsArrayAdapter extends ArrayAdapter<String> implements
202244
AdapterView.OnItemClickListener {
203245

0 commit comments

Comments
 (0)