Merge changes Id876f01f,If7c94cf8 into nyc-mr1-dev

* changes:
  Improving the Reset Demo Warning dialog
  Enabling auto-ota in retail demo mode
This commit is contained in:
TreeHugger Robot
2016-06-29 01:38:01 +00:00
committed by Android (Google) Code Review
5 changed files with 30 additions and 28 deletions

View File

@@ -4382,7 +4382,7 @@
<!-- Title of the dialog shown when user inactivity times out in retail demo mode [CHAR LIMIT=40] --> <!-- 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> <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] --> <!-- 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] --> <!-- 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> <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] --> <!-- Text of button to allow user to abort countdown and immediately start another session in retail demo mode [CHAR LIMIT=40] -->

View File

@@ -456,7 +456,6 @@ public class UserManagerService extends IUserManager.Stub {
setUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, true, currentGuestUser.id); setUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, true, currentGuestUser.id);
} }
maybeInitializeDemoMode(UserHandle.USER_SYSTEM);
mContext.registerReceiver(mDisableQuietModeCallback, mContext.registerReceiver(mDisableQuietModeCallback,
new IntentFilter(ACTION_DISABLE_QUIET_MODE_AFTER_UNLOCK), new IntentFilter(ACTION_DISABLE_QUIET_MODE_AFTER_UNLOCK),
null, mHandler); null, mHandler);
@@ -2901,7 +2900,7 @@ public class UserManagerService extends IUserManager.Stub {
} }
private void maybeInitializeDemoMode(int userId) { private void maybeInitializeDemoMode(int userId) {
if (UserManager.isDeviceInDemoMode(mContext)) { if (UserManager.isDeviceInDemoMode(mContext) && userId != UserHandle.USER_SYSTEM) {
String demoLauncher = String demoLauncher =
mContext.getResources().getString( mContext.getResources().getString(
com.android.internal.R.string.config_demoModeLauncherComponent); com.android.internal.R.string.config_demoModeLauncherComponent);

View File

@@ -8193,6 +8193,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
@Override @Override
public SystemUpdatePolicy getSystemUpdatePolicy() { public SystemUpdatePolicy getSystemUpdatePolicy() {
if (UserManager.isDeviceInDemoMode(mContext)) {
// Pretending to have an automatic update policy when the device is in retail demo
// mode. This will allow the device to download and install an ota without
// any user interaction.
return SystemUpdatePolicy.createAutomaticInstallPolicy();
}
synchronized (this) { synchronized (this) {
SystemUpdatePolicy policy = mOwners.getSystemUpdatePolicy(); SystemUpdatePolicy policy = mOwners.getSystemUpdatePolicy();
if (policy != null && !policy.isValid()) { if (policy != null && !policy.isValid()) {

View File

@@ -106,7 +106,7 @@ public class RetailDemoModeService extends SystemService {
private PendingIntent mResetDemoPendingIntent; private PendingIntent mResetDemoPendingIntent;
private CameraManager mCameraManager; private CameraManager mCameraManager;
private String[] mCameraIdsWithFlash; private String[] mCameraIdsWithFlash;
private Configuration mPrimaryUserConfiguration; private Configuration mSystemUserConfiguration;
final Object mActivityLock = new Object(); final Object mActivityLock = new Object();
// Whether the newly created demo user has interacted with the screen yet // Whether the newly created demo user has interacted with the screen yet
@@ -179,8 +179,8 @@ public class RetailDemoModeService extends SystemService {
private void showInactivityCountdownDialog() { private void showInactivityCountdownDialog() {
UserInactivityCountdownDialog dialog = new UserInactivityCountdownDialog(getContext(), UserInactivityCountdownDialog dialog = new UserInactivityCountdownDialog(getContext(),
WARNING_DIALOG_TIMEOUT, MILLIS_PER_SECOND); WARNING_DIALOG_TIMEOUT, MILLIS_PER_SECOND);
dialog.setPositiveButtonClickListener(null); dialog.setNegativeButtonClickListener(null);
dialog.setNegativeButtonClickListener(new DialogInterface.OnClickListener() { dialog.setPositiveButtonClickListener(new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mHandler.sendEmptyMessage(MSG_START_NEW_SESSION); mHandler.sendEmptyMessage(MSG_START_NEW_SESSION);
@@ -366,12 +366,12 @@ public class RetailDemoModeService extends SystemService {
} }
} }
private Configuration getPrimaryUsersConfiguration() { private Configuration getSystemUsersConfiguration() {
if (mPrimaryUserConfiguration == null) { if (mSystemUserConfiguration == null) {
Settings.System.getConfiguration(getContext().getContentResolver(), Settings.System.getConfiguration(getContext().getContentResolver(),
mPrimaryUserConfiguration = new Configuration()); mSystemUserConfiguration = new Configuration());
} }
return mPrimaryUserConfiguration; return mSystemUserConfiguration;
} }
@Override @Override
@@ -424,10 +424,11 @@ public class RetailDemoModeService extends SystemService {
mWakeLock.acquire(); mWakeLock.acquire();
} }
mCurrentUserId = userId; mCurrentUserId = userId;
mNm.notifyAsUser(TAG, 1, createResetNotification(), UserHandle.of(userId)); mAmi.updatePersistentConfigurationForUser(getSystemUsersConfiguration(), userId);
turnOffAllFlashLights(); turnOffAllFlashLights();
muteVolumeStreams(); muteVolumeStreams();
mAmi.updatePersistentConfigurationForUser(getPrimaryUsersConfiguration(), userId); mNm.notifyAsUser(TAG, 1, createResetNotification(), UserHandle.of(userId));
synchronized (mActivityLock) { synchronized (mActivityLock) {
mUserUntouched = true; mUserUntouched = true;
} }

View File

@@ -20,8 +20,6 @@ import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.TextView; import android.widget.TextView;
@@ -30,25 +28,23 @@ import com.android.internal.R;
public class UserInactivityCountdownDialog extends AlertDialog { public class UserInactivityCountdownDialog extends AlertDialog {
private OnCountDownExpiredListener mOnCountDownExpiredListener; private OnCountDownExpiredListener mOnCountDownExpiredListener;
private View mDialogView;
private CountDownTimer mCountDownTimer; private CountDownTimer mCountDownTimer;
private long mCountDownDuration; private long mCountDownDuration;
private long mRefreshInterval; private long mRefreshInterval;
UserInactivityCountdownDialog(Context context, long duration, long refreshInterval) { UserInactivityCountdownDialog(Context context, long duration, long refreshInterval) {
super(context); super(context);
mCountDownDuration = duration; mCountDownDuration = duration;
mRefreshInterval = refreshInterval; 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_ERROR);
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
WindowManager.LayoutParams attrs = getWindow().getAttributes(); WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; attrs.privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
getWindow().setAttributes(attrs); getWindow().setAttributes(attrs);
setTitle(R.string.demo_user_inactivity_timeout_title); setTitle(R.string.demo_user_inactivity_timeout_title);
setView(mDialogView); setMessage(getContext().getString(R.string.demo_user_inactivity_timeout_countdown,
setMessage(msg); duration));
} }
public void setOnCountDownExpiredListener( public void setOnCountDownExpiredListener(
@@ -58,30 +54,31 @@ public class UserInactivityCountdownDialog extends AlertDialog {
public void setPositiveButtonClickListener(OnClickListener onClickListener) { public void setPositiveButtonClickListener(OnClickListener onClickListener) {
setButton(Dialog.BUTTON_POSITIVE, 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); onClickListener);
} }
public void setNegativeButtonClickListener(OnClickListener onClickListener) { public void setNegativeButtonClickListener(OnClickListener onClickListener) {
setButton(Dialog.BUTTON_NEGATIVE, 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); onClickListener);
} }
@Override @Override
public void show() { public void show() {
super.show(); super.show();
mDialogView.post(new Runnable() { final TextView messageView = (TextView) findViewById(R.id.message);
messageView.post(new Runnable() {
@Override @Override
public void run() { public void run() {
mCountDownTimer = new CountDownTimer(mCountDownDuration, mRefreshInterval) { mCountDownTimer = new CountDownTimer(mCountDownDuration, mRefreshInterval) {
@Override @Override
public void onTick(long millisUntilFinished) { public void onTick(long millisUntilFinished) {
String msg = getContext().getResources().getString( String msg = getContext().getString(
R.string.demo_user_inactivity_timeout_countdown, R.string.demo_user_inactivity_timeout_countdown,
millisUntilFinished / 1000); millisUntilFinished / 1000);
((TextView) mDialogView.findViewById(R.id.message)).setText(msg); messageView.setText(msg);
} }
@Override @Override
@@ -96,8 +93,7 @@ public class UserInactivityCountdownDialog extends AlertDialog {
} }
@Override @Override
public void dismiss() { public void onStop() {
super.dismiss();
if (mCountDownTimer != null) { if (mCountDownTimer != null) {
mCountDownTimer.cancel(); mCountDownTimer.cancel();
} }