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