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 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame^] | 55 | import com.android.internal.policy.ScreenDecorationsUtils; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 56 | import com.android.systemui.Dependency; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 57 | import com.android.systemui.R; |
| 58 | import com.android.systemui.recents.TriangleShape; |
Lyn Han | 754e77b | 2019-04-30 14:34:49 -0700 | [diff] [blame] | 59 | import com.android.systemui.statusbar.AlphaOptimizedButton; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 60 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 61 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 62 | import com.android.systemui.statusbar.notification.stack.ExpandableViewState; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 63 | |
| 64 | /** |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 65 | * 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] | 66 | */ |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 67 | public class BubbleExpandedView extends LinearLayout implements View.OnClickListener { |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 68 | private static final String TAG = "BubbleExpandedView"; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 69 | |
| 70 | // The triangle pointing to the expanded view |
| 71 | private View mPointerView; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 72 | private int mPointerMargin; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 73 | |
Lyn Han | 754e77b | 2019-04-30 14:34:49 -0700 | [diff] [blame] | 74 | private AlphaOptimizedButton mSettingsIcon; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 75 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 76 | // Views for expanded state |
| 77 | private ExpandableNotificationRow mNotifRow; |
| 78 | private ActivityView mActivityView; |
| 79 | |
| 80 | private boolean mActivityViewReady = false; |
| 81 | private PendingIntent mBubbleIntent; |
| 82 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 83 | private boolean mKeyboardVisible; |
| 84 | private boolean mNeedsNewHeight; |
| 85 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 86 | private int mMinHeight; |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 87 | private int mSettingsIconHeight; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 88 | private int mBubbleHeight; |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 89 | private int mPointerWidth; |
| 90 | private int mPointerHeight; |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame^] | 91 | private ShapeDrawable mPointerDrawable; |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 92 | |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 93 | private NotificationEntry mEntry; |
| 94 | private PackageManager mPm; |
| 95 | private String mAppName; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 96 | private Drawable mAppIcon; |
| 97 | |
| 98 | private INotificationManager mNotificationManagerService; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 99 | private BubbleController mBubbleController = Dependency.get(BubbleController.class); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 100 | |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 101 | private BubbleStackView mStackView; |
| 102 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 103 | private BubbleExpandedView.OnBubbleBlockedListener mOnBubbleBlockedListener; |
| 104 | |
| 105 | private ActivityView.StateCallback mStateCallback = new ActivityView.StateCallback() { |
| 106 | @Override |
| 107 | public void onActivityViewReady(ActivityView view) { |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 108 | if (!mActivityViewReady) { |
| 109 | mActivityViewReady = true; |
Mady Mellor | 60101c9 | 2019-04-11 19:04:00 -0700 | [diff] [blame] | 110 | // Custom options so there is no activity transition animation |
| 111 | ActivityOptions options = ActivityOptions.makeCustomAnimation(getContext(), |
| 112 | 0 /* enterResId */, 0 /* exitResId */); |
| 113 | // Post to keep the lifecycle normal |
| 114 | post(() -> mActivityView.startActivity(mBubbleIntent, options)); |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 115 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void onActivityViewDestroyed(ActivityView view) { |
| 120 | mActivityViewReady = false; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * This is only called for tasks on this ActivityView, which is also set to |
| 125 | * single-task mode -- meaning never more than one task on this display. If a task |
| 126 | * is being removed, it's the top Activity finishing and this bubble should |
| 127 | * be removed or collapsed. |
| 128 | */ |
| 129 | @Override |
| 130 | public void onTaskRemovalStarted(int taskId) { |
| 131 | if (mEntry != null) { |
| 132 | // Must post because this is called from a binder thread. |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 133 | post(() -> mBubbleController.removeBubble(mEntry.key, |
| 134 | BubbleController.DISMISS_TASK_FINISHED)); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | }; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 138 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 139 | public BubbleExpandedView(Context context) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 140 | this(context, null); |
| 141 | } |
| 142 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 143 | public BubbleExpandedView(Context context, AttributeSet attrs) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 144 | this(context, attrs, 0); |
| 145 | } |
| 146 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 147 | public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr) { |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 148 | this(context, attrs, defStyleAttr, 0); |
| 149 | } |
| 150 | |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 151 | public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr, |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 152 | int defStyleRes) { |
| 153 | super(context, attrs, defStyleAttr, defStyleRes); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 154 | mPm = context.getPackageManager(); |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 155 | mMinHeight = getResources().getDimensionPixelSize( |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 156 | R.dimen.bubble_expanded_default_height); |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 157 | mPointerMargin = getResources().getDimensionPixelSize(R.dimen.bubble_pointer_margin); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 158 | try { |
| 159 | mNotificationManagerService = INotificationManager.Stub.asInterface( |
| 160 | ServiceManager.getServiceOrThrow(Context.NOTIFICATION_SERVICE)); |
| 161 | } catch (ServiceManager.ServiceNotFoundException e) { |
| 162 | Log.w(TAG, e); |
| 163 | } |
Mady Mellor | dea7ecf | 2018-12-10 15:47:40 -0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | @Override |
| 167 | protected void onFinishInflate() { |
| 168 | super.onFinishInflate(); |
| 169 | |
| 170 | Resources res = getResources(); |
| 171 | mPointerView = findViewById(R.id.pointer_view); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 172 | mPointerWidth = res.getDimensionPixelSize(R.dimen.bubble_pointer_width); |
| 173 | mPointerHeight = res.getDimensionPixelSize(R.dimen.bubble_pointer_height); |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 174 | |
Mady Mellor | dd49705 | 2019-01-30 17:23:48 -0800 | [diff] [blame] | 175 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame^] | 176 | mPointerDrawable = new ShapeDrawable(TriangleShape.create( |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 177 | mPointerWidth, mPointerHeight, false /* pointUp */)); |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame^] | 178 | mPointerView.setBackground(mPointerDrawable); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 179 | |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 180 | mSettingsIconHeight = getContext().getResources().getDimensionPixelSize( |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 181 | R.dimen.bubble_expanded_header_height); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 182 | mSettingsIcon = findViewById(R.id.settings_button); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 183 | mSettingsIcon.setOnClickListener(this); |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 184 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 185 | mActivityView = new ActivityView(mContext, null /* attrs */, 0 /* defStyle */, |
| 186 | true /* singleTaskInstance */); |
| 187 | addView(mActivityView); |
| 188 | |
Mady Mellor | 52b1ac6 | 2019-04-10 16:59:03 -0700 | [diff] [blame] | 189 | // Make sure pointer is below activity view |
| 190 | bringChildToFront(mPointerView); |
| 191 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame^] | 192 | applyThemeAttrs(); |
| 193 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 194 | setOnApplyWindowInsetsListener((View view, WindowInsets insets) -> { |
| 195 | // Keep track of IME displaying because we should not make any adjustments that might |
| 196 | // 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] | 197 | final int keyboardHeight = insets.getSystemWindowInsetBottom() |
| 198 | - insets.getStableInsetBottom(); |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 199 | mKeyboardVisible = keyboardHeight != 0; |
| 200 | if (!mKeyboardVisible && mNeedsNewHeight) { |
| 201 | updateHeight(); |
| 202 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 203 | return view.onApplyWindowInsets(insets); |
| 204 | }); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame^] | 207 | void applyThemeAttrs() { |
| 208 | TypedArray ta = getContext().obtainStyledAttributes(R.styleable.BubbleExpandedView); |
| 209 | int bgColor = ta.getColor( |
| 210 | R.styleable.BubbleExpandedView_android_colorBackgroundFloating, Color.WHITE); |
| 211 | float cornerRadius = ta.getDimension( |
| 212 | R.styleable.BubbleExpandedView_android_dialogCornerRadius, 0); |
| 213 | ta.recycle(); |
| 214 | |
| 215 | // Update triangle color. |
| 216 | mPointerDrawable.setTint(bgColor); |
| 217 | |
| 218 | // Update ActivityView cornerRadius |
| 219 | if (ScreenDecorationsUtils.supportsRoundedCornersOnWindows(mContext.getResources())) { |
| 220 | mActivityView.setCornerRadius(cornerRadius); |
| 221 | } |
| 222 | } |
| 223 | |
Mady Mellor | 5d8f140 | 2019-02-21 18:23:52 -0800 | [diff] [blame] | 224 | @Override |
| 225 | protected void onDetachedFromWindow() { |
| 226 | super.onDetachedFromWindow(); |
| 227 | mKeyboardVisible = false; |
| 228 | mNeedsNewHeight = false; |
| 229 | if (mActivityView != null) { |
| 230 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, 0)); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Called by {@link BubbleStackView} when the insets for the expanded state should be updated. |
| 236 | * This should be done post-move and post-animation. |
| 237 | */ |
| 238 | void updateInsets(WindowInsets insets) { |
| 239 | if (usingActivityView()) { |
| 240 | Point displaySize = new Point(); |
| 241 | mActivityView.getContext().getDisplay().getSize(displaySize); |
| 242 | int[] windowLocation = mActivityView.getLocationOnScreen(); |
| 243 | final int windowBottom = windowLocation[1] + mActivityView.getHeight(); |
| 244 | final int keyboardHeight = insets.getSystemWindowInsetBottom() |
| 245 | - insets.getStableInsetBottom(); |
| 246 | final int insetsBottom = Math.max(0, |
| 247 | windowBottom + keyboardHeight - displaySize.y); |
| 248 | mActivityView.setForwardedInsets(Insets.of(0, 0, 0, insetsBottom)); |
| 249 | } |
| 250 | } |
| 251 | |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 252 | /** |
| 253 | * Sets the listener to notify when a bubble has been blocked. |
| 254 | */ |
| 255 | public void setOnBlockedListener(OnBubbleBlockedListener listener) { |
| 256 | mOnBubbleBlockedListener = listener; |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Sets the notification entry used to populate this view. |
| 261 | */ |
| 262 | public void setEntry(NotificationEntry entry, BubbleStackView stackView) { |
| 263 | mStackView = stackView; |
| 264 | mEntry = entry; |
| 265 | |
| 266 | ApplicationInfo info; |
| 267 | try { |
| 268 | info = mPm.getApplicationInfo( |
| 269 | entry.notification.getPackageName(), |
| 270 | PackageManager.MATCH_UNINSTALLED_PACKAGES |
| 271 | | PackageManager.MATCH_DISABLED_COMPONENTS |
| 272 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
| 273 | | PackageManager.MATCH_DIRECT_BOOT_AWARE); |
| 274 | if (info != null) { |
| 275 | mAppName = String.valueOf(mPm.getApplicationLabel(info)); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 276 | mAppIcon = mPm.getApplicationIcon(info); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 277 | } |
| 278 | } catch (PackageManager.NameNotFoundException e) { |
| 279 | // Ahh... just use package name |
| 280 | mAppName = entry.notification.getPackageName(); |
| 281 | } |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 282 | if (mAppIcon == null) { |
| 283 | mAppIcon = mPm.getDefaultActivityIcon(); |
| 284 | } |
Mark Renouf | 34d04f3 | 2019-05-13 15:53:18 -0400 | [diff] [blame^] | 285 | applyThemeAttrs(); |
Lyn Han | 6914912 | 2019-04-30 12:03:12 -0700 | [diff] [blame] | 286 | showSettingsIcon(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 287 | updateExpandedView(); |
Mady Mellor | 6d00203 | 2019-02-13 13:45:17 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Lets activity view know it should be shown / populated. |
| 292 | */ |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 293 | public void populateExpandedView() { |
| 294 | if (usingActivityView()) { |
| 295 | mActivityView.setCallback(mStateCallback); |
| 296 | } else { |
| 297 | // We're using notification template |
| 298 | ViewGroup parent = (ViewGroup) mNotifRow.getParent(); |
| 299 | if (parent == this) { |
| 300 | // Already added |
| 301 | return; |
| 302 | } else if (parent != null) { |
| 303 | // Still in the shade... remove it |
| 304 | parent.removeView(mNotifRow); |
| 305 | } |
Lyn Han | 3f5c3a4 | 2019-04-01 15:59:56 -0700 | [diff] [blame] | 306 | addView(mNotifRow, 1 /* index */); |
Mady Mellor | 5029fa6 | 2019-03-05 12:16:21 -0800 | [diff] [blame] | 307 | } |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 310 | /** |
| 311 | * 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] | 312 | * 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] | 313 | */ |
| 314 | public void update(NotificationEntry entry) { |
| 315 | if (entry.key.equals(mEntry.key)) { |
| 316 | mEntry = entry; |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 317 | updateSettingsContentDescription(); |
Mady Mellor | fe7ec03 | 2019-01-30 17:32:49 -0800 | [diff] [blame] | 318 | updateHeight(); |
| 319 | } else { |
| 320 | Log.w(TAG, "Trying to update entry with different key, new entry: " |
| 321 | + entry.key + " old entry: " + mEntry.key); |
| 322 | } |
| 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 | } |