MTK6577+Android4.0之增加重启功能
MTK6577+Android4.0之增加重启功能
长按power按键,弹出下图:
图1
这里要实现增加Reboot的功能,下面记下要实现所做的修改。
1. 在长按power按键弹出的界面增加Reboot界面
首先关机的那个弹出菜单是在
frameworks/base/policy/src/com/android/internal/policy/impl/GlobalActions.java这个文件中的private AlertDialog createDialog(),如下:
/**
* Create the global actions dialog.
* @return A new dialog.
*/
private AlertDialog createDialog() {
mSilentModeAction = newSilentModeAction(mAudioManager, mHandler);
mAirplaneModeOn = new ToggleAction(
R.drawable.ic_lock_airplane_mode,
R.drawable.ic_lock_airplane_mode_off,
R.string.global_actions_toggle_airplane_mode,
R.string.global_actions_airplane_mode_on_status,
R.string.global_actions_airplane_mode_off_status) {
void onToggle(boolean on) {
if (Boolean.parseBoolean(
SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))){
mIsWaitingForEcmExit =true;
// Launch ECM exit dialog
Intent ecmDialogIntent =
new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS,null);
ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(ecmDialogIntent);
} else {
changeAirplaneModeSystemSetting(on);
}
}
@Override
protected voidchangeStateFromPress(boolean buttonOn) {
// In ECM mode airplane statecannot be changed
if (!(Boolean.parseBoolean(
SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))) {
mState = buttonOn ?State.TurningOn : State.TurningOff;
mAirplaneState = mState;
}
}
public boolean showDuringKeyguard(){
return true;
}
public booleanshowBeforeProvisioning() {
return false;
}
//M{
public boolean isEnabled() {
if(KeyguardUpdateMonitor.dual_sim_setting == 0){
Log.e(TAG, "if userunselect the dual sim mode setting on phone starting, the airplane mode can notbe set.");
return false; //if user hasnot yet selected any item in the dual_sim_mode_setting dialog on phonestarting, the airplane mode should be disabled.
}
else {
returnsuper.isEnabled();
}
}
//}M
};
mItems = new ArrayList<Action>();
// first: power off
mItems.add(
new SinglePressAction(
com.android.internal.R.drawable.ic_lock_power_off,
R.string.global_action_power_off) {
public void onPress() {
// shutdown by making sureradio and power are handled accordingly.
ShutdownThread.shutdown(mContext, true);
}
public booleanshowDuringKeyguard() {
return true;
}
public booleanshowBeforeProvisioning() {
return true;
}
});
// next: airplane mode
mItems.add(mAirplaneModeOn);
// last: silent mode
if (SHOW_SILENT_TOGGLE) {
mItems.add(mSilentModeAction);
}
mAdapter = new MyAdapter();
final AlertDialog.Builder ab = newAlertDialog.Builder(mContext);
ab.setAdapter(mAdapter, this)
.setInverseBackgroundForced(true);
final AlertDialog dialog = ab.create();
dialog.getListView().setItemsCanFocus(true);
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
dialog.setOnDismissListener(this);
return dialog;
}上面的代码在// first: power off和// next: airplane mode之间增加了reboot部分,代码如下:
// second:reboot,kandi add at 2015.01.21
mItems.add(
new SinglePressAction(
com.android.internal.R.drawable.ic_lock_reboot,
R.string.global_action_reboot) {
public void onPress() {
// shutdown by making sureradio and power are handled accordingly.
ShutdownThread.reboot(mContext,null, true);
}
public booleanshowDuringKeyguard() {
return true;
}
public booleanshowBeforeProvisioning() {
return true;
}
});此代码主要阐述下面几点:
(1) 增加字符串global_action_reboot和图片资源ic_lock_reboot,这些的定义在后面描述。
(2) ShutdownThread.reboot(mContext,null, true)此函数是调用
/**
* Request a clean shutdown, waiting forsubsystems to clean up their
* state etc. Must be called from a Looper thread in whichits UI
* is shown.
*
* @param context Context used to displaythe shutdown progress dialog.
* @param reason code to pass to the kernel(e.g. "recovery"), or null.
* @param confirm true if user confirmationis needed before shutting down.
*/
public static void reboot(final Contextcontext, String reason, boolean confirm) {
mReboot = true;
mRebootReason = reason;
shutdown(context, confirm);
}reason 如果值为是null,正常重启;如果是recovery,系统重启进入recovery mode
confirm true显示关机提示框,需要用户;false不显示提示框,直接关机。
2. 增加点击Reboot后的重启
为了在按下重启选项之后,能出现”重启“之类的提示,还需要修改\frameworks\base\core\java\com\android\internal\app\ ShutdownThread.java中的shutdown函数和beginShutdownSequence函数:
(1) shutdown函数
修改之前
final intresourceId = longPressBehavior == 2
? com.android.internal.R.string.shutdown_confirm_question
: com.android.internal.R.string.shutdown_confirm;
修改之后
final intresourceId = longPressBehavior == 2
? com.android.internal.R.string.shutdown_confirm_question
: (mReboot ?com.android.internal.R.string.reboot_confirm :
com.android.internal.R.string.shutdown_confirm);(2) beginShutdownSequence函数
修改之前:
pd.setTitle(context.getText(com.android.internal.R.string.power_off));
pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
修改之后:
if(mReboot)
{
pd.setTitle(context.getText(com.android.internal.R.string.global_action_reboot));
pd.setMessage(context.getText(com.android.internal.R.string.reboot_progress));
}
else
{
pd.setTitle(context.getText(com.android.internal.R.string.power_off));
pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
}3. 增加字符串和图片资源
(1) 增加字符串
在frameworks/base/core/res/res/values/strings.xml中添加一下字符串:
<stringname="reboot_progress">Reboot...\u2026</string> <stringname="reboot_confirm" product="default">Your phone willReboot.</string> <stringname="reboot_confirm" product="default">Your phone willReboot.</string> <stringname="global_action_reboot">Reboot</string> <stringname="reboot">Reboot2</string>
在\frameworks\base\core\res\res\values\public.xml增加以下字符串
<publictype="drawable" name="ic_menu_sort_by_size"id="0x0108009d" />//已有 <publictype="drawable" name="ic_lock_reboot"id="0x0108009e" />//增加
(2) 增加重启的图片资源
把ic_lock_reboot.png拷贝到\frameworks\base\core\res\res\drawable-hdpi目录下
4. 编译及升级
./mk r dr,然后单独升级system.img