2009-07-30 01:21:08 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.server;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2012-10-03 16:38:22 -07:00
|
|
|
import android.content.Context;
|
2009-07-30 01:21:08 -07:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
2012-10-03 16:38:22 -07:00
|
|
|
import android.os.IPowerManager;
|
|
|
|
import android.os.RemoteException;
|
|
|
|
import android.os.ServiceManager;
|
2010-02-26 18:56:32 -08:00
|
|
|
import android.util.Slog;
|
2012-05-11 18:42:42 -07:00
|
|
|
|
2012-06-18 18:29:13 -07:00
|
|
|
import com.android.server.power.ShutdownThread;
|
2009-07-30 01:21:08 -07:00
|
|
|
|
|
|
|
public class ShutdownActivity extends Activity {
|
|
|
|
|
|
|
|
private static final String TAG = "ShutdownActivity";
|
2010-09-08 07:21:07 -04:00
|
|
|
private boolean mReboot;
|
2009-07-30 01:21:08 -07:00
|
|
|
private boolean mConfirm;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2010-09-08 07:21:07 -04:00
|
|
|
Intent intent = getIntent();
|
|
|
|
mReboot = Intent.ACTION_REBOOT.equals(intent.getAction());
|
|
|
|
mConfirm = intent.getBooleanExtra(Intent.EXTRA_KEY_CONFIRM, false);
|
2010-02-26 18:56:32 -08:00
|
|
|
Slog.i(TAG, "onCreate(): confirm=" + mConfirm);
|
2009-07-30 01:21:08 -07:00
|
|
|
|
2012-10-03 16:38:22 -07:00
|
|
|
Thread thr = new Thread("ShutdownActivity") {
|
|
|
|
@Override
|
2009-07-30 01:21:08 -07:00
|
|
|
public void run() {
|
2012-10-03 16:38:22 -07:00
|
|
|
IPowerManager pm = IPowerManager.Stub.asInterface(
|
|
|
|
ServiceManager.getService(Context.POWER_SERVICE));
|
|
|
|
try {
|
|
|
|
if (mReboot) {
|
|
|
|
pm.reboot(mConfirm, null, false);
|
|
|
|
} else {
|
|
|
|
pm.shutdown(mConfirm, false);
|
|
|
|
}
|
|
|
|
} catch (RemoteException e) {
|
2010-09-08 07:21:07 -04:00
|
|
|
}
|
2009-07-30 01:21:08 -07:00
|
|
|
}
|
2012-10-03 16:38:22 -07:00
|
|
|
};
|
|
|
|
thr.start();
|
|
|
|
finish();
|
|
|
|
// Wait for us to tell the power manager to shutdown.
|
|
|
|
try {
|
|
|
|
thr.join();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
}
|
2009-07-30 01:21:08 -07:00
|
|
|
}
|
|
|
|
}
|