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 | |
| 20 | import android.content.Context; |
| 21 | import android.os.Binder; |
| 22 | import android.os.RemoteException; |
| 23 | import android.os.IBinder; |
| 24 | import android.os.ServiceManager; |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 25 | import android.util.Slog; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 26 | import android.view.View; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 28 | import com.android.internal.statusbar.IStatusBarService; |
| 29 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | /** |
| 31 | * Allows an app to control the status bar. |
| 32 | * |
| 33 | * @hide |
| 34 | */ |
| 35 | public class StatusBarManager { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 37 | public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND; |
| 38 | public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS; |
| 39 | public static final int DISABLE_NOTIFICATION_ALERTS |
| 40 | = View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS; |
| 41 | public static final int DISABLE_NOTIFICATION_TICKER |
| 42 | = View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER; |
| 43 | 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] | 44 | public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME; |
| 45 | public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT; |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 46 | public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 47 | public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK; |
Daniel Sandler | d5483c3 | 2012-10-19 16:44:15 -0400 | [diff] [blame] | 48 | 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] | 49 | |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 50 | @Deprecated |
| 51 | public static final int DISABLE_NAVIGATION = |
| 52 | View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT; |
| 53 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | public static final int DISABLE_NONE = 0x00000000; |
| 55 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 56 | public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS |
| 57 | | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER |
Daniel Sandler | d5483c3 | 2012-10-19 16:44:15 -0400 | [diff] [blame] | 58 | | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK |
| 59 | | DISABLE_SEARCH; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 60 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 61 | public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0; |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame] | 62 | |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 63 | public static final int WINDOW_STATUS_BAR = 1; |
| 64 | public static final int WINDOW_NAVIGATION_BAR = 2; |
| 65 | |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 66 | public static final int WINDOW_STATE_SHOWING = 0; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 67 | public static final int WINDOW_STATE_HIDING = 1; |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 68 | public static final int WINDOW_STATE_HIDDEN = 2; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 69 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | private Context mContext; |
Joe Onorato | 25f95f9 | 2010-04-08 18:37:10 -0500 | [diff] [blame] | 71 | private IStatusBarService mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | private IBinder mToken = new Binder(); |
| 73 | |
| 74 | StatusBarManager(Context context) { |
| 75 | mContext = context; |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | private synchronized IStatusBarService getService() { |
| 79 | if (mService == null) { |
| 80 | mService = IStatusBarService.Stub.asInterface( |
| 81 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
| 82 | if (mService == null) { |
| 83 | Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE"); |
| 84 | } |
| 85 | } |
| 86 | return mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags. |
| 91 | * To re-enable everything, pass {@link #DISABLE_NONE}. |
| 92 | */ |
| 93 | public void disable(int what) { |
| 94 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 95 | final IStatusBarService svc = getService(); |
| 96 | if (svc != null) { |
| 97 | svc.disable(what, mToken, mContext.getPackageName()); |
Jim Miller | 305c78c | 2011-10-16 14:54:38 -0700 | [diff] [blame] | 98 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | } catch (RemoteException ex) { |
| 100 | // system process is dead anyway. |
| 101 | throw new RuntimeException(ex); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 106 | * Expand the notifications panel. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | */ |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 108 | public void expandNotificationsPanel() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 110 | final IStatusBarService svc = getService(); |
| 111 | if (svc != null) { |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 112 | svc.expandNotificationsPanel(); |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 113 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | } catch (RemoteException ex) { |
| 115 | // system process is dead anyway. |
| 116 | throw new RuntimeException(ex); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | /** |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 121 | * Collapse the notifications and settings panels. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | */ |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 123 | public void collapsePanels() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 125 | final IStatusBarService svc = getService(); |
| 126 | if (svc != null) { |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 127 | svc.collapsePanels(); |
Svetoslav Ganov | e20a177 | 2012-09-25 16:07:46 -0700 | [diff] [blame] | 128 | } |
| 129 | } catch (RemoteException ex) { |
| 130 | // system process is dead anyway. |
| 131 | throw new RuntimeException(ex); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /** |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 136 | * Expand the settings panel. |
Svetoslav Ganov | e20a177 | 2012-09-25 16:07:46 -0700 | [diff] [blame] | 137 | */ |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 138 | public void expandSettingsPanel() { |
Svetoslav Ganov | e20a177 | 2012-09-25 16:07:46 -0700 | [diff] [blame] | 139 | try { |
| 140 | final IStatusBarService svc = getService(); |
| 141 | if (svc != null) { |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 142 | svc.expandSettingsPanel(); |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 143 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | } catch (RemoteException ex) { |
| 145 | // system process is dead anyway. |
| 146 | throw new RuntimeException(ex); |
| 147 | } |
| 148 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 150 | 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] | 151 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 152 | final IStatusBarService svc = getService(); |
| 153 | if (svc != null) { |
| 154 | svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel, |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 155 | contentDescription); |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 156 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | } catch (RemoteException ex) { |
| 158 | // system process is dead anyway. |
| 159 | throw new RuntimeException(ex); |
| 160 | } |
| 161 | } |
| 162 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 163 | public void removeIcon(String slot) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 165 | final IStatusBarService svc = getService(); |
| 166 | if (svc != null) { |
| 167 | svc.removeIcon(slot); |
| 168 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | } catch (RemoteException ex) { |
| 170 | // system process is dead anyway. |
| 171 | throw new RuntimeException(ex); |
| 172 | } |
| 173 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 174 | |
| 175 | public void setIconVisibility(String slot, boolean visible) { |
| 176 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 177 | final IStatusBarService svc = getService(); |
| 178 | if (svc != null) { |
| 179 | svc.setIconVisibility(slot, visible); |
| 180 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 181 | } catch (RemoteException ex) { |
| 182 | // system process is dead anyway. |
| 183 | throw new RuntimeException(ex); |
| 184 | } |
| 185 | } |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 186 | |
| 187 | /** @hide */ |
| 188 | public static String windowStateToString(int state) { |
| 189 | if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING"; |
| 190 | if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN"; |
| 191 | if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING"; |
| 192 | return "WINDOW_STATE_UNKNOWN"; |
| 193 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | } |