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