Merge "Adding Reset Demo Notification" into nyc-mr1-dev

This commit is contained in:
TreeHugger Robot
2016-05-27 23:57:09 +00:00
committed by Android (Google) Code Review
4 changed files with 44 additions and 1 deletions

View File

@@ -481,6 +481,8 @@
<protected-broadcast android:name="android.intent.action.MANAGED_PROFILE_AVAILABLE" />
<protected-broadcast android:name="android.intent.action.MANAGED_PROFILE_UNAVAILABLE" />
<protected-broadcast android:name="com.android.server.am.ACTION_RESET_DEMO" />
<!-- ====================================================================== -->
<!-- RUNTIME PERMISSIONS -->
<!-- ====================================================================== -->

View File

@@ -4362,6 +4362,11 @@
<!-- The representation of a time duration when negative. An example is -1:14. This can be used with a countdown timer for example.-->
<string name="negative_duration">\u2212<xliff:g id="time" example="1:14">%1$s</xliff:g></string>
<!-- Title of notification to start a new demo session when device is in retail mode [CHAR LIMIT=NONE] -->
<string name="reset_retail_demo_mode_title">Restart Session</string>
<!-- Text of notification to start a new demo session when device is in retail mode [CHAR LIMIT=NONE] -->
<string name="reset_retail_demo_mode_text">Tap to start a new demo session</string>
<!-- Title of notification shown when device has been forced to safe mode after a security compromise. -->
<string name="audit_safemode_notification">Factory reset to use this device without restrictions</string>
<!-- Description of notification shown when device has been forced to safe mode after a security compromise. -->

View File

@@ -1888,6 +1888,8 @@
<java-symbol type="string" name="config_persistentDataPackageName" />
<java-symbol type="string" name="audit_safemode_notification" />
<java-symbol type="string" name="audit_safemode_notification_details" />
<java-symbol type="string" name="reset_retail_demo_mode_title" />
<java-symbol type="string" name="reset_retail_demo_mode_text" />
<java-symbol type="layout" name="resolver_list" />
<java-symbol type="id" name="resolver_list" />

View File

@@ -17,6 +17,9 @@
package com.android.server.am;
import android.app.ActivityManagerNative;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -36,6 +39,7 @@ import android.provider.Settings;
import android.util.Slog;
import com.android.internal.os.BackgroundThread;
import com.android.internal.R;
import com.android.server.ServiceThread;
import com.android.server.SystemService;
import com.android.server.pm.UserManagerService;
@@ -47,15 +51,18 @@ public class RetailDemoModeService extends SystemService {
private static final String TAG = RetailDemoModeService.class.getSimpleName();
private static final String DEMO_USER_NAME = "Demo";
private static final String ACTION_RESET_DEMO = "com.android.server.am.ACTION_RESET_DEMO";
private static final long SCREEN_WAKEUP_DELAY = 5000;
private ActivityManagerService mAms;
private UserManagerService mUms;
private NotificationManager mNm;
private PowerManager mPm;
private PowerManager.WakeLock mWakeLock;
private Handler mHandler;
private ServiceThread mHandlerThread;
private PendingIntent mResetDemoPendingIntent;
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
@@ -75,6 +82,9 @@ public class RetailDemoModeService extends SystemService {
}
}, SCREEN_WAKEUP_DELAY);
break;
case ACTION_RESET_DEMO:
createAndSwitchToDemoUser();
break;
}
}
};
@@ -83,6 +93,26 @@ public class RetailDemoModeService extends SystemService {
super(context);
}
private Notification createResetNotification() {
return new Notification.Builder(getContext())
.setContentTitle(getContext().getString(R.string.reset_retail_demo_mode_title))
.setContentText(getContext().getString(R.string.reset_retail_demo_mode_text))
.setOngoing(true)
.setSmallIcon(R.drawable.platlogo)
.setShowWhen(false)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentIntent(getResetDemoPendingIntent())
.build();
}
private PendingIntent getResetDemoPendingIntent() {
if (mResetDemoPendingIntent == null) {
Intent intent = new Intent(ACTION_RESET_DEMO);
mResetDemoPendingIntent = PendingIntent.getBroadcast(getContext(), 0, intent, 0);
}
return mResetDemoPendingIntent;
}
private void createAndSwitchToDemoUser() {
if (DEBUG) {
Slog.d(TAG, "Switching to a new demo user");
@@ -162,7 +192,8 @@ public class RetailDemoModeService extends SystemService {
private void registerBroadcastReceiver() {
final IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF);
getContext().registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
filter.addAction(ACTION_RESET_DEMO);
getContext().registerReceiver(mBroadcastReceiver, filter);
}
@Override
@@ -184,6 +215,8 @@ public class RetailDemoModeService extends SystemService {
mPm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
mWakeLock = mPm
.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG);
mNm = NotificationManager.from(getContext());
if (UserManager.isDeviceInDemoMode(getContext())) {
createAndSwitchToDemoUser();
}
@@ -208,5 +241,6 @@ public class RetailDemoModeService extends SystemService {
if (!mWakeLock.isHeld()) {
mWakeLock.acquire();
}
mNm.notifyAsUser(TAG, 1, createResetNotification(), UserHandle.of(userId));
}
}