The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 18 | package android.app; |
| 19 | |
| 20 | import android.content.Context; |
| 21 | import android.os.Binder; |
| 22 | import android.os.RemoteException; |
| 23 | import android.os.IBinder; |
| 24 | import android.os.ServiceManager; |
| 25 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 26 | import com.android.internal.statusbar.IStatusBarService; |
| 27 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | /** |
| 29 | * Allows an app to control the status bar. |
| 30 | * |
| 31 | * @hide |
| 32 | */ |
| 33 | public class StatusBarManager { |
| 34 | /** |
| 35 | * Flag for {@link #disable} to make the status bar not expandable. Unless you also |
Daniel Sandler | 91e1d0c | 2010-02-04 15:41:20 -0800 | [diff] [blame] | 36 | * set {@link #DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | */ |
| 38 | public static final int DISABLE_EXPAND = 0x00000001; |
| 39 | |
| 40 | /** |
Daniel Sandler | 91e1d0c | 2010-02-04 15:41:20 -0800 | [diff] [blame] | 41 | * Flag for {@link #disable} to hide notification icons and scrolling ticker text. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | */ |
| 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 Sandler | 91e1d0c | 2010-02-04 15:41:20 -0800 | [diff] [blame] | 52 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | * 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 Onorato | 25f95f9 | 2010-04-08 18:37:10 -0500 | [diff] [blame] | 63 | private IStatusBarService mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | private IBinder mToken = new Binder(); |
| 65 | |
| 66 | StatusBarManager(Context context) { |
| 67 | mContext = context; |
Joe Onorato | 25f95f9 | 2010-04-08 18:37:10 -0500 | [diff] [blame] | 68 | mService = IStatusBarService.Stub.asInterface( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | 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 Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 90 | mService.expand(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 { |
Joe Onorato | f3f0e05 | 2010-05-14 18:49:29 -0700 | [diff] [blame] | 102 | mService.collapse(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | } catch (RemoteException ex) { |
| 104 | // system process is dead anyway. |
| 105 | throw new RuntimeException(ex); |
| 106 | } |
| 107 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 109 | public void setIcon(String slot, int iconId, int iconLevel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | try { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 111 | mService.setIcon(slot, mContext.getPackageName(), iconId, iconLevel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | } catch (RemoteException ex) { |
| 113 | // system process is dead anyway. |
| 114 | throw new RuntimeException(ex); |
| 115 | } |
| 116 | } |
| 117 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 118 | public void removeIcon(String slot) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | try { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 120 | mService.removeIcon(slot); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | } catch (RemoteException ex) { |
| 122 | // system process is dead anyway. |
| 123 | throw new RuntimeException(ex); |
| 124 | } |
| 125 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 126 | |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | } |