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