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.content.Context; 22 import android.os.Binder; 23 import android.os.RemoteException; 24 import android.os.IBinder; 25 import android.os.ServiceManager; 26 import android.util.Slog; 27 import android.view.View; 28 29 import com.android.internal.statusbar.IStatusBarService; 30 31 import java.lang.annotation.Retention; 32 import java.lang.annotation.RetentionPolicy; 33 34 /** 35 * Allows an app to control the status bar. 36 * 37 * @hide 38 */ 39 public class StatusBarManager { 40 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; 45 @Deprecated 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; 49 public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME; 50 public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT; 51 public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK; 52 public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK; 53 public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH; 54 55 @Deprecated 56 public static final int DISABLE_NAVIGATION = 57 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT; 58 59 public static final int DISABLE_NONE = 0x00000000; 60 61 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS 62 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER 63 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK 64 | DISABLE_SEARCH; 65 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 74 public static final int DISABLE2_NONE = 0x00000000; 75 76 public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS; 77 78 @IntDef(flag = true, 79 value = {DISABLE2_NONE, DISABLE2_MASK, DISABLE2_QUICK_SETTINGS}) 80 @Retention(RetentionPolicy.SOURCE) 81 public @interface Disable2Flags {} 82 83 public static final int NAVIGATION_HINT_BACK_ALT = 1 << 0; 84 public static final int NAVIGATION_HINT_IME_SHOWN = 1 << 1; 85 86 public static final int WINDOW_STATUS_BAR = 1; 87 public static final int WINDOW_NAVIGATION_BAR = 2; 88 89 public static final int WINDOW_STATE_SHOWING = 0; 90 public static final int WINDOW_STATE_HIDING = 1; 91 public static final int WINDOW_STATE_HIDDEN = 2; 92 93 private Context mContext; 94 private IStatusBarService mService; 95 private IBinder mToken = new Binder(); 96 StatusBarManager(Context context)97 StatusBarManager(Context context) { 98 mContext = context; 99 } 100 getService()101 private synchronized IStatusBarService getService() { 102 if (mService == null) { 103 mService = IStatusBarService.Stub.asInterface( 104 ServiceManager.getService(Context.STATUS_BAR_SERVICE)); 105 if (mService == null) { 106 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE"); 107 } 108 } 109 return mService; 110 } 111 112 /** 113 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags. 114 * To re-enable everything, pass {@link #DISABLE_NONE}. 115 */ disable(int what)116 public void disable(int what) { 117 try { 118 final IStatusBarService svc = getService(); 119 if (svc != null) { 120 svc.disable(what, mToken, mContext.getPackageName()); 121 } 122 } catch (RemoteException ex) { 123 // system process is dead anyway. 124 throw new RuntimeException(ex); 125 } 126 } 127 128 /** 129 * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags. 130 * To re-enable everything, pass {@link #DISABLE_NONE}. 131 * 132 * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags. 133 */ disable2(@isable2Flags int what)134 public void disable2(@Disable2Flags int what) { 135 try { 136 final IStatusBarService svc = getService(); 137 if (svc != null) { 138 svc.disable2(what, mToken, mContext.getPackageName()); 139 } 140 } catch (RemoteException ex) { 141 // system process is dead anyway. 142 throw new RuntimeException(ex); 143 } 144 } 145 146 /** 147 * Expand the notifications panel. 148 */ expandNotificationsPanel()149 public void expandNotificationsPanel() { 150 try { 151 final IStatusBarService svc = getService(); 152 if (svc != null) { 153 svc.expandNotificationsPanel(); 154 } 155 } catch (RemoteException ex) { 156 // system process is dead anyway. 157 throw new RuntimeException(ex); 158 } 159 } 160 161 /** 162 * Collapse the notifications and settings panels. 163 */ collapsePanels()164 public void collapsePanels() { 165 try { 166 final IStatusBarService svc = getService(); 167 if (svc != null) { 168 svc.collapsePanels(); 169 } 170 } catch (RemoteException ex) { 171 // system process is dead anyway. 172 throw new RuntimeException(ex); 173 } 174 } 175 176 /** 177 * Expand the settings panel. 178 */ expandSettingsPanel()179 public void expandSettingsPanel() { 180 try { 181 final IStatusBarService svc = getService(); 182 if (svc != null) { 183 svc.expandSettingsPanel(); 184 } 185 } catch (RemoteException ex) { 186 // system process is dead anyway. 187 throw new RuntimeException(ex); 188 } 189 } 190 setIcon(String slot, int iconId, int iconLevel, String contentDescription)191 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) { 192 try { 193 final IStatusBarService svc = getService(); 194 if (svc != null) { 195 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel, 196 contentDescription); 197 } 198 } catch (RemoteException ex) { 199 // system process is dead anyway. 200 throw new RuntimeException(ex); 201 } 202 } 203 removeIcon(String slot)204 public void removeIcon(String slot) { 205 try { 206 final IStatusBarService svc = getService(); 207 if (svc != null) { 208 svc.removeIcon(slot); 209 } 210 } catch (RemoteException ex) { 211 // system process is dead anyway. 212 throw new RuntimeException(ex); 213 } 214 } 215 setIconVisibility(String slot, boolean visible)216 public void setIconVisibility(String slot, boolean visible) { 217 try { 218 final IStatusBarService svc = getService(); 219 if (svc != null) { 220 svc.setIconVisibility(slot, visible); 221 } 222 } catch (RemoteException ex) { 223 // system process is dead anyway. 224 throw new RuntimeException(ex); 225 } 226 } 227 228 /** @hide */ windowStateToString(int state)229 public static String windowStateToString(int state) { 230 if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING"; 231 if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN"; 232 if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING"; 233 return "WINDOW_STATE_UNKNOWN"; 234 } 235 } 236