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