Skip to content

Commit

Permalink
Merge /usr/local/google/home/ascull/ub-testdpc-oc-release/vendor/unbu…
Browse files Browse the repository at this point in the history
…ndled_google/packages/TestDPC into new-version
  • Loading branch information
AndrewScull committed Sep 1, 2017
2 parents 5e5a8ae + 6b1e816 commit 18cea73
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ext {
// exactly 1 digit
versionMinor = 0
// exactly 2 digits
versionBuild = 04
versionBuild = 05
}

android {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.INFO"/>
</intent-filter>
</activity-alias>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.afwsamples.testdpc;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.NotificationCompat;
import android.support.v7.app.NotificationCompat.Builder;
import android.text.TextUtils;

import com.afwsamples.testdpc.common.NotificationUtil;
Expand All @@ -27,10 +31,16 @@ public void onReceive(Context context, Intent intent) {
return;
}
String notificationBody = buildNotificationText(context, packageName, action);
NotificationUtil.showNotification(context,
R.string.package_changed_notification_title,
notificationBody,
PACKAGE_CHANGED_NOTIIFICATION_ID);
Notification notification = NotificationUtil.getNotificationBuilder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(context.getString(R.string.package_changed_notification_title))
.setContentText(notificationBody)
.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBody))
.setDefaults(Notification.DEFAULT_LIGHTS)
.build();
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(PACKAGE_CHANGED_NOTIIFICATION_ID, notification);
}

private String getPackageNameFromIntent(Intent intent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.os.BuildCompat;
import android.util.ArrayMap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -75,6 +77,13 @@ public class KioskModeActivity extends Activity {
public static final String LOCKED_APP_PACKAGE_LIST
= "com.afwsamples.testdpc.policy.locktask.LOCKED_APP_PACKAGE_LIST";

private static final String[] KIOSK_USER_RESTRICTIONS = {
DISALLOW_SAFE_BOOT,
DISALLOW_FACTORY_RESET,
DISALLOW_ADD_USER,
DISALLOW_MOUNT_PHYSICAL_MEDIA,
DISALLOW_ADJUST_VOLUME };

private ComponentName mAdminComponentName;
private ArrayList<String> mKioskPackages;
private DevicePolicyManager mDevicePolicyManager;
Expand All @@ -98,6 +107,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
mKioskPackages.remove(getPackageName());
mKioskPackages.add(getPackageName());

setDefaultKioskPolicies(true);
} else {
// after a reboot there is no need to set the policies again
Expand Down Expand Up @@ -164,12 +174,17 @@ private void setUserRestriction(String restriction, boolean disallow) {
}

private void setDefaultKioskPolicies(boolean active) {
// set user restrictions
setUserRestriction(DISALLOW_SAFE_BOOT, active);
setUserRestriction(DISALLOW_FACTORY_RESET, active);
setUserRestriction(DISALLOW_ADD_USER, active);
setUserRestriction(DISALLOW_MOUNT_PHYSICAL_MEDIA, active);
setUserRestriction(DISALLOW_ADJUST_VOLUME, active);
// restore or save previous configuration
if (active) {
saveCurrentConfiguration();
setUserRestriction(DISALLOW_SAFE_BOOT, active);
setUserRestriction(DISALLOW_FACTORY_RESET, active);
setUserRestriction(DISALLOW_ADD_USER, active);
setUserRestriction(DISALLOW_MOUNT_PHYSICAL_MEDIA, active);
setUserRestriction(DISALLOW_ADJUST_VOLUME, active);
} else {
restorePreviousConfiguration();
}

// disable keyguard and status bar
mDevicePolicyManager.setKeyguardDisabled(mAdminComponentName, active);
Expand Down Expand Up @@ -198,6 +213,33 @@ private void setDefaultKioskPolicies(boolean active) {
editor.commit();
}

@TargetApi(Build.VERSION_CODES.N)
private void saveCurrentConfiguration() {
if (BuildCompat.isAtLeastN()) {
Bundle settingsBundle = mDevicePolicyManager.getUserRestrictions(mAdminComponentName);
SharedPreferences.Editor editor = getSharedPreferences(KIOSK_PREFERENCE_FILE,
MODE_PRIVATE).edit();

for (String userRestriction : KIOSK_USER_RESTRICTIONS) {
boolean currentSettingValue = settingsBundle.getBoolean(userRestriction);
editor.putBoolean(userRestriction, currentSettingValue);
}
editor.commit();
}
}

private void restorePreviousConfiguration() {
if (BuildCompat.isAtLeastN()) {
SharedPreferences sharedPreferences = getSharedPreferences(KIOSK_PREFERENCE_FILE,
MODE_PRIVATE);

for (String userRestriction : KIOSK_USER_RESTRICTIONS) {
boolean prevSettingValue = sharedPreferences.getBoolean(userRestriction, false);
setUserRestriction(userRestriction, prevSettingValue);
}
}
}

private class KioskAppsArrayAdapter extends ArrayAdapter<String> implements
AdapterView.OnItemClickListener {

Expand Down

0 comments on commit 18cea73

Please sign in to comment.