1, 添加reboot
添加reboot可以仿照power off 来写
首先涉及到的几个java文件,文件不多,大家可以先看一下
frameworks/base/core/java/android/view/WindowManagerPolicy.java
frameworks/base/policy/src/com/android/internal/policy/impl/GlobalActions.java
frameworks/base/services/core/java/com/android/server/power/ShutdownThread.java
frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
WindowManagerPolicy.java 文件可以模仿关机写一个接口
public void shutdown(boolean confirm);
public void reboot(boolean confirm);
public void rebootSafeMode(boolean confirm);
GlobalActions.java 文件修改长按power键弹出框的显示列表 直接上代码
private static final String GLOBAL_ACTION_KEY_POWER = "power";
+ private static final String GLOBAL_ACTION_KEY_REBOOT = "reboot";
private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
private static final String GLOBAL_ACTION_KEY_SILENT = "silent";
添加重启选项
if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
mItems.add(new PowerAction());
+ } else if(GLOBAL_ACTION_KEY_REBOOT.equals(actionKey)){
+ mItems.add(new RebootAction());
+ } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
mItems.add(mAirplaneModeOn);
} else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
if (Settings.Global.getInt(mContext.getContentResolver(),
+ private final class RebootAction extends SinglePressAction {
+ private RebootAction() {
+ super(com.android.internal.R.drawable.ic_lock_power_reboot,
+ R.string.global_action_power_reboot);
+ }
+
+ @Override
+ public boolean showDuringKeyguard() {
+ return true;
+ }
+
+ @Override
+ public boolean showBeforeProvisioning() {
+ return true;
+ }
+ @Override
+ public void onPress() {
+ // reboot by making sure radio and power are handled accordingly.
+ mWindowManagerFuncs.reboot(false /* confirm */);
+ }
+ }
显示飞行模式
private void onAirplaneModeChanged() {
// Let the service state callbacks handle the state.
+ if (!mHasTelephony) return;
boolean airplaneModeOn = Settings.Global.getInt(
mContext.getContentResolver(),
这里的常量字符是和config.xml里面对应的,如果config.xml里面配置了相应的字符串,列表就会显示对应的项
+
+
ShutdownThread.java 文件修改的是点击关机或重启的时候显示字串
final int resourceId = mRebootSafeMode
? com.android.internal.R.string.reboot_safemode_confirm
: (longPressBehavior == 2
+ ? (mReboot ? com.android.internal.R.string.reboot_confirm_question : com.android.internal.R.string.shutdown_confirm_question)
+ : (mReboot ? com.android.internal.R.string.reboot_confirm : com.android.internal.R.string.shutdown_confirm));
Log.d(TAG, "Notifying thread to start shutdown longPressBehavior=" + longPressBehavior);
@@ -136,10 +137,13 @@ public final class ShutdownThread extends Thread {
if (sConfirmDialog != null) {
sConfirmDialog.dismiss();
}
sConfirmDialog = new AlertDialog.Builder(context)
.setTitle(mRebootSafeMode
? com.android.internal.R.string.reboot_safemode_title
+ : (mReboot
+ ? com.android.internal.R.string.reboot_title
+ :com.android.internal.R.string.power_off))
.setMessage(resourceId)
.setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
@@ -220,8 +224,8 @@ public final class ShutdownThread extends Thread {
// throw up an indeterminate system dialog to indicate radio is
// shutting down.
ProgressDialog pd = new ProgressDialog(context);
+ pd.setTitle(context.getText(mReboot ? com.android.internal.R.string.reboot_title : com.android.internal.R.string.power_off));
+ pd.setMessage(context.getText(mReboot ? com.android.internal.R.string.reboot_progress : com.android.internal.R.string.shutdown_progress));
pd.setIndeterminate(true);
pd.setCancelable(false);
pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
WindowManagerService.java 修改
+ @Override
+ public void reboot(boolean confirm) {
+ ShutdownThread.reboot(mContext, null, confirm);
+ }
+