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