@@ -127,6 +127,8 @@ public final class BatteryService extends Binder {
127127 private long mDischargeStartTime ;
128128 private int mDischargeStartLevel ;
129129
130+ private boolean mUpdatesStopped ;
131+
130132 private Led mLed ;
131133
132134 private boolean mSentLowBatteryBroadcast = false ;
@@ -231,7 +233,7 @@ private void shutdownIfNoPowerLocked() {
231233 Intent intent = new Intent (Intent .ACTION_REQUEST_SHUTDOWN );
232234 intent .putExtra (Intent .EXTRA_KEY_CONFIRM , false );
233235 intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
234- mContext .startActivity (intent );
236+ mContext .startActivityAsUser (intent , UserHandle . CURRENT );
235237 }
236238 }
237239
@@ -244,16 +246,18 @@ private void shutdownIfOverTempLocked() {
244246 Intent intent = new Intent (Intent .ACTION_REQUEST_SHUTDOWN );
245247 intent .putExtra (Intent .EXTRA_KEY_CONFIRM , false );
246248 intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
247- mContext .startActivity (intent );
249+ mContext .startActivityAsUser (intent , UserHandle . CURRENT );
248250 }
249251 }
250252
251253 private void updateLocked () {
252- // Update the values of mAcOnline, et. all.
253- native_update ();
254+ if (!mUpdatesStopped ) {
255+ // Update the values of mAcOnline, et. all.
256+ native_update ();
254257
255- // Process the new values.
256- processValuesLocked ();
258+ // Process the new values.
259+ processValuesLocked ();
260+ }
257261 }
258262
259263 private void processValuesLocked () {
@@ -543,6 +547,9 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
543547 synchronized (mLock ) {
544548 if (args == null || args .length == 0 || "-a" .equals (args [0 ])) {
545549 pw .println ("Current Battery Service state:" );
550+ if (mUpdatesStopped ) {
551+ pw .println (" (UPDATES STOPPED -- use 'reset' to restart)" );
552+ }
546553 pw .println (" AC powered: " + mAcOnline );
547554 pw .println (" USB powered: " + mUsbOnline );
548555 pw .println (" Wireless powered: " + mWirelessOnline );
@@ -554,35 +561,41 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
554561 pw .println (" voltage:" + mBatteryVoltage );
555562 pw .println (" temperature: " + mBatteryTemperature );
556563 pw .println (" technology: " + mBatteryTechnology );
557- } else if (false ) {
558- // DO NOT SUBMIT WITH THIS TURNED ON
559- if (args .length == 3 && "set" .equals (args [0 ])) {
560- String key = args [1 ];
561- String value = args [2 ];
562- try {
563- boolean update = true ;
564- if ("ac" .equals (key )) {
565- mAcOnline = Integer .parseInt (value ) != 0 ;
566- } else if ("usb" .equals (key )) {
567- mUsbOnline = Integer .parseInt (value ) != 0 ;
568- } else if ("wireless" .equals (key )) {
569- mWirelessOnline = Integer .parseInt (value ) != 0 ;
570- } else if ("status" .equals (key )) {
571- mBatteryStatus = Integer .parseInt (value );
572- } else if ("level" .equals (key )) {
573- mBatteryLevel = Integer .parseInt (value );
574- } else if ("invalid" .equals (key )) {
575- mInvalidCharger = Integer .parseInt (value );
576- } else {
577- update = false ;
578- }
579- if (update ) {
580- processValuesLocked ();
581- }
582- } catch (NumberFormatException ex ) {
583- pw .println ("Bad value: " + value );
564+ } else if (args .length == 3 && "set" .equals (args [0 ])) {
565+ String key = args [1 ];
566+ String value = args [2 ];
567+ try {
568+ boolean update = true ;
569+ if ("ac" .equals (key )) {
570+ mAcOnline = Integer .parseInt (value ) != 0 ;
571+ } else if ("usb" .equals (key )) {
572+ mUsbOnline = Integer .parseInt (value ) != 0 ;
573+ } else if ("wireless" .equals (key )) {
574+ mWirelessOnline = Integer .parseInt (value ) != 0 ;
575+ } else if ("status" .equals (key )) {
576+ mBatteryStatus = Integer .parseInt (value );
577+ } else if ("level" .equals (key )) {
578+ mBatteryLevel = Integer .parseInt (value );
579+ } else if ("invalid" .equals (key )) {
580+ mInvalidCharger = Integer .parseInt (value );
581+ } else {
582+ pw .println ("Unknown set option: " + key );
583+ update = false ;
584584 }
585+ if (update ) {
586+ mUpdatesStopped = true ;
587+ processValuesLocked ();
588+ }
589+ } catch (NumberFormatException ex ) {
590+ pw .println ("Bad value: " + value );
585591 }
592+ } else if (args .length == 1 && "reset" .equals (args [0 ])) {
593+ mUpdatesStopped = false ;
594+ updateLocked ();
595+ } else {
596+ pw .println ("Dump current battery state, or:" );
597+ pw .println (" set ac|usb|wireless|status|level|invalid <value>" );
598+ pw .println (" reset" );
586599 }
587600 }
588601 }
0 commit comments