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