blob: 746b2d50a676ca60946d3967d18a1dbc6260a16d [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Daniel Sandler91e1d0c2010-02-04 15:41:20 -080034 * set {@link #DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 */
36 public static final int DISABLE_EXPAND = 0x00000001;
37
38 /**
Daniel Sandler91e1d0c2010-02-04 15:41:20 -080039 * Flag for {@link #disable} to hide notification icons and scrolling ticker text.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 */
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 /**
Daniel Sandler91e1d0c2010-02-04 15:41:20 -080050 * 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 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 * 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;
Joe Onorato25f95f92010-04-08 18:37:10 -050061 private IStatusBarService mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 private IBinder mToken = new Binder();
63
64 StatusBarManager(Context context) {
65 mContext = context;
Joe Onorato25f95f92010-04-08 18:37:10 -050066 mService = IStatusBarService.Stub.asInterface(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 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}