需求场景
定制案子,长按Power按键,弹出的紧急呼叫按钮需要去掉
如下图所示:
参考资料
这方面的修改,务必了解关机流程、重启流程,作为基础更好了解。之前的文章有过相关分析,可参考:
Android 实现关机和重启功能:
需要修改的文件
frameworks\base\packages\SystemUI\src\com\android\systemui\globalactions\GlobalActionsDialogLite.java
frameworks/base/core/res/res/values/config.xml
解决方案如下:
添加item 到界面的核心方法:
@VisibleForTesting
protected void createActionItems() {
// Simple toggle style if there’s no vibrator, otherwise use a tri-state
if (!mHasVibrator) {
mSilentModeAction = new SilentModeToggleAction();
} else {
mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
}
mAirplaneModeOn = new AirplaneModeAction();
onAirplaneModeChanged();
mItems.clear();
mOverflowItems.clear();
mPowerItems.clear();
String[] defaultActions = getDefaultActions();
ShutDownAction shutdownAction = new ShutDownAction();
RestartAction restartAction = new RestartAction();
ArraySet<String> addedKeys = new ArraySet<>();
List<Action> tempActions = new ArrayList<>();
CurrentUserProvider currentUser = new CurrentUserProvider();
// make sure emergency affordance action is first, if needed
if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
addIfShouldShowAction(tempActions, new EmergencyAffordanceAction());
addedKeys.add(GLOBAL_ACTION_KEY_EMERGENCY);
}
for (int i = 0; i < defaultActions.length; i++) {
String actionKey = defaultActions[i];
if (addedKeys.contains(actionKey)) {
// If we already have added this, don't add it again.
continue;
}
if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {