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_ALT = 1 << 0; 62 63 public static final int WINDOW_STATUS_BAR = 1; 64 public static final int WINDOW_NAVIGATION_BAR = 2; 65 66 public static final int WINDOW_STATE_SHOWING = 0; 67 public static final int WINDOW_STATE_HIDING = 1; 68 public static final int WINDOW_STATE_HIDDEN = 2; 69 70 private Context mContext; 71 private IStatusBarService mService; 72 private IBinder mToken = new Binder(); 73 74 StatusBarManager(Context context) { 75 mContext = context; 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; 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 { 95 final IStatusBarService svc = getService(); 96 if (svc != null) { 97 svc.disable(what, mToken, mContext.getPackageName()); 98 } 99 } catch (RemoteException ex) { 100 // system process is dead anyway. 101 throw new RuntimeException(ex); 102 } 103 } 104 105 /** 106 * Expand the notifications panel. 107 */ 108 public void expandNotificationsPanel() { 109 try { 110 final IStatusBarService svc = getService(); 111 if (svc != null) { 112 svc.expandNotificationsPanel(); 113 } 114 } catch (RemoteException ex) { 115 // system process is dead anyway. 116 throw new RuntimeException(ex); 117 } 118 } 119 120 /** 121 * Collapse the notifications and settings panels. 122 */ 123 public void collapsePanels() { 124 try { 125 final IStatusBarService svc = getService(); 126 if (svc != null) { 127 svc.collapsePanels(); 128 } 129 } catch (RemoteException ex) { 130 // system process is dead anyway. 131 throw new RuntimeException(ex); 132 } 133 } 134 135 /** 136 * Expand the settings panel. 137 */ 138 public void expandSettingsPanel() { 139 try { 140 final IStatusBarService svc = getService(); 141 if (svc != null) { 142 svc.expandSettingsPanel(); 143 } 144 } catch (RemoteException ex) { 145 // system process is dead anyway. 146 throw new RuntimeException(ex); 147 } 148 } 149 150 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) { 151 try { 152 final IStatusBarService svc = getService(); 153 if (svc != null) { 154 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel, 155 contentDescription); 156 } 157 } catch (RemoteException ex) { 158 // system process is dead anyway. 159 throw new RuntimeException(ex); 160 } 161 } 162 163 public void removeIcon(String slot) { 164 try { 165 final IStatusBarService svc = getService(); 166 if (svc != null) { 167 svc.removeIcon(slot); 168 } 169 } catch (RemoteException ex) { 170 // system process is dead anyway. 171 throw new RuntimeException(ex); 172 } 173 } 174 175 public void setIconVisibility(String slot, boolean visible) { 176 try { 177 final IStatusBarService svc = getService(); 178 if (svc != null) { 179 svc.setIconVisibility(slot, visible); 180 } 181 } catch (RemoteException ex) { 182 // system process is dead anyway. 183 throw new RuntimeException(ex); 184 } 185 } 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 } 194 } 195