本文主要是针对android4.2关机菜单添加重启功能
private void handleShow() {
// 本函数不需要修改...
awakenIfNecessary();
mDialog = createDialog();
prepareDialog();
WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
attrs.setTitle("GlobalActions");
mDialog.getWindow().setAttributes(attrs);
mDialog.show();// 关机选择对话框
mDialog.getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_DISABLE_EXPAND);
/****************
如果只需要关机确认可以修改为:
awakenIfNecessary();
mWindowManagerFuncs.shutdown(true);
*******************/
}
private GlobalActionsDialog createDialog() {
....// 省略
// first: power off
mItems.add(
....// 省略
});
/
// second:reboot 添加这一项
try {// 添加try catch 为了避免错误...
mItems.add(
new SinglePressAction(
com.android.internal.R.drawable.ic_lock_power_off,
R.string.global_action_reboot) {
public void onPress() {
// shutdown by making sure radio and power are handled accordingly.
// mWindowManagerFuncs.rebootSafeMode(true);
// mWindowManagerFuncs.reboot(mContext,null,false);
// ShutdownThread.reboot(mContext,null,false);
try {
mWindowManagerFuncs.reboot(true);
} catch (Exception e) {
// TODO: handle exception 如果有问题, 最好在这里打印一些信息看看是不是这里出问题了
}
}
public boolean showDuringKeyguard() {
return true;
}
public boolean showBeforeProvisioning() {
return true;
}
});
} catch (Exception e) {
// TODO: handle exception
}
}
/
public interface WindowManagerFuncs {
public void reboot(boolean confirm);
}
// Called by window manager policy. Not exposed externally.
@Override
public void reboot(boolean confirm) {
ShutdownThread.reboot(mContext, confirm);
}
C. 修改关机时的进度框提示
android4.2/frameworks/base/services/java/com/android/server/power/ShutdownThread.java
/*/
//修改前:
……
pd.setTitle(context.getText(com.android.internal.R.string.power_off));
pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
……
/*/
//修改后:
……
if(mReboot){ // reboot progress
pd.setTitle(context.getText(com.android.internal.R.string.global_action_reboot));
pd.setMessage(context.getText(com.android.internal.R.string.reboot_progress));
}else{ // shutdown progress
pd.setTitle(context.getText(com.android.internal.R.string.power_off));
pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
}
……
//*/
D. 重启询问对话框 // 这部分可能代码不一样 不过都是修改shutdownInner函数里面的sConfirmDialog这个dialog的
shutdownInner(final Context context, boolean confirm)//
if(Settings.Global.getInt(context.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1)==1 &&
SystemProperties.getBoolean("ro.sys.bootfast", false)){
......
// 这部分可能代码不一样 不过都是修改sConfirmDialog这个dialog的
if(mReboot){
idBootMode = com.android.internal.R.string.reboot_confirm_question;
}else{
idBootMode = com.android.internal.R.string.shutdown_confirm_question;
}
sConfirmDialog = new AlertDialog.Builder(context)
.setTitle(mReboot
? com.android.internal.R.string.global_action_reboot
: com.android.internal.R.string.power_off)
.setMessage(idBootMode)
.setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(mPolicy!=null)
mPolicy.acquireBAView();
beginShutdownSequence(context);
}
})
.setNegativeButton(com.android.internal.R.string.no, null)
.create();
}
/说明 无关 只做注释///
/end说明///
F. 重启功能实现了,但是不能到此结束,定制Android系统的重启功能,添加选项和修改重启提示框时加入了“重启”和“正在重启”的字符串,
路径: framework/base/core/res/res/valuse/ or framework/base/core/res/res/values-zh-rCN/
上面是拷贝别人的, 实际上我发现如果不在symbols.xml添加相关的字符串信息, 编译会报错的, 故应该在framework/base/core/res/res/valuse/ symbols.xml参考其他的把自己的添加上:
strings.xml:
"Do you want to reboot?"
"Reboot"
"Rebooting..."
symbols.xml
步骤4.编译frameworks/base/policy,在同样目录下生成android.policy.jar 包
参考:
http://blog.csdn.net/zzp16/article/details/7829063
http://www.2cto.com/kf/201403/288710.html