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 17 18 package android.app; 19 20 import android.annotation.IntDef; 21 import android.annotation.SystemService; 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; 27 import android.util.Slog; 28 import android.view.View; 29 30 import com.android.internal.statusbar.IStatusBarService; 31 32 import java.lang.annotation.Retention; 33 import java.lang.annotation.RetentionPolicy; 34 35 /** 36 * Allows an app to control the status bar. 37 * 38 * @hide 39 */ 40 @SystemService(Context.STATUS_BAR_SERVICE) 41 public class StatusBarManager { 42 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; 47 @Deprecated 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; 51 public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME; 52 public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT; 53 public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK; 54 public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK; 55 public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH; 56 57 @Deprecated 58 public static final int DISABLE_NAVIGATION = 59 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT; 60 61 public static final int DISABLE_NONE = 0x00000000; 62 63 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS 64 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER 65 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK 66 | DISABLE_SEARCH; 67 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 76 public static final int DISABLE2_NONE = 0x00000000; 77 78 public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS; 79 80 @IntDef(flag = true, 81 value = {DISABLE2_NONE, DISABLE2_MASK, DISABLE2_QUICK_SETTINGS}) 82 @Retention(RetentionPolicy.SOURCE) 83 public @interface Disable2Flags {} 84 85 public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0; 86 public static final int NAVIGATION_HINT_IME_SHOWN = 1 << 1; 87 88 public static final int WINDOW_STATUS_BAR = 1; 89 public static final int WINDOW_NAVIGATION_BAR = 2; 90 91 public static final int WINDOW_STATE_SHOWING = 0; 92 public static final int WINDOW_STATE_HIDING = 1; 93 public static final int WINDOW_STATE_HIDDEN = 2; 94 95 public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0; 96 public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1; 97 98 private Context mContext; 99 private IStatusBarService mService; 100 private IBinder mToken = new Binder(); 101 StatusBarManager(Context context)102 StatusBarManager(Context context) { 103 mContext = context; 104 } 105 getService()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; 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 */ disable(int what)121 public void disable(int what) { 122 try { 123 final IStatusBarService svc = getService(); 124 if (svc != null) { 125 svc.disable(what, mToken, mContext.getPackageName()); 126 } 127 } catch (RemoteException ex) { 128 throw ex.rethrowFromSystemServer(); 129 } 130 } 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 */ disable2(@isable2Flags int what)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) { 145 throw ex.rethrowFromSystemServer(); 146 } 147 } 148 149 /** 150 * Expand the notifications panel. 151 */ expandNotificationsPanel()152 public void expandNotificationsPanel() { 153 try { 154 final IStatusBarService svc = getService(); 155 if (svc != null) { 156 svc.expandNotificationsPanel(); 157 } 158 } catch (RemoteException ex) { 159 throw ex.rethrowFromSystemServer(); 160 } 161 } 162 163 /** 164 * Collapse the notifications and settings panels. 165 */ collapsePanels()166 public void collapsePanels() { 167 try { 168 final IStatusBarService svc = getService(); 169 if (svc != null) { 170 svc.collapsePanels(); 171 } 172 } catch (RemoteException ex) { 173 throw ex.rethrowFromSystemServer(); 174 } 175 } 176 177 /** 178 * Expand the settings panel. 179 */ expandSettingsPanel()180 public void expandSettingsPanel() { 181 expandSettingsPanel(null); 182 } 183 184 /** 185 * Expand the settings panel and open a subPanel, pass null to just open the settings panel. 186 */ expandSettingsPanel(String subPanel)187 public void expandSettingsPanel(String subPanel) { 188 try { 189 final IStatusBarService svc = getService(); 190 if (svc != null) { 191 svc.expandSettingsPanel(subPanel); 192 } 193 } catch (RemoteException ex) { 194 throw ex.rethrowFromSystemServer(); 195 } 196 } 197 setIcon(String slot, int iconId, int iconLevel, String contentDescription)198 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) { 199 try { 200 final IStatusBarService svc = getService(); 201 if (svc != null) { 202 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel, 203 contentDescription); 204 } 205 } catch (RemoteException ex) { 206 throw ex.rethrowFromSystemServer(); 207 } 208 } 209 removeIcon(String slot)210 public void removeIcon(String slot) { 211 try { 212 final IStatusBarService svc = getService(); 213 if (svc != null) { 214 svc.removeIcon(slot); 215 } 216 } catch (RemoteException ex) { 217 throw ex.rethrowFromSystemServer(); 218 } 219 } 220 setIconVisibility(String slot, boolean visible)221 public void setIconVisibility(String slot, boolean visible) { 222 try { 223 final IStatusBarService svc = getService(); 224 if (svc != null) { 225 svc.setIconVisibility(slot, visible); 226 } 227 } catch (RemoteException ex) { 228 throw ex.rethrowFromSystemServer(); 229 } 230 } 231 232 /** @hide */ windowStateToString(int state)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 } 239 } 240