blob: 8905268a8f91f18032279f3bb7185fd5e1ac9b82 [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
Joe Onorato0cbda992010-05-02 16:28:15 -070026import com.android.internal.statusbar.IStatusBarService;
27
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028/**
29 * Allows an app to control the status bar.
30 *
31 * @hide
32 */
33public class StatusBarManager {
34 /**
35 * Flag for {@link #disable} to make the status bar not expandable. Unless you also
Daniel Sandler91e1d0c2010-02-04 15:41:20 -080036 * set {@link #DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 */
38 public static final int DISABLE_EXPAND = 0x00000001;
39
40 /**
Daniel Sandler91e1d0c2010-02-04 15:41:20 -080041 * Flag for {@link #disable} to hide notification icons and scrolling ticker text.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 */
43 public static final int DISABLE_NOTIFICATION_ICONS = 0x00000002;
44
45 /**
46 * Flag for {@link #disable} to disable incoming notification alerts. This will not block
47 * icons, but it will block sound, vibrating and other visual or aural notifications.
48 */
49 public static final int DISABLE_NOTIFICATION_ALERTS = 0x00000004;
50
51 /**
Daniel Sandler91e1d0c2010-02-04 15:41:20 -080052 * Flag for {@link #disable} to hide only the scrolling ticker. Note that
53 * {@link #DISABLE_NOTIFICATION_ICONS} implies {@link #DISABLE_NOTIFICATION_TICKER}.
54 */
55 public static final int DISABLE_NOTIFICATION_TICKER = 0x00000008;
56
57 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 * Re-enable all of the status bar features that you've disabled.
59 */
60 public static final int DISABLE_NONE = 0x00000000;
61
62 private Context mContext;
Joe Onorato25f95f92010-04-08 18:37:10 -050063 private IStatusBarService mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 private IBinder mToken = new Binder();
65
66 StatusBarManager(Context context) {
67 mContext = context;
Joe Onorato25f95f92010-04-08 18:37:10 -050068 mService = IStatusBarService.Stub.asInterface(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
70 }
71
72 /**
73 * Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags.
74 * To re-enable everything, pass {@link #DISABLE_NONE}.
75 */
76 public void disable(int what) {
77 try {
78 mService.disable(what, mToken, mContext.getPackageName());
79 } catch (RemoteException ex) {
80 // system process is dead anyway.
81 throw new RuntimeException(ex);
82 }
83 }
84
85 /**
86 * Expand the status bar.
87 */
88 public void expand() {
89 try {
90 mService.activate();
91 } catch (RemoteException ex) {
92 // system process is dead anyway.
93 throw new RuntimeException(ex);
94 }
95 }
96
97 /**
98 * Collapse the status bar.
99 */
100 public void collapse() {
101 try {
102 mService.deactivate();
103 } catch (RemoteException ex) {
104 // system process is dead anyway.
105 throw new RuntimeException(ex);
106 }
107 }
108
109 /**
110 * Toggle the status bar.
111 */
112 public void toggle() {
113 try {
114 mService.toggle();
115 } catch (RemoteException ex) {
116 // system process is dead anyway.
117 throw new RuntimeException(ex);
118 }
119 }
120
Joe Onorato0cbda992010-05-02 16:28:15 -0700121 public void setIcon(String slot, int iconId, int iconLevel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 try {
Joe Onorato0cbda992010-05-02 16:28:15 -0700123 mService.setIcon(slot, mContext.getPackageName(), iconId, iconLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 } catch (RemoteException ex) {
125 // system process is dead anyway.
126 throw new RuntimeException(ex);
127 }
128 }
129
Joe Onorato0cbda992010-05-02 16:28:15 -0700130 public void removeIcon(String slot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 try {
Joe Onorato0cbda992010-05-02 16:28:15 -0700132 mService.removeIcon(slot);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 } catch (RemoteException ex) {
134 // system process is dead anyway.
135 throw new RuntimeException(ex);
136 }
137 }
138}