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.content.Context; 21 import android.os.Binder; 22 import android.os.RemoteException; 23 import android.os.IBinder; 24 import android.os.ServiceManager; 25 import android.util.Slog; 26 import android.view.View; 27 28 import com.android.internal.statusbar.IStatusBarService; 29 30 /** 31 * Allows an app to control the status bar. 32 * 33 * @hide 34 */ 35 public class StatusBarManager { 36 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; 44 public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME; 45 public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT; 46 public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK; 47 public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK; 48 public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH; 49 50 @Deprecated 51 public static final int DISABLE_NAVIGATION = 52 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT; 53 54 public static final int DISABLE_NONE = 0x00000000; 55 56 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS 57 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER 58 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK 59 | DISABLE_SEARCH; 60 61 public static final int NAVIGATION_HINT_BACK_NOP = 1 << 0; 62 public static final int NAVIGATION_HINT_HOME_NOP = 1 << 1; 63 public static final int NAVIGATION_HINT_RECENT_NOP = 1 << 2; 64 public static final int NAVIGATION_HINT_BACK_ALT = 1 << 3; 65 66 public static final int WINDOW_STATUS_BAR = 1; 67 public static final int WINDOW_NAVIGATION_BAR = 2; 68 69 public static final int WINDOW_STATE_SHOWING = 0; 70 public static final int WINDOW_STATE_HIDING = 1; 71 public static final int WINDOW_STATE_HIDDEN = 2; 72 73 private Context mContext; 74 private IStatusBarService mService; 75 private IBinder mToken = new Binder(); 76 77 StatusBarManager(Context context) { 78 mContext = context; 79 } 80 81 private synchronized IStatusBarService getService() { 82 if (mService == null) { 83 mService = IStatusBarService.Stub.asInterface( 84 ServiceManager.getService(Context.STATUS_BAR_SERVICE)); 85 if (mService == null) { 86 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE"); 87 } 88 } 89 return mService; 90 } 91 92 /** 93 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags. 94 * To re-enable everything, pass {@link #DISABLE_NONE}. 95 */ 96 public void disable(int what) { 97 try { 98 final IStatusBarService svc = getService(); 99 if (svc != null) { 100 svc.disable(what, mToken, mContext.getPackageName()); 101 } 102 } catch (RemoteException ex) { 103 // system process is dead anyway. 104 throw new RuntimeException(ex); 105 } 106 } 107 108 /** 109 * Expand the notifications panel. 110 */ 111 public void expandNotificationsPanel() { 112 try { 113 final IStatusBarService svc = getService(); 114 if (svc != null) { 115 svc.expandNotificationsPanel(); 116 } 117 } catch (RemoteException ex) { 118 // system process is dead anyway. 119 throw new RuntimeException(ex); 120 } 121 } 122 123 /** 124 * Collapse the notifications and settings panels. 125 */ 126 public void collapsePanels() { 127 try { 128 final IStatusBarService svc = getService(); 129 if (svc != null) { 130 svc.collapsePanels(); 131 } 132 } catch (RemoteException ex) { 133 // system process is dead anyway. 134 throw new RuntimeException(ex); 135 } 136 } 137 138 /** 139 * Expand the settings panel. 140 */ 141 public void expandSettingsPanel() { 142 try { 143 final IStatusBarService svc = getService(); 144 if (svc != null) { 145 svc.expandSettingsPanel(); 146 } 147 } catch (RemoteException ex) { 148 // system process is dead anyway. 149 throw new RuntimeException(ex); 150 } 151 } 152 153 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) { 154 try { 155 final IStatusBarService svc = getService(); 156 if (svc != null) { 157 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel, 158 contentDescription); 159 } 160 } catch (RemoteException ex) { 161 // system process is dead anyway. 162 throw new RuntimeException(ex); 163 } 164 } 165 166 public void removeIcon(String slot) { 167 try { 168 final IStatusBarService svc = getService(); 169 if (svc != null) { 170 svc.removeIcon(slot); 171 } 172 } catch (RemoteException ex) { 173 // system process is dead anyway. 174 throw new RuntimeException(ex); 175 } 176 } 177 178 public void setIconVisibility(String slot, boolean visible) { 179 try { 180 final IStatusBarService svc = getService(); 181 if (svc != null) { 182 svc.setIconVisibility(slot, visible); 183 } 184 } catch (RemoteException ex) { 185 // system process is dead anyway. 186 throw new RuntimeException(ex); 187 } 188 } 189 190 /** @hide */ 191 public static String windowStateToString(int state) { 192 if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING"; 193 if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN"; 194 if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING"; 195 return "WINDOW_STATE_UNKNOWN"; 196 } 197 } 198