blob: de544fb5485f2db2b74cf3bb34ea8f0edbf2806a [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 {
Joe Onoratof3f0e052010-05-14 18:49:29 -070090 mService.expand();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 } 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 {
Joe Onoratof3f0e052010-05-14 18:49:29 -0700102 mService.collapse();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 } catch (RemoteException ex) {
104 // system process is dead anyway.
105 throw new RuntimeException(ex);
106 }
107 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108
Joe Onorato0cbda992010-05-02 16:28:15 -0700109 public void setIcon(String slot, int iconId, int iconLevel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 try {
Joe Onorato0cbda992010-05-02 16:28:15 -0700111 mService.setIcon(slot, mContext.getPackageName(), iconId, iconLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 } catch (RemoteException ex) {
113 // system process is dead anyway.
114 throw new RuntimeException(ex);
115 }
116 }
117
Joe Onorato0cbda992010-05-02 16:28:15 -0700118 public void removeIcon(String slot) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 try {
Joe Onorato0cbda992010-05-02 16:28:15 -0700120 mService.removeIcon(slot);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 } catch (RemoteException ex) {
122 // system process is dead anyway.
123 throw new RuntimeException(ex);
124 }
125 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400126
127 public void setIconVisibility(String slot, boolean visible) {
128 try {
129 mService.setIconVisibility(slot, visible);
130 } catch (RemoteException ex) {
131 // system process is dead anyway.
132 throw new RuntimeException(ex);
133 }
134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135}