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 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.TimeInterpolator; |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 22 | import android.app.ActivityManager; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 23 | import android.app.ActivityManagerNative; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 24 | import android.app.Notification; |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 25 | import android.app.NotificationManager; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 26 | import android.app.PendingIntent; |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 27 | import android.app.RemoteInput; |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 28 | import android.app.TaskStackBuilder; |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 29 | import android.app.admin.DevicePolicyManager; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 30 | import android.content.BroadcastReceiver; |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 31 | import android.content.ComponentName; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 32 | import android.content.Context; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 33 | import android.content.Intent; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 34 | import android.content.IntentFilter; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 35 | import android.content.pm.ApplicationInfo; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 37 | import android.content.pm.PackageManager.NameNotFoundException; |
Dan Sandler | f4db75c | 2014-09-03 18:02:31 +0200 | [diff] [blame] | 38 | import android.content.pm.ResolveInfo; |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 39 | import android.content.pm.UserInfo; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 40 | import android.content.res.Configuration; |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 41 | import android.content.res.Resources; |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 42 | import android.database.ContentObserver; |
Jorim Jaggi | a1eeade | 2014-09-08 22:34:39 +0200 | [diff] [blame] | 43 | import android.graphics.PorterDuff; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 44 | import android.graphics.drawable.Drawable; |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 45 | import android.os.AsyncTask; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 46 | import android.os.Build; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 47 | import android.os.Handler; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 48 | import android.os.IBinder; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 49 | import android.os.Message; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 50 | import android.os.PowerManager; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 51 | import android.os.RemoteException; |
| 52 | import android.os.ServiceManager; |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 53 | import android.os.SystemProperties; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 55 | import android.os.UserManager; |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 56 | import android.provider.Settings; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 57 | import android.service.dreams.DreamService; |
| 58 | import android.service.dreams.IDreamManager; |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 59 | import android.service.notification.NotificationListenerService; |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 60 | import android.service.notification.NotificationListenerService.RankingMap; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 61 | import android.service.notification.StatusBarNotification; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 62 | import android.text.TextUtils; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 63 | import android.util.Log; |
Dan Sandler | e163a64 | 2015-03-01 22:58:32 -0500 | [diff] [blame] | 64 | import android.util.Slog; |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 65 | import android.util.SparseArray; |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 66 | import android.util.SparseBooleanArray; |
Daniel Sandler | c638c1e | 2011-08-24 16:19:23 -0700 | [diff] [blame] | 67 | import android.view.Display; |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 68 | import android.view.IWindowManager; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 69 | import android.view.LayoutInflater; |
| 70 | import android.view.MotionEvent; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 71 | import android.view.View; |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 72 | import android.view.ViewAnimationUtils; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 73 | import android.view.ViewGroup; |
Christoph Studer | 4da84cd | 2014-10-21 17:24:20 +0200 | [diff] [blame] | 74 | import android.view.ViewParent; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 75 | import android.view.WindowManager; |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 76 | import android.view.WindowManagerGlobal; |
Selim Cinek | a8fefa5 | 2014-09-08 16:10:50 +0200 | [diff] [blame] | 77 | import android.view.accessibility.AccessibilityManager; |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 78 | import android.view.animation.AnimationUtils; |
Dan Sandler | 18bb4f9 | 2014-07-14 16:48:27 -0400 | [diff] [blame] | 79 | import android.widget.DateTimeView; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 80 | import android.widget.ImageView; |
Michael Jurka | a600fd9 | 2012-06-25 15:57:05 -0700 | [diff] [blame] | 81 | import android.widget.RemoteViews; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 82 | import android.widget.TextView; |
Kenny Guy | dae30d5 | 2015-04-01 19:11:35 +0100 | [diff] [blame] | 83 | import android.widget.Toast; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 84 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 85 | import com.android.internal.statusbar.IStatusBarService; |
| 86 | import com.android.internal.statusbar.StatusBarIcon; |
| 87 | import com.android.internal.statusbar.StatusBarIconList; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 88 | import com.android.internal.util.NotificationColorUtil; |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 89 | import com.android.internal.widget.LockPatternUtils; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 90 | import com.android.systemui.R; |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 91 | import com.android.systemui.RecentsComponent; |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 92 | import com.android.systemui.SwipeHelper; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 93 | import com.android.systemui.SystemUI; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 94 | import com.android.systemui.recents.Recents; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 95 | import com.android.systemui.statusbar.NotificationData.Entry; |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 96 | import com.android.systemui.statusbar.phone.NavigationBarView; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 97 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 98 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 99 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 100 | import com.android.systemui.statusbar.policy.PreviewInflater; |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 101 | import com.android.systemui.statusbar.policy.RemoteInputView; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 102 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 103 | |
Michael Jurka | a600fd9 | 2012-06-25 15:57:05 -0700 | [diff] [blame] | 104 | import java.util.ArrayList; |
Dan Sandler | f4db75c | 2014-09-03 18:02:31 +0200 | [diff] [blame] | 105 | import java.util.List; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 106 | import java.util.Locale; |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 107 | |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 108 | import static com.android.keyguard.KeyguardHostView.OnDismissAction; |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 109 | |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 110 | public abstract class BaseStatusBar extends SystemUI implements |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 111 | CommandQueue.Callbacks, ActivatableNotificationView.OnActivatedListener, |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 112 | RecentsComponent.Callbacks, ExpandableNotificationRow.ExpansionLogger, |
| 113 | NotificationData.Environment { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 114 | public static final String TAG = "StatusBar"; |
John Spurlock | 7e6809a | 2014-08-06 16:03:14 -0400 | [diff] [blame] | 115 | public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 116 | public static final boolean MULTIUSER_DEBUG = false; |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 117 | |
Chris Wren | 79ac09e | 2014-10-29 14:20:19 -0400 | [diff] [blame] | 118 | // STOPSHIP disable once we resolve b/18102199 |
Chris Wren | 755f402 | 2014-10-29 16:43:26 -0400 | [diff] [blame] | 119 | private static final boolean NOTIFICATION_CLICK_DEBUG = true; |
Chris Wren | 79ac09e | 2014-10-29 14:20:19 -0400 | [diff] [blame] | 120 | |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 121 | public static final boolean ENABLE_REMOTE_INPUT = |
| 122 | Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.enable_remote_input", false); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 123 | public static final boolean ENABLE_CHILD_NOTIFICATIONS = Build.IS_DEBUGGABLE |
| 124 | && SystemProperties.getBoolean("debug.child_notifs", false); |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 125 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 126 | protected static final int MSG_SHOW_RECENT_APPS = 1019; |
| 127 | protected static final int MSG_HIDE_RECENT_APPS = 1020; |
| 128 | protected static final int MSG_TOGGLE_RECENTS_APPS = 1021; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 129 | protected static final int MSG_PRELOAD_RECENT_APPS = 1022; |
| 130 | protected static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 1023; |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 131 | protected static final int MSG_SHOW_NEXT_AFFILIATED_TASK = 1024; |
| 132 | protected static final int MSG_SHOW_PREV_AFFILIATED_TASK = 1025; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 133 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 134 | protected static final boolean ENABLE_HEADS_UP = true; |
| 135 | // scores above this threshold should be displayed in heads up mode. |
Chris Wren | 5d9b153 | 2014-03-21 14:31:05 -0400 | [diff] [blame] | 136 | protected static final int INTERRUPTION_THRESHOLD = 10; |
Chris Wren | 22ae46e | 2014-02-26 18:08:09 -0500 | [diff] [blame] | 137 | protected static final String SETTING_HEADS_UP_TICKER = "ticker_gets_heads_up"; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 138 | |
Michael Jurka | 56a5783 | 2012-05-14 13:24:43 -0700 | [diff] [blame] | 139 | // Should match the value in PhoneWindowManager |
| 140 | public static final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
| 141 | |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 142 | private static final String BANNER_ACTION_CANCEL = |
| 143 | "com.android.systemui.statusbar.banner_action_cancel"; |
| 144 | private static final String BANNER_ACTION_SETUP = |
| 145 | "com.android.systemui.statusbar.banner_action_setup"; |
| 146 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 147 | protected CommandQueue mCommandQueue; |
| 148 | protected IStatusBarService mBarService; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 149 | protected H mHandler = createHandler(); |
| 150 | |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 151 | // all notifications |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 152 | protected NotificationData mNotificationData; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 153 | protected NotificationStackScrollLayout mStackScroller; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 154 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 155 | protected NotificationGroupManager mGroupManager = new NotificationGroupManager(); |
| 156 | |
Chris Wren | a4ef620 | 2014-06-09 18:07:30 -0400 | [diff] [blame] | 157 | // for heads up notifications |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 158 | protected HeadsUpManager mHeadsUpManager; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 159 | |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 160 | protected int mCurrentUserId = 0; |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 161 | final protected SparseArray<UserInfo> mCurrentProfiles = new SparseArray<UserInfo>(); |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 162 | |
Daniel Sandler | 777dcde | 2013-09-30 10:21:45 -0400 | [diff] [blame] | 163 | protected int mLayoutDirection = -1; // invalid |
Selim Cinek | a8fefa5 | 2014-09-08 16:10:50 +0200 | [diff] [blame] | 164 | protected AccessibilityManager mAccessibilityManager; |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 165 | |
| 166 | // on-screen navigation buttons |
| 167 | protected NavigationBarView mNavigationBarView = null; |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 168 | |
| 169 | protected Boolean mScreenOn; |
| 170 | |
| 171 | // The second field is a bit different from the first one because it only listens to screen on/ |
| 172 | // screen of events from Keyguard. We need this so we don't have a race condition with the |
| 173 | // broadcast. In the future, we should remove the first field altogether and rename the second |
| 174 | // field. |
| 175 | protected boolean mScreenOnFromKeyguard; |
| 176 | |
| 177 | protected boolean mVisible; |
| 178 | |
| 179 | // mScreenOnFromKeyguard && mVisible. |
| 180 | private boolean mVisibleToUser; |
| 181 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 182 | private Locale mLocale; |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 183 | private float mFontScale; |
| 184 | |
Chris Wren | f6e83f4 | 2013-09-11 14:02:59 -0400 | [diff] [blame] | 185 | protected boolean mUseHeadsUp = false; |
Chris Wren | 22ae46e | 2014-02-26 18:08:09 -0500 | [diff] [blame] | 186 | protected boolean mHeadsUpTicker = false; |
Jason Monk | f701954 | 2014-07-31 12:42:25 -0400 | [diff] [blame] | 187 | protected boolean mDisableNotificationAlerts = false; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 188 | |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 189 | protected DevicePolicyManager mDevicePolicyManager; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 190 | protected IDreamManager mDreamManager; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 191 | PowerManager mPowerManager; |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 192 | protected StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 193 | protected int mRowMinHeight; |
| 194 | protected int mRowMaxHeight; |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 195 | |
| 196 | // public mode, private notifications, etc |
| 197 | private boolean mLockscreenPublicMode = false; |
| 198 | private final SparseBooleanArray mUsersAllowingPrivateNotifications = new SparseBooleanArray(); |
Dan Sandler | 05c362d | 2014-09-03 00:16:27 +0200 | [diff] [blame] | 199 | private NotificationColorUtil mNotificationColorUtil; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 200 | |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 201 | private UserManager mUserManager; |
| 202 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 203 | // UI-specific methods |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 204 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 205 | /** |
| 206 | * Create all windows necessary for the status bar (including navigation, overlay panels, etc) |
| 207 | * and add them to the window manager. |
| 208 | */ |
| 209 | protected abstract void createAndAddWindows(); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 210 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 211 | protected WindowManager mWindowManager; |
| 212 | protected IWindowManager mWindowManagerService; |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 213 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 214 | protected abstract void refreshLayout(int layoutDirection); |
| 215 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 216 | protected Display mDisplay; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 217 | |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 218 | private boolean mDeviceProvisioned = false; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 219 | |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 220 | private RecentsComponent mRecents; |
| 221 | |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 222 | protected int mZenMode; |
| 223 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 224 | // which notification is currently being longpress-examined by the user |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 225 | private NotificationGuts mNotificationGutsExposed; |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 226 | |
| 227 | private TimeInterpolator mLinearOutSlowIn, mFastOutLinearIn; |
| 228 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 229 | /** |
| 230 | * The {@link StatusBarState} of the status bar. |
| 231 | */ |
| 232 | protected int mState; |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 233 | protected boolean mBouncerShowing; |
John Spurlock | 4b3bda2 | 2014-05-22 14:32:20 -0400 | [diff] [blame] | 234 | protected boolean mShowLockscreenNotifications; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 235 | |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 236 | protected NotificationOverflowContainer mKeyguardIconOverflowContainer; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 237 | protected DismissView mDismissView; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 238 | protected EmptyShadeView mEmptyShadeView; |
Jorim Jaggi | 649b708 | 2014-04-03 13:15:18 +0200 | [diff] [blame] | 239 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 240 | @Override // NotificationData.Environment |
Daniel Sandler | 3ffdcc7 | 2012-09-23 14:31:48 -0400 | [diff] [blame] | 241 | public boolean isDeviceProvisioned() { |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 242 | return mDeviceProvisioned; |
| 243 | } |
| 244 | |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 245 | protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) { |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 246 | @Override |
| 247 | public void onChange(boolean selfChange) { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 248 | final boolean provisioned = 0 != Settings.Global.getInt( |
| 249 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0); |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 250 | if (provisioned != mDeviceProvisioned) { |
| 251 | mDeviceProvisioned = provisioned; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 252 | updateNotifications(); |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 253 | } |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 254 | final int mode = Settings.Global.getInt(mContext.getContentResolver(), |
| 255 | Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE_OFF); |
| 256 | setZenMode(mode); |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 257 | |
| 258 | updateLockscreenNotificationSetting(); |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 259 | } |
| 260 | }; |
| 261 | |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 262 | private final ContentObserver mLockscreenSettingsObserver = new ContentObserver(mHandler) { |
| 263 | @Override |
| 264 | public void onChange(boolean selfChange) { |
| 265 | // We don't know which user changed LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, |
| 266 | // so we just dump our cache ... |
| 267 | mUsersAllowingPrivateNotifications.clear(); |
| 268 | // ... and refresh all the notifications |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 269 | updateNotifications(); |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 270 | } |
| 271 | }; |
| 272 | |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 273 | private RemoteViews.OnClickHandler mOnClickHandler = new RemoteViews.OnClickHandler() { |
| 274 | @Override |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 275 | public boolean onClickHandler( |
| 276 | final View view, final PendingIntent pendingIntent, final Intent fillInIntent) { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 277 | if (DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 278 | Log.v(TAG, "Notification click handler invoked for intent: " + pendingIntent); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 279 | } |
Christoph Studer | 4da84cd | 2014-10-21 17:24:20 +0200 | [diff] [blame] | 280 | logActionClick(view); |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 281 | // The intent we are sending is for the application, which |
| 282 | // won't have permission to immediately start an activity after |
| 283 | // the user switches to home. We know it is safe to do at this |
| 284 | // point, so make sure new activity switches are now allowed. |
| 285 | try { |
| 286 | ActivityManagerNative.getDefault().resumeAppSwitches(); |
| 287 | } catch (RemoteException e) { |
| 288 | } |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 289 | final boolean isActivity = pendingIntent.isActivity(); |
| 290 | if (isActivity) { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 291 | final boolean keyguardShowing = mStatusBarKeyguardViewManager.isShowing(); |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 292 | final boolean afterKeyguardGone = PreviewInflater.wouldLaunchResolverActivity( |
| 293 | mContext, pendingIntent.getIntent(), mCurrentUserId); |
Adrian Roos | 4314f6d | 2014-05-28 14:10:27 +0200 | [diff] [blame] | 294 | dismissKeyguardThenExecute(new OnDismissAction() { |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 295 | @Override |
| 296 | public boolean onDismiss() { |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 297 | if (keyguardShowing && !afterKeyguardGone) { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 298 | try { |
| 299 | ActivityManagerNative.getDefault() |
| 300 | .keyguardWaitingForActivityDrawn(); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 301 | } catch (RemoteException e) { |
| 302 | } |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 303 | } |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 304 | |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 305 | boolean handled = superOnClickHandler(view, pendingIntent, fillInIntent); |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 306 | overrideActivityPendingAppTransition(keyguardShowing && !afterKeyguardGone); |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 307 | |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 308 | // close the shade if it was open |
| 309 | if (handled) { |
Jorim Jaggi | 4eedc1d | 2014-10-27 13:45:56 +0100 | [diff] [blame] | 310 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, |
| 311 | true /* force */); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 312 | visibilityChanged(false); |
| 313 | } |
Adrian Roos | 4314f6d | 2014-05-28 14:10:27 +0200 | [diff] [blame] | 314 | // Wait for activity start. |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 315 | return handled; |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 316 | } |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 317 | }, afterKeyguardGone); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 318 | return true; |
| 319 | } else { |
| 320 | return super.onClickHandler(view, pendingIntent, fillInIntent); |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 321 | } |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 322 | } |
| 323 | |
Christoph Studer | 4da84cd | 2014-10-21 17:24:20 +0200 | [diff] [blame] | 324 | private void logActionClick(View view) { |
| 325 | ViewParent parent = view.getParent(); |
| 326 | String key = getNotificationKeyForParent(parent); |
| 327 | if (key == null) { |
| 328 | Log.w(TAG, "Couldn't determine notification for click."); |
| 329 | return; |
| 330 | } |
| 331 | int index = -1; |
| 332 | // If this is a default template, determine the index of the button. |
| 333 | if (view.getId() == com.android.internal.R.id.action0 && |
| 334 | parent != null && parent instanceof ViewGroup) { |
| 335 | ViewGroup actionGroup = (ViewGroup) parent; |
| 336 | index = actionGroup.indexOfChild(view); |
| 337 | } |
Chris Wren | 79ac09e | 2014-10-29 14:20:19 -0400 | [diff] [blame] | 338 | if (NOTIFICATION_CLICK_DEBUG) { |
| 339 | Log.d(TAG, "Clicked on button " + index + " for " + key); |
| 340 | } |
Christoph Studer | 4da84cd | 2014-10-21 17:24:20 +0200 | [diff] [blame] | 341 | try { |
| 342 | mBarService.onNotificationActionClick(key, index); |
| 343 | } catch (RemoteException e) { |
| 344 | // Ignore |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | private String getNotificationKeyForParent(ViewParent parent) { |
| 349 | while (parent != null) { |
| 350 | if (parent instanceof ExpandableNotificationRow) { |
| 351 | return ((ExpandableNotificationRow) parent).getStatusBarNotification().getKey(); |
| 352 | } |
| 353 | parent = parent.getParent(); |
| 354 | } |
| 355 | return null; |
| 356 | } |
| 357 | |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 358 | private boolean superOnClickHandler(View view, PendingIntent pendingIntent, |
| 359 | Intent fillInIntent) { |
| 360 | return super.onClickHandler(view, pendingIntent, fillInIntent); |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 361 | } |
| 362 | }; |
| 363 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 364 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 365 | @Override |
| 366 | public void onReceive(Context context, Intent intent) { |
| 367 | String action = intent.getAction(); |
| 368 | if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 369 | mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 370 | updateCurrentProfilesCache(); |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 371 | if (true) Log.v(TAG, "userId " + mCurrentUserId + " is in the house"); |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 372 | |
| 373 | updateLockscreenNotificationSetting(); |
| 374 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 375 | userSwitched(mCurrentUserId); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 376 | } else if (Intent.ACTION_USER_ADDED.equals(action)) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 377 | updateCurrentProfilesCache(); |
Kenny Guy | dae30d5 | 2015-04-01 19:11:35 +0100 | [diff] [blame] | 378 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 379 | List<ActivityManager.RecentTaskInfo> recentTask = null; |
| 380 | try { |
| 381 | recentTask = ActivityManagerNative.getDefault().getRecentTasks(1, |
| 382 | ActivityManager.RECENT_WITH_EXCLUDED |
| 383 | | ActivityManager.RECENT_INCLUDE_PROFILES, |
| 384 | mCurrentUserId); |
| 385 | } catch (RemoteException e) { |
| 386 | // Abandon hope activity manager not running. |
| 387 | } |
| 388 | if (recentTask != null && recentTask.size() > 0) { |
| 389 | UserInfo user = mUserManager.getUserInfo(recentTask.get(0).userId); |
| 390 | if (user != null && user.isManagedProfile()) { |
| 391 | Toast.makeText(mContext, R.string.managed_profile_foreground_toast, |
| 392 | Toast.LENGTH_SHORT).show(); |
| 393 | } |
| 394 | } |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 395 | } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals( |
| 396 | action)) { |
| 397 | mUsersAllowingPrivateNotifications.clear(); |
| 398 | updateLockscreenNotificationSetting(); |
| 399 | updateNotifications(); |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 400 | } else if (BANNER_ACTION_CANCEL.equals(action) || BANNER_ACTION_SETUP.equals(action)) { |
| 401 | NotificationManager noMan = (NotificationManager) |
| 402 | mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
Chris Wren | d877510 | 2015-01-16 16:16:43 -0500 | [diff] [blame] | 403 | noMan.cancel(R.id.notification_hidden); |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 404 | |
| 405 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 406 | Settings.Secure.SHOW_NOTE_ABOUT_NOTIFICATION_HIDING, 0); |
| 407 | if (BANNER_ACTION_SETUP.equals(action)) { |
Jorim Jaggi | 4eedc1d | 2014-10-27 13:45:56 +0100 | [diff] [blame] | 408 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, |
| 409 | true /* force */); |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 410 | mContext.startActivity(new Intent(Settings.ACTION_APP_NOTIFICATION_REDACTION) |
| 411 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| 412 | |
| 413 | ); |
| 414 | } |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | }; |
| 418 | |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 419 | private final NotificationListenerService mNotificationListener = |
| 420 | new NotificationListenerService() { |
| 421 | @Override |
| 422 | public void onListenerConnected() { |
| 423 | if (DEBUG) Log.d(TAG, "onListenerConnected"); |
| 424 | final StatusBarNotification[] notifications = getActiveNotifications(); |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 425 | final RankingMap currentRanking = getCurrentRanking(); |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 426 | mHandler.post(new Runnable() { |
| 427 | @Override |
| 428 | public void run() { |
| 429 | for (StatusBarNotification sbn : notifications) { |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 430 | addNotification(sbn, currentRanking, null /* oldEntry */); |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | }); |
| 434 | } |
| 435 | |
| 436 | @Override |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 437 | public void onNotificationPosted(final StatusBarNotification sbn, |
| 438 | final RankingMap rankingMap) { |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 439 | if (DEBUG) Log.d(TAG, "onNotificationPosted: " + sbn); |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 440 | if (sbn != null) { |
| 441 | mHandler.post(new Runnable() { |
| 442 | @Override |
| 443 | public void run() { |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 444 | processForRemoteInput(sbn.getNotification()); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 445 | String key = sbn.getKey(); |
| 446 | boolean isUpdate = mNotificationData.get(key) != null; |
Christoph Studer | d722f27 | 2014-09-02 11:49:19 +0200 | [diff] [blame] | 447 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 448 | // In case we don't allow child notifications, we ignore children of |
| 449 | // notifications that have a summary, since we're not going to show them |
| 450 | // anyway. This is true also when the summary is canceled, |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 451 | // because children are automatically canceled by NoMan in that case. |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 452 | if (!ENABLE_CHILD_NOTIFICATIONS |
| 453 | && mGroupManager.isChildInGroupWithSummary(sbn)) { |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 454 | if (DEBUG) { |
| 455 | Log.d(TAG, "Ignoring group child due to existing summary: " + sbn); |
| 456 | } |
| 457 | |
| 458 | // Remove existing notification to avoid stale data. |
| 459 | if (isUpdate) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 460 | removeNotification(key, rankingMap); |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 461 | } else { |
| 462 | mNotificationData.updateRanking(rankingMap); |
| 463 | } |
| 464 | return; |
Christoph Studer | d722f27 | 2014-09-02 11:49:19 +0200 | [diff] [blame] | 465 | } |
Christoph Studer | d722f27 | 2014-09-02 11:49:19 +0200 | [diff] [blame] | 466 | if (isUpdate) { |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 467 | updateNotification(sbn, rankingMap); |
Christoph Studer | d722f27 | 2014-09-02 11:49:19 +0200 | [diff] [blame] | 468 | } else { |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 469 | addNotification(sbn, rankingMap, null /* oldEntry */); |
Christoph Studer | d722f27 | 2014-09-02 11:49:19 +0200 | [diff] [blame] | 470 | } |
Christoph Studer | d722f27 | 2014-09-02 11:49:19 +0200 | [diff] [blame] | 471 | } |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 472 | }); |
| 473 | } |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | @Override |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 477 | public void onNotificationRemoved(StatusBarNotification sbn, |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 478 | final RankingMap rankingMap) { |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 479 | if (DEBUG) Log.d(TAG, "onNotificationRemoved: " + sbn); |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 480 | if (sbn != null) { |
| 481 | final String key = sbn.getKey(); |
| 482 | mHandler.post(new Runnable() { |
| 483 | @Override |
| 484 | public void run() { |
| 485 | removeNotification(key, rankingMap); |
| 486 | } |
| 487 | }); |
| 488 | } |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | @Override |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 492 | public void onNotificationRankingUpdate(final RankingMap rankingMap) { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 493 | if (DEBUG) Log.d(TAG, "onRankingUpdate"); |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 494 | if (rankingMap != null) { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 495 | mHandler.post(new Runnable() { |
| 496 | @Override |
| 497 | public void run() { |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 498 | updateNotificationRanking(rankingMap); |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 499 | } |
| 500 | }); |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 501 | } } |
Christoph Studer | 5b63826 | 2014-07-07 11:21:49 +0200 | [diff] [blame] | 502 | |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 503 | }; |
| 504 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 505 | private void updateCurrentProfilesCache() { |
| 506 | synchronized (mCurrentProfiles) { |
| 507 | mCurrentProfiles.clear(); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 508 | if (mUserManager != null) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 509 | for (UserInfo user : mUserManager.getProfiles(mCurrentUserId)) { |
| 510 | mCurrentProfiles.put(user.id, user); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | } |
| 514 | } |
| 515 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 516 | public void start() { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 517 | mWindowManager = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 518 | mWindowManagerService = WindowManagerGlobal.getWindowManagerService(); |
| 519 | mDisplay = mWindowManager.getDefaultDisplay(); |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 520 | mDevicePolicyManager = (DevicePolicyManager)mContext.getSystemService( |
| 521 | Context.DEVICE_POLICY_SERVICE); |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 522 | |
Dan Sandler | 05c362d | 2014-09-03 00:16:27 +0200 | [diff] [blame] | 523 | mNotificationColorUtil = NotificationColorUtil.getInstance(mContext); |
| 524 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 525 | mNotificationData = new NotificationData(this); |
| 526 | |
Selim Cinek | a8fefa5 | 2014-09-08 16:10:50 +0200 | [diff] [blame] | 527 | mAccessibilityManager = (AccessibilityManager) |
| 528 | mContext.getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 529 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 530 | mDreamManager = IDreamManager.Stub.asInterface( |
| 531 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 532 | mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 533 | |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 534 | mContext.getContentResolver().registerContentObserver( |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 535 | Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), true, |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 536 | mSettingsObserver); |
| 537 | mContext.getContentResolver().registerContentObserver( |
| 538 | Settings.Global.getUriFor(Settings.Global.ZEN_MODE), false, |
| 539 | mSettingsObserver); |
John Spurlock | 4b3bda2 | 2014-05-22 14:32:20 -0400 | [diff] [blame] | 540 | mContext.getContentResolver().registerContentObserver( |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 541 | Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS), false, |
| 542 | mSettingsObserver, |
| 543 | UserHandle.USER_ALL); |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 544 | |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 545 | mContext.getContentResolver().registerContentObserver( |
| 546 | Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS), |
| 547 | true, |
| 548 | mLockscreenSettingsObserver, |
| 549 | UserHandle.USER_ALL); |
| 550 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 551 | mBarService = IStatusBarService.Stub.asInterface( |
| 552 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 553 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 554 | mRecents = getComponent(Recents.class); |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 555 | mRecents.setCallback(this); |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 556 | |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 557 | final Configuration currentConfig = mContext.getResources().getConfiguration(); |
| 558 | mLocale = currentConfig.locale; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 559 | mLayoutDirection = TextUtils.getLayoutDirectionFromLocale(mLocale); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 560 | mFontScale = currentConfig.fontScale; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 561 | |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 562 | mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
| 563 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 564 | mLinearOutSlowIn = AnimationUtils.loadInterpolator(mContext, |
| 565 | android.R.interpolator.linear_out_slow_in); |
| 566 | mFastOutLinearIn = AnimationUtils.loadInterpolator(mContext, |
| 567 | android.R.interpolator.fast_out_linear_in); |
| 568 | |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 569 | // Connect in to the status bar manager service |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 570 | StatusBarIconList iconList = new StatusBarIconList(); |
Joe Onorato | 66d7d01 | 2010-05-14 10:05:10 -0700 | [diff] [blame] | 571 | mCommandQueue = new CommandQueue(this, iconList); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 572 | |
Jason Monk | b605fec | 2014-05-02 17:04:10 -0400 | [diff] [blame] | 573 | int[] switches = new int[8]; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 574 | ArrayList<IBinder> binders = new ArrayList<IBinder>(); |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 575 | try { |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 576 | mBarService.registerStatusBar(mCommandQueue, iconList, switches, binders); |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 577 | } catch (RemoteException ex) { |
| 578 | // If the system process isn't there we're doomed anyway. |
| 579 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 580 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 581 | createAndAddWindows(); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 582 | |
Jorim Jaggi | 66ac133 | 2015-01-21 19:22:26 +0100 | [diff] [blame] | 583 | mSettingsObserver.onChange(false); // set up |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 584 | disable(switches[0], false /* animate */); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 585 | setSystemUiVisibility(switches[1], 0xffffffff); |
Dianne Hackborn | 7d04932 | 2011-06-14 15:00:32 -0700 | [diff] [blame] | 586 | topAppWindowChanged(switches[2] != 0); |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 587 | // StatusBarManagerService has a back up of IME token and it's restored here. |
Michael Wright | 665366a | 2014-08-07 15:44:40 -0700 | [diff] [blame] | 588 | setImeWindowStatus(binders.get(0), switches[3], switches[4], switches[5] != 0); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 589 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 590 | // Set up the initial icon state |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 591 | int N = iconList.size(); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 592 | int viewIndex = 0; |
| 593 | for (int i=0; i<N; i++) { |
| 594 | StatusBarIcon icon = iconList.getIcon(i); |
| 595 | if (icon != null) { |
| 596 | addIcon(iconList.getSlot(i), i, viewIndex, icon); |
| 597 | viewIndex++; |
| 598 | } |
| 599 | } |
| 600 | |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 601 | // Set up the initial notification state. |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 602 | try { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 603 | mNotificationListener.registerAsSystemService(mContext, |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 604 | new ComponentName(mContext.getPackageName(), getClass().getCanonicalName()), |
| 605 | UserHandle.USER_ALL); |
| 606 | } catch (RemoteException e) { |
| 607 | Log.e(TAG, "Unable to register notification listener", e); |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 608 | } |
| 609 | |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 610 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 611 | if (DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 612 | Log.d(TAG, String.format( |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 613 | "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] | 614 | iconList.size(), |
| 615 | switches[0], |
| 616 | switches[1], |
| 617 | switches[2], |
| 618 | switches[3] |
| 619 | )); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 620 | } |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 621 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 622 | mCurrentUserId = ActivityManager.getCurrentUser(); |
Chris Wren | a6d4fb6 | 2014-11-20 14:46:23 -0500 | [diff] [blame] | 623 | setHeadsUpUser(mCurrentUserId); |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 624 | |
| 625 | IntentFilter filter = new IntentFilter(); |
| 626 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 627 | filter.addAction(Intent.ACTION_USER_ADDED); |
Kenny Guy | dae30d5 | 2015-04-01 19:11:35 +0100 | [diff] [blame] | 628 | filter.addAction(Intent.ACTION_USER_PRESENT); |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 629 | filter.addAction(BANNER_ACTION_CANCEL); |
| 630 | filter.addAction(BANNER_ACTION_SETUP); |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 631 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 632 | mContext.registerReceiver(mBroadcastReceiver, filter); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 633 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 634 | updateCurrentProfilesCache(); |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 635 | } |
| 636 | |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 637 | protected void notifyUserAboutHiddenNotifications() { |
| 638 | if (0 != Settings.Secure.getInt(mContext.getContentResolver(), |
| 639 | Settings.Secure.SHOW_NOTE_ABOUT_NOTIFICATION_HIDING, 1)) { |
| 640 | Log.d(TAG, "user hasn't seen notification about hidden notifications"); |
| 641 | final LockPatternUtils lockPatternUtils = new LockPatternUtils(mContext); |
| 642 | if (!lockPatternUtils.isSecure()) { |
| 643 | Log.d(TAG, "insecure lockscreen, skipping notification"); |
| 644 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 645 | Settings.Secure.SHOW_NOTE_ABOUT_NOTIFICATION_HIDING, 0); |
| 646 | return; |
| 647 | } |
| 648 | Log.d(TAG, "disabling lockecreen notifications and alerting the user"); |
| 649 | // disable lockscreen notifications until user acts on the banner. |
| 650 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 651 | Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0); |
Adrian Roos | aee7046 | 2014-09-03 16:27:39 +0200 | [diff] [blame] | 652 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 653 | Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0); |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 654 | |
| 655 | final String packageName = mContext.getPackageName(); |
| 656 | PendingIntent cancelIntent = PendingIntent.getBroadcast(mContext, 0, |
| 657 | new Intent(BANNER_ACTION_CANCEL).setPackage(packageName), |
| 658 | PendingIntent.FLAG_CANCEL_CURRENT); |
| 659 | PendingIntent setupIntent = PendingIntent.getBroadcast(mContext, 0, |
| 660 | new Intent(BANNER_ACTION_SETUP).setPackage(packageName), |
| 661 | PendingIntent.FLAG_CANCEL_CURRENT); |
| 662 | |
| 663 | final Resources res = mContext.getResources(); |
| 664 | final int colorRes = com.android.internal.R.color.system_notification_accent_color; |
| 665 | Notification.Builder note = new Notification.Builder(mContext) |
| 666 | .setSmallIcon(R.drawable.ic_android) |
| 667 | .setContentTitle(mContext.getString(R.string.hidden_notifications_title)) |
| 668 | .setContentText(mContext.getString(R.string.hidden_notifications_text)) |
| 669 | .setPriority(Notification.PRIORITY_HIGH) |
| 670 | .setOngoing(true) |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 671 | .setColor(mContext.getColor(colorRes)) |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 672 | .setContentIntent(setupIntent) |
| 673 | .addAction(R.drawable.ic_close, |
| 674 | mContext.getString(R.string.hidden_notifications_cancel), |
| 675 | cancelIntent) |
| 676 | .addAction(R.drawable.ic_settings, |
| 677 | mContext.getString(R.string.hidden_notifications_setup), |
| 678 | setupIntent); |
| 679 | |
| 680 | NotificationManager noMan = |
| 681 | (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
Chris Wren | d877510 | 2015-01-16 16:16:43 -0500 | [diff] [blame] | 682 | noMan.notify(R.id.notification_hidden, note.build()); |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 686 | public void userSwitched(int newUserId) { |
Chris Wren | a6d4fb6 | 2014-11-20 14:46:23 -0500 | [diff] [blame] | 687 | setHeadsUpUser(newUserId); |
| 688 | } |
| 689 | |
| 690 | private void setHeadsUpUser(int newUserId) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 691 | mHeadsUpManager.setUser(newUserId); |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 692 | } |
| 693 | |
Chris Wren | d04f6ce | 2014-06-11 17:37:28 -0400 | [diff] [blame] | 694 | public boolean isHeadsUp(String key) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 695 | return mHeadsUpManager.isHeadsUp(key); |
Chris Wren | d04f6ce | 2014-06-11 17:37:28 -0400 | [diff] [blame] | 696 | } |
| 697 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 698 | @Override // NotificationData.Environment |
| 699 | public boolean isNotificationForCurrentProfiles(StatusBarNotification n) { |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 700 | final int thisUserId = mCurrentUserId; |
| 701 | final int notificationUserId = n.getUserId(); |
| 702 | if (DEBUG && MULTIUSER_DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 703 | Log.v(TAG, String.format("%s: current userid: %d, notification userid: %d", |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 704 | n, thisUserId, notificationUserId)); |
| 705 | } |
Dan Sandler | e63ba4b | 2014-12-05 00:26:24 -0500 | [diff] [blame] | 706 | return isCurrentProfile(notificationUserId); |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 707 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 708 | |
Kenny Guy | 44fc65f | 2014-11-28 22:18:14 +0000 | [diff] [blame] | 709 | protected boolean isCurrentProfile(int userId) { |
| 710 | synchronized (mCurrentProfiles) { |
Dan Sandler | e63ba4b | 2014-12-05 00:26:24 -0500 | [diff] [blame] | 711 | return userId == UserHandle.USER_ALL || mCurrentProfiles.get(userId) != null; |
Kenny Guy | 44fc65f | 2014-11-28 22:18:14 +0000 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
Christoph Studer | 2e731b5 | 2014-08-22 16:01:51 +0200 | [diff] [blame] | 715 | @Override |
| 716 | public String getCurrentMediaNotificationKey() { |
| 717 | return null; |
| 718 | } |
| 719 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 720 | @Override |
| 721 | public NotificationGroupManager getGroupManager() { |
| 722 | return mGroupManager; |
| 723 | } |
| 724 | |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 725 | /** |
| 726 | * Takes the necessary steps to prepare the status bar for starting an activity, then starts it. |
| 727 | * @param action A dismiss action that is called if it's safe to start the activity. |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 728 | * @param afterKeyguardGone Whether the action should be executed after the Keyguard is gone. |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 729 | */ |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 730 | protected void dismissKeyguardThenExecute(OnDismissAction action, boolean afterKeyguardGone) { |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 731 | action.onDismiss(); |
| 732 | } |
| 733 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 734 | @Override |
| 735 | protected void onConfigurationChanged(Configuration newConfig) { |
Daniel Sandler | 777dcde | 2013-09-30 10:21:45 -0400 | [diff] [blame] | 736 | final Locale locale = mContext.getResources().getConfiguration().locale; |
| 737 | final int ld = TextUtils.getLayoutDirectionFromLocale(locale); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 738 | final float fontScale = newConfig.fontScale; |
| 739 | |
| 740 | if (! locale.equals(mLocale) || ld != mLayoutDirection || fontScale != mFontScale) { |
Daniel Sandler | 777dcde | 2013-09-30 10:21:45 -0400 | [diff] [blame] | 741 | if (DEBUG) { |
| 742 | Log.v(TAG, String.format( |
| 743 | "config changed locale/LD: %s (%d) -> %s (%d)", mLocale, mLayoutDirection, |
| 744 | locale, ld)); |
| 745 | } |
| 746 | mLocale = locale; |
| 747 | mLayoutDirection = ld; |
| 748 | refreshLayout(ld); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 752 | protected View updateNotificationVetoButton(View row, StatusBarNotification n) { |
| 753 | View vetoButton = row.findViewById(R.id.veto); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 754 | if (n.isClearable()) { |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 755 | final String _pkg = n.getPackageName(); |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 756 | final String _tag = n.getTag(); |
| 757 | final int _id = n.getId(); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 758 | final int _userId = n.getUserId(); |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 759 | vetoButton.setOnClickListener(new View.OnClickListener() { |
| 760 | public void onClick(View v) { |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 761 | // Accessibility feedback |
| 762 | v.announceForAccessibility( |
| 763 | mContext.getString(R.string.accessibility_notification_dismissed)); |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 764 | try { |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 765 | mBarService.onNotificationClear(_pkg, _tag, _id, _userId); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 766 | |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 767 | } catch (RemoteException ex) { |
| 768 | // system process is dead if we're here. |
| 769 | } |
| 770 | } |
| 771 | }); |
| 772 | vetoButton.setVisibility(View.VISIBLE); |
| 773 | } else { |
| 774 | vetoButton.setVisibility(View.GONE); |
| 775 | } |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 776 | vetoButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 777 | return vetoButton; |
| 778 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 779 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 780 | |
Christoph Studer | 13b89512 | 2014-08-26 15:42:12 +0200 | [diff] [blame] | 781 | protected void applyColorsAndBackgrounds(StatusBarNotification sbn, |
Jorim Jaggi | 4673985 | 2014-04-15 09:58:24 +0200 | [diff] [blame] | 782 | NotificationData.Entry entry) { |
Dan Sandler | fe266a3 | 2014-05-15 22:28:06 -0400 | [diff] [blame] | 783 | |
Jorim Jaggi | 4673985 | 2014-04-15 09:58:24 +0200 | [diff] [blame] | 784 | if (entry.expanded.getId() != com.android.internal.R.id.status_bar_latest_event_content) { |
Dan Sandler | fe266a3 | 2014-05-15 22:28:06 -0400 | [diff] [blame] | 785 | // Using custom RemoteViews |
Jorim Jaggi | a1eeade | 2014-09-08 22:34:39 +0200 | [diff] [blame] | 786 | if (entry.targetSdk >= Build.VERSION_CODES.GINGERBREAD |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 787 | && entry.targetSdk < Build.VERSION_CODES.LOLLIPOP) { |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 788 | entry.row.setShowingLegacyBackground(true); |
Jorim Jaggi | 36b1523 | 2014-06-10 17:24:20 +0200 | [diff] [blame] | 789 | entry.legacy = true; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 790 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 791 | } else { |
| 792 | // Using platform templates |
| 793 | final int color = sbn.getNotification().color; |
| 794 | if (isMediaNotification(entry)) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 795 | entry.row.setTintColor(color == Notification.COLOR_DEFAULT |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 796 | ? mContext.getColor( |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 797 | R.color.notification_material_background_media_default_color) |
| 798 | : color); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 799 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 800 | } |
Christoph Studer | 13b89512 | 2014-08-26 15:42:12 +0200 | [diff] [blame] | 801 | |
| 802 | if (entry.icon != null) { |
Jorim Jaggi | dd0107a | 2015-01-21 22:23:48 +0100 | [diff] [blame] | 803 | entry.icon.setTag(R.id.icon_is_pre_L, entry.targetSdk < Build.VERSION_CODES.LOLLIPOP); |
Christoph Studer | 13b89512 | 2014-08-26 15:42:12 +0200 | [diff] [blame] | 804 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 805 | } |
| 806 | |
Dan Sandler | 16128f4 | 2014-05-21 12:48:22 -0400 | [diff] [blame] | 807 | public boolean isMediaNotification(NotificationData.Entry entry) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 808 | // TODO: confirm that there's a valid media key |
| 809 | return entry.expandedBig != null && |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 810 | entry.expandedBig.findViewById(com.android.internal.R.id.media_actions) != null; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 811 | } |
| 812 | |
Dan Sandler | f4db75c | 2014-09-03 18:02:31 +0200 | [diff] [blame] | 813 | // The gear button in the guts that links to the app's own notification settings |
| 814 | private void startAppOwnNotificationSettingsActivity(Intent intent, |
| 815 | final int notificationId, final String notificationTag, final int appUid) { |
| 816 | intent.putExtra("notification_id", notificationId); |
| 817 | intent.putExtra("notification_tag", notificationTag); |
| 818 | startNotificationGutsIntent(intent, appUid); |
| 819 | } |
| 820 | |
| 821 | // The (i) button in the guts that links to the system notification settings for that app |
Jorim Jaggi | fb28c0e | 2014-08-22 16:28:42 +0200 | [diff] [blame] | 822 | private void startAppNotificationSettingsActivity(String packageName, final int appUid) { |
| 823 | final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS); |
Dan Sandler | e9a4e90 | 2014-07-31 01:06:43 -0400 | [diff] [blame] | 824 | intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName); |
| 825 | intent.putExtra(Settings.EXTRA_APP_UID, appUid); |
Dan Sandler | f4db75c | 2014-09-03 18:02:31 +0200 | [diff] [blame] | 826 | startNotificationGutsIntent(intent, appUid); |
| 827 | } |
Jorim Jaggi | fb28c0e | 2014-08-22 16:28:42 +0200 | [diff] [blame] | 828 | |
Dan Sandler | f4db75c | 2014-09-03 18:02:31 +0200 | [diff] [blame] | 829 | private void startNotificationGutsIntent(final Intent intent, final int appUid) { |
Jorim Jaggi | fb28c0e | 2014-08-22 16:28:42 +0200 | [diff] [blame] | 830 | final boolean keyguardShowing = mStatusBarKeyguardViewManager.isShowing(); |
| 831 | dismissKeyguardThenExecute(new OnDismissAction() { |
| 832 | @Override |
| 833 | public boolean onDismiss() { |
| 834 | AsyncTask.execute(new Runnable() { |
| 835 | public void run() { |
| 836 | try { |
| 837 | if (keyguardShowing) { |
| 838 | ActivityManagerNative.getDefault() |
| 839 | .keyguardWaitingForActivityDrawn(); |
| 840 | } |
| 841 | TaskStackBuilder.create(mContext) |
| 842 | .addNextIntentWithParentStack(intent) |
| 843 | .startActivities(null, |
| 844 | new UserHandle(UserHandle.getUserId(appUid))); |
| 845 | overrideActivityPendingAppTransition(keyguardShowing); |
| 846 | } catch (RemoteException e) { |
| 847 | } |
| 848 | } |
| 849 | }); |
Jorim Jaggi | 4eedc1d | 2014-10-27 13:45:56 +0100 | [diff] [blame] | 850 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true /* force */); |
Jorim Jaggi | fb28c0e | 2014-08-22 16:28:42 +0200 | [diff] [blame] | 851 | return true; |
| 852 | } |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 853 | }, false /* afterKeyguardGone */); |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 854 | } |
| 855 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 856 | private void bindGuts(ExpandableNotificationRow row) { |
| 857 | row.inflateGuts(); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 858 | final StatusBarNotification sbn = row.getStatusBarNotification(); |
| 859 | PackageManager pmUser = getPackageManagerForUser( |
| 860 | sbn.getUser().getIdentifier()); |
| 861 | row.setTag(sbn.getPackageName()); |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 862 | final View guts = row.getGuts(); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 863 | final String pkg = sbn.getPackageName(); |
| 864 | String appname = pkg; |
| 865 | Drawable pkgicon = null; |
| 866 | int appUid = -1; |
| 867 | try { |
| 868 | final ApplicationInfo info = pmUser.getApplicationInfo(pkg, |
| 869 | PackageManager.GET_UNINSTALLED_PACKAGES |
| 870 | | PackageManager.GET_DISABLED_COMPONENTS); |
| 871 | if (info != null) { |
| 872 | appname = String.valueOf(pmUser.getApplicationLabel(info)); |
| 873 | pkgicon = pmUser.getApplicationIcon(info); |
| 874 | appUid = info.uid; |
| 875 | } |
| 876 | } catch (NameNotFoundException e) { |
| 877 | // app is gone, just show package name and generic icon |
| 878 | pkgicon = pmUser.getDefaultActivityIcon(); |
| 879 | } |
| 880 | ((ImageView) row.findViewById(android.R.id.icon)).setImageDrawable(pkgicon); |
| 881 | ((DateTimeView) row.findViewById(R.id.timestamp)).setTime(sbn.getPostTime()); |
| 882 | ((TextView) row.findViewById(R.id.pkgname)).setText(appname); |
| 883 | final View settingsButton = guts.findViewById(R.id.notification_inspect_item); |
| 884 | final View appSettingsButton |
| 885 | = guts.findViewById(R.id.notification_inspect_app_provided_settings); |
| 886 | if (appUid >= 0) { |
| 887 | final int appUidF = appUid; |
| 888 | settingsButton.setOnClickListener(new View.OnClickListener() { |
| 889 | public void onClick(View v) { |
| 890 | startAppNotificationSettingsActivity(pkg, appUidF); |
| 891 | } |
| 892 | }); |
| 893 | |
| 894 | final Intent appSettingsQueryIntent |
| 895 | = new Intent(Intent.ACTION_MAIN) |
| 896 | .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES) |
| 897 | .setPackage(pkg); |
| 898 | List<ResolveInfo> infos = pmUser.queryIntentActivities(appSettingsQueryIntent, 0); |
| 899 | if (infos.size() > 0) { |
| 900 | appSettingsButton.setVisibility(View.VISIBLE); |
| 901 | appSettingsButton.setContentDescription( |
| 902 | mContext.getResources().getString( |
| 903 | R.string.status_bar_notification_app_settings_title, |
| 904 | appname |
| 905 | )); |
| 906 | final Intent appSettingsLaunchIntent = new Intent(appSettingsQueryIntent) |
| 907 | .setClassName(pkg, infos.get(0).activityInfo.name); |
| 908 | appSettingsButton.setOnClickListener(new View.OnClickListener() { |
| 909 | public void onClick(View v) { |
| 910 | startAppOwnNotificationSettingsActivity(appSettingsLaunchIntent, |
| 911 | sbn.getId(), |
| 912 | sbn.getTag(), |
| 913 | appUidF); |
| 914 | } |
| 915 | }); |
| 916 | } else { |
| 917 | appSettingsButton.setVisibility(View.GONE); |
| 918 | } |
| 919 | } else { |
| 920 | settingsButton.setVisibility(View.GONE); |
| 921 | appSettingsButton.setVisibility(View.GONE); |
| 922 | } |
| 923 | |
| 924 | } |
| 925 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 926 | protected SwipeHelper.LongPressListener getNotificationLongClicker() { |
| 927 | return new SwipeHelper.LongPressListener() { |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 928 | @Override |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 929 | public boolean onLongPress(View v, int x, int y) { |
| 930 | dismissPopups(); |
| 931 | |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 932 | if (!(v instanceof ExpandableNotificationRow)) { |
| 933 | return false; |
| 934 | } |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 935 | if (v.getWindowToken() == null) { |
| 936 | Log.e(TAG, "Trying to show notification guts, but not attached to window"); |
| 937 | return false; |
| 938 | } |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 939 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 940 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 941 | bindGuts(row); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 942 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 943 | // Assume we are a status_bar_notification_row |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 944 | final NotificationGuts guts = row.getGuts(); |
Selim Cinek | bdefcdf | 2014-09-11 12:41:47 +0200 | [diff] [blame] | 945 | if (guts == null) { |
| 946 | // This view has no guts. Examples are the more card or the dismiss all view |
| 947 | return false; |
| 948 | } |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 949 | |
| 950 | // Already showing? |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 951 | if (guts.getVisibility() == View.VISIBLE) { |
| 952 | Log.e(TAG, "Trying to show notification guts, but already visible"); |
| 953 | return false; |
| 954 | } |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 955 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 956 | guts.setVisibility(View.VISIBLE); |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 957 | final double horz = Math.max(guts.getWidth() - x, x); |
| 958 | final double vert = Math.max(guts.getActualHeight() - y, y); |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 959 | final float r = (float) Math.hypot(horz, vert); |
| 960 | final Animator a |
| 961 | = ViewAnimationUtils.createCircularReveal(guts, x, y, 0, r); |
| 962 | a.setDuration(400); |
| 963 | a.setInterpolator(mLinearOutSlowIn); |
| 964 | a.start(); |
| 965 | |
| 966 | mNotificationGutsExposed = guts; |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 967 | |
| 968 | return true; |
| 969 | } |
| 970 | }; |
| 971 | } |
| 972 | |
Daniel Sandler | 469e96e | 2012-05-04 15:56:19 -0400 | [diff] [blame] | 973 | public void dismissPopups() { |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 974 | if (mNotificationGutsExposed != null) { |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 975 | final NotificationGuts v = mNotificationGutsExposed; |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 976 | mNotificationGutsExposed = null; |
| 977 | |
Selim Cinek | edb893b | 2014-09-02 12:51:31 +0200 | [diff] [blame] | 978 | if (v.getWindowToken() == null) return; |
| 979 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 980 | final int x = (v.getLeft() + v.getRight()) / 2; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 981 | final int y = (v.getTop() + v.getActualHeight() / 2); |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 982 | final Animator a = ViewAnimationUtils.createCircularReveal(v, |
| 983 | x, y, x, 0); |
| 984 | a.setDuration(200); |
| 985 | a.setInterpolator(mFastOutLinearIn); |
| 986 | a.addListener(new AnimatorListenerAdapter() { |
| 987 | @Override |
| 988 | public void onAnimationEnd(Animator animation) { |
| 989 | super.onAnimationEnd(animation); |
| 990 | v.setVisibility(View.GONE); |
| 991 | } |
| 992 | }); |
| 993 | a.start(); |
Daniel Sandler | 469e96e | 2012-05-04 15:56:19 -0400 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 997 | @Override |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 998 | public void showRecentApps(boolean triggeredFromAltTab) { |
| 999 | int msg = MSG_SHOW_RECENT_APPS; |
| 1000 | mHandler.removeMessages(msg); |
| 1001 | mHandler.obtainMessage(msg, triggeredFromAltTab ? 1 : 0, 0).sendToTarget(); |
| 1002 | } |
| 1003 | |
| 1004 | @Override |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 1005 | public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1006 | int msg = MSG_HIDE_RECENT_APPS; |
| 1007 | mHandler.removeMessages(msg); |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 1008 | mHandler.obtainMessage(msg, triggeredFromAltTab ? 1 : 0, |
| 1009 | triggeredFromHomeKey ? 1 : 0).sendToTarget(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | @Override |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1013 | public void toggleRecentApps() { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1014 | int msg = MSG_TOGGLE_RECENTS_APPS; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1015 | mHandler.removeMessages(msg); |
| 1016 | mHandler.sendEmptyMessage(msg); |
| 1017 | } |
| 1018 | |
| 1019 | @Override |
| 1020 | public void preloadRecentApps() { |
| 1021 | int msg = MSG_PRELOAD_RECENT_APPS; |
| 1022 | mHandler.removeMessages(msg); |
| 1023 | mHandler.sendEmptyMessage(msg); |
| 1024 | } |
| 1025 | |
| 1026 | @Override |
| 1027 | public void cancelPreloadRecentApps() { |
| 1028 | int msg = MSG_CANCEL_PRELOAD_RECENT_APPS; |
| 1029 | mHandler.removeMessages(msg); |
| 1030 | mHandler.sendEmptyMessage(msg); |
| 1031 | } |
| 1032 | |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 1033 | /** Jumps to the next affiliated task in the group. */ |
| 1034 | public void showNextAffiliatedTask() { |
| 1035 | int msg = MSG_SHOW_NEXT_AFFILIATED_TASK; |
| 1036 | mHandler.removeMessages(msg); |
| 1037 | mHandler.sendEmptyMessage(msg); |
| 1038 | } |
| 1039 | |
| 1040 | /** Jumps to the previous affiliated task in the group. */ |
| 1041 | public void showPreviousAffiliatedTask() { |
| 1042 | int msg = MSG_SHOW_PREV_AFFILIATED_TASK; |
| 1043 | mHandler.removeMessages(msg); |
| 1044 | mHandler.sendEmptyMessage(msg); |
| 1045 | } |
| 1046 | |
Michael Jurka | ecc395a | 2012-03-30 05:31:46 -0700 | [diff] [blame] | 1047 | protected H createHandler() { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1048 | return new H(); |
| 1049 | } |
| 1050 | |
Michael Jurka | 56a5783 | 2012-05-14 13:24:43 -0700 | [diff] [blame] | 1051 | static void sendCloseSystemWindows(Context context, String reason) { |
| 1052 | if (ActivityManagerNative.isSystemReady()) { |
| 1053 | try { |
| 1054 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 1055 | } catch (RemoteException e) { |
| 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1060 | protected abstract View getStatusBarView(); |
| 1061 | |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 1062 | protected View.OnTouchListener mRecentsPreloadOnTouchListener = new View.OnTouchListener() { |
| 1063 | // additional optimization when we have software system buttons - start loading the recent |
| 1064 | // tasks on touch down |
| 1065 | @Override |
| 1066 | public boolean onTouch(View v, MotionEvent event) { |
| 1067 | int action = event.getAction() & MotionEvent.ACTION_MASK; |
| 1068 | if (action == MotionEvent.ACTION_DOWN) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1069 | preloadRecents(); |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 1070 | } else if (action == MotionEvent.ACTION_CANCEL) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1071 | cancelPreloadingRecents(); |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 1072 | } else if (action == MotionEvent.ACTION_UP) { |
| 1073 | if (!v.isPressed()) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1074 | cancelPreloadingRecents(); |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | } |
| 1078 | return false; |
| 1079 | } |
| 1080 | }; |
| 1081 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1082 | /** Proxy for RecentsComponent */ |
| 1083 | |
| 1084 | protected void showRecents(boolean triggeredFromAltTab) { |
| 1085 | if (mRecents != null) { |
| 1086 | sendCloseSystemWindows(mContext, SYSTEM_DIALOG_REASON_RECENT_APPS); |
| 1087 | mRecents.showRecents(triggeredFromAltTab, getStatusBarView()); |
| 1088 | } |
| 1089 | } |
| 1090 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 1091 | protected void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1092 | if (mRecents != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 1093 | mRecents.hideRecents(triggeredFromAltTab, triggeredFromHomeKey); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | protected void toggleRecents() { |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1098 | if (mRecents != null) { |
Winson Chung | 4c71aef | 2014-03-21 15:15:11 -0700 | [diff] [blame] | 1099 | sendCloseSystemWindows(mContext, SYSTEM_DIALOG_REASON_RECENT_APPS); |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1100 | mRecents.toggleRecents(mDisplay, mLayoutDirection, getStatusBarView()); |
| 1101 | } |
| 1102 | } |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 1103 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1104 | protected void preloadRecents() { |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1105 | if (mRecents != null) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1106 | mRecents.preloadRecents(); |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1107 | } |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 1108 | } |
| 1109 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1110 | protected void cancelPreloadingRecents() { |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1111 | if (mRecents != null) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1112 | mRecents.cancelPreloadingRecents(); |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1113 | } |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 1114 | } |
| 1115 | |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 1116 | protected void showRecentsNextAffiliatedTask() { |
| 1117 | if (mRecents != null) { |
| 1118 | mRecents.showNextAffiliatedTask(); |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | protected void showRecentsPreviousAffiliatedTask() { |
| 1123 | if (mRecents != null) { |
| 1124 | mRecents.showPrevAffiliatedTask(); |
| 1125 | } |
| 1126 | } |
| 1127 | |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 1128 | @Override |
| 1129 | public void onVisibilityChanged(boolean visible) { |
| 1130 | // Do nothing |
| 1131 | } |
| 1132 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1133 | /** |
| 1134 | * if the interrupting notification had a fullscreen intent, fire it now. |
| 1135 | */ |
| 1136 | public abstract void escalateHeadsUp(); |
Chris Wren | a4ef620 | 2014-06-09 18:07:30 -0400 | [diff] [blame] | 1137 | |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 1138 | /** |
| 1139 | * Save the current "public" (locked and secure) state of the lockscreen. |
| 1140 | */ |
| 1141 | public void setLockscreenPublicMode(boolean publicMode) { |
| 1142 | mLockscreenPublicMode = publicMode; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1143 | } |
| 1144 | |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 1145 | public boolean isLockscreenPublicMode() { |
| 1146 | return mLockscreenPublicMode; |
| 1147 | } |
| 1148 | |
| 1149 | /** |
| 1150 | * Has the given user chosen to allow their private (full) notifications to be shown even |
| 1151 | * when the lockscreen is in "public" (secure & locked) mode? |
| 1152 | */ |
| 1153 | public boolean userAllowsPrivateNotificationsInPublic(int userHandle) { |
| 1154 | if (userHandle == UserHandle.USER_ALL) { |
| 1155 | return true; |
| 1156 | } |
| 1157 | |
| 1158 | if (mUsersAllowingPrivateNotifications.indexOfKey(userHandle) < 0) { |
Kenny Guy | b0d3ab2 | 2015-02-10 16:13:11 +0000 | [diff] [blame] | 1159 | final boolean allowedByUser = 0 != Settings.Secure.getIntForUser( |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 1160 | mContext.getContentResolver(), |
| 1161 | Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, userHandle); |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 1162 | final int dpmFlags = mDevicePolicyManager.getKeyguardDisabledFeatures(null /* admin */, |
| 1163 | userHandle); |
| 1164 | final boolean allowedByDpm = (dpmFlags |
| 1165 | & DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS) == 0; |
Kenny Guy | b0d3ab2 | 2015-02-10 16:13:11 +0000 | [diff] [blame] | 1166 | final boolean allowed = allowedByUser && allowedByDpm; |
| 1167 | mUsersAllowingPrivateNotifications.append(userHandle, allowed); |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 1168 | return allowed; |
| 1169 | } |
| 1170 | |
| 1171 | return mUsersAllowingPrivateNotifications.get(userHandle); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1172 | } |
| 1173 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 1174 | /** |
| 1175 | * Returns true if we're on a secure lockscreen and the user wants to hide "sensitive" |
| 1176 | * notification data. If so, private notifications should show their (possibly |
| 1177 | * auto-generated) publicVersion, and secret notifications should be totally invisible. |
| 1178 | */ |
| 1179 | @Override // NotificationData.Environment |
| 1180 | public boolean shouldHideSensitiveContents(int userid) { |
| 1181 | return isLockscreenPublicMode() && !userAllowsPrivateNotificationsInPublic(userid); |
| 1182 | } |
| 1183 | |
Chris Wren | a4ef620 | 2014-06-09 18:07:30 -0400 | [diff] [blame] | 1184 | public void onNotificationClear(StatusBarNotification notification) { |
| 1185 | try { |
| 1186 | mBarService.onNotificationClear( |
| 1187 | notification.getPackageName(), |
| 1188 | notification.getTag(), |
| 1189 | notification.getId(), |
| 1190 | notification.getUserId()); |
| 1191 | } catch (android.os.RemoteException ex) { |
| 1192 | // oh well |
| 1193 | } |
| 1194 | } |
| 1195 | |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1196 | protected class H extends Handler { |
| 1197 | public void handleMessage(Message m) { |
| 1198 | switch (m.what) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1199 | case MSG_SHOW_RECENT_APPS: |
| 1200 | showRecents(m.arg1 > 0); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1201 | break; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1202 | case MSG_HIDE_RECENT_APPS: |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 1203 | hideRecents(m.arg1 > 0, m.arg2 > 0); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1204 | break; |
| 1205 | case MSG_TOGGLE_RECENTS_APPS: |
| 1206 | toggleRecents(); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1207 | break; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1208 | case MSG_PRELOAD_RECENT_APPS: |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1209 | preloadRecents(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1210 | break; |
| 1211 | case MSG_CANCEL_PRELOAD_RECENT_APPS: |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1212 | cancelPreloadingRecents(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1213 | break; |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 1214 | case MSG_SHOW_NEXT_AFFILIATED_TASK: |
| 1215 | showRecentsNextAffiliatedTask(); |
| 1216 | break; |
| 1217 | case MSG_SHOW_PREV_AFFILIATED_TASK: |
| 1218 | showRecentsPreviousAffiliatedTask(); |
| 1219 | break; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1224 | protected void workAroundBadLayerDrawableOpacity(View v) { |
| 1225 | } |
| 1226 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1227 | protected boolean inflateViews(Entry entry, ViewGroup parent) { |
Dan Sandler | e9a4e90 | 2014-07-31 01:06:43 -0400 | [diff] [blame] | 1228 | PackageManager pmUser = getPackageManagerForUser( |
| 1229 | entry.notification.getUser().getIdentifier()); |
| 1230 | |
Chris Wren | d04f6ce | 2014-06-11 17:37:28 -0400 | [diff] [blame] | 1231 | int maxHeight = mRowMaxHeight; |
Dan Sandler | f4db75c | 2014-09-03 18:02:31 +0200 | [diff] [blame] | 1232 | final StatusBarNotification sbn = entry.notification; |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 1233 | RemoteViews contentView = sbn.getNotification().contentView; |
| 1234 | RemoteViews bigContentView = sbn.getNotification().bigContentView; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1235 | RemoteViews headsUpContentView = sbn.getNotification().headsUpContentView; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1236 | |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 1237 | if (contentView == null) { |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1238 | return false; |
| 1239 | } |
| 1240 | |
Dan Sandler | f68448e | 2014-04-24 15:54:16 -0400 | [diff] [blame] | 1241 | if (DEBUG) { |
| 1242 | Log.v(TAG, "publicNotification: " + sbn.getNotification().publicVersion); |
| 1243 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1244 | |
| 1245 | Notification publicNotification = sbn.getNotification().publicVersion; |
| 1246 | |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1247 | ExpandableNotificationRow row; |
| 1248 | |
| 1249 | // Stash away previous user expansion state so we can restore it at |
| 1250 | // the end. |
| 1251 | boolean hasUserChangedExpansion = false; |
| 1252 | boolean userExpanded = false; |
| 1253 | boolean userLocked = false; |
| 1254 | |
| 1255 | if (entry.row != null) { |
| 1256 | row = entry.row; |
| 1257 | hasUserChangedExpansion = row.hasUserChangedExpansion(); |
| 1258 | userExpanded = row.isUserExpanded(); |
| 1259 | userLocked = row.isUserLocked(); |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 1260 | entry.reset(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1261 | if (hasUserChangedExpansion) { |
| 1262 | row.setUserExpanded(userExpanded); |
| 1263 | } |
| 1264 | } else { |
| 1265 | // create the row view |
| 1266 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( |
| 1267 | Context.LAYOUT_INFLATER_SERVICE); |
| 1268 | row = (ExpandableNotificationRow) inflater.inflate(R.layout.status_bar_notification_row, |
| 1269 | parent, false); |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1270 | row.setExpansionLogger(this, entry.notification.getKey()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1271 | row.setGroupManager(mGroupManager); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1272 | } |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 1273 | |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1274 | workAroundBadLayerDrawableOpacity(row); |
| 1275 | View vetoButton = updateNotificationVetoButton(row, sbn); |
| 1276 | vetoButton.setContentDescription(mContext.getString( |
| 1277 | R.string.accessibility_remove_notification)); |
| 1278 | |
| 1279 | // NB: the large icon is now handled entirely by the template |
| 1280 | |
| 1281 | // bind the click event to the content area |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1282 | NotificationContentView contentContainer = row.getPrivateLayout(); |
| 1283 | NotificationContentView contentContainerPublic = row.getPublicLayout(); |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 1284 | |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 1285 | row.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 1286 | if (ENABLE_REMOTE_INPUT) { |
| 1287 | row.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); |
| 1288 | } |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 1289 | |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 1290 | PendingIntent contentIntent = sbn.getNotification().contentIntent; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1291 | if (contentIntent != null) { |
Chris Wren | 930ecca | 2014-11-12 17:43:41 -0500 | [diff] [blame] | 1292 | final View.OnClickListener listener = makeClicker(contentIntent, sbn.getKey()); |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 1293 | row.setOnClickListener(listener); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1294 | } else { |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 1295 | row.setOnClickListener(null); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1296 | } |
| 1297 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1298 | // set up the adaptive layout |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 1299 | View contentViewLocal = null; |
| 1300 | View bigContentViewLocal = null; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1301 | View headsUpContentViewLocal = null; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1302 | try { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1303 | contentViewLocal = contentView.apply(mContext, contentContainer, |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 1304 | mOnClickHandler); |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 1305 | if (bigContentView != null) { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1306 | bigContentViewLocal = bigContentView.apply(mContext, contentContainer, |
| 1307 | mOnClickHandler); |
| 1308 | } |
| 1309 | if (headsUpContentView != null) { |
| 1310 | headsUpContentViewLocal = headsUpContentView.apply(mContext, contentContainer, |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 1311 | mOnClickHandler); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1312 | } |
| 1313 | } |
| 1314 | catch (RuntimeException e) { |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 1315 | final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId()); |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 1316 | Log.e(TAG, "couldn't inflate view for notification " + ident, e); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1317 | return false; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1318 | } |
| 1319 | |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 1320 | if (contentViewLocal != null) { |
Dan Sandler | 6d94aa7 | 2014-03-12 00:53:21 -0400 | [diff] [blame] | 1321 | contentViewLocal.setIsRootNamespace(true); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1322 | contentContainer.setContractedChild(contentViewLocal); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1323 | } |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 1324 | if (bigContentViewLocal != null) { |
Dan Sandler | 6d94aa7 | 2014-03-12 00:53:21 -0400 | [diff] [blame] | 1325 | bigContentViewLocal.setIsRootNamespace(true); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1326 | contentContainer.setExpandedChild(bigContentViewLocal); |
| 1327 | } |
| 1328 | if (headsUpContentViewLocal != null) { |
| 1329 | headsUpContentViewLocal.setIsRootNamespace(true); |
| 1330 | contentContainer.setHeadsUpChild(headsUpContentViewLocal); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1331 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1332 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1333 | // now the public version |
| 1334 | View publicViewLocal = null; |
| 1335 | if (publicNotification != null) { |
| 1336 | try { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1337 | publicViewLocal = publicNotification.contentView.apply(mContext, contentContainerPublic, |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 1338 | mOnClickHandler); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1339 | |
| 1340 | if (publicViewLocal != null) { |
Dan Sandler | 6d94aa7 | 2014-03-12 00:53:21 -0400 | [diff] [blame] | 1341 | publicViewLocal.setIsRootNamespace(true); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1342 | contentContainerPublic.setContractedChild(publicViewLocal); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | catch (RuntimeException e) { |
| 1346 | final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId()); |
| 1347 | Log.e(TAG, "couldn't inflate public view for notification " + ident, e); |
| 1348 | publicViewLocal = null; |
| 1349 | } |
| 1350 | } |
| 1351 | |
Jorim Jaggi | a1eeade | 2014-09-08 22:34:39 +0200 | [diff] [blame] | 1352 | // Extract target SDK version. |
| 1353 | try { |
| 1354 | ApplicationInfo info = pmUser.getApplicationInfo(sbn.getPackageName(), 0); |
| 1355 | entry.targetSdk = info.targetSdkVersion; |
| 1356 | } catch (NameNotFoundException ex) { |
| 1357 | Log.e(TAG, "Failed looking up ApplicationInfo for " + sbn.getPackageName(), ex); |
| 1358 | } |
| 1359 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1360 | if (publicViewLocal == null) { |
| 1361 | // Add a basic notification template |
| 1362 | publicViewLocal = LayoutInflater.from(mContext).inflate( |
Jorim Jaggi | ed713ee | 2014-09-09 23:56:09 +0200 | [diff] [blame] | 1363 | R.layout.notification_public_default, |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1364 | contentContainerPublic, false); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 1365 | publicViewLocal.setIsRootNamespace(true); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1366 | contentContainerPublic.setContractedChild(publicViewLocal); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1367 | |
Jorim Jaggi | ed713ee | 2014-09-09 23:56:09 +0200 | [diff] [blame] | 1368 | final TextView title = (TextView) publicViewLocal.findViewById(R.id.title); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1369 | try { |
Dan Sandler | e9a4e90 | 2014-07-31 01:06:43 -0400 | [diff] [blame] | 1370 | title.setText(pmUser.getApplicationLabel( |
| 1371 | pmUser.getApplicationInfo(entry.notification.getPackageName(), 0))); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1372 | } catch (NameNotFoundException e) { |
| 1373 | title.setText(entry.notification.getPackageName()); |
| 1374 | } |
| 1375 | |
Jorim Jaggi | ed713ee | 2014-09-09 23:56:09 +0200 | [diff] [blame] | 1376 | final ImageView icon = (ImageView) publicViewLocal.findViewById(R.id.icon); |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 1377 | final ImageView profileBadge = (ImageView) publicViewLocal.findViewById( |
Jorim Jaggi | ed713ee | 2014-09-09 23:56:09 +0200 | [diff] [blame] | 1378 | R.id.profile_badge_line3); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1379 | |
| 1380 | final StatusBarIcon ic = new StatusBarIcon(entry.notification.getPackageName(), |
| 1381 | entry.notification.getUser(), |
| 1382 | entry.notification.getNotification().icon, |
| 1383 | entry.notification.getNotification().iconLevel, |
| 1384 | entry.notification.getNotification().number, |
| 1385 | entry.notification.getNotification().tickerText); |
| 1386 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 1387 | Drawable iconDrawable = StatusBarIconView.getIcon(mContext, ic); |
| 1388 | icon.setImageDrawable(iconDrawable); |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 1389 | if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP |
Jorim Jaggi | a1eeade | 2014-09-08 22:34:39 +0200 | [diff] [blame] | 1390 | || mNotificationColorUtil.isGrayscaleIcon(iconDrawable)) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 1391 | icon.setBackgroundResource( |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 1392 | com.android.internal.R.drawable.notification_icon_legacy_bg); |
| 1393 | int padding = mContext.getResources().getDimensionPixelSize( |
| 1394 | com.android.internal.R.dimen.notification_large_icon_circle_padding); |
| 1395 | icon.setPadding(padding, padding, padding, padding); |
Jorim Jaggi | a1eeade | 2014-09-08 22:34:39 +0200 | [diff] [blame] | 1396 | if (sbn.getNotification().color != Notification.COLOR_DEFAULT) { |
| 1397 | icon.getBackground().setColorFilter( |
| 1398 | sbn.getNotification().color, PorterDuff.Mode.SRC_ATOP); |
| 1399 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 1400 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1401 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 1402 | if (profileBadge != null) { |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 1403 | Drawable profileDrawable = mContext.getPackageManager().getUserBadgeForDensity( |
| 1404 | entry.notification.getUser(), 0); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 1405 | if (profileDrawable != null) { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 1406 | profileBadge.setImageDrawable(profileDrawable); |
| 1407 | profileBadge.setVisibility(View.VISIBLE); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 1408 | } else { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 1409 | profileBadge.setVisibility(View.GONE); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 1410 | } |
| 1411 | } |
| 1412 | |
Dan Sandler | 18bb4f9 | 2014-07-14 16:48:27 -0400 | [diff] [blame] | 1413 | final View privateTime = contentViewLocal.findViewById(com.android.internal.R.id.time); |
Jorim Jaggi | ed713ee | 2014-09-09 23:56:09 +0200 | [diff] [blame] | 1414 | final DateTimeView time = (DateTimeView) publicViewLocal.findViewById(R.id.time); |
Dan Sandler | 18bb4f9 | 2014-07-14 16:48:27 -0400 | [diff] [blame] | 1415 | if (privateTime != null && privateTime.getVisibility() == View.VISIBLE) { |
Jorim Jaggi | ed713ee | 2014-09-09 23:56:09 +0200 | [diff] [blame] | 1416 | time.setVisibility(View.VISIBLE); |
| 1417 | time.setTime(entry.notification.getNotification().when); |
Dan Sandler | 18bb4f9 | 2014-07-14 16:48:27 -0400 | [diff] [blame] | 1418 | } |
| 1419 | |
Jorim Jaggi | ed713ee | 2014-09-09 23:56:09 +0200 | [diff] [blame] | 1420 | final TextView text = (TextView) publicViewLocal.findViewById(R.id.text); |
Dan Sandler | 18bb4f9 | 2014-07-14 16:48:27 -0400 | [diff] [blame] | 1421 | if (text != null) { |
| 1422 | text.setText(R.string.notification_hidden_text); |
| 1423 | text.setTextAppearance(mContext, |
Alan Viverette | 41ad394 | 2014-08-27 15:06:51 -0700 | [diff] [blame] | 1424 | R.style.TextAppearance_Material_Notification_Parenthetical); |
Dan Sandler | 18bb4f9 | 2014-07-14 16:48:27 -0400 | [diff] [blame] | 1425 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1426 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 1427 | int topPadding = Notification.Builder.calculateTopPadding(mContext, |
| 1428 | false /* hasThreeLines */, |
| 1429 | mContext.getResources().getConfiguration().fontScale); |
| 1430 | title.setPadding(0, topPadding, 0, 0); |
| 1431 | |
Jorim Jaggi | 36b1523 | 2014-06-10 17:24:20 +0200 | [diff] [blame] | 1432 | entry.autoRedacted = true; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1433 | } |
| 1434 | |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 1435 | if (MULTIUSER_DEBUG) { |
| 1436 | TextView debug = (TextView) row.findViewById(R.id.debug_info); |
| 1437 | if (debug != null) { |
| 1438 | debug.setVisibility(View.VISIBLE); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 1439 | debug.setText("CU " + mCurrentUserId +" NU " + entry.notification.getUserId()); |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 1440 | } |
| 1441 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1442 | entry.row = row; |
Chris Wren | d04f6ce | 2014-06-11 17:37:28 -0400 | [diff] [blame] | 1443 | entry.row.setHeightRange(mRowMinHeight, maxHeight); |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 1444 | entry.row.setOnActivatedListener(this); |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 1445 | entry.expanded = contentViewLocal; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1446 | entry.expandedPublic = publicViewLocal; |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 1447 | entry.setBigContentView(bigContentViewLocal); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1448 | |
Christoph Studer | 13b89512 | 2014-08-26 15:42:12 +0200 | [diff] [blame] | 1449 | applyColorsAndBackgrounds(sbn, entry); |
Jorim Jaggi | 4673985 | 2014-04-15 09:58:24 +0200 | [diff] [blame] | 1450 | |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1451 | // Restore previous flags. |
| 1452 | if (hasUserChangedExpansion) { |
| 1453 | // Note: setUserExpanded() conveniently ignores calls with |
| 1454 | // userExpanded=true if !isExpandable(). |
| 1455 | row.setUserExpanded(userExpanded); |
| 1456 | } |
| 1457 | row.setUserLocked(userLocked); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1458 | row.setStatusBarNotification(entry.notification); |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 1459 | applyRemoteInput(entry); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1460 | return true; |
| 1461 | } |
| 1462 | |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 1463 | /** |
| 1464 | * Adds RemoteInput actions from the WearableExtender; to be removed once more apps support this |
| 1465 | * via first-class API. |
| 1466 | * |
| 1467 | * TODO: Remove once enough apps specify remote inputs on their own. |
| 1468 | */ |
| 1469 | private void processForRemoteInput(Notification n) { |
| 1470 | if (!ENABLE_REMOTE_INPUT) return; |
| 1471 | |
| 1472 | if (n.extras != null && n.extras.containsKey("android.wearable.EXTENSIONS") && |
| 1473 | (n.actions == null || n.actions.length == 0)) { |
| 1474 | Notification.Action viableAction = null; |
| 1475 | Notification.WearableExtender we = new Notification.WearableExtender(n); |
| 1476 | |
| 1477 | List<Notification.Action> actions = we.getActions(); |
| 1478 | final int numActions = actions.size(); |
| 1479 | |
| 1480 | for (int i = 0; i < numActions; i++) { |
| 1481 | Notification.Action action = actions.get(i); |
| 1482 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
| 1483 | for (RemoteInput ri : action.getRemoteInputs()) { |
| 1484 | if (ri.getAllowFreeFormInput()) { |
| 1485 | viableAction = action; |
| 1486 | break; |
| 1487 | } |
| 1488 | } |
| 1489 | if (viableAction != null) { |
| 1490 | break; |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | if (viableAction != null) { |
| 1495 | Notification stripped = n.clone(); |
| 1496 | Notification.Builder.stripForDelivery(stripped); |
| 1497 | stripped.actions = new Notification.Action[] { viableAction }; |
| 1498 | stripped.extras.putBoolean("android.rebuild.contentView", true); |
| 1499 | stripped.contentView = null; |
| 1500 | stripped.extras.putBoolean("android.rebuild.bigView", true); |
| 1501 | stripped.bigContentView = null; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1502 | stripped.extras.putBoolean("android.rebuild.hudView", true); |
| 1503 | stripped.headsUpContentView = null; |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 1504 | |
| 1505 | Notification rebuilt = Notification.Builder.rebuild(mContext, stripped); |
| 1506 | |
| 1507 | n.actions = rebuilt.actions; |
| 1508 | n.bigContentView = rebuilt.bigContentView; |
| 1509 | n.headsUpContentView = rebuilt.headsUpContentView; |
| 1510 | n.publicVersion = rebuilt.publicVersion; |
| 1511 | } |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | private void applyRemoteInput(final Entry entry) { |
| 1516 | if (!ENABLE_REMOTE_INPUT) return; |
| 1517 | |
| 1518 | RemoteInput remoteInput = null; |
| 1519 | |
| 1520 | // See if the notification has exactly one action and this action allows free-form input |
| 1521 | // TODO: relax restrictions once we support more than one remote input action. |
| 1522 | Notification.Action[] actions = entry.notification.getNotification().actions; |
| 1523 | if (actions != null && actions.length == 1) { |
| 1524 | if (actions[0].getRemoteInputs() != null) { |
| 1525 | for (RemoteInput ri : actions[0].getRemoteInputs()) { |
| 1526 | if (ri.getAllowFreeFormInput()) { |
| 1527 | remoteInput = ri; |
| 1528 | break; |
| 1529 | } |
| 1530 | } |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | // See if we have somewhere to put that remote input |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1535 | if (remoteInput != null) { |
| 1536 | if (entry.expandedBig != null) { |
| 1537 | inflateRemoteInput(entry.expandedBig, remoteInput, actions); |
| 1538 | } |
| 1539 | View headsUpChild = entry.row.getPrivateLayout().getHeadsUpChild(); |
| 1540 | if (headsUpChild != null) { |
| 1541 | inflateRemoteInput(headsUpChild, remoteInput, actions); |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | private void inflateRemoteInput(View view, RemoteInput remoteInput, |
| 1548 | Notification.Action[] actions) { |
| 1549 | View actionContainerCandidate = view.findViewById(com.android.internal.R.id.actions); |
| 1550 | if (actionContainerCandidate instanceof ViewGroup) { |
| 1551 | ViewGroup actionContainer = (ViewGroup) actionContainerCandidate; |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 1552 | actionContainer.removeAllViews(); |
| 1553 | actionContainer.addView( |
| 1554 | RemoteInputView.inflate(mContext, actionContainer, actions[0], remoteInput)); |
| 1555 | } |
| 1556 | } |
| 1557 | |
Chris Wren | 930ecca | 2014-11-12 17:43:41 -0500 | [diff] [blame] | 1558 | public NotificationClicker makeClicker(PendingIntent intent, String notificationKey) { |
| 1559 | return new NotificationClicker(intent, notificationKey); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1560 | } |
| 1561 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 1562 | protected class NotificationClicker implements View.OnClickListener { |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1563 | private PendingIntent mIntent; |
Christoph Studer | 03b87a2 | 2014-04-30 17:33:27 +0200 | [diff] [blame] | 1564 | private final String mNotificationKey; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1565 | |
Chris Wren | 930ecca | 2014-11-12 17:43:41 -0500 | [diff] [blame] | 1566 | public NotificationClicker(PendingIntent intent, String notificationKey) { |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1567 | mIntent = intent; |
Christoph Studer | 03b87a2 | 2014-04-30 17:33:27 +0200 | [diff] [blame] | 1568 | mNotificationKey = notificationKey; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1569 | } |
| 1570 | |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1571 | public void onClick(final View v) { |
Chris Wren | 79ac09e | 2014-10-29 14:20:19 -0400 | [diff] [blame] | 1572 | if (NOTIFICATION_CLICK_DEBUG) { |
| 1573 | Log.d(TAG, "Clicked on content of " + mNotificationKey); |
| 1574 | } |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1575 | final boolean keyguardShowing = mStatusBarKeyguardViewManager.isShowing(); |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 1576 | final boolean afterKeyguardGone = mIntent.isActivity() |
| 1577 | && PreviewInflater.wouldLaunchResolverActivity(mContext, mIntent.getIntent(), |
| 1578 | mCurrentUserId); |
Adrian Roos | 4314f6d | 2014-05-28 14:10:27 +0200 | [diff] [blame] | 1579 | dismissKeyguardThenExecute(new OnDismissAction() { |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1580 | public boolean onDismiss() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1581 | if (mHeadsUpManager.isHeadsUp(mNotificationKey)) { |
Christoph Studer | c6a656c | 2015-01-22 15:02:49 +0100 | [diff] [blame] | 1582 | // Release the HUN notification to the shade. |
| 1583 | // |
| 1584 | // In most cases, when FLAG_AUTO_CANCEL is set, the notification will |
| 1585 | // become canceled shortly by NoMan, but we can't assume that. |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1586 | mHeadsUpManager.releaseImmediately(mNotificationKey); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1587 | } |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 1588 | new Thread() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1589 | @Override |
| 1590 | public void run() { |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 1591 | try { |
| 1592 | if (keyguardShowing && !afterKeyguardGone) { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1593 | ActivityManagerNative.getDefault() |
| 1594 | .keyguardWaitingForActivityDrawn(); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1595 | } |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 1596 | |
| 1597 | // The intent we are sending is for the application, which |
| 1598 | // won't have permission to immediately start an activity after |
| 1599 | // the user switches to home. We know it is safe to do at this |
| 1600 | // point, so make sure new activity switches are now allowed. |
| 1601 | ActivityManagerNative.getDefault().resumeAppSwitches(); |
| 1602 | } catch (RemoteException e) { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1603 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1604 | |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1605 | if (mIntent != null) { |
| 1606 | try { |
| 1607 | mIntent.send(); |
| 1608 | } catch (PendingIntent.CanceledException e) { |
| 1609 | // the stack trace isn't very helpful here. |
| 1610 | // Just log the exception message. |
| 1611 | Log.w(TAG, "Sending contentIntent failed: " + e); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1612 | |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1613 | // TODO: Dismiss Keyguard. |
| 1614 | } |
| 1615 | if (mIntent.isActivity()) { |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 1616 | overrideActivityPendingAppTransition(keyguardShowing |
| 1617 | && !afterKeyguardGone); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | try { |
| 1622 | mBarService.onNotificationClick(mNotificationKey); |
| 1623 | } catch (RemoteException ex) { |
| 1624 | // system process is dead if we're here. |
| 1625 | } |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1626 | } |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 1627 | }.start(); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1628 | |
| 1629 | // close the shade if it was open |
Jorim Jaggi | 4eedc1d | 2014-10-27 13:45:56 +0100 | [diff] [blame] | 1630 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 1631 | true /* force */, true /* delayed */); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1632 | visibilityChanged(false); |
| 1633 | |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1634 | return mIntent != null && mIntent.isActivity(); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1635 | } |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 1636 | }, afterKeyguardGone); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1637 | } |
| 1638 | } |
Chris Wren | f29c3b4 | 2013-11-27 16:30:30 -0500 | [diff] [blame] | 1639 | |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1640 | public void animateCollapsePanels(int flags, boolean force) { |
| 1641 | } |
| 1642 | |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 1643 | public void animateCollapsePanels(int flags, boolean force, boolean delayed) { |
| 1644 | } |
| 1645 | |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1646 | public void overrideActivityPendingAppTransition(boolean keyguardShowing) { |
| 1647 | if (keyguardShowing) { |
| 1648 | try { |
| 1649 | mWindowManagerService.overridePendingAppTransition(null, 0, 0, null); |
| 1650 | } catch (RemoteException e) { |
| 1651 | Log.w(TAG, "Error overriding app transition: " + e); |
| 1652 | } |
| 1653 | } |
| 1654 | } |
| 1655 | |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 1656 | protected void visibilityChanged(boolean visible) { |
| 1657 | if (mVisible != visible) { |
| 1658 | mVisible = visible; |
| 1659 | if (!visible) { |
| 1660 | dismissPopups(); |
| 1661 | } |
| 1662 | } |
| 1663 | updateVisibleToUser(); |
| 1664 | } |
| 1665 | |
| 1666 | protected void updateVisibleToUser() { |
| 1667 | boolean oldVisibleToUser = mVisibleToUser; |
| 1668 | mVisibleToUser = mVisible && mScreenOnFromKeyguard; |
| 1669 | |
| 1670 | if (oldVisibleToUser != mVisibleToUser) { |
| 1671 | handleVisibleToUserChanged(mVisibleToUser); |
| 1672 | } |
| 1673 | } |
| 1674 | |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1675 | /** |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 1676 | * The LEDs are turned off when the notification panel is shown, even just a little bit. |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1677 | * This was added last-minute and is inconsistent with the way the rest of the notifications |
| 1678 | * are handled, because the notification isn't really cancelled. The lights are just |
| 1679 | * turned off. If any other notifications happen, the lights will turn back on. Steve says |
| 1680 | * this is what he wants. (see bug 1131461) |
| 1681 | */ |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 1682 | protected void handleVisibleToUserChanged(boolean visibleToUser) { |
| 1683 | try { |
| 1684 | if (visibleToUser) { |
Christoph Studer | 1f32c65 | 2014-11-26 15:32:20 +0100 | [diff] [blame] | 1685 | // Only stop blinking, vibrating, ringing when the user went into the shade |
| 1686 | // manually (SHADE or SHADE_LOCKED). |
| 1687 | boolean clearNotificationEffects = |
| 1688 | (mState == StatusBarState.SHADE || mState == StatusBarState.SHADE_LOCKED); |
| 1689 | mBarService.onPanelRevealed(clearNotificationEffects); |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 1690 | } else { |
| 1691 | mBarService.onPanelHidden(); |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 1692 | } |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 1693 | } catch (RemoteException ex) { |
| 1694 | // Won't fail unless the world has ended. |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1695 | } |
| 1696 | } |
| 1697 | |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1698 | /** |
| 1699 | * Cancel this notification and tell the StatusBarManagerService / NotificationManagerService |
| 1700 | * about the failure. |
| 1701 | * |
| 1702 | * WARNING: this will call back into us. Don't hold any locks. |
| 1703 | */ |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 1704 | void handleNotificationError(StatusBarNotification n, String message) { |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 1705 | removeNotification(n.getKey(), null); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1706 | try { |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 1707 | mBarService.onNotificationError(n.getPackageName(), n.getTag(), n.getId(), n.getUid(), |
| 1708 | n.getInitialPid(), message, n.getUserId()); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1709 | } catch (RemoteException ex) { |
| 1710 | // The end is nigh. |
| 1711 | } |
| 1712 | } |
| 1713 | |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 1714 | protected StatusBarNotification removeNotificationViews(String key, RankingMap ranking) { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 1715 | NotificationData.Entry entry = mNotificationData.remove(key, ranking); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1716 | if (entry == null) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 1717 | Log.w(TAG, "removeNotification for unknown key: " + key); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1718 | return null; |
| 1719 | } |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 1720 | updateNotifications(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1721 | return entry.notification; |
| 1722 | } |
| 1723 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1724 | protected NotificationData.Entry createNotificationViews(StatusBarNotification sbn) { |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1725 | if (DEBUG) { |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 1726 | Log.d(TAG, "createNotificationViews(notification=" + sbn); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1727 | } |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 1728 | final StatusBarIconView iconView = createIcon(sbn); |
| 1729 | if (iconView == null) { |
| 1730 | return null; |
| 1731 | } |
| 1732 | |
| 1733 | // Construct the expanded view. |
| 1734 | NotificationData.Entry entry = new NotificationData.Entry(sbn, iconView); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1735 | if (!inflateViews(entry, mStackScroller)) { |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 1736 | handleNotificationError(sbn, "Couldn't expand RemoteViews for: " + sbn); |
| 1737 | return null; |
| 1738 | } |
| 1739 | return entry; |
| 1740 | } |
| 1741 | |
| 1742 | protected StatusBarIconView createIcon(StatusBarNotification sbn) { |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1743 | // Construct the icon. |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 1744 | Notification n = sbn.getNotification(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1745 | final StatusBarIconView iconView = new StatusBarIconView(mContext, |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 1746 | sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId()), n); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1747 | iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); |
| 1748 | |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 1749 | final StatusBarIcon ic = new StatusBarIcon(sbn.getPackageName(), |
| 1750 | sbn.getUser(), |
| 1751 | n.icon, |
| 1752 | n.iconLevel, |
| 1753 | n.number, |
| 1754 | n.tickerText); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1755 | if (!iconView.set(ic)) { |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 1756 | handleNotificationError(sbn, "Couldn't create icon: " + ic); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1757 | return null; |
| 1758 | } |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 1759 | return iconView; |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 1760 | } |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1761 | |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 1762 | protected void addNotificationViews(Entry entry, RankingMap ranking) { |
Raju Yadav | 5f33026 | 2014-03-24 10:44:00 +0100 | [diff] [blame] | 1763 | if (entry == null) { |
| 1764 | return; |
| 1765 | } |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1766 | // Add the expanded view and icon. |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 1767 | mNotificationData.add(entry, ranking); |
| 1768 | updateNotifications(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1769 | } |
| 1770 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 1771 | /** |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 1772 | * @return The number of notifications we show on Keyguard. |
| 1773 | */ |
| 1774 | protected abstract int getMaxKeyguardNotifications(); |
| 1775 | |
| 1776 | /** |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 1777 | * Updates expanded, dimmed and locked states of notification rows. |
| 1778 | */ |
| 1779 | protected void updateRowStates() { |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1780 | int maxKeyguardNotifications = getMaxKeyguardNotifications(); |
| 1781 | mKeyguardIconOverflowContainer.getIconsView().removeAllViews(); |
| 1782 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 1783 | ArrayList<Entry> activeNotifications = mNotificationData.getActiveNotifications(); |
| 1784 | final int N = activeNotifications.size(); |
| 1785 | |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1786 | int visibleNotifications = 0; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1787 | boolean onKeyguard = mState == StatusBarState.KEYGUARD; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 1788 | for (int i = 0; i < N; i++) { |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 1789 | NotificationData.Entry entry = activeNotifications.get(i); |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1790 | if (onKeyguard) { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 1791 | entry.row.setExpansionDisabled(true); |
Chris Wren | 3ddab0d | 2012-08-02 16:52:21 -0400 | [diff] [blame] | 1792 | } else { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 1793 | entry.row.setExpansionDisabled(false); |
Jorim Jaggi | 649b708 | 2014-04-03 13:15:18 +0200 | [diff] [blame] | 1794 | if (!entry.row.isUserLocked()) { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 1795 | boolean top = (i == 0); |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 1796 | entry.row.setSystemExpanded(top); |
Jorim Jaggi | 649b708 | 2014-04-03 13:15:18 +0200 | [diff] [blame] | 1797 | } |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 1798 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1799 | boolean isInvisibleChild = !mGroupManager.isVisible(entry.notification); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1800 | boolean showOnKeyguard = shouldShowOnKeyguard(entry.notification); |
Jorim Jaggi | 9261b3b | 2014-09-08 14:02:07 +0200 | [diff] [blame] | 1801 | if ((isLockscreenPublicMode() && !mShowLockscreenNotifications) || |
Jorim Jaggi | da30a03 | 2014-09-05 15:11:46 +0200 | [diff] [blame] | 1802 | (onKeyguard && (visibleNotifications >= maxKeyguardNotifications |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1803 | || !showOnKeyguard || isInvisibleChild))) { |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1804 | entry.row.setVisibility(View.GONE); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1805 | if (onKeyguard && showOnKeyguard && !isInvisibleChild) { |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1806 | mKeyguardIconOverflowContainer.getIconsView().addNotification(entry); |
| 1807 | } |
| 1808 | } else { |
| 1809 | boolean wasGone = entry.row.getVisibility() == View.GONE; |
| 1810 | entry.row.setVisibility(View.VISIBLE); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1811 | if (!isInvisibleChild) { |
| 1812 | if (wasGone) { |
| 1813 | // notify the scroller of a child addition |
| 1814 | mStackScroller.generateAddAnimation(entry.row, true /* fromMoreCard */); |
| 1815 | } |
| 1816 | visibleNotifications++; |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1817 | } |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1818 | } |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 1819 | } |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1820 | |
| 1821 | if (onKeyguard && mKeyguardIconOverflowContainer.getIconsView().getChildCount() > 0) { |
| 1822 | mKeyguardIconOverflowContainer.setVisibility(View.VISIBLE); |
| 1823 | } else { |
| 1824 | mKeyguardIconOverflowContainer.setVisibility(View.GONE); |
| 1825 | } |
| 1826 | |
| 1827 | mStackScroller.changeViewPosition(mKeyguardIconOverflowContainer, |
| 1828 | mStackScroller.getChildCount() - 3); |
Selim Cinek | becf5e3 | 2014-08-12 14:29:18 +0200 | [diff] [blame] | 1829 | mStackScroller.changeViewPosition(mEmptyShadeView, mStackScroller.getChildCount() - 2); |
| 1830 | mStackScroller.changeViewPosition(mDismissView, mStackScroller.getChildCount() - 1); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | private boolean shouldShowOnKeyguard(StatusBarNotification sbn) { |
| 1834 | return mShowLockscreenNotifications && !mNotificationData.isAmbient(sbn.getKey()); |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 1835 | } |
| 1836 | |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 1837 | protected void setZenMode(int mode) { |
John Spurlock | 110e5b1 | 2014-02-27 13:09:35 -0500 | [diff] [blame] | 1838 | if (!isDeviceProvisioned()) return; |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 1839 | mZenMode = mode; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 1840 | updateNotifications(); |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 1841 | } |
| 1842 | |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 1843 | // extended in PhoneStatusBar |
| 1844 | protected void setShowLockscreenNotifications(boolean show) { |
| 1845 | mShowLockscreenNotifications = show; |
| 1846 | } |
| 1847 | |
| 1848 | private void updateLockscreenNotificationSetting() { |
| 1849 | final boolean show = Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 1850 | Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, |
| 1851 | 1, |
| 1852 | mCurrentUserId) != 0; |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 1853 | final int dpmFlags = mDevicePolicyManager.getKeyguardDisabledFeatures( |
| 1854 | null /* admin */, mCurrentUserId); |
| 1855 | final boolean allowedByDpm = (dpmFlags |
| 1856 | & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) == 0; |
| 1857 | setShowLockscreenNotifications(show && allowedByDpm); |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 1858 | } |
| 1859 | |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1860 | protected abstract void setAreThereNotifications(); |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 1861 | protected abstract void updateNotifications(); |
Jorim Jaggi | 2fdeeab | 2015-04-01 15:13:03 -0700 | [diff] [blame] | 1862 | public abstract boolean shouldDisableNavbarGestures(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1863 | |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 1864 | public abstract void addNotification(StatusBarNotification notification, |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 1865 | RankingMap ranking, Entry oldEntry); |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 1866 | protected abstract void updateNotificationRanking(RankingMap ranking); |
| 1867 | public abstract void removeNotification(String key, RankingMap ranking); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1868 | |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 1869 | public void updateNotification(StatusBarNotification notification, RankingMap ranking) { |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 1870 | if (DEBUG) Log.d(TAG, "updateNotification(" + notification + ")"); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1871 | |
Chris Wren | d04f6ce | 2014-06-11 17:37:28 -0400 | [diff] [blame] | 1872 | final String key = notification.getKey(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1873 | Entry entry = mNotificationData.get(key); |
| 1874 | if (entry == null) { |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1875 | return; |
| 1876 | } |
| 1877 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1878 | Notification n = notification.getNotification(); |
| 1879 | if (DEBUG) { |
| 1880 | logUpdate(entry, n); |
| 1881 | } |
| 1882 | boolean applyInPlace = shouldApplyInPlace(entry, n); |
| 1883 | final boolean shouldInterrupt = shouldInterrupt(notification); |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1884 | final boolean alertAgain = alertAgain(entry, n); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1885 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1886 | entry.notification = notification; |
| 1887 | mGroupManager.onEntryUpdated(entry, entry.notification); |
| 1888 | |
| 1889 | boolean updateSuccessful = false; |
| 1890 | if (applyInPlace) { |
| 1891 | // We can just reapply the notifications in place |
| 1892 | if (DEBUG) Log.d(TAG, "reusing notification for key: " + key); |
| 1893 | try { |
| 1894 | if (entry.icon != null) { |
| 1895 | // Update the icon |
| 1896 | final StatusBarIcon ic = new StatusBarIcon(notification.getPackageName(), |
| 1897 | notification.getUser(), |
| 1898 | n.icon, |
| 1899 | n.iconLevel, |
| 1900 | n.number, |
| 1901 | n.tickerText); |
| 1902 | entry.icon.setNotification(n); |
| 1903 | if (!entry.icon.set(ic)) { |
| 1904 | handleNotificationError(notification, "Couldn't update icon: " + ic); |
| 1905 | return; |
| 1906 | } |
| 1907 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1908 | updateNotificationViews(entry, notification); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1909 | updateSuccessful = true; |
| 1910 | } |
| 1911 | catch (RuntimeException e) { |
| 1912 | // It failed to add cleanly. Log, and remove the view from the panel. |
| 1913 | Log.w(TAG, "Couldn't reapply views for package " + n.contentView.getPackage(), e); |
| 1914 | } |
| 1915 | } |
| 1916 | if (!updateSuccessful) { |
| 1917 | if (DEBUG) Log.d(TAG, "not reusing notification for key: " + key); |
| 1918 | final StatusBarIcon ic = new StatusBarIcon(notification.getPackageName(), |
| 1919 | notification.getUser(), |
| 1920 | n.icon, |
| 1921 | n.iconLevel, |
| 1922 | n.number, |
| 1923 | n.tickerText); |
| 1924 | entry.icon.setNotification(n); |
| 1925 | entry.icon.set(ic); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1926 | inflateViews(entry, mStackScroller); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1927 | } |
Selim Cinek | fbe9a44 | 2015-04-13 16:09:49 -0700 | [diff] [blame] | 1928 | updateHeadsUp(key, entry, shouldInterrupt, alertAgain); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1929 | mNotificationData.updateRanking(ranking); |
| 1930 | updateNotifications(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1931 | |
| 1932 | // Update the veto button accordingly (and as a result, whether this row is |
| 1933 | // swipe-dismissable) |
| 1934 | updateNotificationVetoButton(entry.row, notification); |
| 1935 | |
| 1936 | // Is this for you? |
| 1937 | boolean isForCurrentUser = isNotificationForCurrentProfiles(notification); |
| 1938 | if (DEBUG) Log.d(TAG, "notification is " + (isForCurrentUser ? "" : "not ") + "for you"); |
| 1939 | |
| 1940 | // Recalculate the position of the sliding windows and the titles. |
| 1941 | setAreThereNotifications(); |
| 1942 | } |
| 1943 | |
| 1944 | private void updateHeadsUp(String key, Entry entry, boolean shouldInterrupt, |
| 1945 | boolean alertAgain) { |
| 1946 | final boolean wasHeadsUp = isHeadsUp(key); |
| 1947 | if (wasHeadsUp) { |
| 1948 | mHeadsUpManager.updateNotification(entry, alertAgain); |
| 1949 | if (!shouldInterrupt) { |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1950 | // We don't want this to be interrupting anymore, lets remove it |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1951 | mHeadsUpManager.removeNotification(key); |
| 1952 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 1953 | } else if (shouldInterrupt && alertAgain) { |
| 1954 | // This notification was updated to be a heads-up, show it! |
| 1955 | mHeadsUpManager.showNotification(entry); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | private void logUpdate(Entry oldEntry, Notification n) { |
| 1960 | StatusBarNotification oldNotification = oldEntry.notification; |
| 1961 | Log.d(TAG, "old notification: when=" + oldNotification.getNotification().when |
| 1962 | + " ongoing=" + oldNotification.isOngoing() |
| 1963 | + " expanded=" + oldEntry.expanded |
| 1964 | + " contentView=" + oldNotification.getNotification().contentView |
| 1965 | + " bigContentView=" + oldNotification.getNotification().bigContentView |
| 1966 | + " publicView=" + oldNotification.getNotification().publicVersion |
| 1967 | + " rowParent=" + oldEntry.row.getParent()); |
| 1968 | Log.d(TAG, "new notification: when=" + n.when |
| 1969 | + " ongoing=" + oldNotification.isOngoing() |
| 1970 | + " contentView=" + n.contentView |
| 1971 | + " bigContentView=" + n.bigContentView |
| 1972 | + " publicView=" + n.publicVersion); |
| 1973 | } |
| 1974 | |
| 1975 | /** |
| 1976 | * @return whether we can just reapply the RemoteViews in place when it is updated |
| 1977 | */ |
| 1978 | private boolean shouldApplyInPlace(Entry entry, Notification n) { |
| 1979 | StatusBarNotification oldNotification = entry.notification; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1980 | // 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] | 1981 | final RemoteViews oldContentView = oldNotification.getNotification().contentView; |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 1982 | final RemoteViews contentView = n.contentView; |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 1983 | final RemoteViews oldBigContentView = oldNotification.getNotification().bigContentView; |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 1984 | final RemoteViews bigContentView = n.bigContentView; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1985 | final RemoteViews oldHeadsUpContentView |
| 1986 | = oldNotification.getNotification().headsUpContentView; |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 1987 | final RemoteViews headsUpContentView = n.headsUpContentView; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1988 | final Notification oldPublicNotification = oldNotification.getNotification().publicVersion; |
| 1989 | final RemoteViews oldPublicContentView = oldPublicNotification != null |
| 1990 | ? oldPublicNotification.contentView : null; |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 1991 | final Notification publicNotification = n.publicVersion; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1992 | final RemoteViews publicContentView = publicNotification != null |
| 1993 | ? publicNotification.contentView : null; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1994 | boolean contentsUnchanged = entry.expanded != null |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 1995 | && contentView.getPackage() != null |
| 1996 | && oldContentView.getPackage() != null |
| 1997 | && oldContentView.getPackage().equals(contentView.getPackage()) |
| 1998 | && oldContentView.getLayoutId() == contentView.getLayoutId(); |
Chris Wren | e9e3772 | 2012-05-11 17:40:14 -0400 | [diff] [blame] | 1999 | // large view may be null |
| 2000 | boolean bigContentsUnchanged = |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2001 | (entry.getBigContentView() == null && bigContentView == null) |
| 2002 | || ((entry.getBigContentView() != null && bigContentView != null) |
Chris Wren | e9e3772 | 2012-05-11 17:40:14 -0400 | [diff] [blame] | 2003 | && bigContentView.getPackage() != null |
| 2004 | && oldBigContentView.getPackage() != null |
| 2005 | && oldBigContentView.getPackage().equals(bigContentView.getPackage()) |
| 2006 | && oldBigContentView.getLayoutId() == bigContentView.getLayoutId()); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2007 | boolean headsUpContentsUnchanged = |
| 2008 | (oldHeadsUpContentView == null && headsUpContentView == null) |
| 2009 | || ((oldHeadsUpContentView != null && headsUpContentView != null) |
| 2010 | && headsUpContentView.getPackage() != null |
| 2011 | && oldHeadsUpContentView.getPackage() != null |
| 2012 | && oldHeadsUpContentView.getPackage().equals(headsUpContentView.getPackage()) |
| 2013 | && oldHeadsUpContentView.getLayoutId() == headsUpContentView.getLayoutId()); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 2014 | boolean publicUnchanged = |
| 2015 | (oldPublicContentView == null && publicContentView == null) |
| 2016 | || ((oldPublicContentView != null && publicContentView != null) |
| 2017 | && publicContentView.getPackage() != null |
| 2018 | && oldPublicContentView.getPackage() != null |
| 2019 | && oldPublicContentView.getPackage().equals(publicContentView.getPackage()) |
| 2020 | && oldPublicContentView.getLayoutId() == publicContentView.getLayoutId()); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2021 | return contentsUnchanged && bigContentsUnchanged && headsUpContentsUnchanged |
| 2022 | && publicUnchanged; |
Chris Wren | f29c3b4 | 2013-11-27 16:30:30 -0500 | [diff] [blame] | 2023 | } |
| 2024 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 2025 | private void updateNotificationViews(Entry entry, StatusBarNotification notification) { |
Chris Wren | e03f4e1 | 2013-08-08 16:48:48 -0400 | [diff] [blame] | 2026 | final RemoteViews contentView = notification.getNotification().contentView; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 2027 | final RemoteViews bigContentView = notification.getNotification().bigContentView; |
| 2028 | final RemoteViews headsUpContentView = notification.getNotification().headsUpContentView; |
John Spurlock | 70cf4c1 | 2014-02-13 09:39:14 -0500 | [diff] [blame] | 2029 | final Notification publicVersion = notification.getNotification().publicVersion; |
| 2030 | final RemoteViews publicContentView = publicVersion != null ? publicVersion.contentView |
| 2031 | : null; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 2032 | |
Chris Wren | e03f4e1 | 2013-08-08 16:48:48 -0400 | [diff] [blame] | 2033 | // Reapply the RemoteViews |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2034 | contentView.reapply(mContext, entry.expanded, mOnClickHandler); |
Chris Wren | e03f4e1 | 2013-08-08 16:48:48 -0400 | [diff] [blame] | 2035 | if (bigContentView != null && entry.getBigContentView() != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2036 | bigContentView.reapply(mContext, entry.getBigContentView(), |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2037 | mOnClickHandler); |
Chris Wren | e03f4e1 | 2013-08-08 16:48:48 -0400 | [diff] [blame] | 2038 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 2039 | View headsUpChild = entry.row.getPrivateLayout().getHeadsUpChild(); |
| 2040 | if (headsUpContentView != null && headsUpChild != null) { |
| 2041 | headsUpContentView.reapply(mContext, headsUpChild, mOnClickHandler); |
| 2042 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 2043 | if (publicContentView != null && entry.getPublicContentView() != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2044 | publicContentView.reapply(mContext, entry.getPublicContentView(), mOnClickHandler); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 2045 | } |
Chris Wren | e03f4e1 | 2013-08-08 16:48:48 -0400 | [diff] [blame] | 2046 | // update the contentIntent |
| 2047 | final PendingIntent contentIntent = notification.getNotification().contentIntent; |
| 2048 | if (contentIntent != null) { |
Chris Wren | 930ecca | 2014-11-12 17:43:41 -0500 | [diff] [blame] | 2049 | final View.OnClickListener listener = makeClicker(contentIntent, notification.getKey()); |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 2050 | entry.row.setOnClickListener(listener); |
Chris Wren | e03f4e1 | 2013-08-08 16:48:48 -0400 | [diff] [blame] | 2051 | } else { |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 2052 | entry.row.setOnClickListener(null); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2053 | } |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 2054 | entry.row.setStatusBarNotification(notification); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2055 | entry.row.notifyContentUpdated(); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 2056 | entry.row.resetHeight(); |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 2057 | |
| 2058 | applyRemoteInput(entry); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2059 | } |
John Spurlock | 3623128 | 2012-06-23 17:11:27 -0400 | [diff] [blame] | 2060 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2061 | protected void notifyHeadsUpScreenOff() { |
| 2062 | escalateHeadsUp(); |
Chris Wren | e97f90b | 2013-08-07 17:39:35 -0400 | [diff] [blame] | 2063 | } |
| 2064 | |
Chris Wren | d93d5ad | 2014-09-08 16:34:03 -0400 | [diff] [blame] | 2065 | private boolean alertAgain(Entry oldEntry, Notification newNotification) { |
| 2066 | return oldEntry == null || !oldEntry.hasInterrupted() |
| 2067 | || (newNotification.flags & Notification.FLAG_ONLY_ALERT_ONCE) == 0; |
Chris Wren | d04f6ce | 2014-06-11 17:37:28 -0400 | [diff] [blame] | 2068 | } |
| 2069 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2070 | protected boolean shouldInterrupt(StatusBarNotification sbn) { |
Christoph Studer | 2f9dbba | 2014-09-03 17:35:54 +0200 | [diff] [blame] | 2071 | if (mNotificationData.shouldFilterOut(sbn)) { |
| 2072 | if (DEBUG) { |
| 2073 | Log.d(TAG, "Skipping HUN check for " + sbn.getKey() + " since it's filtered out."); |
| 2074 | } |
| 2075 | return false; |
| 2076 | } |
| 2077 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2078 | if (mHeadsUpManager.isSnoozed(sbn.getPackageName())) { |
Chris Wren | a6d4fb6 | 2014-11-20 14:46:23 -0500 | [diff] [blame] | 2079 | return false; |
| 2080 | } |
| 2081 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2082 | Notification notification = sbn.getNotification(); |
| 2083 | // some predicates to make the boolean logic legible |
| 2084 | boolean isNoisy = (notification.defaults & Notification.DEFAULT_SOUND) != 0 |
| 2085 | || (notification.defaults & Notification.DEFAULT_VIBRATE) != 0 |
| 2086 | || notification.sound != null |
| 2087 | || notification.vibrate != null; |
| 2088 | boolean isHighPriority = sbn.getScore() >= INTERRUPTION_THRESHOLD; |
| 2089 | boolean isFullscreen = notification.fullScreenIntent != null; |
Chris Wren | 22ae46e | 2014-02-26 18:08:09 -0500 | [diff] [blame] | 2090 | boolean hasTicker = mHeadsUpTicker && !TextUtils.isEmpty(notification.tickerText); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2091 | boolean isAllowed = notification.extras.getInt(Notification.EXTRA_AS_HEADS_UP, |
| 2092 | Notification.HEADS_UP_ALLOWED) != Notification.HEADS_UP_NEVER; |
Selim Cinek | a8fefa5 | 2014-09-08 16:10:50 +0200 | [diff] [blame] | 2093 | boolean accessibilityForcesLaunch = isFullscreen |
| 2094 | && mAccessibilityManager.isTouchExplorationEnabled(); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2095 | |
Chris Wren | 22ae46e | 2014-02-26 18:08:09 -0500 | [diff] [blame] | 2096 | boolean interrupt = (isFullscreen || (isHighPriority && (isNoisy || hasTicker))) |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2097 | && isAllowed |
Selim Cinek | a8fefa5 | 2014-09-08 16:10:50 +0200 | [diff] [blame] | 2098 | && !accessibilityForcesLaunch |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2099 | && mPowerManager.isScreenOn() |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2100 | && (!mStatusBarKeyguardViewManager.isShowing() |
| 2101 | || mStatusBarKeyguardViewManager.isOccluded()) |
| 2102 | && !mStatusBarKeyguardViewManager.isInputRestricted(); |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 2103 | try { |
| 2104 | interrupt = interrupt && !mDreamManager.isDreaming(); |
| 2105 | } catch (RemoteException e) { |
| 2106 | Log.d(TAG, "failed to query dream manager", e); |
| 2107 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2108 | if (DEBUG) Log.d(TAG, "interrupt: " + interrupt); |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 2109 | return interrupt; |
| 2110 | } |
| 2111 | |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 2112 | public void setInteracting(int barWindow, boolean interacting) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2113 | // hook for subclasses |
| 2114 | } |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 2115 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 2116 | public void setBouncerShowing(boolean bouncerShowing) { |
| 2117 | mBouncerShowing = bouncerShowing; |
| 2118 | } |
| 2119 | |
| 2120 | /** |
| 2121 | * @return Whether the security bouncer from Keyguard is showing. |
| 2122 | */ |
| 2123 | public boolean isBouncerShowing() { |
| 2124 | return mBouncerShowing; |
| 2125 | } |
| 2126 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 2127 | public void destroy() { |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 2128 | mContext.unregisterReceiver(mBroadcastReceiver); |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 2129 | try { |
| 2130 | mNotificationListener.unregisterAsSystemService(); |
| 2131 | } catch (RemoteException e) { |
| 2132 | // Ignore. |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 2133 | } |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 2134 | } |
Kenny Guy | 4dcb0dc | 2014-07-15 12:41:24 +0100 | [diff] [blame] | 2135 | |
| 2136 | /** |
| 2137 | * @return a PackageManger for userId or if userId is < 0 (USER_ALL etc) then |
| 2138 | * return PackageManager for mContext |
| 2139 | */ |
| 2140 | protected PackageManager getPackageManagerForUser(int userId) { |
| 2141 | Context contextForUser = mContext; |
| 2142 | // UserHandle defines special userId as negative values, e.g. USER_ALL |
| 2143 | if (userId >= 0) { |
| 2144 | try { |
| 2145 | // Create a context for the correct user so if a package isn't installed |
| 2146 | // for user 0 we can still load information about the package. |
| 2147 | contextForUser = |
| 2148 | mContext.createPackageContextAsUser(mContext.getPackageName(), |
| 2149 | Context.CONTEXT_RESTRICTED, |
| 2150 | new UserHandle(userId)); |
| 2151 | } catch (NameNotFoundException e) { |
| 2152 | // Shouldn't fail to find the package name for system ui. |
| 2153 | } |
| 2154 | } |
| 2155 | return contextForUser.getPackageManager(); |
| 2156 | } |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 2157 | |
| 2158 | @Override |
| 2159 | public void logNotificationExpansion(String key, boolean userAction, boolean expanded) { |
| 2160 | try { |
| 2161 | mBarService.onNotificationExpansionChanged(key, userAction, expanded); |
| 2162 | } catch (RemoteException e) { |
| 2163 | // Ignore. |
| 2164 | } |
| 2165 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2166 | |
| 2167 | public boolean isKeyguardSecure() { |
Dan Sandler | e163a64 | 2015-03-01 22:58:32 -0500 | [diff] [blame] | 2168 | if (mStatusBarKeyguardViewManager == null) { |
| 2169 | // startKeyguard() hasn't been called yet, so we don't know. |
| 2170 | // Make sure anything that needs to know isKeyguardSecure() checks and re-checks this |
| 2171 | // value onVisibilityChanged(). |
| 2172 | Slog.w(TAG, "isKeyguardSecure() called before startKeyguard(), returning false", |
| 2173 | new Throwable()); |
| 2174 | return false; |
| 2175 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2176 | return mStatusBarKeyguardViewManager.isSecure(); |
| 2177 | } |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 2178 | } |