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 49 @Deprecated 50 public static final int DISABLE_NAVIGATION = 51 View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT; 52 53 public static final int DISABLE_NONE = 0x00000000; 54 55 public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS 56 | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER 57 | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK; 58 59 private Context mContext; 60 private IStatusBarService mService; 61 private IBinder mToken = new Binder(); 62 63 StatusBarManager(Context context) { 64 mContext = context; 65 } 66 67 private synchronized IStatusBarService getService() { 68 if (mService == null) { 69 mService = IStatusBarService.Stub.asInterface( 70 ServiceManager.getService(Context.STATUS_BAR_SERVICE)); 71 if (mService == null) { 72 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE"); 73 } 74 } 75 return mService; 76 } 77 78 /** 79 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags. 80 * To re-enable everything, pass {@link #DISABLE_NONE}. 81 */ 82 public void disable(int what) { 83 try { 84 final IStatusBarService svc = getService(); 85 if (svc != null) { 86 svc.disable(what, mToken, mContext.getPackageName()); 87 } 88 } catch (RemoteException ex) { 89 // system process is dead anyway. 90 throw new RuntimeException(ex); 91 } 92 } 93 94 /** 95 * Expand the status bar. 96 */ 97 public void expand() { 98 try { 99 final IStatusBarService svc = getService(); 100 if (svc != null) { 101 svc.expand(); 102 } 103 } catch (RemoteException ex) { 104 // system process is dead anyway. 105 throw new RuntimeException(ex); 106 } 107 } 108 109 /** 110 * Collapse the status bar. 111 */ 112 public void collapse() { 113 try { 114 final IStatusBarService svc = getService(); 115 if (svc != null) { 116 svc.collapse(); 117 } 118 } catch (RemoteException ex) { 119 // system process is dead anyway. 120 throw new RuntimeException(ex); 121 } 122 } 123 124 public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) { 125 try { 126 final IStatusBarService svc = getService(); 127 if (svc != null) { 128 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel, 129 contentDescription); 130 } 131 } catch (RemoteException ex) { 132 // system process is dead anyway. 133 throw new RuntimeException(ex); 134 } 135 } 136 137 public void removeIcon(String slot) { 138 try { 139 final IStatusBarService svc = getService(); 140 if (svc != null) { 141 svc.removeIcon(slot); 142 } 143 } catch (RemoteException ex) { 144 // system process is dead anyway. 145 throw new RuntimeException(ex); 146 } 147 } 148 149 public void setIconVisibility(String slot, boolean visible) { 150 try { 151 final IStatusBarService svc = getService(); 152 if (svc != null) { 153 svc.setIconVisibility(slot, visible); 154 } 155 } catch (RemoteException ex) { 156 // system process is dead anyway. 157 throw new RuntimeException(ex); 158 } 159 } 160 } 161