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; |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Jorim Jaggi | e6e108e | 2016-03-28 13:38:45 -0700 | [diff] [blame] | 22 | import android.app.ActivityManager.StackId; |
Jorim Jaggi | e6e108e | 2016-03-28 13:38:45 -0700 | [diff] [blame] | 23 | import android.app.ActivityOptions; |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 24 | import android.app.INotificationManager; |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 25 | import android.app.KeyguardManager; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 26 | import android.app.Notification; |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 27 | import android.app.NotificationManager; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 29 | import android.app.RemoteInput; |
Adam Powell | 0fc5b2b | 2012-07-18 18:20:29 -0700 | [diff] [blame] | 30 | import android.app.TaskStackBuilder; |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 31 | import android.app.admin.DevicePolicyManager; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 32 | import android.content.BroadcastReceiver; |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 33 | import android.content.ComponentName; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 34 | import android.content.Context; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 35 | import android.content.Intent; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 36 | import android.content.IntentFilter; |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 37 | import android.content.IntentSender; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 38 | import android.content.pm.ApplicationInfo; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 39 | import android.content.pm.PackageManager; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 40 | import android.content.pm.PackageManager.NameNotFoundException; |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 41 | import android.content.pm.UserInfo; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 42 | import android.content.res.Configuration; |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 43 | import android.database.ContentObserver; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 44 | import android.graphics.Rect; |
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; |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 47 | import android.os.Bundle; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 48 | import android.os.Handler; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 49 | import android.os.IBinder; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 50 | import android.os.Message; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 51 | import android.os.PowerManager; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 52 | import android.os.RemoteException; |
| 53 | import android.os.ServiceManager; |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 54 | import android.os.SystemProperties; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 56 | import android.os.UserManager; |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 57 | import android.provider.Settings; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 58 | import android.service.dreams.DreamService; |
| 59 | import android.service.dreams.IDreamManager; |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 60 | import android.service.notification.NotificationListenerService; |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 61 | import android.service.notification.NotificationListenerService.RankingMap; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 62 | import android.service.notification.StatusBarNotification; |
Dan Sandler | dc34df5 | 2016-04-07 21:04:46 -0400 | [diff] [blame] | 63 | import android.service.vr.IVrManager; |
| 64 | import android.service.vr.IVrStateCallbacks; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 65 | import android.text.TextUtils; |
Selim Cinek | 2d79f63 | 2015-11-02 15:13:29 -0800 | [diff] [blame] | 66 | import android.util.ArraySet; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 67 | import android.util.Log; |
Dan Sandler | e163a64 | 2015-03-01 22:58:32 -0500 | [diff] [blame] | 68 | import android.util.Slog; |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 69 | import android.util.SparseArray; |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 70 | import android.util.SparseBooleanArray; |
Daniel Sandler | c638c1e | 2011-08-24 16:19:23 -0700 | [diff] [blame] | 71 | import android.view.Display; |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 72 | import android.view.IWindowManager; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 73 | import android.view.LayoutInflater; |
| 74 | import android.view.MotionEvent; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 75 | import android.view.View; |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 76 | import android.view.ViewAnimationUtils; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 77 | import android.view.ViewGroup; |
Christoph Studer | 4da84cd | 2014-10-21 17:24:20 +0200 | [diff] [blame] | 78 | import android.view.ViewParent; |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 79 | import android.view.WindowManager; |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 80 | import android.view.WindowManagerGlobal; |
Selim Cinek | a8fefa5 | 2014-09-08 16:10:50 +0200 | [diff] [blame] | 81 | import android.view.accessibility.AccessibilityManager; |
Michael Jurka | a600fd9 | 2012-06-25 15:57:05 -0700 | [diff] [blame] | 82 | import android.widget.RemoteViews; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 83 | import android.widget.TextView; |
Kenny Guy | dae30d5 | 2015-04-01 19:11:35 +0100 | [diff] [blame] | 84 | import android.widget.Toast; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 85 | |
Chris Wren | bd6b5fb | 2015-06-09 14:58:34 -0400 | [diff] [blame] | 86 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 87 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Chris Wren | 5e6c0ff | 2017-01-05 12:57:06 -0500 | [diff] [blame] | 88 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 89 | import com.android.internal.statusbar.IStatusBarService; |
| 90 | import com.android.internal.statusbar.StatusBarIcon; |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 91 | import com.android.internal.widget.LockPatternUtils; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 92 | import com.android.keyguard.KeyguardHostView.OnDismissAction; |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 93 | import com.android.keyguard.KeyguardUpdateMonitor; |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 94 | import com.android.systemui.DejankUtils; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 95 | import com.android.systemui.Interpolators; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 96 | import com.android.systemui.R; |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 97 | import com.android.systemui.RecentsComponent; |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 98 | import com.android.systemui.SwipeHelper; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 99 | import com.android.systemui.SystemUI; |
Jorim Jaggi | b835dd7 | 2015-06-08 12:28:42 -0700 | [diff] [blame] | 100 | import com.android.systemui.assist.AssistManager; |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 101 | import com.android.systemui.recents.Recents; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 102 | import com.android.systemui.statusbar.NotificationData.Entry; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 103 | import com.android.systemui.statusbar.NotificationGuts.OnGutsClosedListener; |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 104 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 105 | import com.android.systemui.statusbar.phone.NavigationBarView; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 106 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 107 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 108 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 109 | import com.android.systemui.statusbar.policy.PreviewInflater; |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 110 | import com.android.systemui.statusbar.policy.RemoteInputView; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 111 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 112 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 113 | |
Michael Jurka | a600fd9 | 2012-06-25 15:57:05 -0700 | [diff] [blame] | 114 | import java.util.ArrayList; |
Julia Reynolds | 98a4486 | 2016-09-12 08:53:47 -0400 | [diff] [blame] | 115 | import java.util.Collections; |
| 116 | import java.util.HashSet; |
Dan Sandler | f4db75c | 2014-09-03 18:02:31 +0200 | [diff] [blame] | 117 | import java.util.List; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 118 | import java.util.Locale; |
Julia Reynolds | 98a4486 | 2016-09-12 08:53:47 -0400 | [diff] [blame] | 119 | import java.util.Set; |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 120 | import java.util.Stack; |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 121 | |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 122 | public abstract class BaseStatusBar extends SystemUI implements |
Winson Chung | 9214eff | 2014-06-12 13:59:25 -0700 | [diff] [blame] | 123 | CommandQueue.Callbacks, ActivatableNotificationView.OnActivatedListener, |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 124 | ExpandableNotificationRow.ExpansionLogger, NotificationData.Environment, |
dongwan0605.kim | fc975d6 | 2017-01-05 10:01:11 +0900 | [diff] [blame] | 125 | ExpandableNotificationRow.OnExpandClickListener { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 126 | public static final String TAG = "StatusBar"; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 127 | public static final boolean DEBUG = false; |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 128 | public static final boolean MULTIUSER_DEBUG = false; |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 129 | |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 130 | public static final boolean ENABLE_REMOTE_INPUT = |
Adrian Roos | 9531c9b | 2015-11-03 17:43:01 -0800 | [diff] [blame] | 131 | SystemProperties.getBoolean("debug.enable_remote_input", true); |
Selim Cinek | 4041249 | 2015-12-08 18:03:22 -0800 | [diff] [blame] | 132 | public static final boolean ENABLE_CHILD_NOTIFICATIONS |
| 133 | = SystemProperties.getBoolean("debug.child_notifs", true); |
Adrian Roos | c0a579e | 2016-03-30 16:43:58 -0700 | [diff] [blame] | 134 | public static final boolean FORCE_REMOTE_INPUT_HISTORY = |
| 135 | SystemProperties.getBoolean("debug.force_remoteinput_history", false); |
Adrian Roos | b27d7a5 | 2016-06-16 13:04:47 -0700 | [diff] [blame] | 136 | private static boolean ENABLE_LOCK_SCREEN_ALLOW_REMOTE_INPUT = false; |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 137 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 138 | protected static final int MSG_SHOW_RECENT_APPS = 1019; |
| 139 | protected static final int MSG_HIDE_RECENT_APPS = 1020; |
| 140 | protected static final int MSG_TOGGLE_RECENTS_APPS = 1021; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 141 | protected static final int MSG_PRELOAD_RECENT_APPS = 1022; |
| 142 | protected static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 1023; |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 143 | protected static final int MSG_SHOW_NEXT_AFFILIATED_TASK = 1024; |
| 144 | protected static final int MSG_SHOW_PREV_AFFILIATED_TASK = 1025; |
Andrei Stingaceanu | c22ab79 | 2016-01-07 12:39:38 +0000 | [diff] [blame] | 145 | protected static final int MSG_TOGGLE_KEYBOARD_SHORTCUTS_MENU = 1026; |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 146 | protected static final int MSG_DISMISS_KEYBOARD_SHORTCUTS_MENU = 1027; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 147 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 148 | protected static final boolean ENABLE_HEADS_UP = true; |
Chris Wren | 22ae46e | 2014-02-26 18:08:09 -0500 | [diff] [blame] | 149 | protected static final String SETTING_HEADS_UP_TICKER = "ticker_gets_heads_up"; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 150 | |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 151 | private static final String PERMISSION_SELF = "com.android.systemui.permission.SELF"; |
| 152 | |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 153 | // Should match the values in PhoneWindowManager |
Michael Jurka | 56a5783 | 2012-05-14 13:24:43 -0700 | [diff] [blame] | 154 | public static final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Winson | d8b1d63 | 2016-01-04 17:51:18 -0800 | [diff] [blame] | 155 | public static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Michael Jurka | 56a5783 | 2012-05-14 13:24:43 -0700 | [diff] [blame] | 156 | |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 157 | private static final String BANNER_ACTION_CANCEL = |
| 158 | "com.android.systemui.statusbar.banner_action_cancel"; |
| 159 | private static final String BANNER_ACTION_SETUP = |
| 160 | "com.android.systemui.statusbar.banner_action_setup"; |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 161 | private static final String NOTIFICATION_UNLOCKED_BY_WORK_CHALLENGE_ACTION |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 162 | = "com.android.systemui.statusbar.work_challenge_unlocked_notification_action"; |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 163 | |
Joe Onorato | 808182d | 2010-07-09 18:52:06 -0400 | [diff] [blame] | 164 | protected CommandQueue mCommandQueue; |
| 165 | protected IStatusBarService mBarService; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 166 | protected H mHandler = createHandler(); |
| 167 | |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 168 | // all notifications |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 169 | protected NotificationData mNotificationData; |
Selim Cinek | b6d85eb | 2014-03-28 20:21:01 +0100 | [diff] [blame] | 170 | protected NotificationStackScrollLayout mStackScroller; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 171 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 172 | protected NotificationGroupManager mGroupManager = new NotificationGroupManager(); |
| 173 | |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 174 | protected RemoteInputController mRemoteInputController; |
| 175 | |
Chris Wren | a4ef620 | 2014-06-09 18:07:30 -0400 | [diff] [blame] | 176 | // for heads up notifications |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 177 | protected HeadsUpManager mHeadsUpManager; |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 178 | |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 179 | // handling reordering |
| 180 | protected VisualStabilityManager mVisualStabilityManager = new VisualStabilityManager(); |
| 181 | |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 182 | protected int mCurrentUserId = 0; |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 183 | final protected SparseArray<UserInfo> mCurrentProfiles = new SparseArray<UserInfo>(); |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 184 | |
Daniel Sandler | 777dcde | 2013-09-30 10:21:45 -0400 | [diff] [blame] | 185 | protected int mLayoutDirection = -1; // invalid |
Selim Cinek | a8fefa5 | 2014-09-08 16:10:50 +0200 | [diff] [blame] | 186 | protected AccessibilityManager mAccessibilityManager; |
Selim Cinek | 92d892c | 2014-09-11 15:11:00 +0200 | [diff] [blame] | 187 | |
Jorim Jaggi | 50ff3af | 2015-08-12 18:35:42 -0700 | [diff] [blame] | 188 | protected boolean mDeviceInteractive; |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 189 | |
| 190 | protected boolean mVisible; |
Selim Cinek | 2d79f63 | 2015-11-02 15:13:29 -0800 | [diff] [blame] | 191 | protected ArraySet<Entry> mHeadsUpEntriesToRemoveOnSwitch = new ArraySet<>(); |
Adrian Roos | 18d099a | 2016-05-19 15:28:18 -0700 | [diff] [blame] | 192 | protected ArraySet<Entry> mRemoteInputEntriesToRemoveOnCollapse = new ArraySet<>(); |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 193 | |
Adrian Roos | c0a579e | 2016-03-30 16:43:58 -0700 | [diff] [blame] | 194 | /** |
| 195 | * Notifications with keys in this set are not actually around anymore. We kept them around |
| 196 | * when they were canceled in response to a remote input interaction. This allows us to show |
| 197 | * what you replied and allows you to continue typing into it. |
| 198 | */ |
| 199 | protected ArraySet<String> mKeysKeptForRemoteInput = new ArraySet<>(); |
| 200 | |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 201 | // mScreenOnFromKeyguard && mVisible. |
| 202 | private boolean mVisibleToUser; |
| 203 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 204 | private Locale mLocale; |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 205 | private float mFontScale; |
| 206 | |
Chris Wren | f6e83f4 | 2013-09-11 14:02:59 -0400 | [diff] [blame] | 207 | protected boolean mUseHeadsUp = false; |
Chris Wren | 22ae46e | 2014-02-26 18:08:09 -0500 | [diff] [blame] | 208 | protected boolean mHeadsUpTicker = false; |
Jason Monk | f701954 | 2014-07-31 12:42:25 -0400 | [diff] [blame] | 209 | protected boolean mDisableNotificationAlerts = false; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 210 | |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 211 | protected DevicePolicyManager mDevicePolicyManager; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 212 | protected IDreamManager mDreamManager; |
Julia Reynolds | 0971cb0 | 2016-01-26 17:00:22 -0500 | [diff] [blame] | 213 | protected PowerManager mPowerManager; |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 214 | protected StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 215 | |
| 216 | // public mode, private notifications, etc |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 217 | private final SparseBooleanArray mLockscreenPublicMode = new SparseBooleanArray(); |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 218 | private final SparseBooleanArray mUsersAllowingPrivateNotifications = new SparseBooleanArray(); |
Julia Reynolds | 26fa8a5 | 2016-02-24 08:31:22 -0500 | [diff] [blame] | 219 | private final SparseBooleanArray mUsersAllowingNotifications = new SparseBooleanArray(); |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 220 | |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 221 | private UserManager mUserManager; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 222 | private int mDensity; |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 223 | |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 224 | protected KeyguardManager mKeyguardManager; |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 225 | private LockPatternUtils mLockPatternUtils; |
| 226 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 227 | // UI-specific methods |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 228 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 229 | /** |
| 230 | * Create all windows necessary for the status bar (including navigation, overlay panels, etc) |
| 231 | * and add them to the window manager. |
| 232 | */ |
| 233 | protected abstract void createAndAddWindows(); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 234 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 235 | protected WindowManager mWindowManager; |
| 236 | protected IWindowManager mWindowManagerService; |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 237 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 238 | protected Display mDisplay; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 239 | |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 240 | private boolean mDeviceProvisioned = false; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 241 | |
Jorim Jaggi | 75b2597 | 2015-10-21 14:51:10 +0200 | [diff] [blame] | 242 | protected RecentsComponent mRecents; |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 243 | |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 244 | protected int mZenMode; |
| 245 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 246 | // which notification is currently being longpress-examined by the user |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 247 | private NotificationGuts mNotificationGutsExposed; |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 248 | |
Andrei Stingaceanu | 9d9294c | 2015-08-24 17:19:06 +0100 | [diff] [blame] | 249 | private KeyboardShortcuts mKeyboardShortcuts; |
| 250 | |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 251 | /** |
| 252 | * The {@link StatusBarState} of the status bar. |
| 253 | */ |
| 254 | protected int mState; |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 255 | protected boolean mBouncerShowing; |
John Spurlock | 4b3bda2 | 2014-05-22 14:32:20 -0400 | [diff] [blame] | 256 | protected boolean mShowLockscreenNotifications; |
Adrian Roos | 3aec638 | 2016-02-05 14:19:01 -0800 | [diff] [blame] | 257 | protected boolean mAllowLockscreenRemoteInput; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 258 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 259 | protected NotificationShelf mNotificationShelf; |
Dan Sandler | eceda3d | 2014-07-21 15:35:01 -0400 | [diff] [blame] | 260 | protected DismissView mDismissView; |
Jorim Jaggi | a2052ea | 2014-08-05 16:22:30 +0200 | [diff] [blame] | 261 | protected EmptyShadeView mEmptyShadeView; |
Jorim Jaggi | 649b708 | 2014-04-03 13:15:18 +0200 | [diff] [blame] | 262 | |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 263 | private NotificationClicker mNotificationClicker = new NotificationClicker(); |
| 264 | |
Jorim Jaggi | b835dd7 | 2015-06-08 12:28:42 -0700 | [diff] [blame] | 265 | protected AssistManager mAssistManager; |
| 266 | |
Dan Sandler | dc34df5 | 2016-04-07 21:04:46 -0400 | [diff] [blame] | 267 | protected boolean mVrMode; |
| 268 | |
Julia Reynolds | 98a4486 | 2016-09-12 08:53:47 -0400 | [diff] [blame] | 269 | private Set<String> mNonBlockablePkgs; |
| 270 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 271 | @Override // NotificationData.Environment |
Daniel Sandler | 3ffdcc7 | 2012-09-23 14:31:48 -0400 | [diff] [blame] | 272 | public boolean isDeviceProvisioned() { |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 273 | return mDeviceProvisioned; |
| 274 | } |
| 275 | |
Dan Sandler | dc34df5 | 2016-04-07 21:04:46 -0400 | [diff] [blame] | 276 | private final IVrStateCallbacks mVrStateCallbacks = new IVrStateCallbacks.Stub() { |
| 277 | @Override |
| 278 | public void onVrStateChanged(boolean enabled) { |
| 279 | mVrMode = enabled; |
| 280 | } |
| 281 | }; |
| 282 | |
| 283 | public boolean isDeviceInVrMode() { |
| 284 | return mVrMode; |
| 285 | } |
| 286 | |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 287 | protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) { |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 288 | @Override |
| 289 | public void onChange(boolean selfChange) { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 290 | final boolean provisioned = 0 != Settings.Global.getInt( |
| 291 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0); |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 292 | if (provisioned != mDeviceProvisioned) { |
| 293 | mDeviceProvisioned = provisioned; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 294 | updateNotifications(); |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 295 | } |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 296 | final int mode = Settings.Global.getInt(mContext.getContentResolver(), |
| 297 | Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE_OFF); |
| 298 | setZenMode(mode); |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 299 | |
| 300 | updateLockscreenNotificationSetting(); |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 301 | } |
| 302 | }; |
| 303 | |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 304 | private final ContentObserver mLockscreenSettingsObserver = new ContentObserver(mHandler) { |
| 305 | @Override |
| 306 | public void onChange(boolean selfChange) { |
Daniel U | 5745487 | 2016-03-29 20:28:21 +0100 | [diff] [blame] | 307 | // We don't know which user changed LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS or |
| 308 | // LOCK_SCREEN_SHOW_NOTIFICATIONS, so we just dump our cache ... |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 309 | mUsersAllowingPrivateNotifications.clear(); |
Daniel U | 5745487 | 2016-03-29 20:28:21 +0100 | [diff] [blame] | 310 | mUsersAllowingNotifications.clear(); |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 311 | // ... and refresh all the notifications |
Robin Lee | 9c5799c | 2016-08-26 15:12:22 +0100 | [diff] [blame] | 312 | updateLockscreenNotificationSetting(); |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 313 | updateNotifications(); |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 314 | } |
| 315 | }; |
| 316 | |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 317 | private RemoteViews.OnClickHandler mOnClickHandler = new RemoteViews.OnClickHandler() { |
| 318 | @Override |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 319 | public boolean onClickHandler( |
| 320 | final View view, final PendingIntent pendingIntent, final Intent fillInIntent) { |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 321 | if (handleRemoteInput(view, pendingIntent, fillInIntent)) { |
| 322 | return true; |
| 323 | } |
| 324 | |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 325 | if (DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 326 | Log.v(TAG, "Notification click handler invoked for intent: " + pendingIntent); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 327 | } |
Christoph Studer | 4da84cd | 2014-10-21 17:24:20 +0200 | [diff] [blame] | 328 | logActionClick(view); |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 329 | // The intent we are sending is for the application, which |
| 330 | // won't have permission to immediately start an activity after |
| 331 | // the user switches to home. We know it is safe to do at this |
| 332 | // point, so make sure new activity switches are now allowed. |
| 333 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 334 | ActivityManager.getService().resumeAppSwitches(); |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 335 | } catch (RemoteException e) { |
| 336 | } |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 337 | final boolean isActivity = pendingIntent.isActivity(); |
| 338 | if (isActivity) { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 339 | final boolean keyguardShowing = mStatusBarKeyguardViewManager.isShowing(); |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 340 | final boolean afterKeyguardGone = PreviewInflater.wouldLaunchResolverActivity( |
| 341 | mContext, pendingIntent.getIntent(), mCurrentUserId); |
Adrian Roos | 4314f6d | 2014-05-28 14:10:27 +0200 | [diff] [blame] | 342 | dismissKeyguardThenExecute(new OnDismissAction() { |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 343 | @Override |
| 344 | public boolean onDismiss() { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 345 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 346 | ActivityManager.getService().resumeAppSwitches(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 347 | } catch (RemoteException e) { |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 348 | } |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 349 | |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 350 | boolean handled = superOnClickHandler(view, pendingIntent, fillInIntent); |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 351 | |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 352 | // close the shade if it was open |
| 353 | if (handled) { |
Jorim Jaggi | 4eedc1d | 2014-10-27 13:45:56 +0100 | [diff] [blame] | 354 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, |
| 355 | true /* force */); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 356 | visibilityChanged(false); |
Jorim Jaggi | 91617a7 | 2015-06-25 15:01:29 -0700 | [diff] [blame] | 357 | mAssistManager.hideAssist(); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 358 | } |
Jorim Jaggi | 91617a7 | 2015-06-25 15:01:29 -0700 | [diff] [blame] | 359 | |
Adrian Roos | 4314f6d | 2014-05-28 14:10:27 +0200 | [diff] [blame] | 360 | // Wait for activity start. |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 361 | return handled; |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 362 | } |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 363 | }, afterKeyguardGone); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 364 | return true; |
| 365 | } else { |
Jorim Jaggi | e6e108e | 2016-03-28 13:38:45 -0700 | [diff] [blame] | 366 | return superOnClickHandler(view, pendingIntent, fillInIntent); |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 367 | } |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 368 | } |
| 369 | |
Christoph Studer | 4da84cd | 2014-10-21 17:24:20 +0200 | [diff] [blame] | 370 | private void logActionClick(View view) { |
| 371 | ViewParent parent = view.getParent(); |
| 372 | String key = getNotificationKeyForParent(parent); |
| 373 | if (key == null) { |
| 374 | Log.w(TAG, "Couldn't determine notification for click."); |
| 375 | return; |
| 376 | } |
| 377 | int index = -1; |
| 378 | // If this is a default template, determine the index of the button. |
| 379 | if (view.getId() == com.android.internal.R.id.action0 && |
| 380 | parent != null && parent instanceof ViewGroup) { |
| 381 | ViewGroup actionGroup = (ViewGroup) parent; |
| 382 | index = actionGroup.indexOfChild(view); |
| 383 | } |
| 384 | try { |
| 385 | mBarService.onNotificationActionClick(key, index); |
| 386 | } catch (RemoteException e) { |
| 387 | // Ignore |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | private String getNotificationKeyForParent(ViewParent parent) { |
| 392 | while (parent != null) { |
| 393 | if (parent instanceof ExpandableNotificationRow) { |
| 394 | return ((ExpandableNotificationRow) parent).getStatusBarNotification().getKey(); |
| 395 | } |
| 396 | parent = parent.getParent(); |
| 397 | } |
| 398 | return null; |
| 399 | } |
| 400 | |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 401 | private boolean superOnClickHandler(View view, PendingIntent pendingIntent, |
| 402 | Intent fillInIntent) { |
Jorim Jaggi | e6e108e | 2016-03-28 13:38:45 -0700 | [diff] [blame] | 403 | return super.onClickHandler(view, pendingIntent, fillInIntent, |
| 404 | StackId.FULLSCREEN_WORKSPACE_STACK_ID); |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 405 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 406 | |
| 407 | private boolean handleRemoteInput(View view, PendingIntent pendingIntent, Intent fillInIntent) { |
| 408 | Object tag = view.getTag(com.android.internal.R.id.remote_input_tag); |
| 409 | RemoteInput[] inputs = null; |
| 410 | if (tag instanceof RemoteInput[]) { |
| 411 | inputs = (RemoteInput[]) tag; |
| 412 | } |
| 413 | |
| 414 | if (inputs == null) { |
| 415 | return false; |
| 416 | } |
| 417 | |
| 418 | RemoteInput input = null; |
| 419 | |
| 420 | for (RemoteInput i : inputs) { |
| 421 | if (i.getAllowFreeFormInput()) { |
| 422 | input = i; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | if (input == null) { |
| 427 | return false; |
| 428 | } |
| 429 | |
| 430 | ViewParent p = view.getParent(); |
| 431 | RemoteInputView riv = null; |
| 432 | while (p != null) { |
| 433 | if (p instanceof View) { |
| 434 | View pv = (View) p; |
| 435 | if (pv.isRootNamespace()) { |
| 436 | riv = (RemoteInputView) pv.findViewWithTag(RemoteInputView.VIEW_TAG); |
| 437 | break; |
| 438 | } |
| 439 | } |
| 440 | p = p.getParent(); |
| 441 | } |
Adrian Roos | 3aec638 | 2016-02-05 14:19:01 -0800 | [diff] [blame] | 442 | ExpandableNotificationRow row = null; |
| 443 | while (p != null) { |
| 444 | if (p instanceof ExpandableNotificationRow) { |
| 445 | row = (ExpandableNotificationRow) p; |
| 446 | break; |
| 447 | } |
| 448 | p = p.getParent(); |
| 449 | } |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 450 | |
Adrian Roos | 3aec638 | 2016-02-05 14:19:01 -0800 | [diff] [blame] | 451 | if (riv == null || row == null) { |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 452 | return false; |
| 453 | } |
| 454 | |
Adrian Roos | 3aec638 | 2016-02-05 14:19:01 -0800 | [diff] [blame] | 455 | row.setUserExpanded(true); |
| 456 | |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 457 | if (!mAllowLockscreenRemoteInput) { |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 458 | final int userId = pendingIntent.getCreatorUserHandle().getIdentifier(); |
| 459 | if (isLockscreenPublicMode(userId)) { |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 460 | onLockedRemoteInput(row, view); |
| 461 | return true; |
| 462 | } |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 463 | if (mUserManager.getUserInfo(userId).isManagedProfile() |
| 464 | && mKeyguardManager.isDeviceLocked(userId)) { |
| 465 | onLockedWorkRemoteInput(userId, row, view); |
| 466 | return true; |
| 467 | } |
Adrian Roos | 3aec638 | 2016-02-05 14:19:01 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Adrian Roos | af06bf2 | 2016-07-15 12:26:49 -0700 | [diff] [blame] | 470 | int width = view.getWidth(); |
| 471 | if (view instanceof TextView) { |
| 472 | // Center the reveal on the text which might be off-center from the TextView |
| 473 | TextView tv = (TextView) view; |
| 474 | if (tv.getLayout() != null) { |
| 475 | int innerWidth = (int) tv.getLayout().getLineWidth(0); |
| 476 | innerWidth += tv.getCompoundPaddingLeft() + tv.getCompoundPaddingRight(); |
| 477 | width = Math.min(width, innerWidth); |
| 478 | } |
| 479 | } |
| 480 | int cx = view.getLeft() + width / 2; |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 481 | int cy = view.getTop() + view.getHeight() / 2; |
| 482 | int w = riv.getWidth(); |
| 483 | int h = riv.getHeight(); |
| 484 | int r = Math.max( |
| 485 | Math.max(cx + cy, cx + (h - cy)), |
| 486 | Math.max((w - cx) + cy, (w - cx) + (h - cy))); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 487 | |
Adrian Roos | af06bf2 | 2016-07-15 12:26:49 -0700 | [diff] [blame] | 488 | riv.setRevealParameters(cx, cy, r); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 489 | riv.setPendingIntent(pendingIntent); |
| 490 | riv.setRemoteInput(inputs, input); |
Adrian Roos | af06bf2 | 2016-07-15 12:26:49 -0700 | [diff] [blame] | 491 | riv.focusAnimated(); |
Adrian Roos | fe84e1f | 2015-11-04 15:55:39 -0800 | [diff] [blame] | 492 | |
| 493 | return true; |
| 494 | } |
| 495 | |
Dianne Hackborn | 1927ae8 | 2012-06-22 15:21:36 -0700 | [diff] [blame] | 496 | }; |
| 497 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 498 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 499 | @Override |
| 500 | public void onReceive(Context context, Intent intent) { |
| 501 | String action = intent.getAction(); |
| 502 | if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 503 | mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 504 | updateCurrentProfilesCache(); |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 505 | if (true) Log.v(TAG, "userId " + mCurrentUserId + " is in the house"); |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 506 | |
| 507 | updateLockscreenNotificationSetting(); |
| 508 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 509 | userSwitched(mCurrentUserId); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 510 | } else if (Intent.ACTION_USER_ADDED.equals(action)) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 511 | updateCurrentProfilesCache(); |
Kenny Guy | dae30d5 | 2015-04-01 19:11:35 +0100 | [diff] [blame] | 512 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { |
| 513 | List<ActivityManager.RecentTaskInfo> recentTask = null; |
| 514 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 515 | recentTask = ActivityManager.getService().getRecentTasks(1, |
Kenny Guy | dae30d5 | 2015-04-01 19:11:35 +0100 | [diff] [blame] | 516 | ActivityManager.RECENT_WITH_EXCLUDED |
| 517 | | ActivityManager.RECENT_INCLUDE_PROFILES, |
Jeff Sharkey | 479212c | 2016-06-29 16:00:55 -0600 | [diff] [blame] | 518 | mCurrentUserId).getList(); |
Kenny Guy | dae30d5 | 2015-04-01 19:11:35 +0100 | [diff] [blame] | 519 | } catch (RemoteException e) { |
| 520 | // Abandon hope activity manager not running. |
| 521 | } |
| 522 | if (recentTask != null && recentTask.size() > 0) { |
| 523 | UserInfo user = mUserManager.getUserInfo(recentTask.get(0).userId); |
| 524 | if (user != null && user.isManagedProfile()) { |
Kenny Guy | 63bf8ac | 2015-06-18 15:09:09 +0100 | [diff] [blame] | 525 | Toast toast = Toast.makeText(mContext, |
| 526 | R.string.managed_profile_foreground_toast, |
| 527 | Toast.LENGTH_SHORT); |
| 528 | TextView text = (TextView) toast.getView().findViewById( |
| 529 | android.R.id.message); |
| 530 | text.setCompoundDrawablesRelativeWithIntrinsicBounds( |
| 531 | R.drawable.stat_sys_managed_profile_status, 0, 0, 0); |
| 532 | int paddingPx = mContext.getResources().getDimensionPixelSize( |
| 533 | R.dimen.managed_profile_toast_padding); |
| 534 | text.setCompoundDrawablePadding(paddingPx); |
Kenny Guy | 540f7d2 | 2015-06-08 20:24:23 +0100 | [diff] [blame] | 535 | toast.show(); |
Kenny Guy | dae30d5 | 2015-04-01 19:11:35 +0100 | [diff] [blame] | 536 | } |
| 537 | } |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 538 | } else if (BANNER_ACTION_CANCEL.equals(action) || BANNER_ACTION_SETUP.equals(action)) { |
| 539 | NotificationManager noMan = (NotificationManager) |
| 540 | mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
Chris Wren | 5e6c0ff | 2017-01-05 12:57:06 -0500 | [diff] [blame] | 541 | noMan.cancel(SystemMessage.NOTE_HIDDEN_NOTIFICATIONS); |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 542 | |
| 543 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 544 | Settings.Secure.SHOW_NOTE_ABOUT_NOTIFICATION_HIDING, 0); |
| 545 | if (BANNER_ACTION_SETUP.equals(action)) { |
Jorim Jaggi | 4eedc1d | 2014-10-27 13:45:56 +0100 | [diff] [blame] | 546 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, |
| 547 | true /* force */); |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 548 | mContext.startActivity(new Intent(Settings.ACTION_APP_NOTIFICATION_REDACTION) |
| 549 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| 550 | |
| 551 | ); |
| 552 | } |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 553 | } else if (NOTIFICATION_UNLOCKED_BY_WORK_CHALLENGE_ACTION.equals(action)) { |
Tony Mak | 646fe99 | 2016-04-21 16:43:08 +0100 | [diff] [blame] | 554 | final IntentSender intentSender = intent.getParcelableExtra(Intent.EXTRA_INTENT); |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 555 | final String notificationKey = intent.getStringExtra(Intent.EXTRA_INDEX); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 556 | if (intentSender != null) { |
| 557 | try { |
| 558 | mContext.startIntentSender(intentSender, null, 0, 0, 0); |
| 559 | } catch (IntentSender.SendIntentException e) { |
| 560 | /* ignore */ |
| 561 | } |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 562 | } |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 563 | if (notificationKey != null) { |
| 564 | try { |
| 565 | mBarService.onNotificationClick(notificationKey); |
| 566 | } catch (RemoteException e) { |
| 567 | /* ignore */ |
| 568 | } |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 569 | } |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | }; |
| 573 | |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 574 | private final BroadcastReceiver mAllUsersReceiver = new BroadcastReceiver() { |
| 575 | @Override |
| 576 | public void onReceive(Context context, Intent intent) { |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 577 | final String action = intent.getAction(); |
| 578 | final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL); |
| 579 | |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 580 | if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action) && |
| 581 | isCurrentProfile(getSendingUserId())) { |
| 582 | mUsersAllowingPrivateNotifications.clear(); |
| 583 | updateLockscreenNotificationSetting(); |
| 584 | updateNotifications(); |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 585 | } else if (Intent.ACTION_DEVICE_LOCKED_CHANGED.equals(action)) { |
| 586 | if (userId != mCurrentUserId && isCurrentProfile(userId)) { |
| 587 | onWorkChallengeChanged(); |
| 588 | } |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | }; |
| 592 | |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 593 | private final NotificationListenerService mNotificationListener = |
| 594 | new NotificationListenerService() { |
| 595 | @Override |
| 596 | public void onListenerConnected() { |
| 597 | if (DEBUG) Log.d(TAG, "onListenerConnected"); |
| 598 | final StatusBarNotification[] notifications = getActiveNotifications(); |
Kent Persson | 185e9c2 | 2014-12-10 16:40:13 +0100 | [diff] [blame] | 599 | if (notifications == null) { |
| 600 | Log.w(TAG, "onListenerConnected unable to get active notifications."); |
| 601 | return; |
| 602 | } |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 603 | final RankingMap currentRanking = getCurrentRanking(); |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 604 | mHandler.post(new Runnable() { |
| 605 | @Override |
| 606 | public void run() { |
| 607 | for (StatusBarNotification sbn : notifications) { |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 608 | addNotification(sbn, currentRanking, null /* oldEntry */); |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | }); |
| 612 | } |
| 613 | |
| 614 | @Override |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 615 | public void onNotificationPosted(final StatusBarNotification sbn, |
| 616 | final RankingMap rankingMap) { |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 617 | if (DEBUG) Log.d(TAG, "onNotificationPosted: " + sbn); |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 618 | if (sbn != null) { |
| 619 | mHandler.post(new Runnable() { |
| 620 | @Override |
| 621 | public void run() { |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 622 | processForRemoteInput(sbn.getNotification()); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 623 | String key = sbn.getKey(); |
Adrian Roos | c0a579e | 2016-03-30 16:43:58 -0700 | [diff] [blame] | 624 | mKeysKeptForRemoteInput.remove(key); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 625 | boolean isUpdate = mNotificationData.get(key) != null; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 626 | // In case we don't allow child notifications, we ignore children of |
| 627 | // notifications that have a summary, since we're not going to show them |
| 628 | // anyway. This is true also when the summary is canceled, |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 629 | // because children are automatically canceled by NoMan in that case. |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 630 | if (!ENABLE_CHILD_NOTIFICATIONS |
| 631 | && mGroupManager.isChildInGroupWithSummary(sbn)) { |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 632 | if (DEBUG) { |
| 633 | Log.d(TAG, "Ignoring group child due to existing summary: " + sbn); |
| 634 | } |
| 635 | |
| 636 | // Remove existing notification to avoid stale data. |
| 637 | if (isUpdate) { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 638 | removeNotification(key, rankingMap); |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 639 | } else { |
| 640 | mNotificationData.updateRanking(rankingMap); |
| 641 | } |
| 642 | return; |
Christoph Studer | d722f27 | 2014-09-02 11:49:19 +0200 | [diff] [blame] | 643 | } |
Christoph Studer | d722f27 | 2014-09-02 11:49:19 +0200 | [diff] [blame] | 644 | if (isUpdate) { |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 645 | updateNotification(sbn, rankingMap); |
Christoph Studer | d722f27 | 2014-09-02 11:49:19 +0200 | [diff] [blame] | 646 | } else { |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 647 | addNotification(sbn, rankingMap, null /* oldEntry */); |
Christoph Studer | d722f27 | 2014-09-02 11:49:19 +0200 | [diff] [blame] | 648 | } |
Christoph Studer | d722f27 | 2014-09-02 11:49:19 +0200 | [diff] [blame] | 649 | } |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 650 | }); |
| 651 | } |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | @Override |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 655 | public void onNotificationRemoved(StatusBarNotification sbn, |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 656 | final RankingMap rankingMap) { |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 657 | if (DEBUG) Log.d(TAG, "onNotificationRemoved: " + sbn); |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 658 | if (sbn != null) { |
| 659 | final String key = sbn.getKey(); |
| 660 | mHandler.post(new Runnable() { |
| 661 | @Override |
| 662 | public void run() { |
| 663 | removeNotification(key, rankingMap); |
| 664 | } |
| 665 | }); |
| 666 | } |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | @Override |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 670 | public void onNotificationRankingUpdate(final RankingMap rankingMap) { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 671 | if (DEBUG) Log.d(TAG, "onRankingUpdate"); |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 672 | if (rankingMap != null) { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 673 | mHandler.post(new Runnable() { |
| 674 | @Override |
| 675 | public void run() { |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 676 | updateNotificationRanking(rankingMap); |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 677 | } |
| 678 | }); |
Chris Wren | 5691955 | 2015-02-24 15:56:34 -0500 | [diff] [blame] | 679 | } } |
Christoph Studer | 5b63826 | 2014-07-07 11:21:49 +0200 | [diff] [blame] | 680 | |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 681 | }; |
| 682 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 683 | private void updateCurrentProfilesCache() { |
| 684 | synchronized (mCurrentProfiles) { |
| 685 | mCurrentProfiles.clear(); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 686 | if (mUserManager != null) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 687 | for (UserInfo user : mUserManager.getProfiles(mCurrentUserId)) { |
| 688 | mCurrentProfiles.put(user.id, user); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
Joe Onorato | f3c3c4f | 2010-10-21 11:09:02 -0400 | [diff] [blame] | 694 | public void start() { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 695 | mWindowManager = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 696 | mWindowManagerService = WindowManagerGlobal.getWindowManagerService(); |
| 697 | mDisplay = mWindowManager.getDefaultDisplay(); |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 698 | mDevicePolicyManager = (DevicePolicyManager)mContext.getSystemService( |
| 699 | Context.DEVICE_POLICY_SERVICE); |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 700 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 701 | mNotificationData = new NotificationData(this); |
| 702 | |
Selim Cinek | a8fefa5 | 2014-09-08 16:10:50 +0200 | [diff] [blame] | 703 | mAccessibilityManager = (AccessibilityManager) |
| 704 | mContext.getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 705 | |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 706 | mDreamManager = IDreamManager.Stub.asInterface( |
| 707 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 708 | mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 709 | |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 710 | mContext.getContentResolver().registerContentObserver( |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 711 | Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), true, |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 712 | mSettingsObserver); |
| 713 | mContext.getContentResolver().registerContentObserver( |
| 714 | Settings.Global.getUriFor(Settings.Global.ZEN_MODE), false, |
| 715 | mSettingsObserver); |
John Spurlock | 4b3bda2 | 2014-05-22 14:32:20 -0400 | [diff] [blame] | 716 | mContext.getContentResolver().registerContentObserver( |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 717 | Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS), false, |
Robin Lee | 9c5799c | 2016-08-26 15:12:22 +0100 | [diff] [blame] | 718 | mLockscreenSettingsObserver, |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 719 | UserHandle.USER_ALL); |
Adrian Roos | b27d7a5 | 2016-06-16 13:04:47 -0700 | [diff] [blame] | 720 | if (ENABLE_LOCK_SCREEN_ALLOW_REMOTE_INPUT) { |
| 721 | mContext.getContentResolver().registerContentObserver( |
| 722 | Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT), |
| 723 | false, |
| 724 | mSettingsObserver, |
| 725 | UserHandle.USER_ALL); |
| 726 | } |
Daniel Sandler | 26cda27 | 2012-05-22 15:44:08 -0400 | [diff] [blame] | 727 | |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 728 | mContext.getContentResolver().registerContentObserver( |
| 729 | Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS), |
| 730 | true, |
| 731 | mLockscreenSettingsObserver, |
| 732 | UserHandle.USER_ALL); |
| 733 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 734 | mBarService = IStatusBarService.Stub.asInterface( |
| 735 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 736 | |
Jorim Jaggi | d61f227 | 2014-12-19 20:35:35 +0100 | [diff] [blame] | 737 | mRecents = getComponent(Recents.class); |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 738 | |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 739 | final Configuration currentConfig = mContext.getResources().getConfiguration(); |
| 740 | mLocale = currentConfig.locale; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 741 | mLayoutDirection = TextUtils.getLayoutDirectionFromLocale(mLocale); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 742 | mFontScale = currentConfig.fontScale; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 743 | mDensity = currentConfig.densityDpi; |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 744 | |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 745 | mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 746 | mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); |
| 747 | mLockPatternUtils = new LockPatternUtils(mContext); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 748 | |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 749 | // Connect in to the status bar manager service |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 750 | mCommandQueue = getComponent(CommandQueue.class); |
| 751 | mCommandQueue.addCallbacks(this); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 752 | |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 753 | int[] switches = new int[9]; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 754 | ArrayList<IBinder> binders = new ArrayList<IBinder>(); |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 755 | ArrayList<String> iconSlots = new ArrayList<>(); |
| 756 | ArrayList<StatusBarIcon> icons = new ArrayList<>(); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 757 | Rect fullscreenStackBounds = new Rect(); |
| 758 | Rect dockedStackBounds = new Rect(); |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 759 | try { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 760 | mBarService.registerStatusBar(mCommandQueue, iconSlots, icons, switches, binders, |
| 761 | fullscreenStackBounds, dockedStackBounds); |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 762 | } catch (RemoteException ex) { |
| 763 | // If the system process isn't there we're doomed anyway. |
| 764 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 765 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 766 | createAndAddWindows(); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 767 | |
Jorim Jaggi | 66ac133 | 2015-01-21 19:22:26 +0100 | [diff] [blame] | 768 | mSettingsObserver.onChange(false); // set up |
Benjamin Franz | cde0a2a | 2015-04-23 17:19:48 +0100 | [diff] [blame] | 769 | disable(switches[0], switches[6], false /* animate */); |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 770 | setSystemUiVisibility(switches[1], switches[7], switches[8], 0xffffffff, |
| 771 | fullscreenStackBounds, dockedStackBounds); |
Dianne Hackborn | 7d04932 | 2011-06-14 15:00:32 -0700 | [diff] [blame] | 772 | topAppWindowChanged(switches[2] != 0); |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 773 | // 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] | 774 | setImeWindowStatus(binders.get(0), switches[3], switches[4], switches[5] != 0); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 775 | |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 776 | // Set up the initial icon state |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 777 | int N = iconSlots.size(); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 778 | int viewIndex = 0; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 779 | for (int i=0; i < N; i++) { |
| 780 | setIcon(iconSlots.get(i), icons.get(i)); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 783 | // Set up the initial notification state. |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 784 | try { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 785 | mNotificationListener.registerAsSystemService(mContext, |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 786 | new ComponentName(mContext.getPackageName(), getClass().getCanonicalName()), |
| 787 | UserHandle.USER_ALL); |
| 788 | } catch (RemoteException e) { |
| 789 | Log.e(TAG, "Unable to register notification listener", e); |
Joe Onorato | 75199e3 | 2010-05-29 17:22:51 -0400 | [diff] [blame] | 790 | } |
| 791 | |
Christoph Studer | 60748e7 | 2014-05-22 16:51:41 +0200 | [diff] [blame] | 792 | |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 793 | if (DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 794 | Log.d(TAG, String.format( |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 795 | "init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x", |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 796 | icons.size(), |
Daniel Sandler | c6d29fc | 2012-02-25 00:33:12 -0500 | [diff] [blame] | 797 | switches[0], |
| 798 | switches[1], |
| 799 | switches[2], |
| 800 | switches[3] |
| 801 | )); |
Joe Onorato | 1c95ecb | 2010-06-28 17:19:12 -0400 | [diff] [blame] | 802 | } |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 803 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 804 | mCurrentUserId = ActivityManager.getCurrentUser(); |
Chris Wren | a6d4fb6 | 2014-11-20 14:46:23 -0500 | [diff] [blame] | 805 | setHeadsUpUser(mCurrentUserId); |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 806 | |
| 807 | IntentFilter filter = new IntentFilter(); |
| 808 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 809 | filter.addAction(Intent.ACTION_USER_ADDED); |
Kenny Guy | dae30d5 | 2015-04-01 19:11:35 +0100 | [diff] [blame] | 810 | filter.addAction(Intent.ACTION_USER_PRESENT); |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 811 | mContext.registerReceiver(mBroadcastReceiver, filter); |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 812 | |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 813 | IntentFilter internalFilter = new IntentFilter(); |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 814 | internalFilter.addAction(NOTIFICATION_UNLOCKED_BY_WORK_CHALLENGE_ACTION); |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 815 | internalFilter.addAction(BANNER_ACTION_CANCEL); |
| 816 | internalFilter.addAction(BANNER_ACTION_SETUP); |
| 817 | mContext.registerReceiver(mBroadcastReceiver, internalFilter, PERMISSION_SELF, null); |
| 818 | |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 819 | IntentFilter allUsersFilter = new IntentFilter(); |
| 820 | allUsersFilter.addAction( |
| 821 | DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 822 | allUsersFilter.addAction(Intent.ACTION_DEVICE_LOCKED_CHANGED); |
Kenny Guy | 0b7dd1e | 2015-03-12 17:14:38 +0000 | [diff] [blame] | 823 | mContext.registerReceiverAsUser(mAllUsersReceiver, UserHandle.ALL, allUsersFilter, |
| 824 | null, null); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 825 | updateCurrentProfilesCache(); |
Dan Sandler | dc34df5 | 2016-04-07 21:04:46 -0400 | [diff] [blame] | 826 | |
| 827 | IVrManager vrManager = IVrManager.Stub.asInterface(ServiceManager.getService("vrmanager")); |
| 828 | try { |
| 829 | vrManager.registerListener(mVrStateCallbacks); |
| 830 | } catch (RemoteException e) { |
| 831 | Slog.e(TAG, "Failed to register VR mode state listener: " + e); |
| 832 | } |
| 833 | |
Julia Reynolds | 98a4486 | 2016-09-12 08:53:47 -0400 | [diff] [blame] | 834 | mNonBlockablePkgs = new HashSet<String>(); |
| 835 | Collections.addAll(mNonBlockablePkgs, mContext.getResources().getStringArray( |
| 836 | com.android.internal.R.array.config_nonBlockableNotificationPackages)); |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 837 | } |
| 838 | |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 839 | protected void notifyUserAboutHiddenNotifications() { |
| 840 | if (0 != Settings.Secure.getInt(mContext.getContentResolver(), |
| 841 | Settings.Secure.SHOW_NOTE_ABOUT_NOTIFICATION_HIDING, 1)) { |
| 842 | Log.d(TAG, "user hasn't seen notification about hidden notifications"); |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 843 | if (!mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) { |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 844 | Log.d(TAG, "insecure lockscreen, skipping notification"); |
| 845 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 846 | Settings.Secure.SHOW_NOTE_ABOUT_NOTIFICATION_HIDING, 0); |
| 847 | return; |
| 848 | } |
| 849 | Log.d(TAG, "disabling lockecreen notifications and alerting the user"); |
| 850 | // disable lockscreen notifications until user acts on the banner. |
| 851 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 852 | Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0); |
Adrian Roos | aee7046 | 2014-09-03 16:27:39 +0200 | [diff] [blame] | 853 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 854 | Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0); |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 855 | |
| 856 | final String packageName = mContext.getPackageName(); |
| 857 | PendingIntent cancelIntent = PendingIntent.getBroadcast(mContext, 0, |
| 858 | new Intent(BANNER_ACTION_CANCEL).setPackage(packageName), |
| 859 | PendingIntent.FLAG_CANCEL_CURRENT); |
| 860 | PendingIntent setupIntent = PendingIntent.getBroadcast(mContext, 0, |
| 861 | new Intent(BANNER_ACTION_SETUP).setPackage(packageName), |
| 862 | PendingIntent.FLAG_CANCEL_CURRENT); |
| 863 | |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 864 | final int colorRes = com.android.internal.R.color.system_notification_accent_color; |
| 865 | Notification.Builder note = new Notification.Builder(mContext) |
| 866 | .setSmallIcon(R.drawable.ic_android) |
| 867 | .setContentTitle(mContext.getString(R.string.hidden_notifications_title)) |
| 868 | .setContentText(mContext.getString(R.string.hidden_notifications_text)) |
| 869 | .setPriority(Notification.PRIORITY_HIGH) |
| 870 | .setOngoing(true) |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 871 | .setColor(mContext.getColor(colorRes)) |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 872 | .setContentIntent(setupIntent) |
| 873 | .addAction(R.drawable.ic_close, |
| 874 | mContext.getString(R.string.hidden_notifications_cancel), |
| 875 | cancelIntent) |
| 876 | .addAction(R.drawable.ic_settings, |
| 877 | mContext.getString(R.string.hidden_notifications_setup), |
| 878 | setupIntent); |
Adrian Roos | e25c18d | 2016-06-17 15:59:49 -0700 | [diff] [blame] | 879 | overrideNotificationAppName(mContext, note); |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 880 | |
| 881 | NotificationManager noMan = |
| 882 | (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
Chris Wren | 5e6c0ff | 2017-01-05 12:57:06 -0500 | [diff] [blame] | 883 | noMan.notify(SystemMessage.NOTE_HIDDEN_NOTIFICATIONS, note.build()); |
Chris Wren | cd8f4f7 | 2014-08-27 18:48:13 -0400 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 887 | public void userSwitched(int newUserId) { |
Chris Wren | a6d4fb6 | 2014-11-20 14:46:23 -0500 | [diff] [blame] | 888 | setHeadsUpUser(newUserId); |
| 889 | } |
| 890 | |
Selim Cinek | 29fa89b | 2015-04-17 10:39:11 -0700 | [diff] [blame] | 891 | protected abstract void setHeadsUpUser(int newUserId); |
Chris Wren | d04f6ce | 2014-06-11 17:37:28 -0400 | [diff] [blame] | 892 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 893 | @Override // NotificationData.Environment |
| 894 | public boolean isNotificationForCurrentProfiles(StatusBarNotification n) { |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 895 | final int thisUserId = mCurrentUserId; |
| 896 | final int notificationUserId = n.getUserId(); |
| 897 | if (DEBUG && MULTIUSER_DEBUG) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 898 | Log.v(TAG, String.format("%s: current userid: %d, notification userid: %d", |
Daniel Sandler | b9301c3 | 2012-08-14 15:08:24 -0400 | [diff] [blame] | 899 | n, thisUserId, notificationUserId)); |
| 900 | } |
Dan Sandler | e63ba4b | 2014-12-05 00:26:24 -0500 | [diff] [blame] | 901 | return isCurrentProfile(notificationUserId); |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 902 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 903 | |
Amith Yamasani | f47e51e | 2015-04-17 10:02:15 -0700 | [diff] [blame] | 904 | protected void setNotificationShown(StatusBarNotification n) { |
Chris Wren | 2650558 | 2015-07-22 17:03:17 -0400 | [diff] [blame] | 905 | setNotificationsShown(new String[]{n.getKey()}); |
Amith Yamasani | f47e51e | 2015-04-17 10:02:15 -0700 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | protected void setNotificationsShown(String[] keys) { |
Chris Wren | 2650558 | 2015-07-22 17:03:17 -0400 | [diff] [blame] | 909 | try { |
| 910 | mNotificationListener.setNotificationsShown(keys); |
| 911 | } catch (RuntimeException e) { |
| 912 | Log.d(TAG, "failed setNotificationsShown: ", e); |
| 913 | } |
Amith Yamasani | f47e51e | 2015-04-17 10:02:15 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Kenny Guy | 44fc65f | 2014-11-28 22:18:14 +0000 | [diff] [blame] | 916 | protected boolean isCurrentProfile(int userId) { |
| 917 | synchronized (mCurrentProfiles) { |
Dan Sandler | e63ba4b | 2014-12-05 00:26:24 -0500 | [diff] [blame] | 918 | return userId == UserHandle.USER_ALL || mCurrentProfiles.get(userId) != null; |
Kenny Guy | 44fc65f | 2014-11-28 22:18:14 +0000 | [diff] [blame] | 919 | } |
| 920 | } |
| 921 | |
Christoph Studer | 2e731b5 | 2014-08-22 16:01:51 +0200 | [diff] [blame] | 922 | @Override |
| 923 | public String getCurrentMediaNotificationKey() { |
| 924 | return null; |
| 925 | } |
| 926 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 927 | @Override |
| 928 | public NotificationGroupManager getGroupManager() { |
| 929 | return mGroupManager; |
| 930 | } |
| 931 | |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 932 | /** |
| 933 | * Takes the necessary steps to prepare the status bar for starting an activity, then starts it. |
| 934 | * @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] | 935 | * @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] | 936 | */ |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 937 | protected void dismissKeyguardThenExecute(OnDismissAction action, boolean afterKeyguardGone) { |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 938 | action.onDismiss(); |
| 939 | } |
| 940 | |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 941 | @Override |
| 942 | protected void onConfigurationChanged(Configuration newConfig) { |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 943 | final float fontScale = newConfig.fontScale; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 944 | final int density = newConfig.densityDpi; |
| 945 | if (density != mDensity || mFontScale != fontScale) { |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 946 | onDensityOrFontScaleChanged(); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 947 | mDensity = density; |
| 948 | mFontScale = fontScale; |
| 949 | } |
Fabrice Di Meglio | 8afcd14 | 2012-07-27 18:27:11 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 952 | protected void onDensityOrFontScaleChanged() { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 953 | ArrayList<Entry> activeNotifications = mNotificationData.getActiveNotifications(); |
| 954 | for (int i = 0; i < activeNotifications.size(); i++) { |
| 955 | Entry entry = activeNotifications.get(i); |
| 956 | boolean exposedGuts = entry.row.getGuts() == mNotificationGutsExposed; |
| 957 | entry.row.reInflateViews(); |
| 958 | if (exposedGuts) { |
| 959 | mNotificationGutsExposed = entry.row.getGuts(); |
| 960 | bindGuts(entry.row); |
| 961 | } |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 962 | inflateViews(entry, mStackScroller); |
| 963 | } |
| 964 | } |
| 965 | |
Selim Cinek | e907911 | 2016-12-14 14:41:01 -0800 | [diff] [blame] | 966 | protected void bindDismissRunnable(final ExpandableNotificationRow row) { |
| 967 | row.setOnDismissRunnable(() -> performRemoveNotification(row.getStatusBarNotification())); |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 968 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 969 | |
Selim Cinek | d4740141 | 2016-12-15 14:44:36 -0800 | [diff] [blame] | 970 | protected void performRemoveNotification(StatusBarNotification n) { |
Selim Cinek | 36b0223 | 2016-05-11 23:07:05 -0400 | [diff] [blame] | 971 | final String pkg = n.getPackageName(); |
| 972 | final String tag = n.getTag(); |
| 973 | final int id = n.getId(); |
| 974 | final int userId = n.getUserId(); |
| 975 | try { |
| 976 | mBarService.onNotificationClear(pkg, tag, id, userId); |
| 977 | if (FORCE_REMOTE_INPUT_HISTORY |
| 978 | && mKeysKeptForRemoteInput.contains(n.getKey())) { |
| 979 | mKeysKeptForRemoteInput.remove(n.getKey()); |
Selim Cinek | 36b0223 | 2016-05-11 23:07:05 -0400 | [diff] [blame] | 980 | } |
Selim Cinek | d4740141 | 2016-12-15 14:44:36 -0800 | [diff] [blame] | 981 | removeNotification(n.getKey(), null); |
Selim Cinek | 36b0223 | 2016-05-11 23:07:05 -0400 | [diff] [blame] | 982 | |
| 983 | } catch (RemoteException ex) { |
| 984 | // system process is dead if we're here. |
| 985 | } |
| 986 | } |
| 987 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 988 | |
Christoph Studer | 13b89512 | 2014-08-26 15:42:12 +0200 | [diff] [blame] | 989 | protected void applyColorsAndBackgrounds(StatusBarNotification sbn, |
Jorim Jaggi | 4673985 | 2014-04-15 09:58:24 +0200 | [diff] [blame] | 990 | NotificationData.Entry entry) { |
Dan Sandler | fe266a3 | 2014-05-15 22:28:06 -0400 | [diff] [blame] | 991 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 992 | if (entry.getContentView().getId() |
| 993 | != com.android.internal.R.id.status_bar_latest_event_content) { |
Dan Sandler | fe266a3 | 2014-05-15 22:28:06 -0400 | [diff] [blame] | 994 | // Using custom RemoteViews |
Jorim Jaggi | a1eeade | 2014-09-08 22:34:39 +0200 | [diff] [blame] | 995 | if (entry.targetSdk >= Build.VERSION_CODES.GINGERBREAD |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 996 | && entry.targetSdk < Build.VERSION_CODES.LOLLIPOP) { |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 997 | entry.row.setShowingLegacyBackground(true); |
Jorim Jaggi | 36b1523 | 2014-06-10 17:24:20 +0200 | [diff] [blame] | 998 | entry.legacy = true; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 999 | } |
| 1000 | } |
Christoph Studer | 13b89512 | 2014-08-26 15:42:12 +0200 | [diff] [blame] | 1001 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 1002 | entry.setIconTag(R.id.icon_is_pre_L, entry.targetSdk < Build.VERSION_CODES.LOLLIPOP); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1003 | } |
| 1004 | |
Dan Sandler | 16128f4 | 2014-05-21 12:48:22 -0400 | [diff] [blame] | 1005 | public boolean isMediaNotification(NotificationData.Entry entry) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1006 | // TODO: confirm that there's a valid media key |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1007 | return entry.getExpandedContentView() != null && |
| 1008 | entry.getExpandedContentView() |
| 1009 | .findViewById(com.android.internal.R.id.media_actions) != null; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 1010 | } |
| 1011 | |
Dan Sandler | f4db75c | 2014-09-03 18:02:31 +0200 | [diff] [blame] | 1012 | // 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] | 1013 | private void startAppNotificationSettingsActivity(String packageName, final int appUid) { |
| 1014 | final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS); |
Dan Sandler | e9a4e90 | 2014-07-31 01:06:43 -0400 | [diff] [blame] | 1015 | intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName); |
| 1016 | intent.putExtra(Settings.EXTRA_APP_UID, appUid); |
Dan Sandler | f4db75c | 2014-09-03 18:02:31 +0200 | [diff] [blame] | 1017 | startNotificationGutsIntent(intent, appUid); |
| 1018 | } |
Jorim Jaggi | fb28c0e | 2014-08-22 16:28:42 +0200 | [diff] [blame] | 1019 | |
Dan Sandler | f4db75c | 2014-09-03 18:02:31 +0200 | [diff] [blame] | 1020 | private void startNotificationGutsIntent(final Intent intent, final int appUid) { |
Jorim Jaggi | fb28c0e | 2014-08-22 16:28:42 +0200 | [diff] [blame] | 1021 | dismissKeyguardThenExecute(new OnDismissAction() { |
| 1022 | @Override |
| 1023 | public boolean onDismiss() { |
| 1024 | AsyncTask.execute(new Runnable() { |
| 1025 | public void run() { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1026 | TaskStackBuilder.create(mContext) |
| 1027 | .addNextIntentWithParentStack(intent) |
| 1028 | .startActivities(getActivityOptions(), |
| 1029 | new UserHandle(UserHandle.getUserId(appUid))); |
Jorim Jaggi | fb28c0e | 2014-08-22 16:28:42 +0200 | [diff] [blame] | 1030 | } |
| 1031 | }); |
Jorim Jaggi | 4eedc1d | 2014-10-27 13:45:56 +0100 | [diff] [blame] | 1032 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true /* force */); |
Jorim Jaggi | fb28c0e | 2014-08-22 16:28:42 +0200 | [diff] [blame] | 1033 | return true; |
| 1034 | } |
Jorim Jaggi | 746f7fa | 2014-08-27 17:52:46 +0200 | [diff] [blame] | 1035 | }, false /* afterKeyguardGone */); |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
Mady Mellor | b53bc27 | 2016-02-11 18:28:23 -0800 | [diff] [blame] | 1038 | private void bindGuts(final ExpandableNotificationRow row) { |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 1039 | row.inflateGuts(); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1040 | final StatusBarNotification sbn = row.getStatusBarNotification(); |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 1041 | PackageManager pmUser = getPackageManagerForUser(mContext, sbn.getUser().getIdentifier()); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1042 | row.setTag(sbn.getPackageName()); |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 1043 | final NotificationGuts guts = row.getGuts(); |
dongwan0605.kim | fc975d6 | 2017-01-05 10:01:11 +0900 | [diff] [blame] | 1044 | guts.setClosedListener((NotificationGuts g) -> { |
| 1045 | if (!row.isRemoved()) { |
| 1046 | mStackScroller.onHeightChanged(row, !isPanelFullyCollapsed() /* needsAnimation */); |
| 1047 | } |
| 1048 | mNotificationGutsExposed = null; |
| 1049 | }); |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 1050 | |
| 1051 | final INotificationManager iNotificationManager = INotificationManager.Stub.asInterface( |
| 1052 | ServiceManager.getService(Context.NOTIFICATION_SERVICE)); |
| 1053 | |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1054 | final String pkg = sbn.getPackageName(); |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 1055 | final NotificationGuts.OnSettingsClickListener onSettingsClick = |
| 1056 | (View v, int appUid) -> { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 1057 | MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTE_INFO); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 1058 | guts.resetFalsingCheck(); |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 1059 | startAppNotificationSettingsActivity(pkg, appUid); |
| 1060 | }; |
| 1061 | final View.OnClickListener onDoneClick = |
| 1062 | (View v) -> { |
| 1063 | // If the user has security enabled, show challenge if the setting is changed. |
| 1064 | if (guts.hasImportanceChanged() |
| 1065 | && isLockscreenPublicMode(sbn.getUser().getIdentifier()) |
| 1066 | && (mState == StatusBarState.KEYGUARD |
| 1067 | || mState == StatusBarState.SHADE_LOCKED)) { |
| 1068 | OnDismissAction dismissAction = new OnDismissAction() { |
| 1069 | @Override |
| 1070 | public boolean onDismiss() { |
| 1071 | closeControls(row, guts, v); |
| 1072 | return true; |
| 1073 | } |
| 1074 | }; |
| 1075 | onLockedNotificationImportanceChange(dismissAction); |
| 1076 | } else { |
| 1077 | closeControls(row, guts, v); |
| 1078 | } |
| 1079 | }; |
| 1080 | guts.bindNotification(pmUser, iNotificationManager, sbn, onSettingsClick, onDoneClick, |
| 1081 | mNonBlockablePkgs); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 1084 | private void closeControls( |
Mady Mellor | 8e8a69e | 2016-03-14 12:30:10 -0700 | [diff] [blame] | 1085 | ExpandableNotificationRow row, NotificationGuts guts, View done) { |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 1086 | guts.resetFalsingCheck(); |
Mady Mellor | 8e8a69e | 2016-03-14 12:30:10 -0700 | [diff] [blame] | 1087 | |
| 1088 | int[] rowLocation = new int[2]; |
| 1089 | int[] doneLocation = new int[2]; |
| 1090 | row.getLocationOnScreen(rowLocation); |
| 1091 | done.getLocationOnScreen(doneLocation); |
| 1092 | |
| 1093 | final int centerX = done.getWidth() / 2; |
| 1094 | final int centerY = done.getHeight() / 2; |
| 1095 | final int x = doneLocation[0] - rowLocation[0] + centerX; |
| 1096 | final int y = doneLocation[1] - rowLocation[1] + centerY; |
| 1097 | dismissPopups(x, y); |
| 1098 | } |
| 1099 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 1100 | protected SwipeHelper.LongPressListener getNotificationLongClicker() { |
| 1101 | return new SwipeHelper.LongPressListener() { |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 1102 | @Override |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1103 | public boolean onLongPress(View v, final int x, final int y) { |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1104 | if (!(v instanceof ExpandableNotificationRow)) { |
| 1105 | return false; |
| 1106 | } |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 1107 | if (v.getWindowToken() == null) { |
| 1108 | Log.e(TAG, "Trying to show notification guts, but not attached to window"); |
| 1109 | return false; |
| 1110 | } |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 1111 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1112 | final ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 1113 | bindGuts(row); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1114 | |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 1115 | // Assume we are a status_bar_notification_row |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 1116 | final NotificationGuts guts = row.getGuts(); |
Selim Cinek | bdefcdf | 2014-09-11 12:41:47 +0200 | [diff] [blame] | 1117 | if (guts == null) { |
| 1118 | // This view has no guts. Examples are the more card or the dismiss all view |
| 1119 | return false; |
| 1120 | } |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 1121 | |
| 1122 | // Already showing? |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 1123 | if (guts.getVisibility() == View.VISIBLE) { |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1124 | dismissPopups(x, y); |
Selim Cinek | abdc5a0 | 2014-09-02 13:46:00 +0200 | [diff] [blame] | 1125 | return false; |
| 1126 | } |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 1127 | |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 1128 | MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTE_CONTROLS); |
Julia Reynolds | ead00aa | 2015-12-07 08:23:48 -0500 | [diff] [blame] | 1129 | |
Julia Reynolds | 4077945 | 2016-02-23 13:43:32 -0500 | [diff] [blame] | 1130 | // ensure that it's laid but not visible until actually laid out |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1131 | guts.setVisibility(View.INVISIBLE); |
Julia Reynolds | 4077945 | 2016-02-23 13:43:32 -0500 | [diff] [blame] | 1132 | // Post to ensure the the guts are properly laid out. |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1133 | guts.post(new Runnable() { |
| 1134 | public void run() { |
Selim Cinek | 9724431 | 2017-01-13 17:40:50 -0800 | [diff] [blame] | 1135 | if (row.getWindowToken() == null) { |
| 1136 | Log.e(TAG, "Trying to show notification guts, but not attached to " |
| 1137 | + "window"); |
| 1138 | return; |
| 1139 | } |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 1140 | dismissPopups(-1 /* x */, -1 /* y */, false /* resetGear */, |
| 1141 | false /* animate */); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1142 | guts.setVisibility(View.VISIBLE); |
| 1143 | final double horz = Math.max(guts.getWidth() - x, x); |
| 1144 | final double vert = Math.max(guts.getHeight() - y, y); |
| 1145 | final float r = (float) Math.hypot(horz, vert); |
| 1146 | final Animator a |
| 1147 | = ViewAnimationUtils.createCircularReveal(guts, x, y, 0, r); |
| 1148 | a.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 1149 | a.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1150 | a.addListener(new AnimatorListenerAdapter() { |
| 1151 | @Override |
| 1152 | public void onAnimationEnd(Animator animation) { |
| 1153 | super.onAnimationEnd(animation); |
| 1154 | // Move the notification view back over the gear |
| 1155 | row.resetTranslation(); |
| 1156 | } |
| 1157 | }); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1158 | a.start(); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 1159 | guts.setExposed(true /* exposed */, |
| 1160 | mState == StatusBarState.KEYGUARD /* needsFalsingProtection */); |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 1161 | row.closeRemoteInput(); |
dongwan0605.kim | fc975d6 | 2017-01-05 10:01:11 +0900 | [diff] [blame] | 1162 | mStackScroller.onHeightChanged(row, true /* needsAnimation */); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1163 | mNotificationGutsExposed = guts; |
| 1164 | } |
| 1165 | }); |
Daniel Sandler | f7a1956 | 2012-04-04 14:04:21 -0400 | [diff] [blame] | 1166 | return true; |
| 1167 | } |
| 1168 | }; |
| 1169 | } |
| 1170 | |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 1171 | /** |
| 1172 | * Returns the exposed NotificationGuts or null if none are exposed. |
| 1173 | */ |
| 1174 | public NotificationGuts getExposedGuts() { |
| 1175 | return mNotificationGutsExposed; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1176 | } |
| 1177 | |
Daniel Sandler | 469e96e | 2012-05-04 15:56:19 -0400 | [diff] [blame] | 1178 | public void dismissPopups() { |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 1179 | dismissPopups(-1 /* x */, -1 /* y */, true /* resetGear */, false /* animate */); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | private void dismissPopups(int x, int y) { |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 1183 | dismissPopups(x, y, true /* resetGear */, false /* animate */); |
Mady Mellor | b53bc27 | 2016-02-11 18:28:23 -0800 | [diff] [blame] | 1184 | } |
| 1185 | |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 1186 | public void dismissPopups(int x, int y, boolean resetGear, boolean animate) { |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 1187 | if (mNotificationGutsExposed != null) { |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 1188 | mNotificationGutsExposed.closeControls(x, y, true /* save */); |
Daniel Sandler | 469e96e | 2012-05-04 15:56:19 -0400 | [diff] [blame] | 1189 | } |
Mady Mellor | 7a9b2a6 | 2016-03-23 07:41:47 -0700 | [diff] [blame] | 1190 | if (resetGear) { |
| 1191 | mStackScroller.resetExposedGearView(animate, true /* force */); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1192 | } |
Daniel Sandler | 469e96e | 2012-05-04 15:56:19 -0400 | [diff] [blame] | 1193 | } |
| 1194 | |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1195 | @Override |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 1196 | public void showRecentApps(boolean triggeredFromAltTab, boolean fromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1197 | int msg = MSG_SHOW_RECENT_APPS; |
| 1198 | mHandler.removeMessages(msg); |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 1199 | mHandler.obtainMessage(msg, triggeredFromAltTab ? 1 : 0, fromHome ? 1 : 0).sendToTarget(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | @Override |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 1203 | public void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1204 | int msg = MSG_HIDE_RECENT_APPS; |
| 1205 | mHandler.removeMessages(msg); |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 1206 | mHandler.obtainMessage(msg, triggeredFromAltTab ? 1 : 0, |
| 1207 | triggeredFromHomeKey ? 1 : 0).sendToTarget(); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | @Override |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1211 | public void toggleRecentApps() { |
Jorim Jaggi | 900fb48 | 2015-06-02 15:07:33 -0700 | [diff] [blame] | 1212 | toggleRecents(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | @Override |
Phil Weaver | 315c34e | 2016-02-19 15:12:29 -0800 | [diff] [blame] | 1216 | public void toggleSplitScreen() { |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 1217 | toggleSplitScreenMode(-1 /* metricsDockAction */, -1 /* metricsUndockAction */); |
Phil Weaver | 315c34e | 2016-02-19 15:12:29 -0800 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | @Override |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1221 | public void preloadRecentApps() { |
| 1222 | int msg = MSG_PRELOAD_RECENT_APPS; |
| 1223 | mHandler.removeMessages(msg); |
| 1224 | mHandler.sendEmptyMessage(msg); |
| 1225 | } |
| 1226 | |
| 1227 | @Override |
| 1228 | public void cancelPreloadRecentApps() { |
| 1229 | int msg = MSG_CANCEL_PRELOAD_RECENT_APPS; |
| 1230 | mHandler.removeMessages(msg); |
| 1231 | mHandler.sendEmptyMessage(msg); |
| 1232 | } |
| 1233 | |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 1234 | @Override |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 1235 | public void dismissKeyboardShortcutsMenu() { |
| 1236 | int msg = MSG_DISMISS_KEYBOARD_SHORTCUTS_MENU; |
| 1237 | mHandler.removeMessages(msg); |
| 1238 | mHandler.sendEmptyMessage(msg); |
| 1239 | } |
| 1240 | |
| 1241 | @Override |
Clara Bayarri | 4e850ff | 2016-03-02 11:12:32 -0800 | [diff] [blame] | 1242 | public void toggleKeyboardShortcutsMenu(int deviceId) { |
Andrei Stingaceanu | c22ab79 | 2016-01-07 12:39:38 +0000 | [diff] [blame] | 1243 | int msg = MSG_TOGGLE_KEYBOARD_SHORTCUTS_MENU; |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 1244 | mHandler.removeMessages(msg); |
Clara Bayarri | 4e850ff | 2016-03-02 11:12:32 -0800 | [diff] [blame] | 1245 | mHandler.obtainMessage(msg, deviceId, 0).sendToTarget(); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 1246 | } |
| 1247 | |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 1248 | /** Jumps to the next affiliated task in the group. */ |
| 1249 | public void showNextAffiliatedTask() { |
| 1250 | int msg = MSG_SHOW_NEXT_AFFILIATED_TASK; |
| 1251 | mHandler.removeMessages(msg); |
| 1252 | mHandler.sendEmptyMessage(msg); |
| 1253 | } |
| 1254 | |
| 1255 | /** Jumps to the previous affiliated task in the group. */ |
| 1256 | public void showPreviousAffiliatedTask() { |
| 1257 | int msg = MSG_SHOW_PREV_AFFILIATED_TASK; |
| 1258 | mHandler.removeMessages(msg); |
| 1259 | mHandler.sendEmptyMessage(msg); |
| 1260 | } |
| 1261 | |
Michael Jurka | ecc395a | 2012-03-30 05:31:46 -0700 | [diff] [blame] | 1262 | protected H createHandler() { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1263 | return new H(); |
| 1264 | } |
| 1265 | |
Andrei Stingaceanu | 9d9294c | 2015-08-24 17:19:06 +0100 | [diff] [blame] | 1266 | protected void sendCloseSystemWindows(String reason) { |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 1267 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1268 | ActivityManager.getService().closeSystemDialogs(reason); |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 1269 | } catch (RemoteException e) { |
Michael Jurka | 56a5783 | 2012-05-14 13:24:43 -0700 | [diff] [blame] | 1270 | } |
| 1271 | } |
| 1272 | |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1273 | protected abstract View getStatusBarView(); |
| 1274 | |
Phil Weaver | 315c34e | 2016-02-19 15:12:29 -0800 | [diff] [blame] | 1275 | /** |
| 1276 | * Toggle docking the app window |
| 1277 | * |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 1278 | * @param metricsDockAction the action to log when docking is successful, or -1 to not log |
| 1279 | * anything on successful docking |
| 1280 | * @param metricsUndockAction the action to log when undocking, or -1 to not log anything when |
| 1281 | * undocking |
Matthew Ng | 8d37288 | 2016-12-20 11:06:49 -0800 | [diff] [blame] | 1282 | * @return true if toggle split screen was successful |
Phil Weaver | 315c34e | 2016-02-19 15:12:29 -0800 | [diff] [blame] | 1283 | */ |
Matthew Ng | 8d37288 | 2016-12-20 11:06:49 -0800 | [diff] [blame] | 1284 | protected abstract boolean toggleSplitScreenMode(int metricsDockAction, int metricsUndockAction); |
Phil Weaver | 315c34e | 2016-02-19 15:12:29 -0800 | [diff] [blame] | 1285 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1286 | /** Proxy for RecentsComponent */ |
| 1287 | |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 1288 | protected void showRecents(boolean triggeredFromAltTab, boolean fromHome) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1289 | if (mRecents != null) { |
Andrei Stingaceanu | 9d9294c | 2015-08-24 17:19:06 +0100 | [diff] [blame] | 1290 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 1291 | mRecents.showRecents(triggeredFromAltTab, fromHome); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1292 | } |
| 1293 | } |
| 1294 | |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 1295 | protected void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1296 | if (mRecents != null) { |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 1297 | mRecents.hideRecents(triggeredFromAltTab, triggeredFromHomeKey); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | protected void toggleRecents() { |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1302 | if (mRecents != null) { |
Jorim Jaggi | db21bbd | 2016-04-18 15:32:07 -0700 | [diff] [blame] | 1303 | mRecents.toggleRecents(mDisplay); |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1304 | } |
| 1305 | } |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 1306 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1307 | protected void preloadRecents() { |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1308 | if (mRecents != null) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1309 | mRecents.preloadRecents(); |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1310 | } |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 1311 | } |
| 1312 | |
Clara Bayarri | 4e850ff | 2016-03-02 11:12:32 -0800 | [diff] [blame] | 1313 | protected void toggleKeyboardShortcuts(int deviceId) { |
Andrei Stingaceanu | f86bc97 | 2016-04-12 15:29:25 +0100 | [diff] [blame] | 1314 | KeyboardShortcuts.toggle(mContext, deviceId); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 1315 | } |
| 1316 | |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 1317 | protected void dismissKeyboardShortcuts() { |
| 1318 | KeyboardShortcuts.dismiss(); |
| 1319 | } |
| 1320 | |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1321 | protected void cancelPreloadingRecents() { |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1322 | if (mRecents != null) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1323 | mRecents.cancelPreloadingRecents(); |
John Spurlock | d08de37 | 2013-06-24 13:06:08 -0400 | [diff] [blame] | 1324 | } |
Michael Jurka | 80343f6 | 2012-10-18 13:13:46 +0200 | [diff] [blame] | 1325 | } |
| 1326 | |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 1327 | protected void showRecentsNextAffiliatedTask() { |
| 1328 | if (mRecents != null) { |
| 1329 | mRecents.showNextAffiliatedTask(); |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | protected void showRecentsPreviousAffiliatedTask() { |
| 1334 | if (mRecents != null) { |
| 1335 | mRecents.showPrevAffiliatedTask(); |
| 1336 | } |
| 1337 | } |
| 1338 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1339 | /** |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1340 | * If there is an active heads-up notification and it has a fullscreen intent, fire it now. |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 1341 | */ |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1342 | public abstract void maybeEscalateHeadsUp(); |
Chris Wren | a4ef620 | 2014-06-09 18:07:30 -0400 | [diff] [blame] | 1343 | |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 1344 | /** |
| 1345 | * Save the current "public" (locked and secure) state of the lockscreen. |
| 1346 | */ |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 1347 | public void setLockscreenPublicMode(boolean publicMode, int userId) { |
| 1348 | mLockscreenPublicMode.put(userId, publicMode); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1349 | } |
| 1350 | |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 1351 | public boolean isLockscreenPublicMode(int userId) { |
| 1352 | return mLockscreenPublicMode.get(userId, false); |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 1353 | } |
| 1354 | |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 1355 | protected void onWorkChallengeChanged() {} |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1356 | |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 1357 | /** |
Julia Reynolds | 26fa8a5 | 2016-02-24 08:31:22 -0500 | [diff] [blame] | 1358 | * Has the given user chosen to allow notifications to be shown even when the lockscreen is in |
| 1359 | * "public" (secure & locked) mode? |
| 1360 | */ |
| 1361 | public boolean userAllowsNotificationsInPublic(int userHandle) { |
| 1362 | if (userHandle == UserHandle.USER_ALL) { |
| 1363 | return true; |
| 1364 | } |
| 1365 | |
| 1366 | if (mUsersAllowingNotifications.indexOfKey(userHandle) < 0) { |
| 1367 | final boolean allowed = 0 != Settings.Secure.getIntForUser( |
| 1368 | mContext.getContentResolver(), |
| 1369 | Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, userHandle); |
| 1370 | mUsersAllowingNotifications.append(userHandle, allowed); |
| 1371 | return allowed; |
| 1372 | } |
| 1373 | |
| 1374 | return mUsersAllowingNotifications.get(userHandle); |
| 1375 | } |
| 1376 | |
| 1377 | /** |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 1378 | * Has the given user chosen to allow their private (full) notifications to be shown even |
| 1379 | * when the lockscreen is in "public" (secure & locked) mode? |
| 1380 | */ |
| 1381 | public boolean userAllowsPrivateNotificationsInPublic(int userHandle) { |
| 1382 | if (userHandle == UserHandle.USER_ALL) { |
| 1383 | return true; |
| 1384 | } |
| 1385 | |
| 1386 | if (mUsersAllowingPrivateNotifications.indexOfKey(userHandle) < 0) { |
Kenny Guy | b0d3ab2 | 2015-02-10 16:13:11 +0000 | [diff] [blame] | 1387 | final boolean allowedByUser = 0 != Settings.Secure.getIntForUser( |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 1388 | mContext.getContentResolver(), |
| 1389 | Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, userHandle); |
Sudheer Shanka | f5b850e | 2016-01-25 19:58:59 +0000 | [diff] [blame] | 1390 | final boolean allowedByDpm = adminAllowsUnredactedNotifications(userHandle); |
Kenny Guy | b0d3ab2 | 2015-02-10 16:13:11 +0000 | [diff] [blame] | 1391 | final boolean allowed = allowedByUser && allowedByDpm; |
| 1392 | mUsersAllowingPrivateNotifications.append(userHandle, allowed); |
Dan Sandler | fd16d56 | 2014-02-13 18:43:31 -0800 | [diff] [blame] | 1393 | return allowed; |
| 1394 | } |
| 1395 | |
| 1396 | return mUsersAllowingPrivateNotifications.get(userHandle); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1397 | } |
| 1398 | |
Sudheer Shanka | f5b850e | 2016-01-25 19:58:59 +0000 | [diff] [blame] | 1399 | private boolean adminAllowsUnredactedNotifications(int userHandle) { |
| 1400 | if (userHandle == UserHandle.USER_ALL) { |
| 1401 | return true; |
| 1402 | } |
| 1403 | final int dpmFlags = mDevicePolicyManager.getKeyguardDisabledFeatures(null /* admin */, |
| 1404 | userHandle); |
| 1405 | return (dpmFlags & DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS) == 0; |
| 1406 | } |
| 1407 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 1408 | /** |
Julia Reynolds | 26fa8a5 | 2016-02-24 08:31:22 -0500 | [diff] [blame] | 1409 | * Returns true if we're on a secure lockscreen and the user wants to hide notification data. |
| 1410 | * If so, notifications should be hidden. |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 1411 | */ |
| 1412 | @Override // NotificationData.Environment |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 1413 | public boolean shouldHideNotifications(int userId) { |
Robin Lee | 50a9ad2 | 2016-11-28 15:11:51 +0000 | [diff] [blame] | 1414 | return isLockscreenPublicMode(userId) && !userAllowsNotificationsInPublic(userId) |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 1415 | || (userId != mCurrentUserId && shouldHideNotifications(mCurrentUserId)); |
Julia Reynolds | 26fa8a5 | 2016-02-24 08:31:22 -0500 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | /** |
| 1419 | * Returns true if we're on a secure lockscreen and the user wants to hide notifications via |
| 1420 | * package-specific override. |
| 1421 | */ |
| 1422 | @Override // NotificationDate.Environment |
| 1423 | public boolean shouldHideNotifications(String key) { |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 1424 | return isLockscreenPublicMode(mCurrentUserId) |
Julia Reynolds | 26fa8a5 | 2016-02-24 08:31:22 -0500 | [diff] [blame] | 1425 | && mNotificationData.getVisibilityOverride(key) == Notification.VISIBILITY_SECRET; |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * Returns true if we're on a secure lockscreen. |
| 1430 | */ |
| 1431 | @Override // NotificationData.Environment |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 1432 | public boolean isSecurelyLocked(int userId) { |
| 1433 | return isLockscreenPublicMode(userId); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 1434 | } |
| 1435 | |
Chris Wren | a4ef620 | 2014-06-09 18:07:30 -0400 | [diff] [blame] | 1436 | public void onNotificationClear(StatusBarNotification notification) { |
| 1437 | try { |
| 1438 | mBarService.onNotificationClear( |
| 1439 | notification.getPackageName(), |
| 1440 | notification.getTag(), |
| 1441 | notification.getId(), |
| 1442 | notification.getUserId()); |
| 1443 | } catch (android.os.RemoteException ex) { |
| 1444 | // oh well |
| 1445 | } |
| 1446 | } |
| 1447 | |
Selim Cinek | 5f71bee | 2015-11-18 10:25:23 -0800 | [diff] [blame] | 1448 | /** |
Selim Cinek | 5fbc632 | 2016-01-15 17:17:58 -0800 | [diff] [blame] | 1449 | * Called when the notification panel layouts |
Selim Cinek | 5f71bee | 2015-11-18 10:25:23 -0800 | [diff] [blame] | 1450 | */ |
Selim Cinek | 5fbc632 | 2016-01-15 17:17:58 -0800 | [diff] [blame] | 1451 | public void onPanelLaidOut() { |
Selim Cinek | 5f71bee | 2015-11-18 10:25:23 -0800 | [diff] [blame] | 1452 | if (mState == StatusBarState.KEYGUARD) { |
| 1453 | // Since the number of notifications is determined based on the height of the view, we |
| 1454 | // need to update them. |
Selim Cinek | 5fbc632 | 2016-01-15 17:17:58 -0800 | [diff] [blame] | 1455 | int maxBefore = getMaxKeyguardNotifications(false /* recompute */); |
| 1456 | int maxNotifications = getMaxKeyguardNotifications(true /* recompute */); |
| 1457 | if (maxBefore != maxNotifications) { |
| 1458 | updateRowStates(); |
| 1459 | } |
Selim Cinek | 5f71bee | 2015-11-18 10:25:23 -0800 | [diff] [blame] | 1460 | } |
| 1461 | } |
| 1462 | |
Mady Mellor | 8e8a69e | 2016-03-14 12:30:10 -0700 | [diff] [blame] | 1463 | protected void onLockedNotificationImportanceChange(OnDismissAction dismissAction) {} |
| 1464 | |
Adrian Roos | 3aec638 | 2016-02-05 14:19:01 -0800 | [diff] [blame] | 1465 | protected void onLockedRemoteInput(ExpandableNotificationRow row, View clickedView) {} |
| 1466 | |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1467 | protected void onLockedWorkRemoteInput(int userId, ExpandableNotificationRow row, |
| 1468 | View clicked) {} |
| 1469 | |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 1470 | @Override |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1471 | public void onExpandClicked(Entry clickedEntry, boolean nowExpanded) { |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 1472 | } |
| 1473 | |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1474 | protected class H extends Handler { |
| 1475 | public void handleMessage(Message m) { |
| 1476 | switch (m.what) { |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1477 | case MSG_SHOW_RECENT_APPS: |
Jorim Jaggi | 681fc7b | 2016-04-14 22:02:39 -0700 | [diff] [blame] | 1478 | showRecents(m.arg1 > 0, m.arg2 != 0); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1479 | break; |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1480 | case MSG_HIDE_RECENT_APPS: |
Winson Chung | cdcd487 | 2014-08-05 18:00:13 -0700 | [diff] [blame] | 1481 | hideRecents(m.arg1 > 0, m.arg2 > 0); |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1482 | break; |
| 1483 | case MSG_TOGGLE_RECENTS_APPS: |
| 1484 | toggleRecents(); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 1485 | break; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1486 | case MSG_PRELOAD_RECENT_APPS: |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1487 | preloadRecents(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1488 | break; |
| 1489 | case MSG_CANCEL_PRELOAD_RECENT_APPS: |
Winson Chung | 1e8d71b | 2014-05-16 17:05:22 -0700 | [diff] [blame] | 1490 | cancelPreloadingRecents(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1491 | break; |
Winson Chung | b1f7499 | 2014-08-08 12:53:09 -0700 | [diff] [blame] | 1492 | case MSG_SHOW_NEXT_AFFILIATED_TASK: |
| 1493 | showRecentsNextAffiliatedTask(); |
| 1494 | break; |
| 1495 | case MSG_SHOW_PREV_AFFILIATED_TASK: |
| 1496 | showRecentsPreviousAffiliatedTask(); |
| 1497 | break; |
Andrei Stingaceanu | c22ab79 | 2016-01-07 12:39:38 +0000 | [diff] [blame] | 1498 | case MSG_TOGGLE_KEYBOARD_SHORTCUTS_MENU: |
Clara Bayarri | 4e850ff | 2016-03-02 11:12:32 -0800 | [diff] [blame] | 1499 | toggleKeyboardShortcuts(m.arg1); |
Clara Bayarri | f2debb1 | 2015-07-10 14:47:17 +0100 | [diff] [blame] | 1500 | break; |
Andrei Stingaceanu | 0bf096f | 2016-04-14 18:11:57 +0100 | [diff] [blame] | 1501 | case MSG_DISMISS_KEYBOARD_SHORTCUTS_MENU: |
| 1502 | dismissKeyboardShortcuts(); |
| 1503 | break; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1508 | protected void workAroundBadLayerDrawableOpacity(View v) { |
| 1509 | } |
| 1510 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1511 | protected boolean inflateViews(Entry entry, ViewGroup parent) { |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 1512 | PackageManager pmUser = getPackageManagerForUser(mContext, |
Dan Sandler | e9a4e90 | 2014-07-31 01:06:43 -0400 | [diff] [blame] | 1513 | entry.notification.getUser().getIdentifier()); |
| 1514 | |
Dan Sandler | f4db75c | 2014-09-03 18:02:31 +0200 | [diff] [blame] | 1515 | final StatusBarNotification sbn = entry.notification; |
Adrian Roos | 95f8bea | 2016-07-27 15:49:03 -0700 | [diff] [blame] | 1516 | try { |
| 1517 | entry.cacheContentViews(mContext, null); |
| 1518 | } catch (RuntimeException e) { |
| 1519 | Log.e(TAG, "Unable to get notification remote views", e); |
| 1520 | return false; |
| 1521 | } |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1522 | |
| 1523 | final RemoteViews contentView = entry.cachedContentView; |
| 1524 | final RemoteViews bigContentView = entry.cachedBigContentView; |
| 1525 | final RemoteViews headsUpContentView = entry.cachedHeadsUpContentView; |
| 1526 | final RemoteViews publicContentView = entry.cachedPublicContentView; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1527 | final RemoteViews ambientContentView = entry.cachedAmbientContentView; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1528 | |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 1529 | if (contentView == null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1530 | Log.v(TAG, "no contentView for: " + sbn.getNotification()); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1531 | return false; |
| 1532 | } |
| 1533 | |
Dan Sandler | f68448e | 2014-04-24 15:54:16 -0400 | [diff] [blame] | 1534 | if (DEBUG) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1535 | Log.v(TAG, "publicContentView: " + publicContentView); |
Dan Sandler | f68448e | 2014-04-24 15:54:16 -0400 | [diff] [blame] | 1536 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1537 | |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1538 | ExpandableNotificationRow row; |
| 1539 | |
| 1540 | // Stash away previous user expansion state so we can restore it at |
| 1541 | // the end. |
| 1542 | boolean hasUserChangedExpansion = false; |
| 1543 | boolean userExpanded = false; |
| 1544 | boolean userLocked = false; |
| 1545 | |
| 1546 | if (entry.row != null) { |
| 1547 | row = entry.row; |
| 1548 | hasUserChangedExpansion = row.hasUserChangedExpansion(); |
| 1549 | userExpanded = row.isUserExpanded(); |
| 1550 | userLocked = row.isUserLocked(); |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 1551 | entry.reset(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1552 | if (hasUserChangedExpansion) { |
| 1553 | row.setUserExpanded(userExpanded); |
| 1554 | } |
| 1555 | } else { |
| 1556 | // create the row view |
| 1557 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( |
| 1558 | Context.LAYOUT_INFLATER_SERVICE); |
| 1559 | row = (ExpandableNotificationRow) inflater.inflate(R.layout.status_bar_notification_row, |
| 1560 | parent, false); |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1561 | row.setExpansionLogger(this, entry.notification.getKey()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1562 | row.setGroupManager(mGroupManager); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1563 | row.setHeadsUpManager(mHeadsUpManager); |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1564 | row.setRemoteInputController(mRemoteInputController); |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 1565 | row.setOnExpandClickListener(this); |
Mady Mellor | 3fd273e | 2016-03-15 21:08:14 -0700 | [diff] [blame] | 1566 | |
Dan Sandler | 732bd6c | 2016-04-12 14:20:32 -0400 | [diff] [blame] | 1567 | // Get the app name. |
| 1568 | // Note that Notification.Builder#bindHeaderAppName has similar logic |
| 1569 | // but since this field is used in the guts, it must be accurate. |
| 1570 | // Therefore we will only show the application label, or, failing that, the |
| 1571 | // package name. No substitutions. |
Mady Mellor | 3fd273e | 2016-03-15 21:08:14 -0700 | [diff] [blame] | 1572 | final String pkg = sbn.getPackageName(); |
| 1573 | String appname = pkg; |
| 1574 | try { |
| 1575 | final ApplicationInfo info = pmUser.getApplicationInfo(pkg, |
Amith Yamasani | 0d1fd8d | 2016-10-12 14:21:51 -0700 | [diff] [blame] | 1576 | PackageManager.MATCH_UNINSTALLED_PACKAGES |
| 1577 | | PackageManager.MATCH_DISABLED_COMPONENTS); |
Mady Mellor | 3fd273e | 2016-03-15 21:08:14 -0700 | [diff] [blame] | 1578 | if (info != null) { |
| 1579 | appname = String.valueOf(pmUser.getApplicationLabel(info)); |
| 1580 | } |
| 1581 | } catch (NameNotFoundException e) { |
| 1582 | // Do nothing |
| 1583 | } |
| 1584 | row.setAppName(appname); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1585 | } |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 1586 | |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1587 | workAroundBadLayerDrawableOpacity(row); |
Selim Cinek | e907911 | 2016-12-14 14:41:01 -0800 | [diff] [blame] | 1588 | bindDismissRunnable(row); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1589 | |
| 1590 | // NB: the large icon is now handled entirely by the template |
| 1591 | |
| 1592 | // bind the click event to the content area |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1593 | NotificationContentView contentContainer = row.getPrivateLayout(); |
| 1594 | NotificationContentView contentContainerPublic = row.getPublicLayout(); |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 1595 | |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 1596 | row.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 1597 | if (ENABLE_REMOTE_INPUT) { |
| 1598 | row.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); |
| 1599 | } |
Daniel Sandler | bc5559f | 2012-04-19 01:08:15 -0400 | [diff] [blame] | 1600 | |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1601 | mNotificationClicker.register(row, sbn); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1602 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1603 | // set up the adaptive layout |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 1604 | View contentViewLocal = null; |
| 1605 | View bigContentViewLocal = null; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1606 | View headsUpContentViewLocal = null; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 1607 | View publicViewLocal = null; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1608 | View ambientViewLocal = null; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1609 | try { |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1610 | contentViewLocal = contentView.apply( |
| 1611 | sbn.getPackageContext(mContext), |
| 1612 | contentContainer, |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 1613 | mOnClickHandler); |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 1614 | if (bigContentView != null) { |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1615 | bigContentViewLocal = bigContentView.apply( |
| 1616 | sbn.getPackageContext(mContext), |
| 1617 | contentContainer, |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1618 | mOnClickHandler); |
| 1619 | } |
| 1620 | if (headsUpContentView != null) { |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 1621 | headsUpContentViewLocal = headsUpContentView.apply( |
| 1622 | sbn.getPackageContext(mContext), |
| 1623 | contentContainer, |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 1624 | mOnClickHandler); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1625 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 1626 | if (publicContentView != null) { |
| 1627 | publicViewLocal = publicContentView.apply( |
| 1628 | sbn.getPackageContext(mContext), |
| 1629 | contentContainerPublic, mOnClickHandler); |
| 1630 | } |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1631 | if (ambientContentView != null) { |
| 1632 | ambientViewLocal = ambientContentView.apply( |
| 1633 | sbn.getPackageContext(mContext), |
| 1634 | contentContainer, mOnClickHandler); |
| 1635 | } |
dooyoung.hwang | 78c4114 | 2016-10-04 18:55:31 +0900 | [diff] [blame] | 1636 | |
| 1637 | if (contentViewLocal != null) { |
| 1638 | contentViewLocal.setIsRootNamespace(true); |
| 1639 | contentContainer.setContractedChild(contentViewLocal); |
| 1640 | } |
| 1641 | if (bigContentViewLocal != null) { |
| 1642 | bigContentViewLocal.setIsRootNamespace(true); |
| 1643 | contentContainer.setExpandedChild(bigContentViewLocal); |
| 1644 | } |
| 1645 | if (headsUpContentViewLocal != null) { |
| 1646 | headsUpContentViewLocal.setIsRootNamespace(true); |
| 1647 | contentContainer.setHeadsUpChild(headsUpContentViewLocal); |
| 1648 | } |
| 1649 | if (publicViewLocal != null) { |
| 1650 | publicViewLocal.setIsRootNamespace(true); |
| 1651 | contentContainerPublic.setContractedChild(publicViewLocal); |
| 1652 | } |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1653 | |
| 1654 | if (ambientViewLocal != null) { |
| 1655 | ambientViewLocal.setIsRootNamespace(true); |
| 1656 | contentContainer.setAmbientChild(ambientViewLocal); |
| 1657 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1658 | } |
| 1659 | catch (RuntimeException e) { |
Daniel Sandler | 4f91efd | 2013-04-25 16:38:41 -0400 | [diff] [blame] | 1660 | final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId()); |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 1661 | Log.e(TAG, "couldn't inflate view for notification " + ident, e); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1662 | return false; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1663 | } |
| 1664 | |
Jorim Jaggi | a1eeade | 2014-09-08 22:34:39 +0200 | [diff] [blame] | 1665 | // Extract target SDK version. |
| 1666 | try { |
| 1667 | ApplicationInfo info = pmUser.getApplicationInfo(sbn.getPackageName(), 0); |
| 1668 | entry.targetSdk = info.targetSdkVersion; |
| 1669 | } catch (NameNotFoundException ex) { |
| 1670 | Log.e(TAG, "Failed looking up ApplicationInfo for " + sbn.getPackageName(), ex); |
| 1671 | } |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 1672 | entry.autoRedacted = entry.notification.getNotification().publicVersion == null; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1673 | |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1674 | entry.row = row; |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 1675 | entry.row.setOnActivatedListener(this); |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1676 | entry.row.setExpandable(bigContentViewLocal != null); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1677 | |
Christoph Studer | 13b89512 | 2014-08-26 15:42:12 +0200 | [diff] [blame] | 1678 | applyColorsAndBackgrounds(sbn, entry); |
Jorim Jaggi | 4673985 | 2014-04-15 09:58:24 +0200 | [diff] [blame] | 1679 | |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1680 | // Restore previous flags. |
| 1681 | if (hasUserChangedExpansion) { |
| 1682 | // Note: setUserExpanded() conveniently ignores calls with |
| 1683 | // userExpanded=true if !isExpandable(). |
| 1684 | row.setUserExpanded(userExpanded); |
| 1685 | } |
| 1686 | row.setUserLocked(userLocked); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 1687 | row.onNotificationUpdated(entry); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1688 | return true; |
| 1689 | } |
| 1690 | |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 1691 | /** |
| 1692 | * Adds RemoteInput actions from the WearableExtender; to be removed once more apps support this |
| 1693 | * via first-class API. |
| 1694 | * |
| 1695 | * TODO: Remove once enough apps specify remote inputs on their own. |
| 1696 | */ |
| 1697 | private void processForRemoteInput(Notification n) { |
| 1698 | if (!ENABLE_REMOTE_INPUT) return; |
| 1699 | |
| 1700 | if (n.extras != null && n.extras.containsKey("android.wearable.EXTENSIONS") && |
| 1701 | (n.actions == null || n.actions.length == 0)) { |
| 1702 | Notification.Action viableAction = null; |
| 1703 | Notification.WearableExtender we = new Notification.WearableExtender(n); |
| 1704 | |
| 1705 | List<Notification.Action> actions = we.getActions(); |
| 1706 | final int numActions = actions.size(); |
| 1707 | |
| 1708 | for (int i = 0; i < numActions; i++) { |
| 1709 | Notification.Action action = actions.get(i); |
Adrian Roos | a3539cb | 2015-12-16 16:47:02 -0800 | [diff] [blame] | 1710 | if (action == null) { |
| 1711 | continue; |
| 1712 | } |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 1713 | RemoteInput[] remoteInputs = action.getRemoteInputs(); |
Adrian Roos | a3539cb | 2015-12-16 16:47:02 -0800 | [diff] [blame] | 1714 | if (remoteInputs == null) { |
| 1715 | continue; |
| 1716 | } |
| 1717 | for (RemoteInput ri : remoteInputs) { |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 1718 | if (ri.getAllowFreeFormInput()) { |
| 1719 | viableAction = action; |
| 1720 | break; |
| 1721 | } |
| 1722 | } |
| 1723 | if (viableAction != null) { |
| 1724 | break; |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | if (viableAction != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 1729 | Notification.Builder rebuilder = Notification.Builder.recoverBuilder(mContext, n); |
| 1730 | rebuilder.setActions(viableAction); |
| 1731 | rebuilder.build(); // will rewrite n |
Adrian Roos | 497ab02 | 2015-02-10 20:49:33 +0100 | [diff] [blame] | 1732 | } |
| 1733 | } |
| 1734 | } |
| 1735 | |
Adrian Roos | 62692b2 | 2015-09-11 17:46:23 -0700 | [diff] [blame] | 1736 | public void startPendingIntentDismissingKeyguard(final PendingIntent intent) { |
| 1737 | if (!isDeviceProvisioned()) return; |
| 1738 | |
| 1739 | final boolean keyguardShowing = mStatusBarKeyguardViewManager.isShowing(); |
| 1740 | final boolean afterKeyguardGone = intent.isActivity() |
| 1741 | && PreviewInflater.wouldLaunchResolverActivity(mContext, intent.getIntent(), |
| 1742 | mCurrentUserId); |
| 1743 | dismissKeyguardThenExecute(new OnDismissAction() { |
| 1744 | public boolean onDismiss() { |
| 1745 | new Thread() { |
| 1746 | @Override |
| 1747 | public void run() { |
| 1748 | try { |
Adrian Roos | 62692b2 | 2015-09-11 17:46:23 -0700 | [diff] [blame] | 1749 | // The intent we are sending is for the application, which |
| 1750 | // won't have permission to immediately start an activity after |
| 1751 | // the user switches to home. We know it is safe to do at this |
| 1752 | // point, so make sure new activity switches are now allowed. |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1753 | ActivityManager.getService().resumeAppSwitches(); |
Adrian Roos | 62692b2 | 2015-09-11 17:46:23 -0700 | [diff] [blame] | 1754 | } catch (RemoteException e) { |
| 1755 | } |
Adrian Roos | 62692b2 | 2015-09-11 17:46:23 -0700 | [diff] [blame] | 1756 | try { |
Jorim Jaggi | e6e108e | 2016-03-28 13:38:45 -0700 | [diff] [blame] | 1757 | intent.send(null, 0, null, null, null, null, getActivityOptions()); |
Adrian Roos | 62692b2 | 2015-09-11 17:46:23 -0700 | [diff] [blame] | 1758 | } catch (PendingIntent.CanceledException e) { |
| 1759 | // the stack trace isn't very helpful here. |
| 1760 | // Just log the exception message. |
| 1761 | Log.w(TAG, "Sending intent failed: " + e); |
| 1762 | |
| 1763 | // TODO: Dismiss Keyguard. |
| 1764 | } |
| 1765 | if (intent.isActivity()) { |
| 1766 | mAssistManager.hideAssist(); |
Adrian Roos | 62692b2 | 2015-09-11 17:46:23 -0700 | [diff] [blame] | 1767 | } |
| 1768 | } |
| 1769 | }.start(); |
| 1770 | |
| 1771 | // close the shade if it was open |
| 1772 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, |
| 1773 | true /* force */, true /* delayed */); |
| 1774 | visibilityChanged(false); |
| 1775 | |
| 1776 | return true; |
| 1777 | } |
| 1778 | }, afterKeyguardGone); |
| 1779 | } |
| 1780 | |
Selim Cinek | 36b0223 | 2016-05-11 23:07:05 -0400 | [diff] [blame] | 1781 | public void addPostCollapseAction(Runnable r) { |
| 1782 | } |
| 1783 | |
| 1784 | public boolean isCollapsing() { |
| 1785 | return false; |
| 1786 | } |
| 1787 | |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1788 | private final class NotificationClicker implements View.OnClickListener { |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1789 | public void onClick(final View v) { |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1790 | if (!(v instanceof ExpandableNotificationRow)) { |
| 1791 | Log.e(TAG, "NotificationClicker called on a view that is not a notification row."); |
| 1792 | return; |
| 1793 | } |
| 1794 | |
| 1795 | final ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
| 1796 | final StatusBarNotification sbn = row.getStatusBarNotification(); |
| 1797 | if (sbn == null) { |
| 1798 | Log.e(TAG, "NotificationClicker called on an unclickable notification,"); |
| 1799 | return; |
| 1800 | } |
| 1801 | |
Mady Mellor | f062580 | 2016-02-11 18:03:48 -0800 | [diff] [blame] | 1802 | // Check if the notification is displaying the gear, if so slide notification back |
| 1803 | if (row.getSettingsRow() != null && row.getSettingsRow().isVisible()) { |
| 1804 | row.animateTranslateNotification(0); |
| 1805 | return; |
| 1806 | } |
| 1807 | |
Selim Cinek | c6dd521 | 2015-11-02 14:51:54 -0800 | [diff] [blame] | 1808 | Notification notification = sbn.getNotification(); |
| 1809 | final PendingIntent intent = notification.contentIntent != null |
| 1810 | ? notification.contentIntent |
| 1811 | : notification.fullScreenIntent; |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1812 | final String notificationKey = sbn.getKey(); |
| 1813 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 1814 | // Mark notification for one frame. |
| 1815 | row.setJustClicked(true); |
| 1816 | DejankUtils.postAfterTraversal(new Runnable() { |
| 1817 | @Override |
| 1818 | public void run() { |
| 1819 | row.setJustClicked(false); |
| 1820 | } |
| 1821 | }); |
| 1822 | |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1823 | final boolean keyguardShowing = mStatusBarKeyguardViewManager.isShowing(); |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1824 | final boolean afterKeyguardGone = intent.isActivity() |
| 1825 | && PreviewInflater.wouldLaunchResolverActivity(mContext, intent.getIntent(), |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 1826 | mCurrentUserId); |
Adrian Roos | 4314f6d | 2014-05-28 14:10:27 +0200 | [diff] [blame] | 1827 | dismissKeyguardThenExecute(new OnDismissAction() { |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1828 | public boolean onDismiss() { |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1829 | if (mHeadsUpManager != null && mHeadsUpManager.isHeadsUp(notificationKey)) { |
Christoph Studer | c6a656c | 2015-01-22 15:02:49 +0100 | [diff] [blame] | 1830 | // Release the HUN notification to the shade. |
Selim Cinek | f55f1bc | 2016-05-27 11:19:11 -0700 | [diff] [blame] | 1831 | |
| 1832 | if (isPanelFullyCollapsed()) { |
| 1833 | HeadsUpManager.setIsClickedNotification(row, true); |
| 1834 | } |
Christoph Studer | c6a656c | 2015-01-22 15:02:49 +0100 | [diff] [blame] | 1835 | // |
| 1836 | // In most cases, when FLAG_AUTO_CANCEL is set, the notification will |
| 1837 | // become canceled shortly by NoMan, but we can't assume that. |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1838 | mHeadsUpManager.releaseImmediately(notificationKey); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1839 | } |
Selim Cinek | 36b0223 | 2016-05-11 23:07:05 -0400 | [diff] [blame] | 1840 | StatusBarNotification parentToCancel = null; |
| 1841 | if (shouldAutoCancel(sbn) && mGroupManager.isOnlyChildInGroup(sbn)) { |
| 1842 | StatusBarNotification summarySbn = mGroupManager.getLogicalGroupSummary(sbn) |
| 1843 | .getStatusBarNotification(); |
| 1844 | if (shouldAutoCancel(summarySbn)) { |
| 1845 | parentToCancel = summarySbn; |
| 1846 | } |
| 1847 | } |
| 1848 | final StatusBarNotification parentToCancelFinal = parentToCancel; |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 1849 | new Thread() { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1850 | @Override |
| 1851 | public void run() { |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 1852 | try { |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 1853 | // The intent we are sending is for the application, which |
| 1854 | // won't have permission to immediately start an activity after |
| 1855 | // the user switches to home. We know it is safe to do at this |
| 1856 | // point, so make sure new activity switches are now allowed. |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1857 | ActivityManager.getService().resumeAppSwitches(); |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 1858 | } catch (RemoteException e) { |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1859 | } |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1860 | if (intent != null) { |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 1861 | // If we are launching a work activity and require to launch |
| 1862 | // separate work challenge, we defer the activity action and cancel |
| 1863 | // notification until work challenge is unlocked. |
| 1864 | if (intent.isActivity()) { |
| 1865 | final int userId = intent.getCreatorUserHandle() |
| 1866 | .getIdentifier(); |
| 1867 | if (mLockPatternUtils.isSeparateProfileChallengeEnabled(userId) |
| 1868 | && mKeyguardManager.isDeviceLocked(userId)) { |
Rubin Xu | 89927b3 | 2016-07-28 14:34:26 +0100 | [diff] [blame] | 1869 | boolean canBypass = false; |
| 1870 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1871 | canBypass = ActivityManager.getService() |
Rubin Xu | 89927b3 | 2016-07-28 14:34:26 +0100 | [diff] [blame] | 1872 | .canBypassWorkChallenge(intent); |
| 1873 | } catch (RemoteException e) { |
| 1874 | } |
| 1875 | // For direct-boot aware activities, they can be shown when |
| 1876 | // the device is still locked without triggering the work |
| 1877 | // challenge. |
| 1878 | if ((!canBypass) && startWorkChallengeIfNecessary(userId, |
| 1879 | intent.getIntentSender(), notificationKey)) { |
| 1880 | // Show work challenge, do not run PendingIntent and |
Ricky Wai | a8c37a1 | 2016-04-05 17:10:04 +0100 | [diff] [blame] | 1881 | // remove notification |
| 1882 | return; |
| 1883 | } |
Ricky Wai | 7fa0171 | 2016-03-16 12:13:54 +0000 | [diff] [blame] | 1884 | } |
| 1885 | } |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1886 | try { |
Jorim Jaggi | e6e108e | 2016-03-28 13:38:45 -0700 | [diff] [blame] | 1887 | intent.send(null, 0, null, null, null, null, |
| 1888 | getActivityOptions()); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1889 | } catch (PendingIntent.CanceledException e) { |
| 1890 | // the stack trace isn't very helpful here. |
| 1891 | // Just log the exception message. |
| 1892 | Log.w(TAG, "Sending contentIntent failed: " + e); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1893 | |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1894 | // TODO: Dismiss Keyguard. |
| 1895 | } |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1896 | if (intent.isActivity()) { |
Jorim Jaggi | b835dd7 | 2015-06-08 12:28:42 -0700 | [diff] [blame] | 1897 | mAssistManager.hideAssist(); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | try { |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1902 | mBarService.onNotificationClick(notificationKey); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1903 | } catch (RemoteException ex) { |
| 1904 | // system process is dead if we're here. |
| 1905 | } |
Selim Cinek | 36b0223 | 2016-05-11 23:07:05 -0400 | [diff] [blame] | 1906 | if (parentToCancelFinal != null) { |
| 1907 | // We have to post it to the UI thread for synchronization |
| 1908 | mHandler.post(new Runnable() { |
| 1909 | @Override |
| 1910 | public void run() { |
| 1911 | Runnable removeRunnable = new Runnable() { |
| 1912 | @Override |
| 1913 | public void run() { |
Selim Cinek | d4740141 | 2016-12-15 14:44:36 -0800 | [diff] [blame] | 1914 | performRemoveNotification(parentToCancelFinal); |
Selim Cinek | 36b0223 | 2016-05-11 23:07:05 -0400 | [diff] [blame] | 1915 | } |
| 1916 | }; |
| 1917 | if (isCollapsing()) { |
| 1918 | // To avoid lags we're only performing the remove |
| 1919 | // after the shade was collapsed |
| 1920 | addPostCollapseAction(removeRunnable); |
| 1921 | } else { |
| 1922 | removeRunnable.run(); |
| 1923 | } |
| 1924 | } |
| 1925 | }); |
| 1926 | } |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1927 | } |
Jorim Jaggi | 89f7f28 | 2014-10-17 19:54:15 +0200 | [diff] [blame] | 1928 | }.start(); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1929 | |
| 1930 | // close the shade if it was open |
Jorim Jaggi | 4eedc1d | 2014-10-27 13:45:56 +0100 | [diff] [blame] | 1931 | animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 1932 | true /* force */, true /* delayed */); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 1933 | visibilityChanged(false); |
| 1934 | |
Jorim Jaggi | 8972c2a | 2015-06-05 16:05:54 -0700 | [diff] [blame] | 1935 | return true; |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1936 | } |
Jorim Jaggi | 85dc23c | 2014-09-08 14:42:29 +0200 | [diff] [blame] | 1937 | }, afterKeyguardGone); |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1938 | } |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1939 | |
Selim Cinek | 36b0223 | 2016-05-11 23:07:05 -0400 | [diff] [blame] | 1940 | private boolean shouldAutoCancel(StatusBarNotification sbn) { |
| 1941 | int flags = sbn.getNotification().flags; |
| 1942 | if ((flags & Notification.FLAG_AUTO_CANCEL) != Notification.FLAG_AUTO_CANCEL) { |
| 1943 | return false; |
| 1944 | } |
| 1945 | if ((flags & Notification.FLAG_FOREGROUND_SERVICE) != 0) { |
| 1946 | return false; |
| 1947 | } |
| 1948 | return true; |
| 1949 | } |
| 1950 | |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1951 | public void register(ExpandableNotificationRow row, StatusBarNotification sbn) { |
Selim Cinek | c6dd521 | 2015-11-02 14:51:54 -0800 | [diff] [blame] | 1952 | Notification notification = sbn.getNotification(); |
| 1953 | if (notification.contentIntent != null || notification.fullScreenIntent != null) { |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 1954 | row.setOnClickListener(this); |
| 1955 | } else { |
| 1956 | row.setOnClickListener(null); |
| 1957 | } |
| 1958 | } |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 1959 | } |
Chris Wren | f29c3b4 | 2013-11-27 16:30:30 -0500 | [diff] [blame] | 1960 | |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1961 | public void animateCollapsePanels(int flags, boolean force) { |
| 1962 | } |
| 1963 | |
Jorim Jaggi | 27c9b74 | 2015-04-09 10:34:49 -0700 | [diff] [blame] | 1964 | public void animateCollapsePanels(int flags, boolean force, boolean delayed) { |
| 1965 | } |
| 1966 | |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1967 | protected boolean startWorkChallengeIfNecessary(int userId, IntentSender intendSender, |
| 1968 | String notificationKey) { |
| 1969 | final Intent newIntent = mKeyguardManager.createConfirmDeviceCredentialIntent(null, |
| 1970 | null, userId); |
| 1971 | if (newIntent == null) { |
| 1972 | return false; |
| 1973 | } |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 1974 | final Intent callBackIntent = new Intent(NOTIFICATION_UNLOCKED_BY_WORK_CHALLENGE_ACTION); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1975 | callBackIntent.putExtra(Intent.EXTRA_INTENT, intendSender); |
| 1976 | callBackIntent.putExtra(Intent.EXTRA_INDEX, notificationKey); |
| 1977 | callBackIntent.setPackage(mContext.getPackageName()); |
| 1978 | |
| 1979 | PendingIntent callBackPendingIntent = PendingIntent.getBroadcast( |
| 1980 | mContext, |
| 1981 | 0, |
| 1982 | callBackIntent, |
| 1983 | PendingIntent.FLAG_CANCEL_CURRENT | |
| 1984 | PendingIntent.FLAG_ONE_SHOT | |
| 1985 | PendingIntent.FLAG_IMMUTABLE); |
| 1986 | newIntent.putExtra( |
| 1987 | Intent.EXTRA_INTENT, |
| 1988 | callBackPendingIntent.getIntentSender()); |
| 1989 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1990 | ActivityManager.getService().startConfirmDeviceCredentialIntent(newIntent); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1991 | } catch (RemoteException ex) { |
| 1992 | // ignore |
| 1993 | } |
| 1994 | return true; |
| 1995 | } |
| 1996 | |
Jorim Jaggi | e6e108e | 2016-03-28 13:38:45 -0700 | [diff] [blame] | 1997 | protected Bundle getActivityOptions() { |
| 1998 | // Anything launched from the notification shade should always go into the |
| 1999 | // fullscreen stack. |
| 2000 | ActivityOptions options = ActivityOptions.makeBasic(); |
| 2001 | options.setLaunchStackId(StackId.FULLSCREEN_WORKSPACE_STACK_ID); |
| 2002 | return options.toBundle(); |
| 2003 | } |
| 2004 | |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 2005 | protected void visibilityChanged(boolean visible) { |
| 2006 | if (mVisible != visible) { |
| 2007 | mVisible = visible; |
| 2008 | if (!visible) { |
| 2009 | dismissPopups(); |
| 2010 | } |
| 2011 | } |
| 2012 | updateVisibleToUser(); |
| 2013 | } |
| 2014 | |
| 2015 | protected void updateVisibleToUser() { |
| 2016 | boolean oldVisibleToUser = mVisibleToUser; |
Jorim Jaggi | 50ff3af | 2015-08-12 18:35:42 -0700 | [diff] [blame] | 2017 | mVisibleToUser = mVisible && mDeviceInteractive; |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 2018 | |
| 2019 | if (oldVisibleToUser != mVisibleToUser) { |
| 2020 | handleVisibleToUserChanged(mVisibleToUser); |
| 2021 | } |
| 2022 | } |
| 2023 | |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 2024 | /** |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 2025 | * The LEDs are turned off when the notification panel is shown, even just a little bit. |
Adrian Roos | 18d099a | 2016-05-19 15:28:18 -0700 | [diff] [blame] | 2026 | * See also PhoneStatusBar.setPanelExpanded for another place where we attempt to do this. |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 2027 | */ |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 2028 | protected void handleVisibleToUserChanged(boolean visibleToUser) { |
| 2029 | try { |
| 2030 | if (visibleToUser) { |
Selim Cinek | 6577cae | 2015-08-31 16:15:49 -0700 | [diff] [blame] | 2031 | boolean pinnedHeadsUp = mHeadsUpManager.hasPinnedHeadsUp(); |
| 2032 | boolean clearNotificationEffects = |
Dan Sandler | cb01289 | 2016-03-01 00:45:06 -0500 | [diff] [blame] | 2033 | !isPanelFullyCollapsed() && |
| 2034 | (mState == StatusBarState.SHADE || mState == StatusBarState.SHADE_LOCKED); |
Chris Wren | b659c4f | 2015-06-25 17:12:27 -0400 | [diff] [blame] | 2035 | int notificationLoad = mNotificationData.getActiveNotifications().size(); |
Selim Cinek | 6577cae | 2015-08-31 16:15:49 -0700 | [diff] [blame] | 2036 | if (pinnedHeadsUp && isPanelFullyCollapsed()) { |
Chris Wren | b659c4f | 2015-06-25 17:12:27 -0400 | [diff] [blame] | 2037 | notificationLoad = 1; |
| 2038 | } else { |
| 2039 | MetricsLogger.histogram(mContext, "note_load", notificationLoad); |
| 2040 | } |
| 2041 | mBarService.onPanelRevealed(clearNotificationEffects, notificationLoad); |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 2042 | } else { |
| 2043 | mBarService.onPanelHidden(); |
Dan Sandler | 4247a5c | 2014-07-23 15:58:08 -0400 | [diff] [blame] | 2044 | } |
Christoph Studer | e8e2865 | 2014-10-29 17:27:53 +0100 | [diff] [blame] | 2045 | } catch (RemoteException ex) { |
| 2046 | // Won't fail unless the world has ended. |
Daniel Sandler | 6a858c3 | 2012-03-12 14:38:58 -0400 | [diff] [blame] | 2047 | } |
| 2048 | } |
| 2049 | |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2050 | /** |
Chris Wren | 1689594 | 2015-06-23 11:22:20 -0400 | [diff] [blame] | 2051 | * Clear Buzz/Beep/Blink. |
| 2052 | */ |
| 2053 | public void clearNotificationEffects() { |
| 2054 | try { |
| 2055 | mBarService.clearNotificationEffects(); |
| 2056 | } catch (RemoteException e) { |
| 2057 | // Won't fail unless the world has ended. |
| 2058 | } |
| 2059 | } |
| 2060 | |
Yorke Lee | e4ea6ab | 2016-03-03 14:51:49 -0800 | [diff] [blame] | 2061 | public abstract boolean isPanelFullyCollapsed(); |
Chris Wren | 1689594 | 2015-06-23 11:22:20 -0400 | [diff] [blame] | 2062 | |
| 2063 | /** |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2064 | * Cancel this notification and tell the StatusBarManagerService / NotificationManagerService |
| 2065 | * about the failure. |
| 2066 | * |
| 2067 | * WARNING: this will call back into us. Don't hold any locks. |
| 2068 | */ |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 2069 | void handleNotificationError(StatusBarNotification n, String message) { |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 2070 | removeNotification(n.getKey(), null); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2071 | try { |
Kenny Guy | 3a7c4a5 | 2014-03-03 18:24:03 +0000 | [diff] [blame] | 2072 | mBarService.onNotificationError(n.getPackageName(), n.getTag(), n.getId(), n.getUid(), |
| 2073 | n.getInitialPid(), message, n.getUserId()); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2074 | } catch (RemoteException ex) { |
| 2075 | // The end is nigh. |
| 2076 | } |
| 2077 | } |
| 2078 | |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 2079 | protected StatusBarNotification removeNotificationViews(String key, RankingMap ranking) { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 2080 | NotificationData.Entry entry = mNotificationData.remove(key, ranking); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2081 | if (entry == null) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 2082 | Log.w(TAG, "removeNotification for unknown key: " + key); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2083 | return null; |
| 2084 | } |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 2085 | updateNotifications(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2086 | return entry.notification; |
| 2087 | } |
| 2088 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 2089 | protected NotificationData.Entry createNotificationViews(StatusBarNotification sbn) { |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2090 | if (DEBUG) { |
Christoph Studer | a0506e7 | 2014-07-31 20:27:39 +0200 | [diff] [blame] | 2091 | Log.d(TAG, "createNotificationViews(notification=" + sbn); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2092 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2093 | NotificationData.Entry entry = new NotificationData.Entry(sbn); |
| 2094 | try { |
| 2095 | entry.createIcons(mContext, sbn); |
| 2096 | } catch (NotificationData.IconException exception) { |
| 2097 | handleNotificationError(sbn, exception.getMessage()); |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | // Construct the expanded view. |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 2101 | if (!inflateViews(entry, mStackScroller)) { |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 2102 | handleNotificationError(sbn, "Couldn't expand RemoteViews for: " + sbn); |
| 2103 | return null; |
| 2104 | } |
| 2105 | return entry; |
| 2106 | } |
| 2107 | |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 2108 | protected void addNotificationViews(Entry entry, RankingMap ranking) { |
Raju Yadav | 5f33026 | 2014-03-24 10:44:00 +0100 | [diff] [blame] | 2109 | if (entry == null) { |
| 2110 | return; |
| 2111 | } |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2112 | // Add the expanded view and icon. |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 2113 | mNotificationData.add(entry, ranking); |
| 2114 | updateNotifications(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 2115 | } |
| 2116 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 2117 | /** |
Selim Cinek | 5f71bee | 2015-11-18 10:25:23 -0800 | [diff] [blame] | 2118 | * @param recompute wheter the number should be recomputed |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 2119 | * @return The number of notifications we show on Keyguard. |
| 2120 | */ |
Selim Cinek | 5f71bee | 2015-11-18 10:25:23 -0800 | [diff] [blame] | 2121 | protected abstract int getMaxKeyguardNotifications(boolean recompute); |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 2122 | |
| 2123 | /** |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 2124 | * Updates expanded, dimmed and locked states of notification rows. |
| 2125 | */ |
| 2126 | protected void updateRowStates() { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 2127 | final int N = mStackScroller.getChildCount(); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 2128 | |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2129 | int visibleNotifications = 0; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 2130 | boolean onKeyguard = mState == StatusBarState.KEYGUARD; |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2131 | int maxNotifications = -1; |
Selim Cinek | 5f71bee | 2015-11-18 10:25:23 -0800 | [diff] [blame] | 2132 | if (onKeyguard) { |
| 2133 | maxNotifications = getMaxKeyguardNotifications(true /* recompute */); |
| 2134 | } |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2135 | mStackScroller.setMaxDisplayedNotifications(maxNotifications); |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 2136 | Stack<ExpandableNotificationRow> stack = new Stack<>(); |
| 2137 | for (int i = N - 1; i >= 0; i--) { |
| 2138 | View child = mStackScroller.getChildAt(i); |
| 2139 | if (!(child instanceof ExpandableNotificationRow)) { |
| 2140 | continue; |
| 2141 | } |
| 2142 | stack.push((ExpandableNotificationRow) child); |
| 2143 | } |
| 2144 | while(!stack.isEmpty()) { |
| 2145 | ExpandableNotificationRow row = stack.pop(); |
| 2146 | NotificationData.Entry entry = row.getEntry(); |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 2147 | boolean childNotification = mGroupManager.isChildInGroupWithSummary(entry.notification); |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 2148 | if (onKeyguard) { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 2149 | row.setOnKeyguard(true); |
Chris Wren | 3ddab0d | 2012-08-02 16:52:21 -0400 | [diff] [blame] | 2150 | } else { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 2151 | row.setOnKeyguard(false); |
| 2152 | row.setSystemExpanded(visibleNotifications == 0 && !childNotification); |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 2153 | } |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 2154 | entry.row.setShowAmbient(isDozing()); |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 2155 | int userId = entry.notification.getUserId(); |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 2156 | boolean suppressedSummary = mGroupManager.isSummaryOfSuppressedGroup( |
| 2157 | entry.notification) && !entry.row.isRemoved(); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2158 | boolean showOnKeyguard = shouldShowOnKeyguard(entry.notification); |
Robin Lee | 92b83c6 | 2016-08-31 13:27:51 +0100 | [diff] [blame] | 2159 | if (suppressedSummary |
| 2160 | || (isLockscreenPublicMode(userId) && !mShowLockscreenNotifications) |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 2161 | || (onKeyguard && !showOnKeyguard)) { |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2162 | entry.row.setVisibility(View.GONE); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2163 | } else { |
| 2164 | boolean wasGone = entry.row.getVisibility() == View.GONE; |
Selim Cinek | 01ee2cd5 | 2016-12-21 18:23:11 +0100 | [diff] [blame] | 2165 | if (wasGone) { |
| 2166 | entry.row.setVisibility(View.VISIBLE); |
| 2167 | } |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 2168 | if (!childNotification && !entry.row.isRemoved()) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2169 | if (wasGone) { |
| 2170 | // notify the scroller of a child addition |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 2171 | mStackScroller.generateAddAnimation(entry.row, |
| 2172 | !showOnKeyguard /* fromMoreCard */); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2173 | } |
| 2174 | visibleNotifications++; |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2175 | } |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2176 | } |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 2177 | if (row.isSummaryWithChildren()) { |
| 2178 | List<ExpandableNotificationRow> notificationChildren = |
| 2179 | row.getNotificationChildren(); |
| 2180 | int size = notificationChildren.size(); |
| 2181 | for (int i = size - 1; i >= 0; i--) { |
| 2182 | stack.push(notificationChildren.get(i)); |
| 2183 | } |
| 2184 | } |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 2185 | } |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2186 | |
Selim Cinek | 0cce531 | 2015-05-20 22:13:55 -0700 | [diff] [blame] | 2187 | mStackScroller.changeViewPosition(mDismissView, mStackScroller.getChildCount() - 1); |
| 2188 | mStackScroller.changeViewPosition(mEmptyShadeView, mStackScroller.getChildCount() - 2); |
Selim Cinek | 25b5291 | 2016-11-02 16:12:56 -0700 | [diff] [blame] | 2189 | mStackScroller.changeViewPosition(mNotificationShelf, mStackScroller.getChildCount() - 3); |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 2192 | public boolean isDozing() { |
| 2193 | return false; |
| 2194 | } |
| 2195 | |
Selim Cinek | fa760d4 | 2016-05-10 15:50:53 -0400 | [diff] [blame] | 2196 | public boolean shouldShowOnKeyguard(StatusBarNotification sbn) { |
Jorim Jaggi | f641174 | 2014-08-05 17:10:43 +0000 | [diff] [blame] | 2197 | return mShowLockscreenNotifications && !mNotificationData.isAmbient(sbn.getKey()); |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 2198 | } |
| 2199 | |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 2200 | protected void setZenMode(int mode) { |
John Spurlock | 110e5b1 | 2014-02-27 13:09:35 -0500 | [diff] [blame] | 2201 | if (!isDeviceProvisioned()) return; |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 2202 | mZenMode = mode; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 2203 | updateNotifications(); |
John Spurlock | e677d71 | 2014-02-13 12:52:19 -0500 | [diff] [blame] | 2204 | } |
| 2205 | |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 2206 | // extended in PhoneStatusBar |
| 2207 | protected void setShowLockscreenNotifications(boolean show) { |
| 2208 | mShowLockscreenNotifications = show; |
| 2209 | } |
| 2210 | |
Adrian Roos | 3aec638 | 2016-02-05 14:19:01 -0800 | [diff] [blame] | 2211 | protected void setLockScreenAllowRemoteInput(boolean allowLockscreenRemoteInput) { |
| 2212 | mAllowLockscreenRemoteInput = allowLockscreenRemoteInput; |
| 2213 | } |
| 2214 | |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 2215 | private void updateLockscreenNotificationSetting() { |
| 2216 | final boolean show = Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 2217 | Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, |
| 2218 | 1, |
| 2219 | mCurrentUserId) != 0; |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 2220 | final int dpmFlags = mDevicePolicyManager.getKeyguardDisabledFeatures( |
| 2221 | null /* admin */, mCurrentUserId); |
| 2222 | final boolean allowedByDpm = (dpmFlags |
| 2223 | & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) == 0; |
Adrian Roos | 3aec638 | 2016-02-05 14:19:01 -0800 | [diff] [blame] | 2224 | |
Adrian Roos | bd3409c | 2014-08-12 18:21:09 +0200 | [diff] [blame] | 2225 | setShowLockscreenNotifications(show && allowedByDpm); |
Adrian Roos | b27d7a5 | 2016-06-16 13:04:47 -0700 | [diff] [blame] | 2226 | |
| 2227 | if (ENABLE_LOCK_SCREEN_ALLOW_REMOTE_INPUT) { |
| 2228 | final boolean remoteInput = Settings.Secure.getIntForUser(mContext.getContentResolver(), |
| 2229 | Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT, |
| 2230 | 0, |
| 2231 | mCurrentUserId) != 0; |
| 2232 | final boolean remoteInputDpm = |
| 2233 | (dpmFlags & DevicePolicyManager.KEYGUARD_DISABLE_REMOTE_INPUT) == 0; |
| 2234 | |
| 2235 | setLockScreenAllowRemoteInput(remoteInput && remoteInputDpm); |
| 2236 | } else { |
| 2237 | setLockScreenAllowRemoteInput(false); |
| 2238 | } |
Dan Sandler | 52e5701e | 2014-07-22 23:14:54 -0400 | [diff] [blame] | 2239 | } |
| 2240 | |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2241 | protected abstract void setAreThereNotifications(); |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 2242 | protected abstract void updateNotifications(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2243 | |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 2244 | public abstract void addNotification(StatusBarNotification notification, |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 2245 | RankingMap ranking, Entry oldEntry); |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 2246 | protected abstract void updateNotificationRanking(RankingMap ranking); |
| 2247 | public abstract void removeNotification(String key, RankingMap ranking); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 2248 | |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 2249 | public void updateNotification(StatusBarNotification notification, RankingMap ranking) { |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 2250 | if (DEBUG) Log.d(TAG, "updateNotification(" + notification + ")"); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2251 | |
Chris Wren | d04f6ce | 2014-06-11 17:37:28 -0400 | [diff] [blame] | 2252 | final String key = notification.getKey(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2253 | Entry entry = mNotificationData.get(key); |
| 2254 | if (entry == null) { |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2255 | return; |
Adrian Roos | 18d099a | 2016-05-19 15:28:18 -0700 | [diff] [blame] | 2256 | } else { |
Selim Cinek | 2d79f63 | 2015-11-02 15:13:29 -0800 | [diff] [blame] | 2257 | mHeadsUpEntriesToRemoveOnSwitch.remove(entry); |
Adrian Roos | 18d099a | 2016-05-19 15:28:18 -0700 | [diff] [blame] | 2258 | mRemoteInputEntriesToRemoveOnCollapse.remove(entry); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2259 | } |
| 2260 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2261 | Notification n = notification.getNotification(); |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 2262 | mNotificationData.updateRanking(ranking); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2263 | |
Adrian Roos | 95f8bea | 2016-07-27 15:49:03 -0700 | [diff] [blame] | 2264 | boolean applyInPlace; |
| 2265 | try { |
| 2266 | applyInPlace = entry.cacheContentViews(mContext, notification.getNotification()); |
| 2267 | } catch (RuntimeException e) { |
| 2268 | Log.e(TAG, "Unable to get notification remote views", e); |
| 2269 | applyInPlace = false; |
| 2270 | } |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 2271 | boolean shouldPeek = shouldPeek(entry, notification); |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 2272 | boolean alertAgain = alertAgain(entry, n); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2273 | if (DEBUG) { |
| 2274 | Log.d(TAG, "applyInPlace=" + applyInPlace |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 2275 | + " shouldPeek=" + shouldPeek |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2276 | + " alertAgain=" + alertAgain); |
| 2277 | } |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2278 | |
Dan Sandler | 24813b0 | 2016-01-14 15:49:36 -0500 | [diff] [blame] | 2279 | final StatusBarNotification oldNotification = entry.notification; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2280 | entry.notification = notification; |
Dan Sandler | 24813b0 | 2016-01-14 15:49:36 -0500 | [diff] [blame] | 2281 | mGroupManager.onEntryUpdated(entry, oldNotification); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2282 | |
| 2283 | boolean updateSuccessful = false; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2284 | try { |
| 2285 | if (applyInPlace) { |
| 2286 | if (DEBUG) Log.d(TAG, "reusing notification for key: " + key); |
| 2287 | try { |
| 2288 | entry.updateIcons(mContext, n); |
| 2289 | updateNotificationViews(entry, notification); |
| 2290 | updateSuccessful = true; |
| 2291 | } catch (RuntimeException e) { |
| 2292 | // It failed to apply cleanly. |
| 2293 | Log.w(TAG, "Couldn't reapply views for package " + |
| 2294 | notification.getPackageName(), e); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2295 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2296 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2297 | if (!updateSuccessful) { |
| 2298 | entry.updateIcons(mContext, n); |
| 2299 | if (!inflateViews(entry, mStackScroller)) { |
| 2300 | handleNotificationError(notification, "Couldn't update remote views for: " |
| 2301 | + notification); |
| 2302 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2303 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 2304 | } catch (NotificationData.IconException e) { |
| 2305 | handleNotificationError(notification, e.getMessage()); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2306 | } |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 2307 | updateHeadsUp(key, entry, shouldPeek, alertAgain); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2308 | updateNotifications(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2309 | |
dongwan0605.kim | 30637e4 | 2016-03-02 17:16:47 +0900 | [diff] [blame] | 2310 | if (!notification.isClearable()) { |
| 2311 | // The user may have performed a dismiss action on the notification, since it's |
| 2312 | // not clearable we should snap it back. |
| 2313 | mStackScroller.snapViewIfNeeded(entry.row); |
| 2314 | } |
| 2315 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 2316 | if (DEBUG) { |
| 2317 | // Is this for you? |
| 2318 | boolean isForCurrentUser = isNotificationForCurrentProfiles(notification); |
| 2319 | Log.d(TAG, "notification is " + (isForCurrentUser ? "" : "not ") + "for you"); |
| 2320 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2321 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2322 | setAreThereNotifications(); |
| 2323 | } |
| 2324 | |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 2325 | protected abstract void updateHeadsUp(String key, Entry entry, boolean shouldPeek, |
Selim Cinek | 29fa89b | 2015-04-17 10:39:11 -0700 | [diff] [blame] | 2326 | boolean alertAgain); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2327 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2328 | private void updateNotificationViews(Entry entry, StatusBarNotification sbn) { |
| 2329 | final RemoteViews contentView = entry.cachedContentView; |
| 2330 | final RemoteViews bigContentView = entry.cachedBigContentView; |
| 2331 | final RemoteViews headsUpContentView = entry.cachedHeadsUpContentView; |
| 2332 | final RemoteViews publicContentView = entry.cachedPublicContentView; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 2333 | |
Chris Wren | e03f4e1 | 2013-08-08 16:48:48 -0400 | [diff] [blame] | 2334 | // Reapply the RemoteViews |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 2335 | contentView.reapply(mContext, entry.getContentView(), mOnClickHandler); |
| 2336 | if (bigContentView != null && entry.getExpandedContentView() != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2337 | bigContentView.reapply(sbn.getPackageContext(mContext), |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 2338 | entry.getExpandedContentView(), |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2339 | mOnClickHandler); |
Chris Wren | e03f4e1 | 2013-08-08 16:48:48 -0400 | [diff] [blame] | 2340 | } |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 2341 | View headsUpChild = entry.getHeadsUpContentView(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 2342 | if (headsUpContentView != null && headsUpChild != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2343 | headsUpContentView.reapply(sbn.getPackageContext(mContext), |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 2344 | headsUpChild, mOnClickHandler); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 2345 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 2346 | if (publicContentView != null && entry.getPublicContentView() != null) { |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2347 | publicContentView.reapply(sbn.getPackageContext(mContext), |
Dan Sandler | 68079d5 | 2015-07-22 10:45:30 -0400 | [diff] [blame] | 2348 | entry.getPublicContentView(), mOnClickHandler); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 2349 | } |
Chris Wren | e03f4e1 | 2013-08-08 16:48:48 -0400 | [diff] [blame] | 2350 | // update the contentIntent |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 2351 | mNotificationClicker.register(entry.row, sbn); |
Chris Wren | 42d5dd4 | 2015-05-01 10:39:26 -0400 | [diff] [blame] | 2352 | |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 2353 | entry.row.onNotificationUpdated(entry); |
Selim Cinek | 51ae05d | 2014-09-09 15:51:38 +0200 | [diff] [blame] | 2354 | entry.row.resetHeight(); |
Chris Wren | 0c8275b | 2012-05-08 13:36:48 -0400 | [diff] [blame] | 2355 | } |
John Spurlock | 3623128 | 2012-06-23 17:11:27 -0400 | [diff] [blame] | 2356 | |
Sudheer Shanka | f5b850e | 2016-01-25 19:58:59 +0000 | [diff] [blame] | 2357 | protected void updatePublicContentView(Entry entry, |
| 2358 | StatusBarNotification sbn) { |
| 2359 | final RemoteViews publicContentView = entry.cachedPublicContentView; |
Selim Cinek | e4c068d | 2016-02-19 13:46:55 -0800 | [diff] [blame] | 2360 | View inflatedView = entry.getPublicContentView(); |
| 2361 | if (entry.autoRedacted && publicContentView != null && inflatedView != null) { |
Sudheer Shanka | f5b850e | 2016-01-25 19:58:59 +0000 | [diff] [blame] | 2362 | final boolean disabledByPolicy = |
| 2363 | !adminAllowsUnredactedNotifications(entry.notification.getUserId()); |
Selim Cinek | e4c068d | 2016-02-19 13:46:55 -0800 | [diff] [blame] | 2364 | String notificationHiddenText = mContext.getString(disabledByPolicy |
| 2365 | ? com.android.internal.R.string.notification_hidden_by_policy_text |
| 2366 | : com.android.internal.R.string.notification_hidden_text); |
| 2367 | TextView titleView = (TextView) inflatedView.findViewById(android.R.id.title); |
| 2368 | if (titleView != null |
| 2369 | && !titleView.getText().toString().equals(notificationHiddenText)) { |
| 2370 | publicContentView.setTextViewText(android.R.id.title, notificationHiddenText); |
| 2371 | publicContentView.reapply(sbn.getPackageContext(mContext), |
| 2372 | inflatedView, mOnClickHandler); |
| 2373 | entry.row.onNotificationUpdated(entry); |
| 2374 | } |
Sudheer Shanka | f5b850e | 2016-01-25 19:58:59 +0000 | [diff] [blame] | 2375 | } |
| 2376 | } |
| 2377 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 2378 | protected void notifyHeadsUpScreenOff() { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 2379 | maybeEscalateHeadsUp(); |
Chris Wren | e97f90b | 2013-08-07 17:39:35 -0400 | [diff] [blame] | 2380 | } |
| 2381 | |
Chris Wren | d93d5ad | 2014-09-08 16:34:03 -0400 | [diff] [blame] | 2382 | private boolean alertAgain(Entry oldEntry, Notification newNotification) { |
| 2383 | return oldEntry == null || !oldEntry.hasInterrupted() |
| 2384 | || (newNotification.flags & Notification.FLAG_ONLY_ALERT_ONCE) == 0; |
Chris Wren | d04f6ce | 2014-06-11 17:37:28 -0400 | [diff] [blame] | 2385 | } |
| 2386 | |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 2387 | protected boolean shouldPeek(Entry entry) { |
| 2388 | return shouldPeek(entry, entry.notification); |
Chris Wren | 0c274b1 | 2015-07-17 10:34:53 -0400 | [diff] [blame] | 2389 | } |
| 2390 | |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 2391 | protected boolean shouldPeek(Entry entry, StatusBarNotification sbn) { |
Adrian Roos | f6967e06 | 2016-06-21 16:12:48 -0700 | [diff] [blame] | 2392 | if (!mUseHeadsUp || isDeviceInVrMode()) { |
Dan Sandler | dc34df5 | 2016-04-07 21:04:46 -0400 | [diff] [blame] | 2393 | return false; |
| 2394 | } |
| 2395 | |
Christoph Studer | 2f9dbba | 2014-09-03 17:35:54 +0200 | [diff] [blame] | 2396 | if (mNotificationData.shouldFilterOut(sbn)) { |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 2397 | if (DEBUG) Log.d(TAG, "No peeking: filtered notification: " + sbn.getKey()); |
Christoph Studer | 2f9dbba | 2014-09-03 17:35:54 +0200 | [diff] [blame] | 2398 | return false; |
| 2399 | } |
| 2400 | |
Selim Cinek | 01ee2cd5 | 2016-12-21 18:23:11 +0100 | [diff] [blame] | 2401 | boolean inUse = mPowerManager.isScreenOn(); |
Selim Cinek | d592191 | 2016-02-09 10:33:01 -0800 | [diff] [blame] | 2402 | try { |
| 2403 | inUse = inUse && !mDreamManager.isDreaming(); |
| 2404 | } catch (RemoteException e) { |
| 2405 | Log.d(TAG, "failed to query dream manager", e); |
| 2406 | } |
| 2407 | |
Adrian Roos | 4b820e4 | 2017-01-13 17:40:43 -0800 | [diff] [blame] | 2408 | if (!inUse && !isDozing()) { |
Selim Cinek | d592191 | 2016-02-09 10:33:01 -0800 | [diff] [blame] | 2409 | if (DEBUG) { |
| 2410 | Log.d(TAG, "No peeking: not in use: " + sbn.getKey()); |
| 2411 | } |
| 2412 | return false; |
| 2413 | } |
| 2414 | |
| 2415 | if (mNotificationData.shouldSuppressScreenOn(sbn.getKey())) { |
| 2416 | if (DEBUG) Log.d(TAG, "No peeking: suppressed by DND: " + sbn.getKey()); |
Chris Wren | a6d4fb6 | 2014-11-20 14:46:23 -0500 | [diff] [blame] | 2417 | return false; |
| 2418 | } |
| 2419 | |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 2420 | if (entry.hasJustLaunchedFullScreenIntent()) { |
| 2421 | if (DEBUG) Log.d(TAG, "No peeking: recent fullscreen: " + sbn.getKey()); |
| 2422 | return false; |
| 2423 | } |
| 2424 | |
Julia Reynolds | f0f629f | 2016-02-25 09:34:04 -0500 | [diff] [blame] | 2425 | if (isSnoozedPackage(sbn)) { |
| 2426 | if (DEBUG) Log.d(TAG, "No peeking: snoozed package: " + sbn.getKey()); |
| 2427 | return false; |
| 2428 | } |
| 2429 | |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 2430 | if (mNotificationData.getImportance(sbn.getKey()) < NotificationManager.IMPORTANCE_HIGH) { |
Julia Reynolds | f0f629f | 2016-02-25 09:34:04 -0500 | [diff] [blame] | 2431 | if (DEBUG) Log.d(TAG, "No peeking: unimportant notification: " + sbn.getKey()); |
| 2432 | return false; |
| 2433 | } |
| 2434 | |
Selim Cinek | d592191 | 2016-02-09 10:33:01 -0800 | [diff] [blame] | 2435 | if (sbn.getNotification().fullScreenIntent != null) { |
| 2436 | if (mAccessibilityManager.isTouchExplorationEnabled()) { |
| 2437 | if (DEBUG) Log.d(TAG, "No peeking: accessible fullscreen: " + sbn.getKey()); |
| 2438 | return false; |
| 2439 | } else { |
Selim Cinek | 01ee2cd5 | 2016-12-21 18:23:11 +0100 | [diff] [blame] | 2440 | // we only allow head-up on the lockscreen if it doesn't have a fullscreen intent |
| 2441 | return !mStatusBarKeyguardViewManager.isShowing() |
| 2442 | || mStatusBarKeyguardViewManager.isOccluded(); |
Selim Cinek | d592191 | 2016-02-09 10:33:01 -0800 | [diff] [blame] | 2443 | } |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 2444 | } |
| 2445 | |
Selim Cinek | d592191 | 2016-02-09 10:33:01 -0800 | [diff] [blame] | 2446 | return true; |
Chris Wren | 157026f | 2013-06-28 16:54:01 -0400 | [diff] [blame] | 2447 | } |
| 2448 | |
Selim Cinek | 29fa89b | 2015-04-17 10:39:11 -0700 | [diff] [blame] | 2449 | protected abstract boolean isSnoozedPackage(StatusBarNotification sbn); |
| 2450 | |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 2451 | public void setInteracting(int barWindow, boolean interacting) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2452 | // hook for subclasses |
| 2453 | } |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 2454 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 2455 | public void setBouncerShowing(boolean bouncerShowing) { |
| 2456 | mBouncerShowing = bouncerShowing; |
| 2457 | } |
| 2458 | |
| 2459 | /** |
| 2460 | * @return Whether the security bouncer from Keyguard is showing. |
| 2461 | */ |
| 2462 | public boolean isBouncerShowing() { |
| 2463 | return mBouncerShowing; |
| 2464 | } |
| 2465 | |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 2466 | public void destroy() { |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 2467 | mContext.unregisterReceiver(mBroadcastReceiver); |
Christoph Studer | e71fefc | 2014-06-24 16:16:49 +0200 | [diff] [blame] | 2468 | try { |
| 2469 | mNotificationListener.unregisterAsSystemService(); |
| 2470 | } catch (RemoteException e) { |
| 2471 | // Ignore. |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 2472 | } |
John Spurlock | 5c45412 | 2013-06-17 07:35:46 -0400 | [diff] [blame] | 2473 | } |
Kenny Guy | 4dcb0dc | 2014-07-15 12:41:24 +0100 | [diff] [blame] | 2474 | |
| 2475 | /** |
| 2476 | * @return a PackageManger for userId or if userId is < 0 (USER_ALL etc) then |
| 2477 | * return PackageManager for mContext |
| 2478 | */ |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 2479 | public static PackageManager getPackageManagerForUser(Context context, int userId) { |
| 2480 | Context contextForUser = context; |
Kenny Guy | 4dcb0dc | 2014-07-15 12:41:24 +0100 | [diff] [blame] | 2481 | // UserHandle defines special userId as negative values, e.g. USER_ALL |
| 2482 | if (userId >= 0) { |
| 2483 | try { |
| 2484 | // Create a context for the correct user so if a package isn't installed |
| 2485 | // for user 0 we can still load information about the package. |
| 2486 | contextForUser = |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 2487 | context.createPackageContextAsUser(context.getPackageName(), |
Kenny Guy | 4dcb0dc | 2014-07-15 12:41:24 +0100 | [diff] [blame] | 2488 | Context.CONTEXT_RESTRICTED, |
| 2489 | new UserHandle(userId)); |
| 2490 | } catch (NameNotFoundException e) { |
| 2491 | // Shouldn't fail to find the package name for system ui. |
| 2492 | } |
| 2493 | } |
| 2494 | return contextForUser.getPackageManager(); |
| 2495 | } |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 2496 | |
| 2497 | @Override |
| 2498 | public void logNotificationExpansion(String key, boolean userAction, boolean expanded) { |
| 2499 | try { |
| 2500 | mBarService.onNotificationExpansionChanged(key, userAction, expanded); |
| 2501 | } catch (RemoteException e) { |
| 2502 | // Ignore. |
| 2503 | } |
| 2504 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2505 | |
| 2506 | public boolean isKeyguardSecure() { |
Dan Sandler | e163a64 | 2015-03-01 22:58:32 -0500 | [diff] [blame] | 2507 | if (mStatusBarKeyguardViewManager == null) { |
| 2508 | // startKeyguard() hasn't been called yet, so we don't know. |
| 2509 | // Make sure anything that needs to know isKeyguardSecure() checks and re-checks this |
| 2510 | // value onVisibilityChanged(). |
| 2511 | Slog.w(TAG, "isKeyguardSecure() called before startKeyguard(), returning false", |
| 2512 | new Throwable()); |
| 2513 | return false; |
| 2514 | } |
Jim Miller | ab95454 | 2014-10-10 18:21:49 -0700 | [diff] [blame] | 2515 | return mStatusBarKeyguardViewManager.isSecure(); |
| 2516 | } |
Adrian Roos | 4f43dc0 | 2015-06-17 16:43:38 -0700 | [diff] [blame] | 2517 | |
| 2518 | @Override |
| 2519 | public void showAssistDisclosure() { |
| 2520 | if (mAssistManager != null) { |
| 2521 | mAssistManager.showDisclosure(); |
| 2522 | } |
| 2523 | } |
Jorim Jaggi | 165ce06 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 2524 | |
| 2525 | @Override |
| 2526 | public void startAssist(Bundle args) { |
| 2527 | if (mAssistManager != null) { |
| 2528 | mAssistManager.startAssist(args); |
| 2529 | } |
| 2530 | } |
Joe Onorato | 2314aab | 2010-04-08 16:41:23 -0500 | [diff] [blame] | 2531 | } |