blob: 19b6f8232a9a3d07ff3351243299b41c34ed56b2 [file] [log] [blame]
Jason Monk361915c2017-03-21 20:33:59 -04001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.globalactions;
16
Beverlyae79ab92017-12-11 09:20:02 -050017import android.content.Context;
18import android.os.RemoteException;
19import android.os.ServiceManager;
20
Jason Monk361915c2017-03-21 20:33:59 -040021import com.android.internal.statusbar.IStatusBarService;
22import com.android.systemui.Dependency;
Jason Monk361915c2017-03-21 20:33:59 -040023import com.android.systemui.SystemUI;
24import com.android.systemui.plugins.GlobalActions;
25import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
26import com.android.systemui.statusbar.CommandQueue;
27import com.android.systemui.statusbar.CommandQueue.Callbacks;
28import com.android.systemui.statusbar.policy.ExtensionController;
29import com.android.systemui.statusbar.policy.ExtensionController.Extension;
30
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040031import javax.inject.Inject;
32import javax.inject.Singleton;
33
34/**
35 * Manages power menu plugins and communicates power menu actions to the StatusBar.
36 */
37@Singleton
Jason Monk361915c2017-03-21 20:33:59 -040038public class GlobalActionsComponent extends SystemUI implements Callbacks, GlobalActionsManager {
39
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040040 private final CommandQueue mCommandQueue;
Charles He9851a8d2017-10-10 17:31:30 +010041 private GlobalActions mPlugin;
Jason Monk361915c2017-03-21 20:33:59 -040042 private Extension<GlobalActions> mExtension;
43 private IStatusBarService mBarService;
44
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040045 @Inject
46 public GlobalActionsComponent(Context context, CommandQueue commandQueue) {
Dave Mankoffa5d8a392019-10-10 12:21:09 -040047 super(context);
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040048 mCommandQueue = commandQueue;
Dave Mankoffa5d8a392019-10-10 12:21:09 -040049 }
50
Jason Monk361915c2017-03-21 20:33:59 -040051 @Override
52 public void start() {
53 mBarService = IStatusBarService.Stub.asInterface(
54 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
55 mExtension = Dependency.get(ExtensionController.class).newExtension(GlobalActions.class)
56 .withPlugin(GlobalActions.class)
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040057 .withDefault(() -> new GlobalActionsImpl(mContext, mCommandQueue))
Charles He9851a8d2017-10-10 17:31:30 +010058 .withCallback(this::onExtensionCallback)
Jason Monk361915c2017-03-21 20:33:59 -040059 .build();
Charles He9851a8d2017-10-10 17:31:30 +010060 mPlugin = mExtension.get();
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040061 mCommandQueue.addCallback(this);
Jason Monk361915c2017-03-21 20:33:59 -040062 }
63
Charles He9851a8d2017-10-10 17:31:30 +010064 private void onExtensionCallback(GlobalActions newPlugin) {
65 if (mPlugin != null) {
66 mPlugin.destroy();
67 }
68 mPlugin = newPlugin;
69 }
70
Jason Monk361915c2017-03-21 20:33:59 -040071 @Override
Jason Monkb4302182017-08-04 13:39:17 -040072 public void handleShowShutdownUi(boolean isReboot, String reason) {
73 mExtension.get().showShutdownUi(isReboot, reason);
74 }
75
76 @Override
Jason Monk361915c2017-03-21 20:33:59 -040077 public void handleShowGlobalActionsMenu() {
78 mExtension.get().showGlobalActions(this);
79 }
80
81 @Override
82 public void onGlobalActionsShown() {
83 try {
84 mBarService.onGlobalActionsShown();
85 } catch (RemoteException e) {
86 }
87 }
88
89 @Override
90 public void onGlobalActionsHidden() {
91 try {
92 mBarService.onGlobalActionsHidden();
93 } catch (RemoteException e) {
94 }
95 }
96
97 @Override
98 public void shutdown() {
99 try {
100 mBarService.shutdown();
101 } catch (RemoteException e) {
102 }
103 }
104
105 @Override
106 public void reboot(boolean safeMode) {
107 try {
108 mBarService.reboot(safeMode);
109 } catch (RemoteException e) {
110 }
111 }
112}