Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | package com.android.systemui.globalactions; |
| 16 | |
Beverly | ae79ab9 | 2017-12-11 09:20:02 -0500 | [diff] [blame] | 17 | import android.content.Context; |
| 18 | import android.os.RemoteException; |
| 19 | import android.os.ServiceManager; |
| 20 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 21 | import com.android.internal.statusbar.IStatusBarService; |
| 22 | import com.android.systemui.Dependency; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 23 | import com.android.systemui.SystemUI; |
| 24 | import com.android.systemui.plugins.GlobalActions; |
| 25 | import com.android.systemui.plugins.GlobalActions.GlobalActionsManager; |
| 26 | import com.android.systemui.statusbar.CommandQueue; |
| 27 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
| 28 | import com.android.systemui.statusbar.policy.ExtensionController; |
| 29 | import com.android.systemui.statusbar.policy.ExtensionController.Extension; |
| 30 | |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 31 | import javax.inject.Inject; |
| 32 | import javax.inject.Singleton; |
| 33 | |
| 34 | /** |
| 35 | * Manages power menu plugins and communicates power menu actions to the StatusBar. |
| 36 | */ |
| 37 | @Singleton |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 38 | public class GlobalActionsComponent extends SystemUI implements Callbacks, GlobalActionsManager { |
| 39 | |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 40 | private final CommandQueue mCommandQueue; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 41 | private GlobalActions mPlugin; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 42 | private Extension<GlobalActions> mExtension; |
| 43 | private IStatusBarService mBarService; |
| 44 | |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 45 | @Inject |
| 46 | public GlobalActionsComponent(Context context, CommandQueue commandQueue) { |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 47 | super(context); |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 48 | mCommandQueue = commandQueue; |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 51 | @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 Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 57 | .withDefault(() -> new GlobalActionsImpl(mContext, mCommandQueue)) |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 58 | .withCallback(this::onExtensionCallback) |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 59 | .build(); |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 60 | mPlugin = mExtension.get(); |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 61 | mCommandQueue.addCallback(this); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 62 | } |
| 63 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 64 | private void onExtensionCallback(GlobalActions newPlugin) { |
| 65 | if (mPlugin != null) { |
| 66 | mPlugin.destroy(); |
| 67 | } |
| 68 | mPlugin = newPlugin; |
| 69 | } |
| 70 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 71 | @Override |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 72 | public void handleShowShutdownUi(boolean isReboot, String reason) { |
| 73 | mExtension.get().showShutdownUi(isReboot, reason); |
| 74 | } |
| 75 | |
| 76 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 77 | 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 | } |