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