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