近期一个任务是修改在 system/framework 出现更新的时候,系统重启展示的升级对话框。
第一步,定位文件位置。过程不必赘述,细究起来可以去研究Android系统的启动流程。
目标位置:frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
的4731行的showBootMessage()方法。
public void showBootMessage(final CharSequence msg, final boolean always) {
if (mHeadless) return;
mHandler.post(new Runnable() {
@Override public void run() {
if (mBootMsgDialog == null) {
mBootMsgDialog = new ProgressDialog(mContext) {
// This dialog will consume all events coming in to
// it, to avoid it trying to do things too early in boot.
@Override public boolean dispatchKeyEvent(KeyEvent event) {
return true;
}
@Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
return true;
}
@Override public boolean dispatchTouchEvent(MotionEvent ev) {
return true;
}
@Override public boolean dispatchTrackballEvent(MotionEvent ev) {
return true;
}
@Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
return true;
}
@Override public boolean dispatchPopulateAccessibilityEvent(
AccessibilityEvent event) {
return true;
}
};
mBootMsgDialog.setTitle(R.string.android_upgrading_title);
mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mBootMsgDialog.setIndeterminate(true);
mBootMsgDialog.getWindow().setType(
WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
mBootMsgDialog.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
mBootMsgDialog.getWindow().setDimAmount(1);
WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
mBootMsgDialog.getWindow().setAttributes(lp);
mBootMsgDialog.setCancelable(false);
mBootMsgDialog.show();
WindowManager.LayoutParams wlp = mBootMsgDialog.getWindow().getAttributes(); wlp.width=dip2px(460,mContext);
wlp.height=dip2px(322,mContext);
wlp.gravity= Gravity.CENTER;
mBootMsgDialog.getWindow().setAttributes(wlp); mBootMsgDialog.getWindow().findViewById(R.id.customPanel).setBackgroundColor(mContext.getResources().getColor(R.color.jidou_dialog_transparent));
}
mBootMsgDialog.setMessage(msg);
}
});
}
这里需要注意的是,配置dialog的长宽,和隐藏dialog的背景黑色。最简单的方法请看代码show()和它下面几行的设置。基本上是可以解决问题。注意要先show().
找到了,接下来就是操刀修改了。这个对话框比较简单,截图也比较麻烦,就不上图了。