在 AN 8.0 ,设备首次开机会有一个 即将完成 Android 更新… 的提示(不同的厂商可能不一样),需要去掉,记录下修改的过程。
通过在 frameworks/base
下搜索字符找到
./core/res/res/values-zh-rCN/strings.xml:1060: <string name="android_upgrading_notification_title" msgid="8428357096969413169">"即将完成 Android 更新…"</string>
接着搜索 android_upgrading_notification_title 字段找到调用的代码,
在 frameworks/base/services/core/java/com/android/server/am/PreBootBroadcaster.java
中,
private Handler mHandler = new Handler(UiThread.get().getLooper(), null, true) {
@Override
public void handleMessage(Message msg) {
final Context context = mService.mContext;
final NotificationManager notifManager = context
.getSystemService(NotificationManager.class);
final int max = msg.arg1;
final int index = msg.arg2;
switch (msg.what) {
case MSG_SHOW:
final CharSequence title = context
.getText(R.string.android_upgrading_notification_title);//
final Intent intent = new Intent();
intent.setClassName("com.android.settings",
"com.android.settings.HelpTrampoline");
intent.putExtra(Intent.EXTRA_TEXT, "help_url_upgrading");
final PendingIntent contentIntent;
if (context.getPackageManager().resolveActivity(intent, 0) != null) {
contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
} else {
contentIntent = null;
}
final Notification notif =
new Notification.Builder(mService.mContext,
SystemNotificationChannels.UPDATES)
.setSmallIcon(R.drawable.stat_sys_adb)
.setWhen(0)
.setOngoing(true)
.setTicker(title)
.setColor(context.getColor(
com.android.internal.R.color.system_notification_accent_color))
.setContentTitle(title)
.setContentIntent(contentIntent)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setProgress(max, index, false)
.build();
}
return ; // 直接 return
notifManager.notifyAsUser(TAG, SystemMessage.NOTE_SYSTEM_UPGRADING, notif,
UserHandle.of(mUserId));
break;
case MSG_HIDE:
notifManager.cancelAsUser(TAG, SystemMessage.NOTE_SYSTEM_UPGRADING,
UserHandle.of(mUserId));
break;
}
}
};
简单明了,通过 Notification 创建、显示这个通知。
在 notifManager.notifyAsUser
之前 return 掉即可。