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