ShutdownThreadpublic final class ShutdownThread extends Thread
Fields Summary |
---|
private static final String | TAG | private static final int | MAX_NUM_PHONE_STATE_READS | private static final int | PHONE_STATE_POLL_SLEEP_MSEC | private static final com.android.internal.telephony.ITelephony | sPhone | private static final android.bluetooth.IBluetoothDevice | sBluetooth | private static Object | sIsStartedGuard | private static boolean | sIsStarted | private static final ShutdownThread | sInstance |
Constructors Summary |
---|
private ShutdownThread()
|
Methods Summary |
---|
private static void | beginShutdownSequence(android.content.Context context)
synchronized (sIsStartedGuard) {
sIsStarted = true;
}
// throw up an indeterminate system dialog to indicate radio is
// shutting down.
ProgressDialog pd = new ProgressDialog(context);
pd.setTitle(context.getText(com.android.internal.R.string.power_off));
pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
pd.setIndeterminate(true);
pd.setCancelable(false);
pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
pd.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
pd.show();
// start the thread that initiates shutdown
sInstance.start();
| public void | run()Makes sure we handle the shutdown gracefully.
Shuts off power regardless of radio and bluetooth state if the alloted time has passed.
boolean bluetoothOff;
boolean radioOff;
try {
bluetoothOff = sBluetooth == null ||
sBluetooth.getBluetoothState() == BluetoothDevice.BLUETOOTH_STATE_OFF;
if (!bluetoothOff) {
sBluetooth.disable(false); // disable but don't persist new state
}
} catch (RemoteException ex) {
Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
bluetoothOff = true;
}
try {
radioOff = sPhone == null || !sPhone.isRadioOn();
if (!radioOff) {
sPhone.setRadio(false);
}
} catch (RemoteException ex) {
Log.e(TAG, "RemoteException during radio shutdown", ex);
radioOff = true;
}
// Wait a max of 32 seconds for clean shutdown
for (int i = 0; i < MAX_NUM_PHONE_STATE_READS; i++) {
if (!bluetoothOff) {
try {
bluetoothOff =
sBluetooth.getBluetoothState() == BluetoothDevice.BLUETOOTH_STATE_OFF;
} catch (RemoteException ex) {
Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
bluetoothOff = true;
}
}
if (!radioOff) {
try {
radioOff = !sPhone.isRadioOn();
} catch (RemoteException ex) {
Log.e(TAG, "RemoteException during radio shutdown", ex);
radioOff = true;
}
}
if (radioOff && bluetoothOff) {
Log.d(TAG, "Radio and Bluetooth shutdown complete.");
break;
}
SystemClock.sleep(PHONE_STATE_POLL_SLEEP_MSEC);
}
//shutdown power
Log.d(TAG, "Shutting down power.");
Power.shutdown();
| public static void | shutdownAfterDisablingRadio(android.content.Context context, boolean confirm)request a shutdown.
// ensure that only one thread is trying to power down.
// any additional calls are just returned
synchronized (sIsStartedGuard){
if (sIsStarted) {
Log.d(TAG, "Request to shutdown already running, returning.");
return;
}
}
Log.d(TAG, "Notifying thread to start radio shutdown");
if (confirm) {
final AlertDialog dialog = new AlertDialog.Builder(context)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(com.android.internal.R.string.power_off)
.setMessage(com.android.internal.R.string.shutdown_confirm)
.setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
beginShutdownSequence(context);
}
})
.setNegativeButton(com.android.internal.R.string.no, null)
.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
dialog.show();
} else {
beginShutdownSequence(context);
}
|
|