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     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     private Context mContext;
     67     private IStatusBarService mService;
     68     private IBinder mToken = new Binder();
     69 
     70     StatusBarManager(Context context) {
     71         mContext = context;
     72     }
     73 
     74     private synchronized IStatusBarService getService() {
     75         if (mService == null) {
     76             mService = IStatusBarService.Stub.asInterface(
     77                     ServiceManager.getService(Context.STATUS_BAR_SERVICE));
     78             if (mService == null) {
     79                 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
     80             }
     81         }
     82         return mService;
     83     }
     84 
     85     /**
     86      * Disable some features in the status bar.  Pass the bitwise-or of the DISABLE_* flags.
     87      * To re-enable everything, pass {@link #DISABLE_NONE}.
     88      */
     89     public void disable(int what) {
     90         try {
     91             final IStatusBarService svc = getService();
     92             if (svc != null) {
     93                 svc.disable(what, mToken, mContext.getPackageName());
     94             }
     95         } catch (RemoteException ex) {
     96             // system process is dead anyway.
     97             throw new RuntimeException(ex);
     98         }
     99     }
    100 
    101     /**
    102      * Expand the notifications panel.
    103      */
    104     public void expandNotificationsPanel() {
    105         try {
    106             final IStatusBarService svc = getService();
    107             if (svc != null) {
    108                 svc.expandNotificationsPanel();
    109             }
    110         } catch (RemoteException ex) {
    111             // system process is dead anyway.
    112             throw new RuntimeException(ex);
    113         }
    114     }
    115 
    116     /**
    117      * Collapse the notifications and settings panels.
    118      */
    119     public void collapsePanels() {
    120         try {
    121             final IStatusBarService svc = getService();
    122             if (svc != null) {
    123                 svc.collapsePanels();
    124             }
    125         } catch (RemoteException ex) {
    126             // system process is dead anyway.
    127             throw new RuntimeException(ex);
    128         }
    129     }
    130 
    131     /**
    132      * Expand the settings panel.
    133      */
    134     public void expandSettingsPanel() {
    135         try {
    136             final IStatusBarService svc = getService();
    137             if (svc != null) {
    138                 svc.expandSettingsPanel();
    139             }
    140         } catch (RemoteException ex) {
    141             // system process is dead anyway.
    142             throw new RuntimeException(ex);
    143         }
    144     }
    145 
    146     public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
    147         try {
    148             final IStatusBarService svc = getService();
    149             if (svc != null) {
    150                 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
    151                     contentDescription);
    152             }
    153         } catch (RemoteException ex) {
    154             // system process is dead anyway.
    155             throw new RuntimeException(ex);
    156         }
    157     }
    158 
    159     public void removeIcon(String slot) {
    160         try {
    161             final IStatusBarService svc = getService();
    162             if (svc != null) {
    163                 svc.removeIcon(slot);
    164             }
    165         } catch (RemoteException ex) {
    166             // system process is dead anyway.
    167             throw new RuntimeException(ex);
    168         }
    169     }
    170 
    171     public void setIconVisibility(String slot, boolean visible) {
    172         try {
    173             final IStatusBarService svc = getService();
    174             if (svc != null) {
    175                 svc.setIconVisibility(slot, visible);
    176             }
    177         } catch (RemoteException ex) {
    178             // system process is dead anyway.
    179             throw new RuntimeException(ex);
    180         }
    181     }
    182 }
    183