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