Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
| 17 | package com.android.systemui.bubbles; |
| 18 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 19 | import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS; |
| 20 | import static android.util.StatsLogInternal.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_MISSING; |
| 21 | import static android.util.StatsLogInternal.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_NOT_RESIZABLE; |
| 22 | import static android.util.StatsLogInternal.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__DOCUMENT_LAUNCH_NOT_ALWAYS; |
| 23 | |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 24 | import android.animation.LayoutTransition; |
| 25 | import android.animation.ObjectAnimator; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 27 | import android.app.ActivityView; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 28 | import android.app.INotificationManager; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 29 | import android.app.Notification; |
| 30 | import android.app.PendingIntent; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 31 | import android.content.Context; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 32 | import android.content.Intent; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 33 | import android.content.pm.ActivityInfo; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
| 35 | import android.content.pm.PackageManager; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 36 | import android.content.res.Resources; |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 37 | import android.content.res.TypedArray; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 38 | import android.graphics.Color; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 39 | import android.graphics.Insets; |
| 40 | import android.graphics.Point; |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 41 | import android.graphics.drawable.AdaptiveIconDrawable; |
| 42 | import android.graphics.drawable.ColorDrawable; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 43 | import android.graphics.drawable.Drawable; |
Mady Mellor | 310c7c6 | 2019-02-21 17:03:08 -0800 | [diff] [blame] | 44 | import android.graphics.drawable.GradientDrawable; |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 45 | import android.graphics.drawable.InsetDrawable; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 46 | import android.graphics.drawable.ShapeDrawable; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 47 | import android.os.RemoteException; |
| 48 | import android.os.ServiceManager; |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame] | 49 | import android.os.UserHandle; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 50 | import android.provider.Settings; |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 51 | import android.service.notification.StatusBarNotification; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 52 | import android.util.AttributeSet; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 53 | import android.util.Log; |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 54 | import android.util.StatsLog; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 55 | import android.view.View; |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 56 | import android.view.ViewGroup; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 57 | import android.view.WindowInsets; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 58 | import android.widget.FrameLayout; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 59 | import android.widget.ImageView; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 60 | import android.widget.LinearLayout; |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 61 | import android.widget.TextView; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 62 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 63 | import com.android.systemui.Dependency; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 64 | import com.android.systemui.Interpolators; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 65 | import com.android.systemui.R; |
| 66 | import com.android.systemui.recents.TriangleShape; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 67 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 68 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 69 | import com.android.systemui.statusbar.notification.stack.ExpandableViewState; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Container for the expanded bubble view, handles rendering the caret and header of the view. |
| 73 | */ |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 74 | public class BubbleExpandedView extends LinearLayout implements View.OnClickListener { |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 75 | private static final String TAG = "BubbleExpandedView"; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 76 | |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 77 | // Configurable via bubble settings; just for testing |
| 78 | private boolean mUseFooter; |
| 79 | private boolean mShowOnTop; |
| 80 | |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 81 | // The triangle pointing to the expanded view |
| 82 | private View mPointerView; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 83 | private int mPointerMargin; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 84 | |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 85 | private ImageView mSettingsIcon; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 86 | |
| 87 | // Permission view |
| 88 | private View mPermissionView; |
| 89 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 90 | // Views for expanded state |
| 91 | private ExpandableNotificationRow mNotifRow; |
| 92 | private ActivityView mActivityView; |
| 93 | |
| 94 | private boolean mActivityViewReady = false; |
| 95 | private PendingIntent mBubbleIntent; |
| 96 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 97 | private boolean mKeyboardVisible; |
| 98 | private boolean mNeedsNewHeight; |
| 99 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 100 | private int mMinHeight; |
| 101 | private int mHeaderHeight; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 102 | private int mBubbleHeight; |
| 103 | private int mPermissionHeight; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 104 | |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 105 | private NotificationEntry mEntry; |
| 106 | private PackageManager mPm; |
| 107 | private String mAppName; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 108 | private Drawable mAppIcon; |
| 109 | |
| 110 | private INotificationManager mNotificationManagerService; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 111 | private BubbleController mBubbleController = Dependency.get(BubbleController.class); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 112 | |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 113 | private BubbleStackView mStackView; |
| 114 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 115 | private BubbleExpandedView.OnBubbleBlockedListener mOnBubbleBlockedListener; |
| 116 | |
| 117 | private ActivityView.StateCallback mStateCallback = new ActivityView.StateCallback() { |
| 118 | @Override |
| 119 | public void onActivityViewReady(ActivityView view) { |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 120 | if (!mActivityViewReady) { |
| 121 | mActivityViewReady = true; |
| 122 | mActivityView.startActivity(mBubbleIntent); |
| 123 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public void onActivityViewDestroyed(ActivityView view) { |
| 128 | mActivityViewReady = false; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * This is only called for tasks on this ActivityView, which is also set to |
| 133 | * single-task mode -- meaning never more than one task on this display. If a task |
| 134 | * is being removed, it's the top Activity finishing and this bubble should |
| 135 | * be removed or collapsed. |
| 136 | */ |
| 137 | @Override |
| 138 | public void onTaskRemovalStarted(int taskId) { |
| 139 | if (mEntry != null) { |
| 140 | // Must post because this is called from a binder thread. |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 141 | post(() -> mBubbleController.removeBubble(mEntry.key, |
| 142 | BubbleController.DISMISS_TASK_FINISHED)); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | }; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 146 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 147 | public BubbleExpandedView(Context context) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 148 | this(context, null); |
| 149 | } |
| 150 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 151 | public BubbleExpandedView(Context context, AttributeSet attrs) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 152 | this(context, attrs, 0); |
| 153 | } |
| 154 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 155 | public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 156 | this(context, attrs, defStyleAttr, 0); |
| 157 | } |
| 158 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 159 | public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr, |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 160 | int defStyleRes) { |
| 161 | super(context, attrs, defStyleAttr, defStyleRes); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 162 | mPm = context.getPackageManager(); |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 163 | mMinHeight = getResources().getDimensionPixelSize( |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 164 | R.dimen.bubble_expanded_default_height); |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 165 | mPointerMargin = getResources().getDimensionPixelSize(R.dimen.bubble_pointer_margin); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 166 | try { |
| 167 | mNotificationManagerService = INotificationManager.Stub.asInterface( |
| 168 | ServiceManager.getServiceOrThrow(Context.NOTIFICATION_SERVICE)); |
| 169 | } catch (ServiceManager.ServiceNotFoundException e) { |
| 170 | Log.w(TAG, e); |
| 171 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | @Override |
| 175 | protected void onFinishInflate() { |
| 176 | super.onFinishInflate(); |
| 177 | |
| 178 | Resources res = getResources(); |
| 179 | mPointerView = findViewById(R.id.pointer_view); |
| 180 | int width = res.getDimensionPixelSize(R.dimen.bubble_pointer_width); |
| 181 | int height = res.getDimensionPixelSize(R.dimen.bubble_pointer_height); |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 182 | |
| 183 | TypedArray ta = getContext().obtainStyledAttributes( |
| 184 | new int[] {android.R.attr.colorBackgroundFloating}); |
| 185 | int bgColor = ta.getColor(0, Color.WHITE); |
| 186 | ta.recycle(); |
| 187 | |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 188 | mShowOnTop = BubbleController.showBubblesAtTop(getContext()); |
| 189 | mUseFooter = BubbleController.useFooter(getContext()); |
| 190 | |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 191 | ShapeDrawable triangleDrawable = new ShapeDrawable( |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 192 | TriangleShape.create(width, height, mShowOnTop /* pointUp */)); |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 193 | triangleDrawable.setTint(bgColor); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 194 | mPointerView.setBackground(triangleDrawable); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 195 | |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 196 | FrameLayout viewWrapper = findViewById(R.id.header_permission_wrapper); |
Mady Mellor | 310c7c6 | 2019-02-21 17:03:08 -0800 | [diff] [blame] | 197 | |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 198 | LayoutTransition transition = new LayoutTransition(); |
| 199 | transition.setDuration(200); |
| 200 | |
| 201 | ObjectAnimator appearAnimator = ObjectAnimator.ofFloat(null, View.ALPHA, 0f, 1f); |
| 202 | transition.setAnimator(LayoutTransition.APPEARING, appearAnimator); |
| 203 | transition.setInterpolator(LayoutTransition.APPEARING, Interpolators.ALPHA_IN); |
| 204 | |
| 205 | ObjectAnimator disappearAnimator = ObjectAnimator.ofFloat(null, View.ALPHA, 1f, 0f); |
| 206 | transition.setAnimator(LayoutTransition.DISAPPEARING, disappearAnimator); |
| 207 | transition.setInterpolator(LayoutTransition.DISAPPEARING, Interpolators.ALPHA_OUT); |
| 208 | |
| 209 | transition.setAnimateParentHierarchy(false); |
| 210 | viewWrapper.setLayoutTransition(transition); |
| 211 | viewWrapper.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING); |
| 212 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 213 | mHeaderHeight = getContext().getResources().getDimensionPixelSize( |
| 214 | R.dimen.bubble_expanded_header_height); |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 215 | mPermissionHeight = getContext().getResources().getDimensionPixelSize( |
| 216 | R.dimen.bubble_permission_height); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 217 | |
| 218 | mPermissionView = findViewById(R.id.permission_layout); |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 219 | mSettingsIcon = findViewById(R.id.settings_button); |
| 220 | mSettingsIcon.setOnClickListener(this); |
| 221 | updateHeaderColor(); |
| 222 | |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 223 | findViewById(R.id.no_bubbles_button).setOnClickListener(this); |
| 224 | findViewById(R.id.yes_bubbles_button).setOnClickListener(this); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 225 | |
| 226 | mActivityView = new ActivityView(mContext, null /* attrs */, 0 /* defStyle */, |
| 227 | true /* singleTaskInstance */); |
| 228 | addView(mActivityView); |
| 229 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 230 | setOnApplyWindowInsetsListener((View view, WindowInsets insets) -> { |
| 231 | // Keep track of IME displaying because we should not make any adjustments that might |
| 232 | // cause a config change while the IME is displayed otherwise it'll loose focus. |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 233 | final int keyboardHeight = insets.getSystemWindowInsetBottom() |
| 234 | - insets.getStableInsetBottom(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 235 | mKeyboardVisible = keyboardHeight != 0; |
| 236 | if (!mKeyboardVisible && mNeedsNewHeight) { |
| 237 | updateHeight(); |
| 238 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 239 | return view.onApplyWindowInsets(insets); |
| 240 | }); |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 241 | |
| 242 | if (!mShowOnTop) { |
| 243 | removeView(mPointerView); |
| 244 | if (mUseFooter) { |
Mady Mellor | 310c7c6 | 2019-02-21 17:03:08 -0800 | [diff] [blame] | 245 | View divider = findViewById(R.id.divider); |
| 246 | viewWrapper.removeView(divider); |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 247 | removeView(viewWrapper); |
Mady Mellor | 310c7c6 | 2019-02-21 17:03:08 -0800 | [diff] [blame] | 248 | addView(divider); |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 249 | addView(viewWrapper); |
| 250 | } |
| 251 | addView(mPointerView); |
| 252 | } |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 255 | @Override |
| 256 | protected void onDetachedFromWindow() { |
| 257 | super.onDetachedFromWindow(); |
| 258 | mKeyboardVisible = false; |
| 259 | mNeedsNewHeight = false; |
| 260 | if (mActivityView != null) { |
| 261 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, 0)); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Called by {@link BubbleStackView} when the insets for the expanded state should be updated. |
| 267 | * This should be done post-move and post-animation. |
| 268 | */ |
| 269 | void updateInsets(WindowInsets insets) { |
| 270 | if (usingActivityView()) { |
| 271 | Point displaySize = new Point(); |
| 272 | mActivityView.getContext().getDisplay().getSize(displaySize); |
| 273 | int[] windowLocation = mActivityView.getLocationOnScreen(); |
| 274 | final int windowBottom = windowLocation[1] + mActivityView.getHeight(); |
| 275 | final int keyboardHeight = insets.getSystemWindowInsetBottom() |
| 276 | - insets.getStableInsetBottom(); |
| 277 | final int insetsBottom = Math.max(0, |
| 278 | windowBottom + keyboardHeight - displaySize.y); |
| 279 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, insetsBottom)); |
| 280 | } |
| 281 | } |
| 282 | |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 283 | /** |
Mady Mellor | 310c7c6 | 2019-02-21 17:03:08 -0800 | [diff] [blame] | 284 | * Creates a background with corners rounded based on how the view is configured to display |
| 285 | */ |
| 286 | private Drawable createHeaderPermissionBackground(int bgColor) { |
| 287 | TypedArray ta2 = getContext().obtainStyledAttributes( |
| 288 | new int[] {android.R.attr.dialogCornerRadius}); |
| 289 | final float cr = ta2.getDimension(0, 0f); |
| 290 | ta2.recycle(); |
| 291 | |
| 292 | float[] radii = mUseFooter |
| 293 | ? new float[] {0, 0, 0, 0, cr, cr, cr, cr} |
| 294 | : new float[] {cr, cr, cr, cr, 0, 0, 0, 0}; |
| 295 | GradientDrawable chromeBackground = new GradientDrawable(); |
| 296 | chromeBackground.setShape(GradientDrawable.RECTANGLE); |
| 297 | chromeBackground.setCornerRadii(radii); |
| 298 | chromeBackground.setColor(bgColor); |
| 299 | return chromeBackground; |
| 300 | } |
| 301 | |
| 302 | /** |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 303 | * Sets the listener to notify when a bubble has been blocked. |
| 304 | */ |
| 305 | public void setOnBlockedListener(OnBubbleBlockedListener listener) { |
| 306 | mOnBubbleBlockedListener = listener; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Sets the notification entry used to populate this view. |
| 311 | */ |
| 312 | public void setEntry(NotificationEntry entry, BubbleStackView stackView) { |
| 313 | mStackView = stackView; |
| 314 | mEntry = entry; |
| 315 | |
| 316 | ApplicationInfo info; |
| 317 | try { |
| 318 | info = mPm.getApplicationInfo( |
| 319 | entry.notification.getPackageName(), |
| 320 | PackageManager.MATCH_UNINSTALLED_PACKAGES |
| 321 | | PackageManager.MATCH_DISABLED_COMPONENTS |
| 322 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
| 323 | | PackageManager.MATCH_DIRECT_BOOT_AWARE); |
| 324 | if (info != null) { |
| 325 | mAppName = String.valueOf(mPm.getApplicationLabel(info)); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 326 | mAppIcon = mPm.getApplicationIcon(info); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 327 | } |
| 328 | } catch (PackageManager.NameNotFoundException e) { |
| 329 | // Ahh... just use package name |
| 330 | mAppName = entry.notification.getPackageName(); |
| 331 | } |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 332 | if (mAppIcon == null) { |
| 333 | mAppIcon = mPm.getDefaultActivityIcon(); |
| 334 | } |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 335 | updateHeaderView(); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 336 | updatePermissionView(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 337 | updateExpandedView(); |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Lets activity view know it should be shown / populated. |
| 342 | */ |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 343 | public void populateExpandedView() { |
| 344 | if (usingActivityView()) { |
| 345 | mActivityView.setCallback(mStateCallback); |
| 346 | } else { |
| 347 | // We're using notification template |
| 348 | ViewGroup parent = (ViewGroup) mNotifRow.getParent(); |
| 349 | if (parent == this) { |
| 350 | // Already added |
| 351 | return; |
| 352 | } else if (parent != null) { |
| 353 | // Still in the shade... remove it |
| 354 | parent.removeView(mNotifRow); |
| 355 | } |
| 356 | if (mShowOnTop) { |
| 357 | addView(mNotifRow); |
| 358 | } else { |
| 359 | addView(mNotifRow, mUseFooter ? 0 : 1); |
| 360 | } |
| 361 | } |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 362 | } |
| 363 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 364 | /** |
| 365 | * Updates the entry backing this view. This will not re-populate ActivityView, it will |
| 366 | * only update the deep-links in the header, the title, and the height of the view. |
| 367 | */ |
| 368 | public void update(NotificationEntry entry) { |
| 369 | if (entry.key.equals(mEntry.key)) { |
| 370 | mEntry = entry; |
| 371 | updateHeaderView(); |
| 372 | updateHeight(); |
| 373 | } else { |
| 374 | Log.w(TAG, "Trying to update entry with different key, new entry: " |
| 375 | + entry.key + " old entry: " + mEntry.key); |
| 376 | } |
| 377 | } |
| 378 | |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 379 | /** |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 380 | * Update header color and icon shape when theme changes. |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 381 | */ |
| 382 | void updateHeaderColor() { |
Lyn Han | 76e803d | 2019-03-26 17:31:33 -0700 | [diff] [blame] | 383 | TypedArray ta = mContext.obtainStyledAttributes( |
| 384 | new int[] {android.R.attr.colorBackgroundFloating, android.R.attr.colorForeground}); |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 385 | int backgroundColor = ta.getColor(0, Color.WHITE /* default */); |
| 386 | int foregroundColor = ta.getColor(1, Color.BLACK /* default */); |
Lyn Han | 76e803d | 2019-03-26 17:31:33 -0700 | [diff] [blame] | 387 | ta.recycle(); |
| 388 | |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 389 | mPermissionView.setBackground(createHeaderPermissionBackground(backgroundColor)); |
| 390 | |
| 391 | Drawable settingsIcon = mSettingsIcon.getDrawable(); |
| 392 | settingsIcon.setTint(foregroundColor); |
| 393 | |
| 394 | int mIconInset = getResources().getDimensionPixelSize(R.dimen.bubble_icon_inset); |
| 395 | InsetDrawable foreground = new InsetDrawable(settingsIcon, mIconInset); |
| 396 | ColorDrawable background = new ColorDrawable(backgroundColor); |
| 397 | AdaptiveIconDrawable adaptiveIcon = new AdaptiveIconDrawable(background, |
| 398 | foreground); |
| 399 | mSettingsIcon.setImageDrawable(adaptiveIcon); |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 402 | private void updateHeaderView() { |
| 403 | mSettingsIcon.setContentDescription(getResources().getString( |
| 404 | R.string.bubbles_settings_button_description, mAppName)); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | private void updatePermissionView() { |
| 408 | boolean hasUserApprovedBubblesForPackage = false; |
| 409 | try { |
| 410 | hasUserApprovedBubblesForPackage = |
| 411 | mNotificationManagerService.hasUserApprovedBubblesForPackage( |
| 412 | mEntry.notification.getPackageName(), mEntry.notification.getUid()); |
| 413 | } catch (RemoteException e) { |
| 414 | Log.w(TAG, e); |
| 415 | } |
| 416 | if (hasUserApprovedBubblesForPackage) { |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 417 | showSettingsIcon(); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 418 | } else { |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 419 | showPermissionView(); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 420 | ((ImageView) mPermissionView.findViewById(R.id.pkgicon)).setImageDrawable(mAppIcon); |
| 421 | ((TextView) mPermissionView.findViewById(R.id.pkgname)).setText(mAppName); |
Mady Mellor | 81f734c | 2019-03-20 18:42:50 -0700 | [diff] [blame] | 422 | ((TextView) mPermissionView.findViewById(R.id.prompt)).setText( |
| 423 | getResources().getString(R.string.bubbles_prompt, mAppName)); |
Steven Wu | 45e38ae | 2019-03-25 16:16:59 -0400 | [diff] [blame] | 424 | logBubbleClickEvent(mEntry, |
Steven Wu | a62cb6a | 2019-02-15 17:12:51 -0500 | [diff] [blame] | 425 | StatsLog.BUBBLE_UICHANGED__ACTION__PERMISSION_DIALOG_SHOWN); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 429 | private void updateExpandedView() { |
| 430 | mBubbleIntent = getBubbleIntent(mEntry); |
| 431 | if (mBubbleIntent != null) { |
| 432 | if (mNotifRow != null) { |
| 433 | // Clear out the row if we had it previously |
| 434 | removeView(mNotifRow); |
| 435 | mNotifRow = null; |
| 436 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 437 | mActivityView.setVisibility(VISIBLE); |
| 438 | } else { |
| 439 | // Hide activity view if we had it previously |
| 440 | mActivityView.setVisibility(GONE); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 441 | mNotifRow = mEntry.getRow(); |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 442 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 443 | } |
| 444 | updateView(); |
| 445 | } |
| 446 | |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 447 | boolean performBackPressIfNeeded() { |
Mady Mellor | 323fb0b | 2019-03-25 12:15:22 -0700 | [diff] [blame] | 448 | if (!usingActivityView()) { |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 449 | return false; |
| 450 | } |
| 451 | mActivityView.performBackPress(); |
| 452 | return true; |
| 453 | } |
| 454 | |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 455 | /** |
| 456 | * @return total height that the expanded view occupies. |
| 457 | */ |
| 458 | int getExpandedSize() { |
| 459 | int chromeHeight = mPermissionView.getVisibility() != View.VISIBLE |
| 460 | ? mHeaderHeight |
| 461 | : mPermissionHeight; |
| 462 | return mBubbleHeight + mPointerView.getHeight() + mPointerMargin |
| 463 | + chromeHeight; |
| 464 | } |
| 465 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 466 | void updateHeight() { |
| 467 | if (usingActivityView()) { |
| 468 | Notification.BubbleMetadata data = mEntry.getBubbleMetadata(); |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame] | 469 | float desiredHeight; |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 470 | if (data == null) { |
| 471 | // This is a contentIntent based bubble, lets allow it to be the max height |
| 472 | // as it was forced into this mode and not prepared to be small |
| 473 | desiredHeight = mStackView.getMaxExpandedHeight(); |
| 474 | } else { |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame] | 475 | boolean useRes = data.getDesiredHeightResId() != 0; |
| 476 | float desiredPx; |
| 477 | if (useRes) { |
| 478 | desiredPx = getDimenForPackageUser(data.getDesiredHeightResId(), |
| 479 | mEntry.notification.getPackageName(), |
| 480 | mEntry.notification.getUser().getIdentifier()); |
| 481 | } else { |
| 482 | desiredPx = data.getDesiredHeight() |
| 483 | * getContext().getResources().getDisplayMetrics().density; |
| 484 | } |
| 485 | desiredHeight = desiredPx > 0 ? desiredPx : mMinHeight; |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 486 | } |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 487 | int chromeHeight = mPermissionView.getVisibility() != View.VISIBLE |
| 488 | ? mHeaderHeight |
| 489 | : mPermissionHeight; |
| 490 | int max = mStackView.getMaxExpandedHeight() - chromeHeight - mPointerView.getHeight() |
| 491 | - mPointerMargin; |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame] | 492 | float height = Math.min(desiredHeight, max); |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 493 | height = Math.max(height, mMinHeight); |
| 494 | LayoutParams lp = (LayoutParams) mActivityView.getLayoutParams(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 495 | mNeedsNewHeight = lp.height != height; |
| 496 | if (!mKeyboardVisible) { |
| 497 | // If the keyboard is visible... don't adjust the height because that will cause |
| 498 | // a configuration change and the keyboard will be lost. |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame] | 499 | lp.height = (int) height; |
| 500 | mBubbleHeight = (int) height; |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 501 | mActivityView.setLayoutParams(lp); |
| 502 | mNeedsNewHeight = false; |
| 503 | } |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 504 | } else { |
| 505 | mBubbleHeight = mNotifRow != null ? mNotifRow.getIntrinsicHeight() : mMinHeight; |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 509 | @Override |
| 510 | public void onClick(View view) { |
| 511 | if (mEntry == null) { |
| 512 | return; |
| 513 | } |
| 514 | Notification n = mEntry.notification.getNotification(); |
| 515 | int id = view.getId(); |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 516 | if (id == R.id.settings_button) { |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 517 | Intent intent = getSettingsIntent(mEntry.notification.getPackageName(), |
| 518 | mEntry.notification.getUid()); |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 519 | mStackView.collapseStack(() -> { |
| 520 | mContext.startActivity(intent); |
Steven Wu | 45e38ae | 2019-03-25 16:16:59 -0400 | [diff] [blame] | 521 | logBubbleClickEvent(mEntry, |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 522 | StatsLog.BUBBLE_UICHANGED__ACTION__HEADER_GO_TO_SETTINGS); |
| 523 | }); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 524 | } else if (id == R.id.no_bubbles_button) { |
| 525 | setBubblesAllowed(false); |
| 526 | } else if (id == R.id.yes_bubbles_button) { |
| 527 | setBubblesAllowed(true); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | private void setBubblesAllowed(boolean allowed) { |
| 532 | try { |
| 533 | mNotificationManagerService.setBubblesAllowed( |
| 534 | mEntry.notification.getPackageName(), |
| 535 | mEntry.notification.getUid(), |
| 536 | allowed); |
| 537 | if (allowed) { |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 538 | showSettingsIcon(); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 539 | } else if (mOnBubbleBlockedListener != null) { |
| 540 | mOnBubbleBlockedListener.onBubbleBlocked(mEntry); |
| 541 | } |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 542 | mStackView.onExpandedHeightChanged(); |
Steven Wu | 45e38ae | 2019-03-25 16:16:59 -0400 | [diff] [blame] | 543 | logBubbleClickEvent(mEntry, |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 544 | allowed ? StatsLog.BUBBLE_UICHANGED__ACTION__PERMISSION_OPT_IN : |
| 545 | StatsLog.BUBBLE_UICHANGED__ACTION__PERMISSION_OPT_OUT); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 546 | } catch (RemoteException e) { |
| 547 | Log.w(TAG, e); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 548 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 549 | } |
| 550 | |
Lyn Han | c26ff12 | 2019-03-29 16:46:07 -0700 | [diff] [blame^] | 551 | void showSettingsIcon() { |
| 552 | mPermissionView.setVisibility(GONE); |
| 553 | mSettingsIcon.setVisibility(VISIBLE); |
| 554 | } |
| 555 | |
| 556 | void showPermissionView() { |
| 557 | mSettingsIcon.setVisibility(GONE); |
| 558 | mPermissionView.setVisibility(VISIBLE); |
| 559 | |
| 560 | } |
| 561 | |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 562 | /** |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 563 | * Update appearance of the expanded view being displayed. |
| 564 | */ |
| 565 | public void updateView() { |
| 566 | if (usingActivityView() |
| 567 | && mActivityView.getVisibility() == VISIBLE |
| 568 | && mActivityView.isAttachedToWindow()) { |
| 569 | mActivityView.onLocationChanged(); |
| 570 | } else if (mNotifRow != null) { |
| 571 | applyRowState(mNotifRow); |
| 572 | } |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 573 | updateHeight(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /** |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 577 | * Set the x position that the tip of the triangle should point to. |
| 578 | */ |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 579 | public void setPointerPosition(float x) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 580 | // Adjust for the pointer size |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 581 | x -= (mPointerView.getWidth() / 2f); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 582 | mPointerView.setTranslationX(x); |
| 583 | } |
| 584 | |
| 585 | /** |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 586 | * Removes and releases an ActivityView if one was previously created for this bubble. |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 587 | */ |
Mady Mellor | 94d94a7 | 2019-03-05 18:16:59 -0800 | [diff] [blame] | 588 | public void cleanUpExpandedState() { |
| 589 | removeView(mNotifRow); |
| 590 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 591 | if (mActivityView == null) { |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 592 | return; |
| 593 | } |
Mark Renouf | 28c250d | 2019-02-25 16:47:34 -0500 | [diff] [blame] | 594 | if (mActivityViewReady) { |
| 595 | mActivityView.release(); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 596 | } |
Mark Renouf | 28c250d | 2019-02-25 16:47:34 -0500 | [diff] [blame] | 597 | removeView(mActivityView); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 598 | mActivityView = null; |
| 599 | mActivityViewReady = false; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 600 | } |
| 601 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 602 | private boolean usingActivityView() { |
Mady Mellor | 323fb0b | 2019-03-25 12:15:22 -0700 | [diff] [blame] | 603 | return mBubbleIntent != null && mActivityView != null; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | private void applyRowState(ExpandableNotificationRow view) { |
| 607 | view.reset(); |
| 608 | view.setHeadsUp(false); |
| 609 | view.resetTranslation(); |
| 610 | view.setOnKeyguard(false); |
| 611 | view.setOnAmbient(false); |
| 612 | view.setClipBottomAmount(0); |
| 613 | view.setClipTopAmount(0); |
| 614 | view.setContentTransformationAmount(0, false); |
| 615 | view.setIconsVisible(true); |
| 616 | |
| 617 | // TODO - Need to reset this (and others) when view goes back in shade, leave for now |
| 618 | // view.setTopRoundness(1, false); |
| 619 | // view.setBottomRoundness(1, false); |
| 620 | |
| 621 | ExpandableViewState viewState = view.getViewState(); |
| 622 | viewState = viewState == null ? new ExpandableViewState() : viewState; |
| 623 | viewState.height = view.getIntrinsicHeight(); |
| 624 | viewState.gone = false; |
| 625 | viewState.hidden = false; |
| 626 | viewState.dimmed = false; |
| 627 | viewState.dark = false; |
| 628 | viewState.alpha = 1f; |
| 629 | viewState.notGoneIndex = -1; |
| 630 | viewState.xTranslation = 0; |
| 631 | viewState.yTranslation = 0; |
| 632 | viewState.zTranslation = 0; |
| 633 | viewState.scaleX = 1; |
| 634 | viewState.scaleY = 1; |
| 635 | viewState.inShelf = true; |
| 636 | viewState.headsUpIsVisible = false; |
| 637 | viewState.applyToView(view); |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 638 | } |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 639 | |
| 640 | private Intent getSettingsIntent(String packageName, final int appUid) { |
| 641 | final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS); |
| 642 | intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName); |
| 643 | intent.putExtra(Settings.EXTRA_APP_UID, appUid); |
| 644 | intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); |
| 645 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 646 | return intent; |
| 647 | } |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 648 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 649 | @Nullable |
| 650 | private PendingIntent getBubbleIntent(NotificationEntry entry) { |
| 651 | Notification notif = entry.notification.getNotification(); |
| 652 | String packageName = entry.notification.getPackageName(); |
| 653 | Notification.BubbleMetadata data = notif.getBubbleMetadata(); |
| 654 | if (data != null && canLaunchInActivityView(data.getIntent(), true /* enableLogging */, |
| 655 | packageName)) { |
| 656 | return data.getIntent(); |
| 657 | } else if (BubbleController.shouldUseContentIntent(mContext) |
| 658 | && canLaunchInActivityView(notif.contentIntent, false /* enableLogging */, |
| 659 | packageName)) { |
| 660 | return notif.contentIntent; |
| 661 | } |
| 662 | return null; |
| 663 | } |
| 664 | |
| 665 | /** |
| 666 | * Whether an intent is properly configured to display in an {@link android.app.ActivityView}. |
| 667 | * |
| 668 | * @param intent the pending intent of the bubble. |
| 669 | * @param enableLogging whether bubble developer error should be logged. |
| 670 | * @param packageName the notification package name for this bubble. |
| 671 | * @return |
| 672 | */ |
| 673 | private boolean canLaunchInActivityView(PendingIntent intent, boolean enableLogging, |
| 674 | String packageName) { |
| 675 | if (intent == null) { |
| 676 | return false; |
| 677 | } |
| 678 | ActivityInfo info = |
| 679 | intent.getIntent().resolveActivityInfo(mContext.getPackageManager(), 0); |
| 680 | if (info == null) { |
| 681 | if (enableLogging) { |
| 682 | StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName, |
| 683 | BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_MISSING); |
| 684 | } |
| 685 | return false; |
| 686 | } |
| 687 | if (!ActivityInfo.isResizeableMode(info.resizeMode)) { |
| 688 | if (enableLogging) { |
| 689 | StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName, |
| 690 | BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_NOT_RESIZABLE); |
| 691 | } |
| 692 | return false; |
| 693 | } |
| 694 | if (info.documentLaunchMode != DOCUMENT_LAUNCH_ALWAYS) { |
| 695 | if (enableLogging) { |
| 696 | StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName, |
| 697 | BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__DOCUMENT_LAUNCH_NOT_ALWAYS); |
| 698 | } |
| 699 | return false; |
| 700 | } |
| 701 | return (info.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) != 0; |
| 702 | } |
| 703 | |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 704 | /** |
| 705 | * Listener that is notified when a bubble is blocked. |
| 706 | */ |
| 707 | public interface OnBubbleBlockedListener { |
| 708 | /** |
| 709 | * Called when a bubble is blocked for the provided entry. |
| 710 | */ |
| 711 | void onBubbleBlocked(NotificationEntry entry); |
| 712 | } |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 713 | |
| 714 | /** |
| 715 | * Logs bubble UI click event. |
| 716 | * |
Steven Wu | 45e38ae | 2019-03-25 16:16:59 -0400 | [diff] [blame] | 717 | * @param entry the bubble notification entry that user is interacting with. |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 718 | * @param action the user interaction enum. |
| 719 | */ |
Steven Wu | 45e38ae | 2019-03-25 16:16:59 -0400 | [diff] [blame] | 720 | private void logBubbleClickEvent(NotificationEntry entry, int action) { |
| 721 | StatusBarNotification notification = entry.notification; |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 722 | StatsLog.write(StatsLog.BUBBLE_UI_CHANGED, |
| 723 | notification.getPackageName(), |
| 724 | notification.getNotification().getChannelId(), |
| 725 | notification.getId(), |
| 726 | mStackView.getBubbleIndex(mStackView.getExpandedBubble()), |
| 727 | mStackView.getBubbleCount(), |
| 728 | action, |
| 729 | mStackView.getNormalizedXPosition(), |
Steven Wu | 45e38ae | 2019-03-25 16:16:59 -0400 | [diff] [blame] | 730 | mStackView.getNormalizedYPosition(), |
| 731 | entry.showInShadeWhenBubble()); |
Steven Wu | b00225b | 2019-02-08 14:27:42 -0500 | [diff] [blame] | 732 | } |
Mady Mellor | 7af771a | 2019-03-07 15:04:54 -0800 | [diff] [blame] | 733 | |
| 734 | private int getDimenForPackageUser(int resId, String pkg, int userId) { |
| 735 | Resources r; |
| 736 | if (pkg != null) { |
| 737 | try { |
| 738 | if (userId == UserHandle.USER_ALL) { |
| 739 | userId = UserHandle.USER_SYSTEM; |
| 740 | } |
| 741 | r = mPm.getResourcesForApplicationAsUser(pkg, userId); |
| 742 | return r.getDimensionPixelSize(resId); |
| 743 | } catch (PackageManager.NameNotFoundException ex) { |
| 744 | // Uninstalled, don't care |
| 745 | } catch (Resources.NotFoundException e) { |
| 746 | // Invalid res id, return 0 and user our default |
| 747 | Log.e(TAG, "Couldn't find desired height res id", e); |
| 748 | } |
| 749 | } |
| 750 | return 0; |
| 751 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 752 | } |