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 package android.app;
     18 
     19 import android.annotation.IntDef;
     20 import android.annotation.SystemService;
     21 import android.content.Context;
     22 import android.os.Binder;
     23 import android.os.IBinder;
     24 import android.os.RemoteException;
     25 import android.os.ServiceManager;
     26 import android.util.Slog;
     27 import android.view.View;
     28 
     29 import com.android.internal.statusbar.IStatusBarService;
     30 
     31 import java.lang.annotation.Retention;
     32 import java.lang.annotation.RetentionPolicy;
     33 
     34 /**
     35  * Allows an app to control the status bar.
     36  *
     37  * @hide
     38  */
     39 @SystemService(Context.STATUS_BAR_SERVICE)
     40 public class StatusBarManager {
     41 
     42     public static final int DISABLE_EXPAND = View.STATUS_BAR_DISABLE_EXPAND;
     43     public static final int DISABLE_NOTIFICATION_ICONS = View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS;
     44     public static final int DISABLE_NOTIFICATION_ALERTS
     45             = View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS;
     46     @Deprecated
     47     public static final int DISABLE_NOTIFICATION_TICKER
     48             = View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER;
     49     public static final int DISABLE_SYSTEM_INFO = View.STATUS_BAR_DISABLE_SYSTEM_INFO;
     50     public static final int DISABLE_HOME = View.STATUS_BAR_DISABLE_HOME;
     51     public static final int DISABLE_RECENT = View.STATUS_BAR_DISABLE_RECENT;
     52     public static final int DISABLE_BACK = View.STATUS_BAR_DISABLE_BACK;
     53     public static final int DISABLE_CLOCK = View.STATUS_BAR_DISABLE_CLOCK;
     54     public static final int DISABLE_SEARCH = View.STATUS_BAR_DISABLE_SEARCH;
     55 
     56     @Deprecated
     57     public static final int DISABLE_NAVIGATION =
     58             View.STATUS_BAR_DISABLE_HOME | View.STATUS_BAR_DISABLE_RECENT;
     59 
     60     public static final int DISABLE_NONE = 0x00000000;
     61 
     62     public static final int DISABLE_MASK = DISABLE_EXPAND | DISABLE_NOTIFICATION_ICONS
     63             | DISABLE_NOTIFICATION_ALERTS | DISABLE_NOTIFICATION_TICKER
     64             | DISABLE_SYSTEM_INFO | DISABLE_RECENT | DISABLE_HOME | DISABLE_BACK | DISABLE_CLOCK
     65             | DISABLE_SEARCH;
     66 
     67     /**
     68      * Flag to disable quick settings.
     69      *
     70      * Setting this flag disables quick settings completely, but does not disable expanding the
     71      * notification shade.
     72      */
     73     public static final int DISABLE2_QUICK_SETTINGS = 1;
     74     public static final int DISABLE2_SYSTEM_ICONS = 1 << 1;
     75     public static final int DISABLE2_NOTIFICATION_SHADE = 1 << 2;
     76     public static final int DISABLE2_GLOBAL_ACTIONS = 1 << 3;
     77     public static final int DISABLE2_ROTATE_SUGGESTIONS = 1 << 4;
     78 
     79     public static final int DISABLE2_NONE = 0x00000000;
     80 
     81     public static final int DISABLE2_MASK = DISABLE2_QUICK_SETTINGS | DISABLE2_SYSTEM_ICONS
     82             | DISABLE2_NOTIFICATION_SHADE | DISABLE2_GLOBAL_ACTIONS | DISABLE2_ROTATE_SUGGESTIONS;
     83 
     84     @IntDef(flag = true, prefix = { "DISABLE2_" }, value = {
     85             DISABLE2_NONE,
     86             DISABLE2_MASK,
     87             DISABLE2_QUICK_SETTINGS,
     88             DISABLE2_SYSTEM_ICONS,
     89             DISABLE2_NOTIFICATION_SHADE,
     90             DISABLE2_GLOBAL_ACTIONS,
     91             DISABLE2_ROTATE_SUGGESTIONS
     92     })
     93     @Retention(RetentionPolicy.SOURCE)
     94     public @interface Disable2Flags {}
     95 
     96     public static final int NAVIGATION_HINT_BACK_ALT      = 1 << 0;
     97     public static final int NAVIGATION_HINT_IME_SHOWN     = 1 << 1;
     98 
     99     public static final int WINDOW_STATUS_BAR = 1;
    100     public static final int WINDOW_NAVIGATION_BAR = 2;
    101 
    102     public static final int WINDOW_STATE_SHOWING = 0;
    103     public static final int WINDOW_STATE_HIDING = 1;
    104     public static final int WINDOW_STATE_HIDDEN = 2;
    105 
    106     public static final int CAMERA_LAUNCH_SOURCE_WIGGLE = 0;
    107     public static final int CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP = 1;
    108     public static final int CAMERA_LAUNCH_SOURCE_LIFT_TRIGGER = 2;
    109 
    110     private Context mContext;
    111     private IStatusBarService mService;
    112     private IBinder mToken = new Binder();
    113 
    114     StatusBarManager(Context context) {
    115         mContext = context;
    116     }
    117 
    118     private synchronized IStatusBarService getService() {
    119         if (mService == null) {
    120             mService = IStatusBarService.Stub.asInterface(
    121                     ServiceManager.getService(Context.STATUS_BAR_SERVICE));
    122             if (mService == null) {
    123                 Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE");
    124             }
    125         }
    126         return mService;
    127     }
    128 
    129     /**
    130      * Disable some features in the status bar.  Pass the bitwise-or of the DISABLE_* flags.
    131      * To re-enable everything, pass {@link #DISABLE_NONE}.
    132      */
    133     public void disable(int what) {
    134         try {
    135             final IStatusBarService svc = getService();
    136             if (svc != null) {
    137                 svc.disable(what, mToken, mContext.getPackageName());
    138             }
    139         } catch (RemoteException ex) {
    140             throw ex.rethrowFromSystemServer();
    141         }
    142     }
    143 
    144     /**
    145      * Disable additional status bar features. Pass the bitwise-or of the DISABLE2_* flags.
    146      * To re-enable everything, pass {@link #DISABLE_NONE}.
    147      *
    148      * Warning: Only pass DISABLE2_* flags into this function, do not use DISABLE_* flags.
    149      */
    150     public void disable2(@Disable2Flags int what) {
    151         try {
    152             final IStatusBarService svc = getService();
    153             if (svc != null) {
    154                 svc.disable2(what, mToken, mContext.getPackageName());
    155             }
    156         } catch (RemoteException ex) {
    157             throw ex.rethrowFromSystemServer();
    158         }
    159     }
    160 
    161     /**
    162      * Expand the notifications panel.
    163      */
    164     public void expandNotificationsPanel() {
    165         try {
    166             final IStatusBarService svc = getService();
    167             if (svc != null) {
    168                 svc.expandNotificationsPanel();
    169             }
    170         } catch (RemoteException ex) {
    171             throw ex.rethrowFromSystemServer();
    172         }
    173     }
    174 
    175     /**
    176      * Collapse the notifications and settings panels.
    177      */
    178     public void collapsePanels() {
    179         try {
    180             final IStatusBarService svc = getService();
    181             if (svc != null) {
    182                 svc.collapsePanels();
    183             }
    184         } catch (RemoteException ex) {
    185             throw ex.rethrowFromSystemServer();
    186         }
    187     }
    188 
    189     /**
    190      * Expand the settings panel.
    191      */
    192     public void expandSettingsPanel() {
    193         expandSettingsPanel(null);
    194     }
    195 
    196     /**
    197      * Expand the settings panel and open a subPanel, pass null to just open the settings panel.
    198      */
    199     public void expandSettingsPanel(String subPanel) {
    200         try {
    201             final IStatusBarService svc = getService();
    202             if (svc != null) {
    203                 svc.expandSettingsPanel(subPanel);
    204             }
    205         } catch (RemoteException ex) {
    206             throw ex.rethrowFromSystemServer();
    207         }
    208     }
    209 
    210     public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
    211         try {
    212             final IStatusBarService svc = getService();
    213             if (svc != null) {
    214                 svc.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
    215                     contentDescription);
    216             }
    217         } catch (RemoteException ex) {
    218             throw ex.rethrowFromSystemServer();
    219         }
    220     }
    221 
    222     public void removeIcon(String slot) {
    223         try {
    224             final IStatusBarService svc = getService();
    225             if (svc != null) {
    226                 svc.removeIcon(slot);
    227             }
    228         } catch (RemoteException ex) {
    229             throw ex.rethrowFromSystemServer();
    230         }
    231     }
    232 
    233     public void setIconVisibility(String slot, boolean visible) {
    234         try {
    235             final IStatusBarService svc = getService();
    236             if (svc != null) {
    237                 svc.setIconVisibility(slot, visible);
    238             }
    239         } catch (RemoteException ex) {
    240             throw ex.rethrowFromSystemServer();
    241         }
    242     }
    243 
    244     /** @hide */
    245     public static String windowStateToString(int state) {
    246         if (state == WINDOW_STATE_HIDING) return "WINDOW_STATE_HIDING";
    247         if (state == WINDOW_STATE_HIDDEN) return "WINDOW_STATE_HIDDEN";
    248         if (state == WINDOW_STATE_SHOWING) return "WINDOW_STATE_SHOWING";
    249         return "WINDOW_STATE_UNKNOWN";
    250     }
    251 }
    252