Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | package com.android.internal.app; |
| 19 | |
| 20 | import android.app.ActivityManagerNative; |
| 21 | import android.app.IActivityManager; |
| 22 | import android.app.ProgressDialog; |
| 23 | import android.app.AlertDialog; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 24 | import android.bluetooth.BluetoothAdapter; |
| 25 | import android.bluetooth.IBluetooth; |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 26 | import android.content.BroadcastReceiver; |
| 27 | import android.content.Context; |
| 28 | import android.content.DialogInterface; |
| 29 | import android.content.Intent; |
| 30 | import android.os.Handler; |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 31 | import android.os.Power; |
Dianne Hackborn | f99ae76 | 2010-03-08 12:43:51 -0800 | [diff] [blame] | 32 | import android.os.PowerManager; |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 33 | import android.os.RemoteException; |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 34 | import android.os.ServiceManager; |
| 35 | import android.os.SystemClock; |
Kenny Root | f547d67 | 2010-09-22 10:36:48 -0700 | [diff] [blame] | 36 | import android.os.SystemProperties; |
Mike Lockwood | a717f64 | 2010-04-01 20:01:44 -0700 | [diff] [blame] | 37 | import android.os.Vibrator; |
San Mehat | b104340 | 2010-02-05 08:26:50 -0800 | [diff] [blame] | 38 | import android.os.storage.IMountService; |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 39 | import android.os.storage.IMountShutdownObserver; |
Dianne Hackborn | 568cae5 | 2009-10-07 16:13:39 -0700 | [diff] [blame] | 40 | |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 41 | import com.android.internal.telephony.ITelephony; |
| 42 | import android.util.Log; |
| 43 | import android.view.WindowManager; |
| 44 | |
| 45 | public final class ShutdownThread extends Thread { |
| 46 | // constants |
| 47 | private static final String TAG = "ShutdownThread"; |
| 48 | private static final int MAX_NUM_PHONE_STATE_READS = 16; |
| 49 | private static final int PHONE_STATE_POLL_SLEEP_MSEC = 500; |
| 50 | // maximum time we wait for the shutdown broadcast before going on. |
| 51 | private static final int MAX_BROADCAST_TIME = 10*1000; |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 52 | private static final int MAX_SHUTDOWN_WAIT_TIME = 20*1000; |
Mike Lockwood | a717f64 | 2010-04-01 20:01:44 -0700 | [diff] [blame] | 53 | |
| 54 | // length of vibration before shutting down |
| 55 | private static final int SHUTDOWN_VIBRATE_MS = 500; |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 56 | |
| 57 | // state tracking |
| 58 | private static Object sIsStartedGuard = new Object(); |
| 59 | private static boolean sIsStarted = false; |
| 60 | |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 61 | private static boolean mReboot; |
| 62 | private static String mRebootReason; |
| 63 | |
Kenny Root | f547d67 | 2010-09-22 10:36:48 -0700 | [diff] [blame] | 64 | // Provides shutdown assurance in case the system_server is killed |
| 65 | public static final String SHUTDOWN_ACTION_PROPERTY = "sys.shutdown.requested"; |
| 66 | |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 67 | // static instance of this thread |
| 68 | private static final ShutdownThread sInstance = new ShutdownThread(); |
| 69 | |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 70 | private final Object mActionDoneSync = new Object(); |
| 71 | private boolean mActionDone; |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 72 | private Context mContext; |
Dianne Hackborn | f99ae76 | 2010-03-08 12:43:51 -0800 | [diff] [blame] | 73 | private PowerManager mPowerManager; |
| 74 | private PowerManager.WakeLock mWakeLock; |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 75 | private Handler mHandler; |
| 76 | |
| 77 | private ShutdownThread() { |
| 78 | } |
| 79 | |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 80 | /** |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 81 | * Request a clean shutdown, waiting for subsystems to clean up their |
| 82 | * state etc. Must be called from a Looper thread in which its UI |
| 83 | * is shown. |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 84 | * |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 85 | * @param context Context used to display the shutdown progress dialog. |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 86 | * @param confirm true if user confirmation is needed before shutting down. |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 87 | */ |
| 88 | public static void shutdown(final Context context, boolean confirm) { |
| 89 | // ensure that only one thread is trying to power down. |
| 90 | // any additional calls are just returned |
Mike Lockwood | d67b236 | 2010-07-26 07:18:21 -0400 | [diff] [blame] | 91 | synchronized (sIsStartedGuard) { |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 92 | if (sIsStarted) { |
| 93 | Log.d(TAG, "Request to shutdown already running, returning."); |
| 94 | return; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | Log.d(TAG, "Notifying thread to start radio shutdown"); |
| 99 | |
| 100 | if (confirm) { |
| 101 | final AlertDialog dialog = new AlertDialog.Builder(context) |
| 102 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 103 | .setTitle(com.android.internal.R.string.power_off) |
| 104 | .setMessage(com.android.internal.R.string.shutdown_confirm) |
| 105 | .setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() { |
| 106 | public void onClick(DialogInterface dialog, int which) { |
| 107 | beginShutdownSequence(context); |
| 108 | } |
| 109 | }) |
| 110 | .setNegativeButton(com.android.internal.R.string.no, null) |
| 111 | .create(); |
| 112 | dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); |
Dianne Hackborn | 568cae5 | 2009-10-07 16:13:39 -0700 | [diff] [blame] | 113 | if (!context.getResources().getBoolean( |
| 114 | com.android.internal.R.bool.config_sf_slowBlur)) { |
| 115 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
| 116 | } |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 117 | dialog.show(); |
| 118 | } else { |
| 119 | beginShutdownSequence(context); |
| 120 | } |
| 121 | } |
| 122 | |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 123 | /** |
| 124 | * Request a clean shutdown, waiting for subsystems to clean up their |
| 125 | * state etc. Must be called from a Looper thread in which its UI |
| 126 | * is shown. |
| 127 | * |
| 128 | * @param context Context used to display the shutdown progress dialog. |
| 129 | * @param reason code to pass to the kernel (e.g. "recovery"), or null. |
| 130 | * @param confirm true if user confirmation is needed before shutting down. |
| 131 | */ |
| 132 | public static void reboot(final Context context, String reason, boolean confirm) { |
| 133 | mReboot = true; |
| 134 | mRebootReason = reason; |
| 135 | shutdown(context, confirm); |
| 136 | } |
| 137 | |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 138 | private static void beginShutdownSequence(Context context) { |
| 139 | synchronized (sIsStartedGuard) { |
Mike Lockwood | d67b236 | 2010-07-26 07:18:21 -0400 | [diff] [blame] | 140 | if (sIsStarted) { |
| 141 | Log.d(TAG, "Request to shutdown already running, returning."); |
| 142 | return; |
| 143 | } |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 144 | sIsStarted = true; |
| 145 | } |
| 146 | |
| 147 | // throw up an indeterminate system dialog to indicate radio is |
| 148 | // shutting down. |
| 149 | ProgressDialog pd = new ProgressDialog(context); |
| 150 | pd.setTitle(context.getText(com.android.internal.R.string.power_off)); |
| 151 | pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress)); |
| 152 | pd.setIndeterminate(true); |
| 153 | pd.setCancelable(false); |
| 154 | pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); |
Dianne Hackborn | 568cae5 | 2009-10-07 16:13:39 -0700 | [diff] [blame] | 155 | if (!context.getResources().getBoolean( |
| 156 | com.android.internal.R.bool.config_sf_slowBlur)) { |
| 157 | pd.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
| 158 | } |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 159 | |
| 160 | pd.show(); |
| 161 | |
| 162 | // start the thread that initiates shutdown |
| 163 | sInstance.mContext = context; |
Dianne Hackborn | f99ae76 | 2010-03-08 12:43:51 -0800 | [diff] [blame] | 164 | sInstance.mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 165 | sInstance.mWakeLock = null; |
| 166 | if (sInstance.mPowerManager.isScreenOn()) { |
| 167 | try { |
| 168 | sInstance.mWakeLock = sInstance.mPowerManager.newWakeLock( |
| 169 | PowerManager.FULL_WAKE_LOCK, "Shutdown"); |
| 170 | sInstance.mWakeLock.acquire(); |
| 171 | } catch (SecurityException e) { |
| 172 | Log.w(TAG, "No permission to acquire wake lock", e); |
| 173 | sInstance.mWakeLock = null; |
| 174 | } |
| 175 | } |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 176 | sInstance.mHandler = new Handler() { |
| 177 | }; |
| 178 | sInstance.start(); |
| 179 | } |
| 180 | |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 181 | void actionDone() { |
| 182 | synchronized (mActionDoneSync) { |
| 183 | mActionDone = true; |
| 184 | mActionDoneSync.notifyAll(); |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 185 | } |
| 186 | } |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 187 | |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 188 | /** |
| 189 | * Makes sure we handle the shutdown gracefully. |
| 190 | * Shuts off power regardless of radio and bluetooth state if the alloted time has passed. |
| 191 | */ |
| 192 | public void run() { |
| 193 | boolean bluetoothOff; |
| 194 | boolean radioOff; |
| 195 | |
| 196 | BroadcastReceiver br = new BroadcastReceiver() { |
| 197 | @Override public void onReceive(Context context, Intent intent) { |
| 198 | // We don't allow apps to cancel this, so ignore the result. |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 199 | actionDone(); |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 200 | } |
| 201 | }; |
Kenny Root | f547d67 | 2010-09-22 10:36:48 -0700 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * Write a system property in case the system_server reboots before we |
| 205 | * get to the actual hardware restart. If that happens, we'll retry at |
| 206 | * the beginning of the SystemServer startup. |
| 207 | */ |
| 208 | { |
| 209 | String reason = (mReboot ? "1" : "0") + (mRebootReason != null ? mRebootReason : ""); |
| 210 | SystemProperties.set(SHUTDOWN_ACTION_PROPERTY, reason); |
| 211 | } |
| 212 | |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 213 | Log.i(TAG, "Sending shutdown broadcast..."); |
| 214 | |
| 215 | // First send the high-level shut down broadcast. |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 216 | mActionDone = false; |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 217 | mContext.sendOrderedBroadcast(new Intent(Intent.ACTION_SHUTDOWN), null, |
| 218 | br, mHandler, 0, null, null); |
| 219 | |
Mike Lockwood | 098e58d | 2010-05-13 16:29:49 -0400 | [diff] [blame] | 220 | final long endTime = SystemClock.elapsedRealtime() + MAX_BROADCAST_TIME; |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 221 | synchronized (mActionDoneSync) { |
| 222 | while (!mActionDone) { |
Mike Lockwood | 098e58d | 2010-05-13 16:29:49 -0400 | [diff] [blame] | 223 | long delay = endTime - SystemClock.elapsedRealtime(); |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 224 | if (delay <= 0) { |
| 225 | Log.w(TAG, "Shutdown broadcast timed out"); |
| 226 | break; |
| 227 | } |
| 228 | try { |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 229 | mActionDoneSync.wait(delay); |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 230 | } catch (InterruptedException e) { |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | Log.i(TAG, "Shutting down activity manager..."); |
| 236 | |
| 237 | final IActivityManager am = |
| 238 | ActivityManagerNative.asInterface(ServiceManager.checkService("activity")); |
| 239 | if (am != null) { |
| 240 | try { |
| 241 | am.shutdown(MAX_BROADCAST_TIME); |
| 242 | } catch (RemoteException e) { |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | final ITelephony phone = |
| 247 | ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 248 | final IBluetooth bluetooth = |
| 249 | IBluetooth.Stub.asInterface(ServiceManager.checkService( |
Nick Pelly | f242b7b | 2009-10-08 00:12:45 +0200 | [diff] [blame] | 250 | BluetoothAdapter.BLUETOOTH_SERVICE)); |
San Mehat | 9f7f7ca | 2010-01-07 11:34:59 -0800 | [diff] [blame] | 251 | |
| 252 | final IMountService mount = |
| 253 | IMountService.Stub.asInterface( |
| 254 | ServiceManager.checkService("mount")); |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 255 | |
| 256 | try { |
| 257 | bluetoothOff = bluetooth == null || |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 258 | bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF; |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 259 | if (!bluetoothOff) { |
| 260 | Log.w(TAG, "Disabling Bluetooth..."); |
| 261 | bluetooth.disable(false); // disable but don't persist new state |
| 262 | } |
| 263 | } catch (RemoteException ex) { |
| 264 | Log.e(TAG, "RemoteException during bluetooth shutdown", ex); |
| 265 | bluetoothOff = true; |
| 266 | } |
| 267 | |
| 268 | try { |
| 269 | radioOff = phone == null || !phone.isRadioOn(); |
| 270 | if (!radioOff) { |
| 271 | Log.w(TAG, "Turning off radio..."); |
| 272 | phone.setRadio(false); |
| 273 | } |
| 274 | } catch (RemoteException ex) { |
| 275 | Log.e(TAG, "RemoteException during radio shutdown", ex); |
| 276 | radioOff = true; |
| 277 | } |
| 278 | |
| 279 | Log.i(TAG, "Waiting for Bluetooth and Radio..."); |
| 280 | |
| 281 | // Wait a max of 32 seconds for clean shutdown |
| 282 | for (int i = 0; i < MAX_NUM_PHONE_STATE_READS; i++) { |
| 283 | if (!bluetoothOff) { |
| 284 | try { |
| 285 | bluetoothOff = |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 286 | bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF; |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 287 | } catch (RemoteException ex) { |
| 288 | Log.e(TAG, "RemoteException during bluetooth shutdown", ex); |
| 289 | bluetoothOff = true; |
| 290 | } |
| 291 | } |
| 292 | if (!radioOff) { |
| 293 | try { |
| 294 | radioOff = !phone.isRadioOn(); |
| 295 | } catch (RemoteException ex) { |
| 296 | Log.e(TAG, "RemoteException during radio shutdown", ex); |
| 297 | radioOff = true; |
| 298 | } |
| 299 | } |
| 300 | if (radioOff && bluetoothOff) { |
| 301 | Log.i(TAG, "Radio and Bluetooth shutdown complete."); |
| 302 | break; |
| 303 | } |
| 304 | SystemClock.sleep(PHONE_STATE_POLL_SLEEP_MSEC); |
| 305 | } |
| 306 | |
San Mehat | 9f7f7ca | 2010-01-07 11:34:59 -0800 | [diff] [blame] | 307 | // Shutdown MountService to ensure media is in a safe state |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 308 | IMountShutdownObserver observer = new IMountShutdownObserver.Stub() { |
| 309 | public void onShutDownComplete(int statusCode) throws RemoteException { |
| 310 | Log.w(TAG, "Result code " + statusCode + " from MountService.shutdown"); |
| 311 | actionDone(); |
San Mehat | 9f7f7ca | 2010-01-07 11:34:59 -0800 | [diff] [blame] | 312 | } |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | Log.i(TAG, "Shutting down MountService"); |
| 316 | // Set initial variables and time out time. |
| 317 | mActionDone = false; |
Mike Lockwood | 098e58d | 2010-05-13 16:29:49 -0400 | [diff] [blame] | 318 | final long endShutTime = SystemClock.elapsedRealtime() + MAX_SHUTDOWN_WAIT_TIME; |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 319 | synchronized (mActionDoneSync) { |
| 320 | try { |
| 321 | if (mount != null) { |
| 322 | mount.shutdown(observer); |
| 323 | } else { |
| 324 | Log.w(TAG, "MountService unavailable for shutdown"); |
| 325 | } |
| 326 | } catch (Exception e) { |
| 327 | Log.e(TAG, "Exception during MountService shutdown", e); |
| 328 | } |
| 329 | while (!mActionDone) { |
Mike Lockwood | 098e58d | 2010-05-13 16:29:49 -0400 | [diff] [blame] | 330 | long delay = endShutTime - SystemClock.elapsedRealtime(); |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 331 | if (delay <= 0) { |
| 332 | Log.w(TAG, "Shutdown wait timed out"); |
| 333 | break; |
| 334 | } |
| 335 | try { |
| 336 | mActionDoneSync.wait(delay); |
| 337 | } catch (InterruptedException e) { |
| 338 | } |
| 339 | } |
San Mehat | 9f7f7ca | 2010-01-07 11:34:59 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Kenny Root | f547d67 | 2010-09-22 10:36:48 -0700 | [diff] [blame] | 342 | rebootOrShutdown(mReboot, mRebootReason); |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Do not call this directly. Use {@link #reboot(Context, String, boolean)} |
| 347 | * or {@link #shutdown(Context, boolean)} instead. |
| 348 | * |
| 349 | * @param reboot true to reboot or false to shutdown |
| 350 | * @param reason reason for reboot |
| 351 | */ |
| 352 | public static void rebootOrShutdown(boolean reboot, String reason) { |
| 353 | if (reboot) { |
| 354 | Log.i(TAG, "Rebooting, reason: " + reason); |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 355 | try { |
Kenny Root | f547d67 | 2010-09-22 10:36:48 -0700 | [diff] [blame] | 356 | Power.reboot(reason); |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 357 | } catch (Exception e) { |
| 358 | Log.e(TAG, "Reboot failed, will attempt shutdown instead", e); |
| 359 | } |
Mike Lockwood | a717f64 | 2010-04-01 20:01:44 -0700 | [diff] [blame] | 360 | } else if (SHUTDOWN_VIBRATE_MS > 0) { |
| 361 | // vibrate before shutting down |
| 362 | Vibrator vibrator = new Vibrator(); |
| 363 | vibrator.vibrate(SHUTDOWN_VIBRATE_MS); |
| 364 | // vibrator is asynchronous so we need to wait to avoid shutting down too soon. |
| 365 | try { |
| 366 | Thread.sleep(SHUTDOWN_VIBRATE_MS); |
Brad Fitzpatrick | e331644 | 2010-10-14 19:40:56 -0700 | [diff] [blame] | 367 | } catch (InterruptedException unused) { |
Mike Lockwood | a717f64 | 2010-04-01 20:01:44 -0700 | [diff] [blame] | 368 | } |
Suchi Amalapurapu | 6ffce2e | 2010-03-08 14:48:40 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | // Shutdown power |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 372 | Log.i(TAG, "Performing low-level shutdown..."); |
| 373 | Power.shutdown(); |
| 374 | } |
| 375 | } |