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