Improving the Reset Demo Warning dialog

Removing explicit call to setView which was distorting the layout
of a standard AlertDialog. Used the correct unicode characted for
apostrophe. Also removed calls to enable demo mode launcher for user 0.

Bug: 29520255
Change-Id: Id876f01f8e51c02634c03fce1ea93a15b111fc27
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index ae2a9e4..a32faf8 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -4382,7 +4382,7 @@
     <!-- Title of the dialog shown when user inactivity times out in retail demo mode [CHAR LIMIT=40] -->
     <string name="demo_user_inactivity_timeout_title">Reset device?</string>
     <!-- Warning message shown when user inactivity times out in retail demo mode [CHAR LIMIT=none] -->
-    <string name="demo_user_inactivity_timeout_countdown">You\'ll lose any changes and the demo will start again in <xliff:g id="timeout" example="9">%1$s</xliff:g> seconds\u2026</string>
+    <string name="demo_user_inactivity_timeout_countdown">You\u2019ll lose any changes and the demo will start again in <xliff:g id="timeout" example="9">%1$s</xliff:g> seconds\u2026</string>
     <!-- Text of button to allow user to abort countdown and continue current session in retail demo mode [CHAR LIMIT=40] -->
     <string name="demo_user_inactivity_timeout_left_button">Cancel</string>
     <!-- Text of button to allow user to abort countdown and immediately start another session in retail demo mode [CHAR LIMIT=40] -->
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index d128252..9a733fc 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -456,7 +456,6 @@
             setUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, true, currentGuestUser.id);
         }
 
-        maybeInitializeDemoMode(UserHandle.USER_SYSTEM);
         mContext.registerReceiver(mDisableQuietModeCallback,
                 new IntentFilter(ACTION_DISABLE_QUIET_MODE_AFTER_UNLOCK),
                 null, mHandler);
