Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Joe Onorato | 79de0c5 | 2010-05-26 17:03:26 -0400 | [diff] [blame] | 17 | package com.android.systemui.statusbar; |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 18 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 20 | import android.app.ActivityManagerNative; |
| 21 | import android.app.KeyguardManager; |
| 22 | import android.app.PendingIntent; |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 23 | import android.app.TaskStackBuilder; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 25 | import android.content.Context; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 26 | import android.content.Intent; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 27 | import android.content.IntentFilter; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 28 | import android.content.pm.ApplicationInfo; |
| 29 | import android.content.pm.PackageManager.NameNotFoundException; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 30 | import android.content.res.Configuration; |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 31 | import android.database.ContentObserver; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 32 | import android.graphics.Rect; |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 33 | import android.net.Uri; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 34 | import android.os.Build; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 35 | import android.os.Handler; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 36 | import android.os.IBinder; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 37 | import android.os.Message; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 38 | import android.os.PowerManager; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 39 | import android.os.RemoteException; |
| 40 | import android.os.ServiceManager; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 41 | import android.os.UserHandle; |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 42 | import android.provider.Settings; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 43 | import android.service.dreams.DreamService; |
| 44 | import android.service.dreams.IDreamManager; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 45 | import android.service.notification.StatusBarNotification; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 46 | import android.text.TextUtils; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 47 | import android.util.Log; |
Daniel Sandler | c638c1e | 2011-08-24 16:19:23 -0700 | [diff] [blame] | 48 | import android.view.Display; |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 49 | import android.view.IWindowManager; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 50 | import android.view.LayoutInflater; |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 51 | import android.view.MenuItem; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 52 | import android.view.MotionEvent; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 53 | import android.view.View; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 54 | import android.view.ViewGroup; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 55 | import android.view.ViewGroup.LayoutParams; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 56 | import android.view.WindowManager; |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 57 | import android.view.WindowManagerGlobal; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 58 | import android.widget.ImageView; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 59 | import android.widget.LinearLayout; |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 60 | import android.widget.PopupMenu; |
Michael Jurka | a600fd9 | 2012-06-25 15:57:05 -0700 | [diff] [blame] | 61 | import android.widget.RemoteViews; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 62 | import android.widget.TextView; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 63 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 64 | import com.android.internal.statusbar.IStatusBarService; |
| 65 | import com.android.internal.statusbar.StatusBarIcon; |
| 66 | import com.android.internal.statusbar.StatusBarIconList; |
| 67 | import com.android.internal.widget.SizeAdaptiveLayout; |
| 68 | import com.android.systemui.R; |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 69 | import com.android.systemui.RecentsComponent; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 70 | import com.android.systemui.SearchPanelView; |
| 71 | import com.android.systemui.SystemUI; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 72 | import com.android.systemui.statusbar.policy.NotificationRowLayout; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 73 | |
Michael Jurka | a600fd9 | 2012-06-25 15:57:05 -0700 | [diff] [blame] | 74 | import java.util.ArrayList; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 75 | import java.util.Locale; |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 76 | |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 77 | public abstract class BaseStatusBar extends SystemUI implements |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 78 | CommandQueue.Callbacks { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 79 | public static final String TAG = "StatusBar"; |
| 80 | public static final boolean DEBUG = false; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 81 | public static final boolean MULTIUSER_DEBUG = false; |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 82 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 83 | protected static final int MSG_TOGGLE_RECENTS_PANEL = 1020; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 84 | protected static final int MSG_CLOSE_RECENTS_PANEL = 1021; |
| 85 | protected static final int MSG_PRELOAD_RECENT_APPS = 1022; |
| 86 | protected static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 1023; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 87 | protected static final int MSG_OPEN_SEARCH_PANEL = 1024; |
| 88 | protected static final int MSG_CLOSE_SEARCH_PANEL = 1025; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 89 | protected static final int MSG_SHOW_HEADS_UP = 1026; |
| 90 | protected static final int MSG_HIDE_HEADS_UP = 1027; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 91 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 92 | protected static final boolean ENABLE_HEADS_UP = true; |
| 93 | // scores above this threshold should be displayed in heads up mode. |
| 94 | private static final int INTERRUPTION_THRESHOLD = 10; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 95 | |
Michael Jurka | 56a5783 | 2012-05-14 13:24:43 -0700 | [diff] [blame] | 96 | // Should match the value in PhoneWindowManager |
| 97 | public static final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
| 98 | |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 99 | public static final int EXPANDED_LEAVE_ALONE = -10000; |
| 100 | public static final int EXPANDED_FULL_OPEN = -10001; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 101 | private static final String SETTING_HEADS_UP = "heads_up_enabled"; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 102 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 103 | protected CommandQueue mCommandQueue; |
| 104 | protected IStatusBarService mBarService; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 105 | protected H mHandler = createHandler(); |
| 106 | |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 107 | // all notifications |
| 108 | protected NotificationData mNotificationData = new NotificationData(); |
| 109 | protected NotificationRowLayout mPile; |
| 110 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 111 | protected StatusBarNotification mCurrentlyInterruptingNotification; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 112 | |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 113 | // used to notify status bar for suppressing notification LED |
| 114 | protected boolean mPanelSlightlyVisible; |
| 115 | |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 116 | // Search panel |
| 117 | protected SearchPanelView mSearchPanelView; |
| 118 | |
Daniel Sandler | 469e96e | 2012-05-04 15:56:19 -0400 | [diff] [blame] | 119 | protected PopupMenu mNotificationBlamePopup; |
| 120 | |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 121 | protected int mCurrentUserId = 0; |
| 122 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 123 | protected int mLayoutDirection; |
| 124 | private Locale mLocale; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 125 | protected boolean mUseHeadsUp = true; |
| 126 | |
| 127 | protected IDreamManager mDreamManager; |
| 128 | KeyguardManager mKeyguardManager; |
| 129 | PowerManager mPowerManager; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 130 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 131 | // UI-specific methods |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 132 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 133 | /** |
| 134 | * Create all windows necessary for the status bar (including navigation, overlay panels, etc) |
| 135 | * and add them to the window manager. |
| 136 | */ |
| 137 | protected abstract void createAndAddWindows(); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 138 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 139 | protected WindowManager mWindowManager; |
| 140 | protected IWindowManager mWindowManagerService; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 141 | protected abstract void refreshLayout(int layoutDirection); |
| 142 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 143 | protected Display mDisplay; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 144 | |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 145 | private boolean mDeviceProvisioned = false; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 146 | |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 147 | private RecentsComponent mRecents; |
| 148 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 149 | public IStatusBarService getStatusBarService() { |
| 150 | return mBarService; |
| 151 | } |
Joe Onorato | 2039e48 | 2010-11-29 14:54:24 -0800 | [diff] [blame] | 152 | |
Daniel Sandler | 3ffdcc7 | 2012-09-23 14:31:48 -0400 | [diff] [blame] | 153 | public boolean isDeviceProvisioned() { |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 154 | return mDeviceProvisioned; |
| 155 | } |
| 156 | |
| 157 | private ContentObserver mProvisioningObserver = new ContentObserver(new Handler()) { |
| 158 | @Override |
| 159 | public void onChange(boolean selfChange) { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 160 | final boolean provisioned = 0 != Settings.Global.getInt( |
| 161 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0); |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 162 | if (provisioned != mDeviceProvisioned) { |
| 163 | mDeviceProvisioned = provisioned; |
| 164 | updateNotificationIcons(); |
| 165 | } |
| 166 | } |
| 167 | }; |
| 168 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 169 | final private ContentObserver mHeadsUpObserver = new ContentObserver(mHandler) { |
| 170 | @Override |
| 171 | public void onChange(boolean selfChange) { |
| 172 | mUseHeadsUp = ENABLE_HEADS_UP && 0 != Settings.Global.getInt( |
| 173 | mContext.getContentResolver(), SETTING_HEADS_UP, 0); |
| 174 | Log.d(TAG, "heads up is " + (mUseHeadsUp ? "enabled" : "disabled")); |
| 175 | if (!mUseHeadsUp) { |
| 176 | Log.d(TAG, "dismissing any existing heads up notification on disable event"); |
| 177 | mHandler.sendEmptyMessage(MSG_HIDE_HEADS_UP); |
| 178 | } |
| 179 | } |
| 180 | }; |
| 181 | |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 182 | private RemoteViews.OnClickHandler mOnClickHandler = new RemoteViews.OnClickHandler() { |
| 183 | @Override |
| 184 | public boolean onClickHandler(View view, PendingIntent pendingIntent, Intent fillInIntent) { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 185 | if (DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 186 | Log.v(TAG, "Notification click handler invoked for intent: " + pendingIntent); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 187 | } |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 188 | final boolean isActivity = pendingIntent.isActivity(); |
| 189 | if (isActivity) { |
| 190 | try { |
| 191 | // The intent we are sending is for the application, which |
| 192 | // won't have permission to immediately start an activity after |
| 193 | // the user switches to home. We know it is safe to do at this |
| 194 | // point, so make sure new activity switches are now allowed. |
| 195 | ActivityManagerNative.getDefault().resumeAppSwitches(); |
| 196 | // Also, notifications can be launched from the lock screen, |
| 197 | // so dismiss the lock screen when the activity starts. |
| 198 | ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity(); |
| 199 | } catch (RemoteException e) { |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | boolean handled = super.onClickHandler(view, pendingIntent, fillInIntent); |
| 204 | |
| 205 | if (isActivity && handled) { |
| 206 | // close the shade if it was open |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 207 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 208 | visibilityChanged(false); |
| 209 | } |
| 210 | return handled; |
| 211 | } |
| 212 | }; |
| 213 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 214 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 215 | @Override |
| 216 | public void onReceive(Context context, Intent intent) { |
| 217 | String action = intent.getAction(); |
| 218 | if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 219 | mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); |
| 220 | if (true) Log.v(TAG, "userId " + mCurrentUserId + " is in the house"); |
| 221 | userSwitched(mCurrentUserId); |
| 222 | } |
| 223 | } |
| 224 | }; |
| 225 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 226 | public void start() { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 227 | mWindowManager = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 228 | mWindowManagerService = WindowManagerGlobal.getWindowManagerService(); |
| 229 | mDisplay = mWindowManager.getDefaultDisplay(); |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 230 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 231 | mDreamManager = IDreamManager.Stub.asInterface( |
| 232 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 233 | mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); |
| 234 | mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 235 | |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 236 | mProvisioningObserver.onChange(false); // set up |
| 237 | mContext.getContentResolver().registerContentObserver( |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 238 | Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), true, |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 239 | mProvisioningObserver); |
| 240 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 241 | mHeadsUpObserver.onChange(false); // set up |
| 242 | mContext.getContentResolver().registerContentObserver( |
| 243 | Settings.Global.getUriFor(SETTING_HEADS_UP), true, |
| 244 | mHeadsUpObserver); |
| 245 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 246 | mBarService = IStatusBarService.Stub.asInterface( |
| 247 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 248 | |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 249 | mRecents = getComponent(RecentsComponent.class); |
| 250 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 251 | mLocale = mContext.getResources().getConfiguration().locale; |
| 252 | mLayoutDirection = TextUtils.getLayoutDirectionFromLocale(mLocale); |
| 253 | |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 254 | // Connect in to the status bar manager service |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 255 | StatusBarIconList iconList = new StatusBarIconList(); |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 256 | ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>(); |
| 257 | ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>(); |
Joe Onorato | 66d7d01 | 2010-05-14 10:05:10 -0700 | [diff] [blame] | 258 | mCommandQueue = new CommandQueue(this, iconList); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 259 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 260 | int[] switches = new int[7]; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 261 | ArrayList<IBinder> binders = new ArrayList<IBinder>(); |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 262 | try { |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 263 | mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications, |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 264 | switches, binders); |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 265 | } catch (RemoteException ex) { |
| 266 | // If the system process isn't there we're doomed anyway. |
| 267 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 268 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 269 | createAndAddWindows(); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 270 | |
Joe Onorato | e4c7b3f | 2010-10-30 12:15:03 -0700 | [diff] [blame] | 271 | disable(switches[0]); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 272 | setSystemUiVisibility(switches[1], 0xffffffff); |
Dianne Hackborn | 7d04932 | 2011-06-14 15:00:32 -0700 | [diff] [blame] | 273 | topAppWindowChanged(switches[2] != 0); |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 274 | // StatusBarManagerService has a back up of IME token and it's restored here. |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 275 | setImeWindowStatus(binders.get(0), switches[3], switches[4]); |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 276 | setHardKeyboardStatus(switches[5] != 0, switches[6] != 0); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 277 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 278 | // Set up the initial icon state |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 279 | int N = iconList.size(); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 280 | int viewIndex = 0; |
| 281 | for (int i=0; i<N; i++) { |
| 282 | StatusBarIcon icon = iconList.getIcon(i); |
| 283 | if (icon != null) { |
| 284 | addIcon(iconList.getSlot(i), i, viewIndex, icon); |
| 285 | viewIndex++; |
| 286 | } |
| 287 | } |
| 288 | |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 289 | // Set up the initial notification state |
| 290 | N = notificationKeys.size(); |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 291 | if (N == notifications.size()) { |
| 292 | for (int i=0; i<N; i++) { |
| 293 | addNotification(notificationKeys.get(i), notifications.get(i)); |
| 294 | } |
| 295 | } else { |
| 296 | Log.wtf(TAG, "Notification list length mismatch: keys=" + N |
| 297 | + " notifications=" + notifications.size()); |
| 298 | } |
| 299 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 300 | if (DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 301 | Log.d(TAG, String.format( |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 302 | "init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x", |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 303 | iconList.size(), |
| 304 | switches[0], |
| 305 | switches[1], |
| 306 | switches[2], |
| 307 | switches[3] |
| 308 | )); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 309 | } |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 310 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 311 | mCurrentUserId = ActivityManager.getCurrentUser(); |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 312 | |
| 313 | IntentFilter filter = new IntentFilter(); |
| 314 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 315 | mContext.registerReceiver(mBroadcastReceiver, filter); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 316 | |
| 317 | mLocale = mContext.getResources().getConfiguration().locale; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | public void userSwitched(int newUserId) { |
| 321 | // should be overridden |
| 322 | } |
| 323 | |
| 324 | public boolean notificationIsForCurrentUser(StatusBarNotification n) { |
| 325 | final int thisUserId = mCurrentUserId; |
| 326 | final int notificationUserId = n.getUserId(); |
| 327 | if (DEBUG && MULTIUSER_DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 328 | Log.v(TAG, String.format("%s: current userid: %d, notification userid: %d", |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 329 | n, thisUserId, notificationUserId)); |
| 330 | } |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 331 | return notificationUserId == UserHandle.USER_ALL |
| 332 | || thisUserId == notificationUserId; |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 333 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 334 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 335 | @Override |
| 336 | protected void onConfigurationChanged(Configuration newConfig) { |
| 337 | final Locale newLocale = mContext.getResources().getConfiguration().locale; |
| 338 | if (! newLocale.equals(mLocale)) { |
| 339 | mLocale = newLocale; |
| 340 | mLayoutDirection = TextUtils.getLayoutDirectionFromLocale(mLocale); |
| 341 | refreshLayout(mLayoutDirection); |
| 342 | } |
| 343 | } |
| 344 | |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 345 | protected View updateNotificationVetoButton(View row, StatusBarNotification n) { |
| 346 | View vetoButton = row.findViewById(R.id.veto); |
| 347 | if (n.isClearable()) { |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 348 | final String _pkg = n.getPackageName(); |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 349 | final String _tag = n.getTag(); |
| 350 | final int _id = n.getId(); |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 351 | vetoButton.setOnClickListener(new View.OnClickListener() { |
| 352 | public void onClick(View v) { |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 353 | // Accessibility feedback |
| 354 | v.announceForAccessibility( |
| 355 | mContext.getString(R.string.accessibility_notification_dismissed)); |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 356 | try { |
| 357 | mBarService.onNotificationClear(_pkg, _tag, _id); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 358 | |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 359 | } catch (RemoteException ex) { |
| 360 | // system process is dead if we're here. |
| 361 | } |
| 362 | } |
| 363 | }); |
| 364 | vetoButton.setVisibility(View.VISIBLE); |
| 365 | } else { |
| 366 | vetoButton.setVisibility(View.GONE); |
| 367 | } |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 368 | vetoButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 369 | return vetoButton; |
| 370 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 371 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 372 | |
| 373 | protected void applyLegacyRowBackground(StatusBarNotification sbn, View content) { |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 374 | if (sbn.getNotification().contentView.getLayoutId() != |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 375 | com.android.internal.R.layout.notification_template_base) { |
| 376 | int version = 0; |
| 377 | try { |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 378 | ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(sbn.getPackageName(), 0); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 379 | version = info.targetSdkVersion; |
| 380 | } catch (NameNotFoundException ex) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 381 | Log.e(TAG, "Failed looking up ApplicationInfo for " + sbn.getPackageName(), ex); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 382 | } |
| 383 | if (version > 0 && version < Build.VERSION_CODES.GINGERBREAD) { |
| 384 | content.setBackgroundResource(R.drawable.notification_row_legacy_bg); |
| 385 | } else { |
Chris Wren | d84e593 | 2012-04-19 17:58:03 -0400 | [diff] [blame] | 386 | content.setBackgroundResource(com.android.internal.R.drawable.notification_bg); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 391 | private void startApplicationDetailsActivity(String packageName) { |
| 392 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, |
| 393 | Uri.fromParts("package", packageName, null)); |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 394 | intent.setComponent(intent.resolveActivity(mContext.getPackageManager())); |
Amith Yamasani | ea7e915 | 2012-09-24 16:11:18 -0700 | [diff] [blame] | 395 | TaskStackBuilder.create(mContext).addNextIntentWithParentStack(intent).startActivities( |
| 396 | null, UserHandle.CURRENT); |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 397 | } |
| 398 | |
Jim Miller | 9a720f5 | 2012-05-30 03:19:43 -0700 | [diff] [blame] | 399 | protected View.OnLongClickListener getNotificationLongClicker() { |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 400 | return new View.OnLongClickListener() { |
| 401 | @Override |
| 402 | public boolean onLongClick(View v) { |
| 403 | final String packageNameF = (String) v.getTag(); |
| 404 | if (packageNameF == null) return false; |
Jeff Sharkey | af232ed | 2012-04-30 15:19:39 -0700 | [diff] [blame] | 405 | if (v.getWindowToken() == null) return false; |
Daniel Sandler | 469e96e | 2012-05-04 15:56:19 -0400 | [diff] [blame] | 406 | mNotificationBlamePopup = new PopupMenu(mContext, v); |
| 407 | mNotificationBlamePopup.getMenuInflater().inflate( |
| 408 | R.menu.notification_popup_menu, |
| 409 | mNotificationBlamePopup.getMenu()); |
| 410 | mNotificationBlamePopup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 411 | public boolean onMenuItemClick(MenuItem item) { |
| 412 | if (item.getItemId() == R.id.notification_inspect_item) { |
| 413 | startApplicationDetailsActivity(packageNameF); |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 414 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 415 | } else { |
| 416 | return false; |
| 417 | } |
| 418 | return true; |
| 419 | } |
| 420 | }); |
Daniel Sandler | 469e96e | 2012-05-04 15:56:19 -0400 | [diff] [blame] | 421 | mNotificationBlamePopup.show(); |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 422 | |
| 423 | return true; |
| 424 | } |
| 425 | }; |
| 426 | } |
| 427 | |
Daniel Sandler | 469e96e | 2012-05-04 15:56:19 -0400 | [diff] [blame] | 428 | public void dismissPopups() { |
| 429 | if (mNotificationBlamePopup != null) { |
| 430 | mNotificationBlamePopup.dismiss(); |
| 431 | mNotificationBlamePopup = null; |
| 432 | } |
| 433 | } |
| 434 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 435 | public void dismissHeadsUp() { |
Daniel Sandler | fa7887b | 2012-03-26 09:43:31 -0400 | [diff] [blame] | 436 | // pass |
| 437 | } |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 438 | |
| 439 | @Override |
| 440 | public void toggleRecentApps() { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 441 | int msg = MSG_TOGGLE_RECENTS_PANEL; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 442 | mHandler.removeMessages(msg); |
| 443 | mHandler.sendEmptyMessage(msg); |
| 444 | } |
| 445 | |
| 446 | @Override |
| 447 | public void preloadRecentApps() { |
| 448 | int msg = MSG_PRELOAD_RECENT_APPS; |
| 449 | mHandler.removeMessages(msg); |
| 450 | mHandler.sendEmptyMessage(msg); |
| 451 | } |
| 452 | |
| 453 | @Override |
| 454 | public void cancelPreloadRecentApps() { |
| 455 | int msg = MSG_CANCEL_PRELOAD_RECENT_APPS; |
| 456 | mHandler.removeMessages(msg); |
| 457 | mHandler.sendEmptyMessage(msg); |
| 458 | } |
| 459 | |
| 460 | @Override |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 461 | public void showSearchPanel() { |
| 462 | int msg = MSG_OPEN_SEARCH_PANEL; |
| 463 | mHandler.removeMessages(msg); |
| 464 | mHandler.sendEmptyMessage(msg); |
| 465 | } |
| 466 | |
| 467 | @Override |
| 468 | public void hideSearchPanel() { |
| 469 | int msg = MSG_CLOSE_SEARCH_PANEL; |
| 470 | mHandler.removeMessages(msg); |
| 471 | mHandler.sendEmptyMessage(msg); |
| 472 | } |
| 473 | |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 474 | protected abstract WindowManager.LayoutParams getSearchLayoutParams( |
| 475 | LayoutParams layoutParams); |
| 476 | |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 477 | protected void updateSearchPanel() { |
| 478 | // Search Panel |
| 479 | boolean visible = false; |
| 480 | if (mSearchPanelView != null) { |
| 481 | visible = mSearchPanelView.isShowing(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 482 | mWindowManager.removeView(mSearchPanelView); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | // Provide SearchPanel with a temporary parent to allow layout params to work. |
| 486 | LinearLayout tmpRoot = new LinearLayout(mContext); |
| 487 | mSearchPanelView = (SearchPanelView) LayoutInflater.from(mContext).inflate( |
| 488 | R.layout.status_bar_search_panel, tmpRoot, false); |
| 489 | mSearchPanelView.setOnTouchListener( |
| 490 | new TouchOutsideListener(MSG_CLOSE_SEARCH_PANEL, mSearchPanelView)); |
| 491 | mSearchPanelView.setVisibility(View.GONE); |
| 492 | |
| 493 | WindowManager.LayoutParams lp = getSearchLayoutParams(mSearchPanelView.getLayoutParams()); |
| 494 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 495 | mWindowManager.addView(mSearchPanelView, lp); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 496 | mSearchPanelView.setBar(this); |
| 497 | if (visible) { |
| 498 | mSearchPanelView.show(true, false); |
| 499 | } |
| 500 | } |
| 501 | |
Michael Jurka | ecc395a | 2012-03-30 05:31:46 -0700 | [diff] [blame] | 502 | protected H createHandler() { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 503 | return new H(); |
| 504 | } |
| 505 | |
Michael Jurka | 56a5783 | 2012-05-14 13:24:43 -0700 | [diff] [blame] | 506 | static void sendCloseSystemWindows(Context context, String reason) { |
| 507 | if (ActivityManagerNative.isSystemReady()) { |
| 508 | try { |
| 509 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 510 | } catch (RemoteException e) { |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 515 | protected abstract View getStatusBarView(); |
| 516 | |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 517 | protected View.OnTouchListener mRecentsPreloadOnTouchListener = new View.OnTouchListener() { |
| 518 | // additional optimization when we have software system buttons - start loading the recent |
| 519 | // tasks on touch down |
| 520 | @Override |
| 521 | public boolean onTouch(View v, MotionEvent event) { |
| 522 | int action = event.getAction() & MotionEvent.ACTION_MASK; |
| 523 | if (action == MotionEvent.ACTION_DOWN) { |
| 524 | preloadRecentTasksList(); |
| 525 | } else if (action == MotionEvent.ACTION_CANCEL) { |
| 526 | cancelPreloadingRecentTasksList(); |
| 527 | } else if (action == MotionEvent.ACTION_UP) { |
| 528 | if (!v.isPressed()) { |
| 529 | cancelPreloadingRecentTasksList(); |
| 530 | } |
| 531 | |
| 532 | } |
| 533 | return false; |
| 534 | } |
| 535 | }; |
| 536 | |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 537 | protected void toggleRecentsActivity() { |
| 538 | if (mRecents != null) { |
| 539 | mRecents.toggleRecents(mDisplay, mLayoutDirection, getStatusBarView()); |
| 540 | } |
| 541 | } |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 542 | |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 543 | protected void preloadRecentTasksList() { |
| 544 | if (mRecents != null) { |
| 545 | mRecents.preloadRecentTasksList(); |
| 546 | } |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | protected void cancelPreloadingRecentTasksList() { |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 550 | if (mRecents != null) { |
| 551 | mRecents.cancelPreloadingRecentTasksList(); |
| 552 | } |
| 553 | } |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 554 | |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 555 | protected void closeRecents() { |
| 556 | if (mRecents != null) { |
| 557 | mRecents.closeRecents(); |
| 558 | } |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 559 | } |
| 560 | |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 561 | protected class H extends Handler { |
| 562 | public void handleMessage(Message m) { |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 563 | Intent intent; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 564 | switch (m.what) { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 565 | case MSG_TOGGLE_RECENTS_PANEL: |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 566 | toggleRecentsActivity(); |
| 567 | break; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 568 | case MSG_CLOSE_RECENTS_PANEL: |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 569 | closeRecents(); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 570 | break; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 571 | case MSG_PRELOAD_RECENT_APPS: |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 572 | preloadRecentTasksList(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 573 | break; |
| 574 | case MSG_CANCEL_PRELOAD_RECENT_APPS: |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 575 | cancelPreloadingRecentTasksList(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 576 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 577 | case MSG_OPEN_SEARCH_PANEL: |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 578 | if (DEBUG) Log.d(TAG, "opening search panel"); |
Jim Miller | 0799440 | 2012-05-02 14:22:27 -0700 | [diff] [blame] | 579 | if (mSearchPanelView != null && mSearchPanelView.isAssistantAvailable()) { |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 580 | mSearchPanelView.show(true, true); |
| 581 | } |
| 582 | break; |
| 583 | case MSG_CLOSE_SEARCH_PANEL: |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 584 | if (DEBUG) Log.d(TAG, "closing search panel"); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 585 | if (mSearchPanelView != null && mSearchPanelView.isShowing()) { |
| 586 | mSearchPanelView.show(false, true); |
| 587 | } |
| 588 | break; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | public class TouchOutsideListener implements View.OnTouchListener { |
| 594 | private int mMsg; |
| 595 | private StatusBarPanel mPanel; |
| 596 | |
| 597 | public TouchOutsideListener(int msg, StatusBarPanel panel) { |
| 598 | mMsg = msg; |
| 599 | mPanel = panel; |
| 600 | } |
| 601 | |
| 602 | public boolean onTouch(View v, MotionEvent ev) { |
| 603 | final int action = ev.getAction(); |
| 604 | if (action == MotionEvent.ACTION_OUTSIDE |
| 605 | || (action == MotionEvent.ACTION_DOWN |
| 606 | && !mPanel.isInContentArea((int)ev.getX(), (int)ev.getY()))) { |
| 607 | mHandler.removeMessages(mMsg); |
| 608 | mHandler.sendEmptyMessage(mMsg); |
| 609 | return true; |
| 610 | } |
| 611 | return false; |
| 612 | } |
| 613 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 614 | |
| 615 | protected void workAroundBadLayerDrawableOpacity(View v) { |
| 616 | } |
| 617 | |
| 618 | protected boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) { |
| 619 | int minHeight = |
| 620 | mContext.getResources().getDimensionPixelSize(R.dimen.notification_min_height); |
| 621 | int maxHeight = |
| 622 | mContext.getResources().getDimensionPixelSize(R.dimen.notification_max_height); |
| 623 | StatusBarNotification sbn = entry.notification; |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 624 | RemoteViews contentView = sbn.getNotification().contentView; |
| 625 | RemoteViews bigContentView = sbn.getNotification().bigContentView; |
| 626 | if (contentView == null) { |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 627 | return false; |
| 628 | } |
| 629 | |
| 630 | // create the row view |
| 631 | LayoutInflater inflater = (LayoutInflater)mContext.getSystemService( |
| 632 | Context.LAYOUT_INFLATER_SERVICE); |
| 633 | View row = inflater.inflate(R.layout.status_bar_notification_row, parent, false); |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 634 | |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 635 | // for blaming (see SwipeHelper.setLongPressListener) |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 636 | row.setTag(sbn.getPackageName()); |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 637 | |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 638 | workAroundBadLayerDrawableOpacity(row); |
| 639 | View vetoButton = updateNotificationVetoButton(row, sbn); |
| 640 | vetoButton.setContentDescription(mContext.getString( |
| 641 | R.string.accessibility_remove_notification)); |
| 642 | |
| 643 | // NB: the large icon is now handled entirely by the template |
| 644 | |
| 645 | // bind the click event to the content area |
| 646 | ViewGroup content = (ViewGroup)row.findViewById(R.id.content); |
| 647 | ViewGroup adaptive = (ViewGroup)row.findViewById(R.id.adaptive); |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 648 | |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 649 | content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 650 | |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 651 | PendingIntent contentIntent = sbn.getNotification().contentIntent; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 652 | if (contentIntent != null) { |
| 653 | final View.OnClickListener listener = new NotificationClicker(contentIntent, |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 654 | sbn.getPackageName(), sbn.getTag(), sbn.getId()); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 655 | content.setOnClickListener(listener); |
| 656 | } else { |
| 657 | content.setOnClickListener(null); |
| 658 | } |
| 659 | |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 660 | View contentViewLocal = null; |
| 661 | View bigContentViewLocal = null; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 662 | try { |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 663 | contentViewLocal = contentView.apply(mContext, adaptive, mOnClickHandler); |
| 664 | if (bigContentView != null) { |
| 665 | bigContentViewLocal = bigContentView.apply(mContext, adaptive, mOnClickHandler); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | catch (RuntimeException e) { |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 669 | final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId()); |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 670 | Log.e(TAG, "couldn't inflate view for notification " + ident, e); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 671 | return false; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 672 | } |
| 673 | |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 674 | if (contentViewLocal != null) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 675 | SizeAdaptiveLayout.LayoutParams params = |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 676 | new SizeAdaptiveLayout.LayoutParams(contentViewLocal.getLayoutParams()); |
Chris Wren | ed5cc0e | 2012-06-21 11:25:58 -0400 | [diff] [blame] | 677 | params.minHeight = minHeight; |
| 678 | params.maxHeight = minHeight; |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 679 | adaptive.addView(contentViewLocal, params); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 680 | } |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 681 | if (bigContentViewLocal != null) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 682 | SizeAdaptiveLayout.LayoutParams params = |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 683 | new SizeAdaptiveLayout.LayoutParams(bigContentViewLocal.getLayoutParams()); |
Chris Wren | ed5cc0e | 2012-06-21 11:25:58 -0400 | [diff] [blame] | 684 | params.minHeight = minHeight+1; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 685 | params.maxHeight = maxHeight; |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 686 | adaptive.addView(bigContentViewLocal, params); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 687 | } |
| 688 | row.setDrawingCacheEnabled(true); |
| 689 | |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 690 | applyLegacyRowBackground(sbn, content); |
| 691 | |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 692 | if (MULTIUSER_DEBUG) { |
| 693 | TextView debug = (TextView) row.findViewById(R.id.debug_info); |
| 694 | if (debug != null) { |
| 695 | debug.setVisibility(View.VISIBLE); |
| 696 | debug.setText("U " + entry.notification.getUserId()); |
| 697 | } |
| 698 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 699 | entry.row = row; |
| 700 | entry.content = content; |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 701 | entry.expanded = contentViewLocal; |
| 702 | entry.setBigContentView(bigContentViewLocal); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 703 | |
| 704 | return true; |
| 705 | } |
| 706 | |
| 707 | public NotificationClicker makeClicker(PendingIntent intent, String pkg, String tag, int id) { |
| 708 | return new NotificationClicker(intent, pkg, tag, id); |
| 709 | } |
| 710 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 711 | protected class NotificationClicker implements View.OnClickListener { |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 712 | private PendingIntent mIntent; |
| 713 | private String mPkg; |
| 714 | private String mTag; |
| 715 | private int mId; |
| 716 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 717 | public NotificationClicker(PendingIntent intent, String pkg, String tag, int id) { |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 718 | mIntent = intent; |
| 719 | mPkg = pkg; |
| 720 | mTag = tag; |
| 721 | mId = id; |
| 722 | } |
| 723 | |
| 724 | public void onClick(View v) { |
| 725 | try { |
| 726 | // The intent we are sending is for the application, which |
| 727 | // won't have permission to immediately start an activity after |
| 728 | // the user switches to home. We know it is safe to do at this |
| 729 | // point, so make sure new activity switches are now allowed. |
| 730 | ActivityManagerNative.getDefault().resumeAppSwitches(); |
| 731 | // Also, notifications can be launched from the lock screen, |
| 732 | // so dismiss the lock screen when the activity starts. |
| 733 | ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity(); |
| 734 | } catch (RemoteException e) { |
| 735 | } |
| 736 | |
| 737 | if (mIntent != null) { |
| 738 | int[] pos = new int[2]; |
| 739 | v.getLocationOnScreen(pos); |
| 740 | Intent overlay = new Intent(); |
| 741 | overlay.setSourceBounds( |
| 742 | new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight())); |
| 743 | try { |
| 744 | mIntent.send(mContext, 0, overlay); |
| 745 | } catch (PendingIntent.CanceledException e) { |
| 746 | // the stack trace isn't very helpful here. Just log the exception message. |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 747 | Log.w(TAG, "Sending contentIntent failed: " + e); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | KeyguardManager kgm = |
| 751 | (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); |
| 752 | if (kgm != null) kgm.exitKeyguardSecurely(null); |
| 753 | } |
| 754 | |
| 755 | try { |
| 756 | mBarService.onNotificationClick(mPkg, mTag, mId); |
| 757 | } catch (RemoteException ex) { |
| 758 | // system process is dead if we're here. |
| 759 | } |
| 760 | |
| 761 | // close the shade if it was open |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 762 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 763 | visibilityChanged(false); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | /** |
| 767 | * The LEDs are turned o)ff when the notification panel is shown, even just a little bit. |
| 768 | * This was added last-minute and is inconsistent with the way the rest of the notifications |
| 769 | * are handled, because the notification isn't really cancelled. The lights are just |
| 770 | * turned off. If any other notifications happen, the lights will turn back on. Steve says |
| 771 | * this is what he wants. (see bug 1131461) |
| 772 | */ |
| 773 | protected void visibilityChanged(boolean visible) { |
| 774 | if (mPanelSlightlyVisible != visible) { |
| 775 | mPanelSlightlyVisible = visible; |
| 776 | try { |
| 777 | mBarService.onPanelRevealed(); |
| 778 | } catch (RemoteException ex) { |
| 779 | // Won't fail unless the world has ended. |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 784 | /** |
| 785 | * Cancel this notification and tell the StatusBarManagerService / NotificationManagerService |
| 786 | * about the failure. |
| 787 | * |
| 788 | * WARNING: this will call back into us. Don't hold any locks. |
| 789 | */ |
| 790 | void handleNotificationError(IBinder key, StatusBarNotification n, String message) { |
| 791 | removeNotification(key); |
| 792 | try { |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 793 | mBarService.onNotificationError(n.getPackageName(), n.getTag(), n.getId(), n.getUid(), n.getInitialPid(), message); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 794 | } catch (RemoteException ex) { |
| 795 | // The end is nigh. |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | protected StatusBarNotification removeNotificationViews(IBinder key) { |
| 800 | NotificationData.Entry entry = mNotificationData.remove(key); |
| 801 | if (entry == null) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 802 | Log.w(TAG, "removeNotification for unknown key: " + key); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 803 | return null; |
| 804 | } |
| 805 | // Remove the expanded view. |
| 806 | ViewGroup rowParent = (ViewGroup)entry.row.getParent(); |
| 807 | if (rowParent != null) rowParent.removeView(entry.row); |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 808 | updateExpansionStates(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 809 | updateNotificationIcons(); |
| 810 | |
| 811 | return entry.notification; |
| 812 | } |
| 813 | |
| 814 | protected StatusBarIconView addNotificationViews(IBinder key, |
| 815 | StatusBarNotification notification) { |
| 816 | if (DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 817 | Log.d(TAG, "addNotificationViews(key=" + key + ", notification=" + notification); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 818 | } |
| 819 | // Construct the icon. |
| 820 | final StatusBarIconView iconView = new StatusBarIconView(mContext, |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 821 | notification.getPackageName() + "/0x" + Integer.toHexString(notification.getId()), |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 822 | notification.getNotification()); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 823 | iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); |
| 824 | |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 825 | final StatusBarIcon ic = new StatusBarIcon(notification.getPackageName(), |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 826 | notification.getUser(), |
| 827 | notification.getNotification().icon, |
| 828 | notification.getNotification().iconLevel, |
| 829 | notification.getNotification().number, |
| 830 | notification.getNotification().tickerText); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 831 | if (!iconView.set(ic)) { |
| 832 | handleNotificationError(key, notification, "Couldn't create icon: " + ic); |
| 833 | return null; |
| 834 | } |
| 835 | // Construct the expanded view. |
| 836 | NotificationData.Entry entry = new NotificationData.Entry(key, notification, iconView); |
| 837 | if (!inflateViews(entry, mPile)) { |
| 838 | handleNotificationError(key, notification, "Couldn't expand RemoteViews for: " |
| 839 | + notification); |
| 840 | return null; |
| 841 | } |
| 842 | |
| 843 | // Add the expanded view and icon. |
| 844 | int pos = mNotificationData.add(entry); |
| 845 | if (DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 846 | Log.d(TAG, "addNotificationViews: added at " + pos); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 847 | } |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 848 | updateExpansionStates(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 849 | updateNotificationIcons(); |
| 850 | |
| 851 | return iconView; |
| 852 | } |
| 853 | |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 854 | protected boolean expandView(NotificationData.Entry entry, boolean expand) { |
Chris Wren | 6675721 | 2012-05-14 10:05:42 -0400 | [diff] [blame] | 855 | int rowHeight = |
| 856 | mContext.getResources().getDimensionPixelSize(R.dimen.notification_row_min_height); |
| 857 | ViewGroup.LayoutParams lp = entry.row.getLayoutParams(); |
| 858 | if (entry.expandable() && expand) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 859 | if (DEBUG) Log.d(TAG, "setting expanded row height to WRAP_CONTENT"); |
Chris Wren | 6675721 | 2012-05-14 10:05:42 -0400 | [diff] [blame] | 860 | lp.height = ViewGroup.LayoutParams.WRAP_CONTENT; |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 861 | } else { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 862 | if (DEBUG) Log.d(TAG, "setting collapsed row height to " + rowHeight); |
Chris Wren | 6675721 | 2012-05-14 10:05:42 -0400 | [diff] [blame] | 863 | lp.height = rowHeight; |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 864 | } |
Chris Wren | 6675721 | 2012-05-14 10:05:42 -0400 | [diff] [blame] | 865 | entry.row.setLayoutParams(lp); |
| 866 | return expand; |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | protected void updateExpansionStates() { |
| 870 | int N = mNotificationData.size(); |
| 871 | for (int i = 0; i < N; i++) { |
| 872 | NotificationData.Entry entry = mNotificationData.get(i); |
Chris Wren | 3ddab0d | 2012-08-02 16:52:21 -0400 | [diff] [blame] | 873 | if (!entry.userLocked()) { |
| 874 | if (i == (N-1)) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 875 | if (DEBUG) Log.d(TAG, "expanding top notification at " + i); |
Chris Wren | 3ddab0d | 2012-08-02 16:52:21 -0400 | [diff] [blame] | 876 | expandView(entry, true); |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 877 | } else { |
Chris Wren | 3ddab0d | 2012-08-02 16:52:21 -0400 | [diff] [blame] | 878 | if (!entry.userExpanded()) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 879 | if (DEBUG) Log.d(TAG, "collapsing notification at " + i); |
Chris Wren | 3ddab0d | 2012-08-02 16:52:21 -0400 | [diff] [blame] | 880 | expandView(entry, false); |
| 881 | } else { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 882 | if (DEBUG) Log.d(TAG, "ignoring user-modified notification at " + i); |
Chris Wren | 3ddab0d | 2012-08-02 16:52:21 -0400 | [diff] [blame] | 883 | } |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 884 | } |
Chris Wren | 3ddab0d | 2012-08-02 16:52:21 -0400 | [diff] [blame] | 885 | } else { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 886 | if (DEBUG) Log.d(TAG, "ignoring notification being held by user at " + i); |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 887 | } |
| 888 | } |
| 889 | } |
| 890 | |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 891 | protected abstract void haltTicker(); |
| 892 | protected abstract void setAreThereNotifications(); |
| 893 | protected abstract void updateNotificationIcons(); |
| 894 | protected abstract void tick(IBinder key, StatusBarNotification n, boolean firstTime); |
| 895 | protected abstract void updateExpandedViewPos(int expandedPosition); |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 896 | protected abstract int getExpandedViewMaxHeight(); |
Jim Miller | b4238e0 | 2012-05-14 15:26:20 -0700 | [diff] [blame] | 897 | protected abstract boolean shouldDisableNavbarGestures(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 898 | |
| 899 | protected boolean isTopNotification(ViewGroup parent, NotificationData.Entry entry) { |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 900 | return parent != null && parent.indexOfChild(entry.row) == 0; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | public void updateNotification(IBinder key, StatusBarNotification notification) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 904 | if (DEBUG) Log.d(TAG, "updateNotification(" + key + " -> " + notification + ")"); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 905 | |
| 906 | final NotificationData.Entry oldEntry = mNotificationData.findByKey(key); |
| 907 | if (oldEntry == null) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 908 | Log.w(TAG, "updateNotification for unknown key: " + key); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 909 | return; |
| 910 | } |
| 911 | |
| 912 | final StatusBarNotification oldNotification = oldEntry.notification; |
| 913 | |
| 914 | // XXX: modify when we do something more intelligent with the two content views |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 915 | final RemoteViews oldContentView = oldNotification.getNotification().contentView; |
| 916 | final RemoteViews contentView = notification.getNotification().contentView; |
| 917 | final RemoteViews oldBigContentView = oldNotification.getNotification().bigContentView; |
| 918 | final RemoteViews bigContentView = notification.getNotification().bigContentView; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 919 | |
| 920 | if (DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 921 | Log.d(TAG, "old notification: when=" + oldNotification.getNotification().when |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 922 | + " ongoing=" + oldNotification.isOngoing() |
| 923 | + " expanded=" + oldEntry.expanded |
| 924 | + " contentView=" + oldContentView |
Chris Wren | e9e3772 | 2012-05-11 17:40:14 -0400 | [diff] [blame] | 925 | + " bigContentView=" + oldBigContentView |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 926 | + " rowParent=" + oldEntry.row.getParent()); |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 927 | Log.d(TAG, "new notification: when=" + notification.getNotification().when |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 928 | + " ongoing=" + oldNotification.isOngoing() |
Chris Wren | e9e3772 | 2012-05-11 17:40:14 -0400 | [diff] [blame] | 929 | + " contentView=" + contentView |
| 930 | + " bigContentView=" + bigContentView); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | // Can we just reapply the RemoteViews in place? If when didn't change, the order |
| 934 | // didn't change. |
Chris Wren | e9e3772 | 2012-05-11 17:40:14 -0400 | [diff] [blame] | 935 | |
| 936 | // 1U is never null |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 937 | boolean contentsUnchanged = oldEntry.expanded != null |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 938 | && contentView.getPackage() != null |
| 939 | && oldContentView.getPackage() != null |
| 940 | && oldContentView.getPackage().equals(contentView.getPackage()) |
| 941 | && oldContentView.getLayoutId() == contentView.getLayoutId(); |
Chris Wren | e9e3772 | 2012-05-11 17:40:14 -0400 | [diff] [blame] | 942 | // large view may be null |
| 943 | boolean bigContentsUnchanged = |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 944 | (oldEntry.getBigContentView() == null && bigContentView == null) |
| 945 | || ((oldEntry.getBigContentView() != null && bigContentView != null) |
Chris Wren | e9e3772 | 2012-05-11 17:40:14 -0400 | [diff] [blame] | 946 | && bigContentView.getPackage() != null |
| 947 | && oldBigContentView.getPackage() != null |
| 948 | && oldBigContentView.getPackage().equals(bigContentView.getPackage()) |
| 949 | && oldBigContentView.getLayoutId() == bigContentView.getLayoutId()); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 950 | ViewGroup rowParent = (ViewGroup) oldEntry.row.getParent(); |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 951 | boolean orderUnchanged = notification.getNotification().when== oldNotification.getNotification().when |
| 952 | && notification.getScore() == oldNotification.getScore(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 953 | // score now encompasses/supersedes isOngoing() |
| 954 | |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 955 | boolean updateTicker = notification.getNotification().tickerText != null |
| 956 | && !TextUtils.equals(notification.getNotification().tickerText, |
| 957 | oldEntry.notification.getNotification().tickerText); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 958 | boolean isTopAnyway = isTopNotification(rowParent, oldEntry); |
Chris Wren | e9e3772 | 2012-05-11 17:40:14 -0400 | [diff] [blame] | 959 | if (contentsUnchanged && bigContentsUnchanged && (orderUnchanged || isTopAnyway)) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 960 | if (DEBUG) Log.d(TAG, "reusing notification for key: " + key); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 961 | oldEntry.notification = notification; |
| 962 | try { |
| 963 | // Reapply the RemoteViews |
Dianne Hackborn | a194021 | 2012-06-28 16:07:22 -0700 | [diff] [blame] | 964 | contentView.reapply(mContext, oldEntry.expanded, mOnClickHandler); |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 965 | if (bigContentView != null && oldEntry.getBigContentView() != null) { |
| 966 | bigContentView.reapply(mContext, oldEntry.getBigContentView(), mOnClickHandler); |
Chris Wren | e9e3772 | 2012-05-11 17:40:14 -0400 | [diff] [blame] | 967 | } |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 968 | // update the contentIntent |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 969 | final PendingIntent contentIntent = notification.getNotification().contentIntent; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 970 | if (contentIntent != null) { |
| 971 | final View.OnClickListener listener = makeClicker(contentIntent, |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 972 | notification.getPackageName(), notification.getTag(), notification.getId()); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 973 | oldEntry.content.setOnClickListener(listener); |
| 974 | } else { |
| 975 | oldEntry.content.setOnClickListener(null); |
| 976 | } |
| 977 | // Update the icon. |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 978 | final StatusBarIcon ic = new StatusBarIcon(notification.getPackageName(), |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 979 | notification.getUser(), |
| 980 | notification.getNotification().icon, notification.getNotification().iconLevel, |
| 981 | notification.getNotification().number, |
| 982 | notification.getNotification().tickerText); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 983 | if (!oldEntry.icon.set(ic)) { |
| 984 | handleNotificationError(key, notification, "Couldn't update icon: " + ic); |
| 985 | return; |
| 986 | } |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 987 | updateExpansionStates(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 988 | } |
| 989 | catch (RuntimeException e) { |
| 990 | // It failed to add cleanly. Log, and remove the view from the panel. |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 991 | Log.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 992 | removeNotificationViews(key); |
| 993 | addNotificationViews(key, notification); |
| 994 | } |
| 995 | } else { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 996 | if (DEBUG) Log.d(TAG, "not reusing notification for key: " + key); |
| 997 | if (DEBUG) Log.d(TAG, "contents was " + (contentsUnchanged ? "unchanged" : "changed")); |
| 998 | if (DEBUG) Log.d(TAG, "order was " + (orderUnchanged ? "unchanged" : "changed")); |
| 999 | if (DEBUG) Log.d(TAG, "notification is " + (isTopAnyway ? "top" : "not top")); |
Chris Wren | c9433ecb | 2012-06-27 17:37:03 -0400 | [diff] [blame] | 1000 | final boolean wasExpanded = oldEntry.userExpanded(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1001 | removeNotificationViews(key); |
| 1002 | addNotificationViews(key, notification); |
Chris Wren | c9433ecb | 2012-06-27 17:37:03 -0400 | [diff] [blame] | 1003 | if (wasExpanded) { |
| 1004 | final NotificationData.Entry newEntry = mNotificationData.findByKey(key); |
| 1005 | expandView(newEntry, true); |
Chris Wren | 5ae1ea8 | 2012-06-28 14:35:43 -0400 | [diff] [blame] | 1006 | newEntry.setUserExpanded(true); |
Chris Wren | c9433ecb | 2012-06-27 17:37:03 -0400 | [diff] [blame] | 1007 | } |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | // Update the veto button accordingly (and as a result, whether this row is |
| 1011 | // swipe-dismissable) |
| 1012 | updateNotificationVetoButton(oldEntry.row, notification); |
| 1013 | |
John Spurlock | 61e3683 | 2012-09-10 09:43:27 -0400 | [diff] [blame] | 1014 | // Is this for you? |
| 1015 | boolean isForCurrentUser = notificationIsForCurrentUser(notification); |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 1016 | if (DEBUG) Log.d(TAG, "notification is " + (isForCurrentUser ? "" : "not ") + "for you"); |
John Spurlock | 61e3683 | 2012-09-10 09:43:27 -0400 | [diff] [blame] | 1017 | |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1018 | // Restart the ticker if it's still running |
John Spurlock | 61e3683 | 2012-09-10 09:43:27 -0400 | [diff] [blame] | 1019 | if (updateTicker && isForCurrentUser) { |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1020 | haltTicker(); |
| 1021 | tick(key, notification, false); |
| 1022 | } |
| 1023 | |
| 1024 | // Recalculate the position of the sliding windows and the titles. |
| 1025 | setAreThereNotifications(); |
| 1026 | updateExpandedViewPos(EXPANDED_LEAVE_ALONE); |
| 1027 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 1028 | // See if we need to update the heads up. |
| 1029 | if (ENABLE_HEADS_UP && oldNotification == mCurrentlyInterruptingNotification) { |
| 1030 | if (DEBUG) Log.d(TAG, "updating the current heads up:" + notification); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1031 | // XXX: this is a hack for Alarms. The real implementation will need to *update* |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 1032 | // the heads up. |
| 1033 | if (!shouldInterrupt(notification)) { |
| 1034 | if (DEBUG) Log.d(TAG, "no longer interrupts!"); |
| 1035 | mHandler.sendEmptyMessage(MSG_HIDE_HEADS_UP); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | } |
John Spurlock | 3623128 | 2012-06-23 17:11:27 -0400 | [diff] [blame] | 1039 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 1040 | protected boolean shouldInterrupt(StatusBarNotification notification) { |
| 1041 | boolean interrupt = notification.getNotification().fullScreenIntent == null |
| 1042 | && notification.getScore() >= INTERRUPTION_THRESHOLD |
| 1043 | && mPowerManager.isScreenOn() && !mKeyguardManager.isKeyguardLocked(); |
| 1044 | try { |
| 1045 | interrupt = interrupt && !mDreamManager.isDreaming(); |
| 1046 | } catch (RemoteException e) { |
| 1047 | Log.d(TAG, "failed to query dream manager", e); |
| 1048 | } |
| 1049 | return interrupt; |
| 1050 | } |
| 1051 | |
John Spurlock | 3623128 | 2012-06-23 17:11:27 -0400 | [diff] [blame] | 1052 | // Q: What kinds of notifications should show during setup? |
| 1053 | // A: Almost none! Only things coming from the system (package is "android") that also |
| 1054 | // have special "kind" tags marking them as relevant for setup (see below). |
| 1055 | protected boolean showNotificationEvenIfUnprovisioned(StatusBarNotification sbn) { |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 1056 | if ("android".equals(sbn.getPackageName())) { |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 1057 | if (sbn.getNotification().kind != null) { |
| 1058 | for (String aKind : sbn.getNotification().kind) { |
John Spurlock | 3623128 | 2012-06-23 17:11:27 -0400 | [diff] [blame] | 1059 | // IME switcher, created by InputMethodManagerService |
| 1060 | if ("android.system.imeswitcher".equals(aKind)) return true; |
| 1061 | // OTA availability & errors, created by SystemUpdateService |
| 1062 | if ("android.system.update".equals(aKind)) return true; |
| 1063 | } |
| 1064 | } |
| 1065 | } |
| 1066 | return false; |
| 1067 | } |
John Spurlock | 67ad368 | 2012-06-26 17:42:00 -0400 | [diff] [blame] | 1068 | |
| 1069 | public boolean inKeyguardRestrictedInputMode() { |
| 1070 | KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); |
| 1071 | return km.inKeyguardRestrictedInputMode(); |
| 1072 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 1073 | |
| 1074 | public void suspendAutohide() { |
| 1075 | // hook for subclasses |
| 1076 | } |
| 1077 | |
| 1078 | public void resumeAutohide() { |
| 1079 | // hook for subclasses |
| 1080 | } |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 1081 | |
| 1082 | public void destroy() { |
| 1083 | if (mSearchPanelView != null) { |
| 1084 | mWindowManager.removeViewImmediate(mSearchPanelView); |
| 1085 | } |
| 1086 | mContext.unregisterReceiver(mBroadcastReceiver); |
| 1087 | } |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 1088 | } |