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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 49 | @Deprecated |
| 50 | public static final int DISABLE_NAVIGATION = |
| 51 | View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT; |
| 52 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | public static final int DISABLE_NONE = 0x00000000; |
| 54 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 55 | public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS |
| 56 | | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 57 | | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 58 | |
Daniel Sandler | 328310c | 2011-09-23 15:56:52 -0400 | [diff] [blame^] | 59 | public static final int NAVIGATION_HINT_BACK_NOP = 1 << 0; |
| 60 | public static final int NAVIGATION_HINT_HOME_NOP = 1 << 1; |
| 61 | public static final int NAVIGATION_HINT_RECENT_NOP = 1 << 2; |
| 62 | public static final int NAVIGATION_HINT_BACK_ALT = 1 << 3; |
| 63 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | private Context mContext; |
Joe Onorato | 25f95f9 | 2010-04-08 18:37:10 -0500 | [diff] [blame] | 65 | private IStatusBarService mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | private IBinder mToken = new Binder(); |
| 67 | |
| 68 | StatusBarManager(Context context) { |
| 69 | mContext = context; |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | private synchronized IStatusBarService getService() { |
| 73 | if (mService == null) { |
| 74 | mService = IStatusBarService.Stub.asInterface( |
| 75 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
| 76 | if (mService == null) { |
| 77 | Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE"); |
| 78 | } |
| 79 | } |
| 80 | return mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags. |
| 85 | * To re-enable everything, pass {@link #DISABLE_NONE}. |
| 86 | */ |
| 87 | public void disable(int what) { |
| 88 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 89 | final IStatusBarService svc = getService(); |
| 90 | if (svc != null) { |
| 91 | svc.disable(what, mToken, mContext.getPackageName()); |
Jim Miller | 305c78c | 2011-10-16 14:54:38 -0700 | [diff] [blame] | 92 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | } catch (RemoteException ex) { |
| 94 | // system process is dead anyway. |
| 95 | throw new RuntimeException(ex); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Expand the status bar. |
| 101 | */ |
| 102 | public void expand() { |
| 103 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 104 | final IStatusBarService svc = getService(); |
| 105 | if (svc != null) { |
| 106 | svc.expand(); |
| 107 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | } catch (RemoteException ex) { |
| 109 | // system process is dead anyway. |
| 110 | throw new RuntimeException(ex); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Collapse the status bar. |
| 116 | */ |
| 117 | public void collapse() { |
| 118 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 119 | final IStatusBarService svc = getService(); |
| 120 | if (svc != null) { |
| 121 | svc.collapse(); |
| 122 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | } catch (RemoteException ex) { |
| 124 | // system process is dead anyway. |
| 125 | throw new RuntimeException(ex); |
| 126 | } |
| 127 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 129 | 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] | 130 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 131 | final IStatusBarService svc = getService(); |
| 132 | if (svc != null) { |
| 133 | svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel, |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 134 | contentDescription); |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | } catch (RemoteException ex) { |
| 137 | // system process is dead anyway. |
| 138 | throw new RuntimeException(ex); |
| 139 | } |
| 140 | } |
| 141 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 142 | public void removeIcon(String slot) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 144 | final IStatusBarService svc = getService(); |
| 145 | if (svc != null) { |
| 146 | svc.removeIcon(slot); |
| 147 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | } catch (RemoteException ex) { |
| 149 | // system process is dead anyway. |
| 150 | throw new RuntimeException(ex); |
| 151 | } |
| 152 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 153 | |
| 154 | public void setIconVisibility(String slot, boolean visible) { |
| 155 | try { |
Daniel Sandler | 9cbd360 | 2011-10-18 22:59:00 -0400 | [diff] [blame] | 156 | final IStatusBarService svc = getService(); |
| 157 | if (svc != null) { |
| 158 | svc.setIconVisibility(slot, visible); |
| 159 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 160 | } catch (RemoteException ex) { |
| 161 | // system process is dead anyway. |
| 162 | throw new RuntimeException(ex); |
| 163 | } |
| 164 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | } |