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; |
| 23 | import com.android.systemui.SysUiServiceProvider; |
| 24 | import com.android.systemui.SystemUI; |
| 25 | import com.android.systemui.plugins.GlobalActions; |
| 26 | import com.android.systemui.plugins.GlobalActions.GlobalActionsManager; |
| 27 | import com.android.systemui.statusbar.CommandQueue; |
| 28 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
| 29 | import com.android.systemui.statusbar.policy.ExtensionController; |
| 30 | import com.android.systemui.statusbar.policy.ExtensionController.Extension; |
| 31 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 32 | public class GlobalActionsComponent extends SystemUI implements Callbacks, GlobalActionsManager { |
| 33 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 34 | private GlobalActions mPlugin; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 35 | private Extension<GlobalActions> mExtension; |
| 36 | private IStatusBarService mBarService; |
| 37 | |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 38 | public GlobalActionsComponent(Context context) { |
| 39 | super(context); |
| 40 | } |
| 41 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 42 | @Override |
| 43 | public void start() { |
| 44 | mBarService = IStatusBarService.Stub.asInterface( |
| 45 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
| 46 | mExtension = Dependency.get(ExtensionController.class).newExtension(GlobalActions.class) |
| 47 | .withPlugin(GlobalActions.class) |
| 48 | .withDefault(() -> new GlobalActionsImpl(mContext)) |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 49 | .withCallback(this::onExtensionCallback) |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 50 | .build(); |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 51 | mPlugin = mExtension.get(); |
Jason Monk | d7c9855 | 2018-12-04 11:14:50 -0500 | [diff] [blame] | 52 | SysUiServiceProvider.getComponent(mContext, CommandQueue.class).addCallback(this); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 53 | } |
| 54 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 55 | private void onExtensionCallback(GlobalActions newPlugin) { |
| 56 | if (mPlugin != null) { |
| 57 | mPlugin.destroy(); |
| 58 | } |
| 59 | mPlugin = newPlugin; |
| 60 | } |
| 61 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 62 | @Override |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 63 | public void handleShowShutdownUi(boolean isReboot, String reason) { |
| 64 | mExtension.get().showShutdownUi(isReboot, reason); |
| 65 | } |
| 66 | |
| 67 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 68 | public void handleShowGlobalActionsMenu() { |
| 69 | mExtension.get().showGlobalActions(this); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public void onGlobalActionsShown() { |
| 74 | try { |
| 75 | mBarService.onGlobalActionsShown(); |
| 76 | } catch (RemoteException e) { |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public void onGlobalActionsHidden() { |
| 82 | try { |
| 83 | mBarService.onGlobalActionsHidden(); |
| 84 | } catch (RemoteException e) { |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public void shutdown() { |
| 90 | try { |
| 91 | mBarService.shutdown(); |
| 92 | } catch (RemoteException e) { |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void reboot(boolean safeMode) { |
| 98 | try { |
| 99 | mBarService.reboot(safeMode); |
| 100 | } catch (RemoteException e) { |
| 101 | } |
| 102 | } |
| 103 | } |