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