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