systemui关机dialog相关
1、systemui下拉关机按钮
通过Android 布局分析工具发现
按钮布局
base/packages/SystemUI/res-keyguard/layout/footer_actions.xml
按钮初始化和点击事件
frameworks/base/packages/SystemUI/src/com/android/systemui/qs/FooterActionsController.kt
private val powerMenuLite: View = view.findViewById(R.id.pm_lite)
...
powerMenuLite.setOnClickListener(onClickListener)
...
private val onClickListener = View.OnClickListener { v ->
// Don't do anything if the tap looks suspicious.
if (!visible || falsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) {
return@OnClickListener
}
if (v === settingsButtonContainer) {
if (!deviceProvisionedController.isCurrentUserSetup) {
// If user isn't setup just unlock the device and dump them back at SUW.
activityStarter.postQSRunnableDismissingKeyguard {}
return@OnClickListener
}
metricsLogger.action(MetricsProto.MetricsEvent.ACTION_QS_EXPANDED_SETTINGS_LAUNCH)
startSettingsActivity()
} else if (v === powerMenuLite) {
uiEventLogger.log(GlobalActionsDialogLite.GlobalActionsEvent.GA_OPEN_QS)
globalActionsDialog?.showOrHideDialog(false, true, v)
}
}
GlobalActionsDialogLite
globalActionsDialog?.showOrHideDialog(false, true, v)
到这里,就定位到按钮点击跳出关机dialog的地方
2、GlobalActionsDialogLite
frameworks/base/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java
showOrHideDialog
public void showOrHideDialog(boolean keyguardShowing, boolean isDeviceProvisioned,
@Nullable View view) {
mKeyguardShowing = keyguardShowing;
mDeviceProvisioned = isDeviceProvisioned;
if (mDialog != null && mDialog.isShowing()) {
// In order to force global actions to hide on the same affordance press, we must
// register a call to onGlobalActionsShown() first to prevent the default actions
// menu from showing. This will be followed by a subsequent call to
// onGlobalActionsHidden() on dismiss()
mWindowManagerFuncs.onGlobalActionsShown();
mDialog.dismiss();
mDialog = null;
} else {
handleShow(view);
}
}
3、点击事件
从代码看,这是一个adapter适配器
public void onClickItem(int position) {
Action item = mAdapter.getItem(position);
if (!(item instanceof SilentModeTriStateAction)) {
if (mDialog != null) {
// don't dismiss the dialog if we're opening the power options menu
if (!(item instanceof PowerOptionsAction)) {
// Usually clicking an item shuts down the phone, locks, or starts an
// activity. We don't want to animate back into the power button when that
// happens, so we disable the dialog animation before dismissing.
mDialogLaunchAnimator.disableAllCurrentDialogsExitAnimations();
mDialog.dismiss();
}
} else {
Log.w(TAG, "Action clicked while mDialog is null.");
}
item.onPress();
}
}
4、item.onPress()
GlobalActionsDialogLite内部有很多内部类,继承实现了onPress接口,对应真正的点击事件。
关机按钮的实现类如下
@VisibleForTesting
final class ShutDownAction extends SinglePressAction implements LongPressAction {
ShutDownAction() {
super(R.drawable.ic_lock_power_off,
R.string.global_action_power_off);
}
...
...
@Override
public void onPress() {
mUiEventLogger.log(GlobalActionsEvent.GA_SHUTDOWN_PRESS);
// shutdown by making sure radio and power are handled accordingly.
mWindowManagerFuncs.shutdown();
}
}
5、GlobalActionsComponent
frameworks/base/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsComponent.java
@Override
public void shutdown() {
/*Skip Monkey Test*/
if (ActivityManager.isUserAMonkey()) {
Log.d(TAG, "Cannot shut down during monkey test");
return;
}
/* @} */
try {
mBarService.shutdown();
} catch (RemoteException e) {
}
}
mBarService.shutdown();最终走到frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java