@@ -2901,7 +2900,7 @@
     }
 
     private void maybeInitializeDemoMode(int userId) {
-        if (UserManager.isDeviceInDemoMode(mContext)) {
+        if (UserManager.isDeviceInDemoMode(mContext) && userId != UserHandle.USER_SYSTEM) {
             String demoLauncher =
                     mContext.getResources().getString(
                             com.android.internal.R.string.config_demoModeLauncherComponent);
diff --git a/services/retaildemo/java/com/android/server/retaildemo/RetailDemoModeService.java b/services/retaildemo/java/com/android/server/retaildemo/RetailDemoModeService.java
index 51b1e38..d858e82 100644
--- a/services/retaildemo/java/com/android/server/retaildemo/RetailDemoModeService.java
+++ b/services/retaildemo/java/com/android/server/retaildemo/RetailDemoModeService.java
@@ -106,7 +106,7 @@
     private PendingIntent mResetDemoPendingIntent;
     private CameraManager mCameraManager;
     private String[] mCameraIdsWithFlash;
-    private Configuration mPrimaryUserConfiguration;
+    private Configuration mSystemUserConfiguration;
 
     final Object mActivityLock = new Object();
     // Whether the newly created demo user has interacted with the screen yet
@@ -179,8 +179,8 @@
     private void showInactivityCountdownDialog() {
         UserInactivityCountdownDialog dialog = new UserInactivityCountdownDialog(getContext(),
                 WARNING_DIALOG_TIMEOUT, MILLIS_PER_SECOND);
-        dialog.setPositiveButtonClickListener(null);
-        dialog.setNegativeButtonClickListener(new DialogInterface.OnClickListener() {
+        dialog.setNegativeButtonClickListener(null);
+        dialog.setPositiveButtonClickListener(new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
                 mHandler.sendEmptyMessage(MSG_START_NEW_SESSION);
@@ -366,12 +366,12 @@
         }
     }
 
-    private Configuration getPrimaryUsersConfiguration() {
-        if (mPrimaryUserConfiguration == null) {
+    private Configuration getSystemUsersConfiguration() {
+        if (mSystemUserConfiguration == null) {
             Settings.System.getConfiguration(getContext().getContentResolver(),
-                    mPrimaryUserConfiguration = new Configuration());
+                    mSystemUserConfiguration = new Configuration());
         }
-        return mPrimaryUserConfiguration;
+        return mSystemUserConfiguration;
     }
 
     @Override
@@ -424,10 +424,11 @@
             mWakeLock.acquire();
         }
         mCurrentUserId = userId;
-        mNm.notifyAsUser(TAG, 1, createResetNotification(), UserHandle.of(userId));
+        mAmi.updatePersistentConfigurationForUser(getSystemUsersConfiguration(), userId);
         turnOffAllFlashLights();
         muteVolumeStreams();
-        mAmi.updatePersistentConfigurationForUser(getPrimaryUsersConfiguration(), userId);
+        mNm.notifyAsUser(TAG, 1, createResetNotification(), UserHandle.of(userId));
+
         synchronized (mActivityLock) {
             mUserUntouched = true;
         }
diff --git a/services/retaildemo/java/com/android/server/retaildemo/UserInactivityCountdownDialog.java b/services/retaildemo/java/com/android/server/retaildemo/UserInactivityCountdownDialog.java
index e6548b7..d14f4eb 100644
--- a/services/retaildemo/java/com/android/server/retaildemo/UserInactivityCountdownDialog.java
+++ b/services/retaildemo/java/com/android/server/retaildemo/UserInactivityCountdownDialog.java
@@ -20,8 +20,6 @@
 import android.app.Dialog;
 import android.content.Context;
 import android.os.CountDownTimer;
-import android.view.LayoutInflater;
-import android.view.View;
 import android.view.WindowManager;
 import android.widget.TextView;
 
@@ -30,25 +28,23 @@
 public class UserInactivityCountdownDialog extends AlertDialog {
 
     private OnCountDownExpiredListener mOnCountDownExpiredListener;
-    private View mDialogView;
     private CountDownTimer mCountDownTimer;
     private long mCountDownDuration;
     private long mRefreshInterval;
 
     UserInactivityCountdownDialog(Context context, long duration, long refreshInterval) {
         super(context);
-
         mCountDownDuration = duration;
         mRefreshInterval = refreshInterval;
-        mDialogView = LayoutInflater.from(context).inflate(R.layout.alert_dialog, null);
-        String msg = context.getString(R.string.demo_user_inactivity_timeout_countdown, duration);
-        getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+
+        getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
         WindowManager.LayoutParams attrs = getWindow().getAttributes();
         attrs.privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
         getWindow().setAttributes(attrs);
+
         setTitle(R.string.demo_user_inactivity_timeout_title);
-        setView(mDialogView);
-        setMessage(msg);
+        setMessage(getContext().getString(R.string.demo_user_inactivity_timeout_countdown,
+                duration));
     }
 
     public void setOnCountDownExpiredListener(
@@ -58,30 +54,31 @@
 
     public void setPositiveButtonClickListener(OnClickListener onClickListener) {
         setButton(Dialog.BUTTON_POSITIVE,
-                getContext().getString(R.string.demo_user_inactivity_timeout_left_button),
+                getContext().getString(R.string.demo_user_inactivity_timeout_right_button),
                 onClickListener);
     }
 
     public void setNegativeButtonClickListener(OnClickListener onClickListener) {
         setButton(Dialog.BUTTON_NEGATIVE,
-                getContext().getString(R.string.demo_user_inactivity_timeout_right_button),
+                getContext().getString(R.string.demo_user_inactivity_timeout_left_button),
                 onClickListener);
     }
 
     @Override
     public void show() {
         super.show();
-        mDialogView.post(new Runnable() {
+        final TextView messageView = (TextView) findViewById(R.id.message);
+        messageView.post(new Runnable() {
             @Override
             public void run() {
                 mCountDownTimer = new CountDownTimer(mCountDownDuration, mRefreshInterval) {
 
                     @Override
                     public void onTick(long millisUntilFinished) {
-                        String msg = getContext().getResources().getString(
+                        String msg = getContext().getString(
                                 R.string.demo_user_inactivity_timeout_countdown,
                                 millisUntilFinished / 1000);
-                        ((TextView) mDialogView.findViewById(R.id.message)).setText(msg);
+                        messageView.setText(msg);
                     }
 
                     @Override
@@ -96,8 +93,7 @@
     }
 
     @Override
-    public void dismiss() {
-        super.dismiss();
+    public void onStop() {
         if (mCountDownTimer != null) {
             mCountDownTimer.cancel();
         }