Home | History | Annotate | Download | only in app
      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 
     26 import com.android.internal.statusbar.IStatusBarService;
     27 
     28 /**
     29  * Allows an app to control the status bar.
     30  *
     31  * @hide
     32  */
     33 public class StatusBarManager {
     34     /**
     35      * Flag for {@link #disable} to make the status bar not expandable.  Unless you also
     36      * set {@link #DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show.
     37      */
     38     public static final int DISABLE_EXPAND = 0x00000001;
     39 
     40     /**
     41      * Flag for {@link #disable} to hide notification icons and scrolling ticker text.
     42      */
     43     public static final int DISABLE_NOTIFICATION_ICONS = 0x00000002;
     44 
     45     /**
     46      * Flag for {@link #disable} to disable incoming notification alerts.  This will not block
     47      * icons, but it will block sound, vibrating and other visual or aural notifications.
     48      */
     49     public static final int DISABLE_NOTIFICATION_ALERTS = 0x00000004;
     50 
     51     /**
     52      * Flag for {@link #disable} to hide only the scrolling ticker.  Note that
     53      * {@link #DISABLE_NOTIFICATION_ICONS} implies {@link #DISABLE_NOTIFICATION_TICKER}.
     54      */
     55     public static final int DISABLE_NOTIFICATION_TICKER = 0x00000008;
     56 
     57     /**
     58      * Re-enable all of the status bar features that you've disabled.
     59      */
     60     public static final int DISABLE_NONE = 0x00000000;
     61 
     62     private Context mContext;
     63     private IStatusBarService mService;
     64     private IBinder mToken = new Binder();
     65 
     66     StatusBarManager(Context context) {
     67         mContext = context;
     68         mService = IStatusBarService.Stub.asInterface(
     69                 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
     70     }
     71 
     72     /**
     73      * Disable some features in the status bar.  Pass the bitwise-or of the DISABLE_* flags.
     74      * To re-enable everything, pass {@link #DISABLE_NONE}.
     75      */
     76     public void disable(int what) {
     77         try {
     78             mService.disable(what, mToken, mContext.getPackageName());
     79         } catch (RemoteException ex) {
     80             // system process is dead anyway.
     81             throw new RuntimeException(ex);
     82         }
     83     }
     84 
     85     /**
     86      * Expand the status bar.
     87      */
     88     public void expand() {
     89         try {
     90             mService.expand();
     91         } catch (RemoteException ex) {
     92             // system process is dead anyway.
     93             throw new RuntimeException(ex);
     94         }
     95     }
     96 
     97     /**
     98      * Collapse the status bar.
     99      */
    100     public void collapse() {
    101         try {
    102             mService.collapse();
    103         } catch (RemoteException ex) {
    104             // system process is dead anyway.
    105             throw new RuntimeException(ex);
    106         }
    107     }
    108 
    109     public void setIcon(String slot, int iconId, int iconLevel) {
    110         try {
    111             mService.setIcon(slot, mContext.getPackageName(), iconId, iconLevel);
    112         } catch (RemoteException ex) {
    113             // system process is dead anyway.
    114             throw new RuntimeException(ex);
    115         }
    116     }
    117 
    118     public void removeIcon(String slot) {
    119         try {
    120             mService.removeIcon(slot);
    121         } catch (RemoteException ex) {
    122             // system process is dead anyway.
    123             throw new RuntimeException(ex);
    124         }
    125     }
    126 
    127     public void setIconVisibility(String slot, boolean visible) {
    128         try {
    129             mService.setIconVisibility(slot, visible);
    130         } catch (RemoteException ex) {
    131             // system process is dead anyway.
    132             throw new RuntimeException(ex);
    133         }
    134     }
    135 }
    136