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; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 22 | import com.android.systemui.SystemUI; |
| 23 | import com.android.systemui.plugins.GlobalActions; |
| 24 | import com.android.systemui.plugins.GlobalActions.GlobalActionsManager; |
| 25 | import com.android.systemui.statusbar.CommandQueue; |
| 26 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 27 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 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; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 32 | import javax.inject.Provider; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 33 | import javax.inject.Singleton; |
| 34 | |
| 35 | /** |
| 36 | * Manages power menu plugins and communicates power menu actions to the StatusBar. |
| 37 | */ |
| 38 | @Singleton |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 39 | public class GlobalActionsComponent extends SystemUI implements Callbacks, GlobalActionsManager { |
| 40 | |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 41 | private final CommandQueue mCommandQueue; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 42 | private final ExtensionController mExtensionController; |
| 43 | private final Provider<GlobalActions> mGlobalActionsProvider; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 44 | private GlobalActions mPlugin; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 45 | private Extension<GlobalActions> mExtension; |
| 46 | private IStatusBarService mBarService; |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 47 | private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 48 | |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 49 | @Inject |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 50 | public GlobalActionsComponent(Context context, CommandQueue commandQueue, |
| 51 | ExtensionController extensionController, |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 52 | Provider<GlobalActions> globalActionsProvider, |
| 53 | StatusBarKeyguardViewManager statusBarKeyguardViewManager) { |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 54 | super(context); |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 55 | mCommandQueue = commandQueue; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 56 | mExtensionController = extensionController; |
| 57 | mGlobalActionsProvider = globalActionsProvider; |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 58 | mStatusBarKeyguardViewManager = statusBarKeyguardViewManager; |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 61 | @Override |
| 62 | public void start() { |
| 63 | mBarService = IStatusBarService.Stub.asInterface( |
| 64 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 65 | mExtension = mExtensionController.newExtension(GlobalActions.class) |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 66 | .withPlugin(GlobalActions.class) |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 67 | .withDefault(mGlobalActionsProvider::get) |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 68 | .withCallback(this::onExtensionCallback) |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 69 | .build(); |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 70 | mPlugin = mExtension.get(); |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 71 | mCommandQueue.addCallback(this); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 74 | private void onExtensionCallback(GlobalActions newPlugin) { |
| 75 | if (mPlugin != null) { |
| 76 | mPlugin.destroy(); |
| 77 | } |
| 78 | mPlugin = newPlugin; |
| 79 | } |
| 80 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 81 | @Override |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 82 | public void handleShowShutdownUi(boolean isReboot, String reason) { |
| 83 | mExtension.get().showShutdownUi(isReboot, reason); |
| 84 | } |
| 85 | |
| 86 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 87 | public void handleShowGlobalActionsMenu() { |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 88 | mStatusBarKeyguardViewManager.setGlobalActionsVisible(true); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 89 | mExtension.get().showGlobalActions(this); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public void onGlobalActionsShown() { |
| 94 | try { |
| 95 | mBarService.onGlobalActionsShown(); |
| 96 | } catch (RemoteException e) { |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public void onGlobalActionsHidden() { |
| 102 | try { |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 103 | mStatusBarKeyguardViewManager.setGlobalActionsVisible(false); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 104 | mBarService.onGlobalActionsHidden(); |
| 105 | } catch (RemoteException e) { |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void shutdown() { |
| 111 | try { |
| 112 | mBarService.shutdown(); |
| 113 | } catch (RemoteException e) { |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void reboot(boolean safeMode) { |
| 119 | try { |
| 120 | mBarService.reboot(safeMode); |
| 121 | } catch (RemoteException e) { |
| 122 | } |
| 123 | } |
| 124 | } |