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