The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jim Miller | 305c78c | 2011-10-16 14:54:38 -0700 | [diff] [blame] | 17 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | package android.app; |
| 19 | |
Benjamin Franz | cde0a2a | 2015-04-23 17:19:48 +0100 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 21 | import android.annotation.SystemService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.os.Binder; |
| 24 | import android.os.RemoteException; |
| 25 | import android.os.IBinder; |
| 26 | import android.os.ServiceManager; |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 27 | import android.util.Slog; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 28 | import android.view.View; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 30 | import com.android.internal.statusbar.IStatusBarService; |
| 31 | |
Benjamin Franz | cde0a2a | 2015-04-23 17:19:48 +0100 | [diff] [blame] | 32 | import java.lang.annotation.Retention; |
| 33 | import java.lang.annotation.RetentionPolicy; |
| 34 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | /** |
| 36 | * Allows an app to control the status bar. |
| 37 | * |
| 38 | * @hide |
| 39 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 40 | @SystemService(Context.STATUS_BAR_SERVICE) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | public class StatusBarManager { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 43 | public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND; |
| 44 | public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS; |
| 45 | public static final int DISABLE_NOTIFICATION_ALERTS |
| 46 | = View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 47 | @Deprecated |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 48 | public static final int DISABLE_NOTIFICATION_TICKER |
| 49 | = View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER; |
| 50 | public static final int DISABLE_SYSTEM_INFO = View.STATUS_BAR_DISABLE_SYSTEM_INFO; |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 51 | public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME; |
| 52 | public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT; |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 53 | public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 54 | public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK; |
Daniel Sandler | d5483c3 | 2012-10-19 16:44:15 -0400 | [diff] [blame] | 55 | public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 57 | @Deprecated |
| 58 | public static final int DISABLE_NAVIGATION = |
| 59 | View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT; |
| 60 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | public static final int DISABLE_NONE = 0x00000000; |
| 62 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 63 | public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS |
| 64 | | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER |
Daniel Sandler | d5483c3 | 2012-10-19 16:44:15 -0400 | [diff] [blame] | 65 | | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK |
| 66 | | DISABLE_SEARCH; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 67 | |
Benjamin Franz | 27cf146 | 2015-04-23 19:36:42 +0100 | [diff] [blame] | 68 | /** |
| 69 | * Flag to disable quick settings. |
| 70 | * |
| 71 | * Setting this flag disables quick settings completely, but does not disable expanding the |
| 72 | * notification shade. |
| 73 | */ |
| 74 | public static final int DISABLE2_QUICK_SETTINGS = 0x00000001; |
| 75 | |
Benjamin Franz | cde0a2a | 2015-04-23 17:19:48 +0100 | [diff] [blame] | 76 | public static final int DISABLE2_NONE = 0x00000000; |
| 77 | |
Benjamin Franz | 27cf146 | 2015-04-23 19:36:42 +0100 | [diff] [blame] | 78 | public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS; |
Benjamin Franz | cde0a2a | 2015-04-23 17:19:48 +0100 | [diff] [blame] | 79 | |
| 80 | @IntDef(flag = true, |
Benjamin Franz | 27cf146 | 2015-04-23 19:36:42 +0100 | [diff] [blame] | 81 | value = {DISABLE2_NONE, DISABLE2_MASK, DISABLE2_QUICK_SETTINGS}) |
Benjamin Franz | cde0a2a | 2015-04-23 17:19:48 +0100 | [diff] [blame] | 82 | @Retention(RetentionPolicy.SOURCE) |
| 83 | public @interface Disable2Flags {} |
| 84 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 85 | public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0; |
Jason Monk | f1ff209 | 2014-04-29 16:50:53 -0400 | [diff] [blame] | 86 | public static final int NAVIGATION_HINT_IME_SHOWN = 1 << 1; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 87 | |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 88 | public static final int WINDOW_STATUS_BAR = 1; |
| 89 | public static final int WINDOW_NAVIGATION_BAR = 2; |
| 90 | |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 91 | public static final int WINDOW_STATE_SHOWING = 0; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 92 | public static final int WINDOW_STATE_HIDING = 1; |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 93 | public static final int WINDOW_STATE_HIDDEN = 2; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 94 | |
Jorim Jaggi | 40aa881 | 2015-09-23 12:59:22 -0700 | [diff] [blame] | 95 | public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0; |
| 96 | public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1; |
| 97 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | private Context mContext; |
Joe Onorato | 25f95f9 | 2010-04-08 18:37:10 -0500 | [diff] [blame] | 99 | private IStatusBarService mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | private IBinder mToken = new Binder(); |
| 101 | |
| 102 | StatusBarManager(Context context) { |
| 103 | mContext = context; |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | private synchronized IStatusBarService getService() { |
| 107 | if (mService == null) { |
| 108 | mService = IStatusBarService.Stub.asInterface( |
| 109 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
| 110 | if (mService == null) { |
| 111 | Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE"); |
| 112 | } |
| 113 | } |
| 114 | return mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags. |
| 119 | * To re-enable everything, pass {@link #DISABLE_NONE}. |
| 120 | */ |
| 121 | public void disable(int what) { |
| 122 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 123 | final IStatusBarService svc = getService(); |
| 124 | if (svc != null) { |
| 125 | svc.disable(what, mToken, mContext.getPackageName()); |
Jim Miller | 305c78c | 2011-10-16 14:54:38 -0700 | [diff] [blame] | 126 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | } catch (RemoteException ex) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 128 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | } |
| 130 | } |
Benjamin Franz | cde0a2a | 2015-04-23 17:19:48 +0100 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags. |
| 134 | * To re-enable everything, pass {@link #DISABLE_NONE}. |
| 135 | * |
| 136 | * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags. |
| 137 | */ |
| 138 | public void disable2(@Disable2Flags int what) { |
| 139 | try { |
| 140 | final IStatusBarService svc = getService(); |
| 141 | if (svc != null) { |
| 142 | svc.disable2(what, mToken, mContext.getPackageName()); |
| 143 | } |
| 144 | } catch (RemoteException ex) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 145 | throw ex.rethrowFromSystemServer(); |
Benjamin Franz | cde0a2a | 2015-04-23 17:19:48 +0100 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | /** |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 150 | * Expand the notifications panel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | */ |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 152 | public void expandNotificationsPanel() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 154 | final IStatusBarService svc = getService(); |
| 155 | if (svc != null) { |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 156 | svc.expandNotificationsPanel(); |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 157 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | } catch (RemoteException ex) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 159 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
| 163 | /** |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 164 | * Collapse the notifications and settings panels. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | */ |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 166 | public void collapsePanels() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 168 | final IStatusBarService svc = getService(); |
| 169 | if (svc != null) { |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 170 | svc.collapsePanels(); |
Svetoslav Ganov | e20a177 | 2012-09-25 16:07:46 -0700 | [diff] [blame] | 171 | } |
| 172 | } catch (RemoteException ex) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 173 | throw ex.rethrowFromSystemServer(); |
Svetoslav Ganov | e20a177 | 2012-09-25 16:07:46 -0700 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
| 177 | /** |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 178 | * Expand the settings panel. |
Svetoslav Ganov | e20a177 | 2012-09-25 16:07:46 -0700 | [diff] [blame] | 179 | */ |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 180 | public void expandSettingsPanel() { |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 181 | expandSettingsPanel(null); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Expand the settings panel and open a subPanel, pass null to just open the settings panel. |
| 186 | */ |
| 187 | public void expandSettingsPanel(String subPanel) { |
Svetoslav Ganov | e20a177 | 2012-09-25 16:07:46 -0700 | [diff] [blame] | 188 | try { |
| 189 | final IStatusBarService svc = getService(); |
| 190 | if (svc != null) { |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 191 | svc.expandSettingsPanel(subPanel); |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 192 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | } catch (RemoteException ex) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 194 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | } |
| 196 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 198 | public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 200 | final IStatusBarService svc = getService(); |
| 201 | if (svc != null) { |
| 202 | svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel, |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 203 | contentDescription); |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 204 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | } catch (RemoteException ex) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 206 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 210 | public void removeIcon(String slot) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 212 | final IStatusBarService svc = getService(); |
| 213 | if (svc != null) { |
| 214 | svc.removeIcon(slot); |
| 215 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | } catch (RemoteException ex) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 217 | throw ex.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | } |
| 219 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 220 | |
| 221 | public void setIconVisibility(String slot, boolean visible) { |
| 222 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 223 | final IStatusBarService svc = getService(); |
| 224 | if (svc != null) { |
| 225 | svc.setIconVisibility(slot, visible); |
| 226 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 227 | } catch (RemoteException ex) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 228 | throw ex.rethrowFromSystemServer(); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 229 | } |
| 230 | } |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 231 | |
| 232 | /** @hide */ |
| 233 | public static String windowStateToString(int state) { |
| 234 | if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING"; |
| 235 | if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN"; |
| 236 | if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING"; |
| 237 | return "WINDOW_STATE_UNKNOWN"; |
| 238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | } |