blob: 492eadd240ed6d7ea8436bf749aa2c11eff40c36 [file] [log] [blame]
Mady Mellordea7ecf2018-12-10 15:47:40 -08001/*
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
17package com.android.systemui.bubbles;
18
Mady Mellor3dff9e62019-02-05 18:12:53 -080019import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS;
20import static android.util.StatsLogInternal.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_MISSING;
21import static android.util.StatsLogInternal.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_NOT_RESIZABLE;
22import static android.util.StatsLogInternal.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__DOCUMENT_LAUNCH_NOT_ALWAYS;
23
Mady Mellore8e07712019-01-23 12:45:33 -080024import android.animation.LayoutTransition;
25import android.animation.ObjectAnimator;
Mady Mellordea7ecf2018-12-10 15:47:40 -080026import android.annotation.Nullable;
Mady Mellor3dff9e62019-02-05 18:12:53 -080027import android.app.ActivityView;
Mady Mellore8e07712019-01-23 12:45:33 -080028import android.app.INotificationManager;
Mady Mellor9801e852019-01-22 14:50:28 -080029import android.app.Notification;
30import android.app.PendingIntent;
Mady Mellordea7ecf2018-12-10 15:47:40 -080031import android.content.Context;
Mady Mellor9801e852019-01-22 14:50:28 -080032import android.content.Intent;
Mady Mellor3dff9e62019-02-05 18:12:53 -080033import android.content.pm.ActivityInfo;
Mady Mellor9801e852019-01-22 14:50:28 -080034import android.content.pm.ApplicationInfo;
35import android.content.pm.PackageManager;
Mady Mellordea7ecf2018-12-10 15:47:40 -080036import android.content.res.Resources;
Mady Mellordd497052019-01-30 17:23:48 -080037import android.content.res.TypedArray;
Mady Mellordea7ecf2018-12-10 15:47:40 -080038import android.graphics.Color;
Mady Mellor3dff9e62019-02-05 18:12:53 -080039import android.graphics.Insets;
40import android.graphics.Point;
Mady Mellore8e07712019-01-23 12:45:33 -080041import android.graphics.drawable.Drawable;
Mady Mellordea7ecf2018-12-10 15:47:40 -080042import android.graphics.drawable.ShapeDrawable;
Mady Mellore8e07712019-01-23 12:45:33 -080043import android.os.RemoteException;
44import android.os.ServiceManager;
Mady Mellor9801e852019-01-22 14:50:28 -080045import android.provider.Settings;
Steven Wub00225b2019-02-08 14:27:42 -050046import android.service.notification.StatusBarNotification;
Mady Mellordea7ecf2018-12-10 15:47:40 -080047import android.util.AttributeSet;
Mady Mellor9801e852019-01-22 14:50:28 -080048import android.util.Log;
Steven Wub00225b2019-02-08 14:27:42 -050049import android.util.StatsLog;
Mady Mellordea7ecf2018-12-10 15:47:40 -080050import android.view.View;
Mady Mellor3dff9e62019-02-05 18:12:53 -080051import android.view.ViewGroup;
52import android.view.WindowInsets;
Mady Mellore8e07712019-01-23 12:45:33 -080053import android.widget.FrameLayout;
Mady Mellor9801e852019-01-22 14:50:28 -080054import android.widget.ImageButton;
Mady Mellore8e07712019-01-23 12:45:33 -080055import android.widget.ImageView;
Mady Mellordea7ecf2018-12-10 15:47:40 -080056import android.widget.LinearLayout;
Mark Renouf89b1a4a2018-12-04 14:59:45 -050057import android.widget.TextView;
Mady Mellordea7ecf2018-12-10 15:47:40 -080058
Mady Mellor3dff9e62019-02-05 18:12:53 -080059import com.android.systemui.Dependency;
Mady Mellore8e07712019-01-23 12:45:33 -080060import com.android.systemui.Interpolators;
Mady Mellordea7ecf2018-12-10 15:47:40 -080061import com.android.systemui.R;
62import com.android.systemui.recents.TriangleShape;
Mady Mellor9801e852019-01-22 14:50:28 -080063import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Mady Mellor3dff9e62019-02-05 18:12:53 -080064import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
65import com.android.systemui.statusbar.notification.stack.ExpandableViewState;
Mady Mellordea7ecf2018-12-10 15:47:40 -080066
67/**
68 * Container for the expanded bubble view, handles rendering the caret and header of the view.
69 */
Mady Mellor3d82e682019-02-05 13:34:48 -080070public class BubbleExpandedView extends LinearLayout implements View.OnClickListener {
Mady Mellor9801e852019-01-22 14:50:28 -080071 private static final String TAG = "BubbleExpandedView";
Mady Mellordea7ecf2018-12-10 15:47:40 -080072
73 // The triangle pointing to the expanded view
74 private View mPointerView;
Mady Mellore8e07712019-01-23 12:45:33 -080075
76 // Header
77 private View mHeaderView;
78 private TextView mHeaderTextView;
Mady Mellor9801e852019-01-22 14:50:28 -080079 private ImageButton mDeepLinkIcon;
Mady Mellor9801e852019-01-22 14:50:28 -080080 private ImageButton mSettingsIcon;
Mady Mellore8e07712019-01-23 12:45:33 -080081
82 // Permission view
83 private View mPermissionView;
84
Mady Mellor3dff9e62019-02-05 18:12:53 -080085 // Views for expanded state
86 private ExpandableNotificationRow mNotifRow;
87 private ActivityView mActivityView;
88
89 private boolean mActivityViewReady = false;
90 private PendingIntent mBubbleIntent;
91
92 private int mBubbleHeight;
93 private int mDefaultHeight;
Mady Mellordea7ecf2018-12-10 15:47:40 -080094
Mady Mellor9801e852019-01-22 14:50:28 -080095 private NotificationEntry mEntry;
96 private PackageManager mPm;
97 private String mAppName;
Mady Mellore8e07712019-01-23 12:45:33 -080098 private Drawable mAppIcon;
99
100 private INotificationManager mNotificationManagerService;
Mady Mellor3dff9e62019-02-05 18:12:53 -0800101 private BubbleController mBubbleController = Dependency.get(BubbleController.class);
Mady Mellor9801e852019-01-22 14:50:28 -0800102
Mady Mellor9801e852019-01-22 14:50:28 -0800103 private BubbleStackView mStackView;
104
Mady Mellor3dff9e62019-02-05 18:12:53 -0800105 private BubbleExpandedView.OnBubbleBlockedListener mOnBubbleBlockedListener;
106
107 private ActivityView.StateCallback mStateCallback = new ActivityView.StateCallback() {
108 @Override
109 public void onActivityViewReady(ActivityView view) {
Mady Mellor6d002032019-02-13 13:45:17 -0800110 if (!mActivityViewReady) {
111 mActivityViewReady = true;
112 mActivityView.startActivity(mBubbleIntent);
113 }
Mady Mellor3dff9e62019-02-05 18:12:53 -0800114 }
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.
131 post(() -> mBubbleController.removeBubble(mEntry.key));
132 }
133 }
134 };
Mady Mellore8e07712019-01-23 12:45:33 -0800135
Mady Mellor3d82e682019-02-05 13:34:48 -0800136 public BubbleExpandedView(Context context) {
Mady Mellordea7ecf2018-12-10 15:47:40 -0800137 this(context, null);
138 }
139
Mady Mellor3d82e682019-02-05 13:34:48 -0800140 public BubbleExpandedView(Context context, AttributeSet attrs) {
Mady Mellordea7ecf2018-12-10 15:47:40 -0800141 this(context, attrs, 0);
142 }
143
Mady Mellor3d82e682019-02-05 13:34:48 -0800144 public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr) {
Mady Mellordea7ecf2018-12-10 15:47:40 -0800145 this(context, attrs, defStyleAttr, 0);
146 }
147
Mady Mellor3d82e682019-02-05 13:34:48 -0800148 public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr,
Mady Mellordea7ecf2018-12-10 15:47:40 -0800149 int defStyleRes) {
150 super(context, attrs, defStyleAttr, defStyleRes);
Mady Mellor9801e852019-01-22 14:50:28 -0800151 mPm = context.getPackageManager();
Mady Mellor3dff9e62019-02-05 18:12:53 -0800152 mDefaultHeight = getResources().getDimensionPixelSize(
153 R.dimen.bubble_expanded_default_height);
Mady Mellore8e07712019-01-23 12:45:33 -0800154 try {
155 mNotificationManagerService = INotificationManager.Stub.asInterface(
156 ServiceManager.getServiceOrThrow(Context.NOTIFICATION_SERVICE));
157 } catch (ServiceManager.ServiceNotFoundException e) {
158 Log.w(TAG, e);
159 }
Mady Mellordea7ecf2018-12-10 15:47:40 -0800160 }
161
162 @Override
163 protected void onFinishInflate() {
164 super.onFinishInflate();
165
166 Resources res = getResources();
167 mPointerView = findViewById(R.id.pointer_view);
168 int width = res.getDimensionPixelSize(R.dimen.bubble_pointer_width);
169 int height = res.getDimensionPixelSize(R.dimen.bubble_pointer_height);
Mady Mellordd497052019-01-30 17:23:48 -0800170
171 TypedArray ta = getContext().obtainStyledAttributes(
172 new int[] {android.R.attr.colorBackgroundFloating});
173 int bgColor = ta.getColor(0, Color.WHITE);
174 ta.recycle();
175
Mady Mellordea7ecf2018-12-10 15:47:40 -0800176 ShapeDrawable triangleDrawable = new ShapeDrawable(
177 TriangleShape.create(width, height, true /* pointUp */));
Mady Mellordd497052019-01-30 17:23:48 -0800178 triangleDrawable.setTint(bgColor);
Mady Mellordea7ecf2018-12-10 15:47:40 -0800179 mPointerView.setBackground(triangleDrawable);
Mady Mellor9801e852019-01-22 14:50:28 -0800180
Mady Mellore8e07712019-01-23 12:45:33 -0800181 FrameLayout viewWrapper = findViewById(R.id.header_permission_wrapper);
182 LayoutTransition transition = new LayoutTransition();
183 transition.setDuration(200);
184
185 ObjectAnimator appearAnimator = ObjectAnimator.ofFloat(null, View.ALPHA, 0f, 1f);
186 transition.setAnimator(LayoutTransition.APPEARING, appearAnimator);
187 transition.setInterpolator(LayoutTransition.APPEARING, Interpolators.ALPHA_IN);
188
189 ObjectAnimator disappearAnimator = ObjectAnimator.ofFloat(null, View.ALPHA, 1f, 0f);
190 transition.setAnimator(LayoutTransition.DISAPPEARING, disappearAnimator);
191 transition.setInterpolator(LayoutTransition.DISAPPEARING, Interpolators.ALPHA_OUT);
192
193 transition.setAnimateParentHierarchy(false);
194 viewWrapper.setLayoutTransition(transition);
195 viewWrapper.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
196
197 mHeaderView = findViewById(R.id.header_layout);
198 mHeaderTextView = findViewById(R.id.header_text);
Mady Mellor9801e852019-01-22 14:50:28 -0800199 mDeepLinkIcon = findViewById(R.id.deep_link_button);
200 mSettingsIcon = findViewById(R.id.settings_button);
201 mDeepLinkIcon.setOnClickListener(this);
202 mSettingsIcon.setOnClickListener(this);
Mady Mellore8e07712019-01-23 12:45:33 -0800203
204 mPermissionView = findViewById(R.id.permission_layout);
205 findViewById(R.id.no_bubbles_button).setOnClickListener(this);
206 findViewById(R.id.yes_bubbles_button).setOnClickListener(this);
Mady Mellor3dff9e62019-02-05 18:12:53 -0800207
208 mActivityView = new ActivityView(mContext, null /* attrs */, 0 /* defStyle */,
209 true /* singleTaskInstance */);
210 addView(mActivityView);
211
212 mActivityView.setOnApplyWindowInsetsListener((View view, WindowInsets insets) -> {
213 ActivityView activityView = (ActivityView) view;
214 // Here we assume that the position of the ActivityView on the screen
215 // remains regardless of IME status. When we move ActivityView, the
216 // forwardedInsets should be computed not against the current location
217 // and size, but against the post-moved location and size.
218 Point displaySize = new Point();
219 view.getContext().getDisplay().getSize(displaySize);
220 int[] windowLocation = view.getLocationOnScreen();
221 final int windowBottom = windowLocation[1] + view.getHeight();
222 final int keyboardHeight = insets.getSystemWindowInsetBottom()
223 - insets.getStableInsetBottom();
224 final int insetsBottom = Math.max(0,
225 windowBottom + keyboardHeight - displaySize.y);
226 activityView.setForwardedInsets(Insets.of(0, 0, 0, insetsBottom));
227 return view.onApplyWindowInsets(insets);
228 });
Mady Mellore8e07712019-01-23 12:45:33 -0800229 }
230
231 /**
232 * Sets the listener to notify when a bubble has been blocked.
233 */
234 public void setOnBlockedListener(OnBubbleBlockedListener listener) {
235 mOnBubbleBlockedListener = listener;
Mady Mellor9801e852019-01-22 14:50:28 -0800236 }
237
238 /**
239 * Sets the notification entry used to populate this view.
240 */
241 public void setEntry(NotificationEntry entry, BubbleStackView stackView) {
242 mStackView = stackView;
243 mEntry = entry;
244
245 ApplicationInfo info;
246 try {
247 info = mPm.getApplicationInfo(
248 entry.notification.getPackageName(),
249 PackageManager.MATCH_UNINSTALLED_PACKAGES
250 | PackageManager.MATCH_DISABLED_COMPONENTS
251 | PackageManager.MATCH_DIRECT_BOOT_UNAWARE
252 | PackageManager.MATCH_DIRECT_BOOT_AWARE);
253 if (info != null) {
254 mAppName = String.valueOf(mPm.getApplicationLabel(info));
Mady Mellore8e07712019-01-23 12:45:33 -0800255 mAppIcon = mPm.getApplicationIcon(info);
Mady Mellor9801e852019-01-22 14:50:28 -0800256 }
257 } catch (PackageManager.NameNotFoundException e) {
258 // Ahh... just use package name
259 mAppName = entry.notification.getPackageName();
260 }
Mady Mellore8e07712019-01-23 12:45:33 -0800261 if (mAppIcon == null) {
262 mAppIcon = mPm.getDefaultActivityIcon();
263 }
Mady Mellor9801e852019-01-22 14:50:28 -0800264 updateHeaderView();
Mady Mellore8e07712019-01-23 12:45:33 -0800265 updatePermissionView();
Mady Mellor3dff9e62019-02-05 18:12:53 -0800266 updateExpandedView();
Mady Mellor6d002032019-02-13 13:45:17 -0800267 }
268
269 /**
270 * Lets activity view know it should be shown / populated.
271 */
272 public void populateActivityView() {
Mady Mellor3dff9e62019-02-05 18:12:53 -0800273 mActivityView.setCallback(mStateCallback);
Mady Mellor9801e852019-01-22 14:50:28 -0800274 }
275
276 private void updateHeaderView() {
277 mSettingsIcon.setContentDescription(getResources().getString(
278 R.string.bubbles_settings_button_description, mAppName));
279 mDeepLinkIcon.setContentDescription(getResources().getString(
280 R.string.bubbles_deep_link_button_description, mAppName));
281 if (mEntry != null && mEntry.getBubbleMetadata() != null) {
Mady Mellore8e07712019-01-23 12:45:33 -0800282 mHeaderTextView.setText(mEntry.getBubbleMetadata().getTitle());
Mady Mellor9801e852019-01-22 14:50:28 -0800283 } else {
284 // This should only happen if we're auto-bubbling notification content that isn't
285 // explicitly a bubble
Mady Mellore8e07712019-01-23 12:45:33 -0800286 mHeaderTextView.setText(mAppName);
287 }
288 }
289
290 private void updatePermissionView() {
291 boolean hasUserApprovedBubblesForPackage = false;
292 try {
293 hasUserApprovedBubblesForPackage =
294 mNotificationManagerService.hasUserApprovedBubblesForPackage(
295 mEntry.notification.getPackageName(), mEntry.notification.getUid());
296 } catch (RemoteException e) {
297 Log.w(TAG, e);
298 }
299 if (hasUserApprovedBubblesForPackage) {
300 mHeaderView.setVisibility(VISIBLE);
301 mPermissionView.setVisibility(GONE);
302 } else {
303 mHeaderView.setVisibility(GONE);
304 mPermissionView.setVisibility(VISIBLE);
305 ((ImageView) mPermissionView.findViewById(R.id.pkgicon)).setImageDrawable(mAppIcon);
306 ((TextView) mPermissionView.findViewById(R.id.pkgname)).setText(mAppName);
Mady Mellor9801e852019-01-22 14:50:28 -0800307 }
308 }
309
Mady Mellor3dff9e62019-02-05 18:12:53 -0800310 private void updateExpandedView() {
311 mBubbleIntent = getBubbleIntent(mEntry);
312 if (mBubbleIntent != null) {
313 if (mNotifRow != null) {
314 // Clear out the row if we had it previously
315 removeView(mNotifRow);
316 mNotifRow = null;
317 }
318 Notification.BubbleMetadata data = mEntry.getBubbleMetadata();
319 mBubbleHeight = data != null && data.getDesiredHeight() > 0
320 ? data.getDesiredHeight()
321 : mDefaultHeight;
322 // XXX: enforce max / min height
323 LayoutParams lp = (LayoutParams) mActivityView.getLayoutParams();
324 lp.height = mBubbleHeight;
325 mActivityView.setLayoutParams(lp);
326 mActivityView.setVisibility(VISIBLE);
327 } else {
328 // Hide activity view if we had it previously
329 mActivityView.setVisibility(GONE);
330
331 // Use notification view
332 mNotifRow = mEntry.getRow();
333 addView(mNotifRow);
334 }
335 updateView();
336 }
337
Mady Mellor9801e852019-01-22 14:50:28 -0800338 @Override
339 public void onClick(View view) {
340 if (mEntry == null) {
341 return;
342 }
343 Notification n = mEntry.notification.getNotification();
344 int id = view.getId();
345 if (id == R.id.deep_link_button) {
346 mStackView.collapseStack(() -> {
347 try {
348 n.contentIntent.send();
Steven Wub00225b2019-02-08 14:27:42 -0500349 logBubbleClickEvent(mEntry.notification,
350 StatsLog.BUBBLE_UICHANGED__ACTION__HEADER_GO_TO_APP);
Mady Mellor9801e852019-01-22 14:50:28 -0800351 } catch (PendingIntent.CanceledException e) {
352 Log.w(TAG, "Failed to send intent for bubble with key: "
353 + (mEntry != null ? mEntry.key : " null entry"));
354 }
355 });
356 } else if (id == R.id.settings_button) {
357 Intent intent = getSettingsIntent(mEntry.notification.getPackageName(),
358 mEntry.notification.getUid());
Steven Wub00225b2019-02-08 14:27:42 -0500359 mStackView.collapseStack(() -> {
360 mContext.startActivity(intent);
361 logBubbleClickEvent(mEntry.notification,
362 StatsLog.BUBBLE_UICHANGED__ACTION__HEADER_GO_TO_SETTINGS);
363 });
Mady Mellore8e07712019-01-23 12:45:33 -0800364 } else if (id == R.id.no_bubbles_button) {
365 setBubblesAllowed(false);
366 } else if (id == R.id.yes_bubbles_button) {
367 setBubblesAllowed(true);
368 }
369 }
370
371 private void setBubblesAllowed(boolean allowed) {
372 try {
373 mNotificationManagerService.setBubblesAllowed(
374 mEntry.notification.getPackageName(),
375 mEntry.notification.getUid(),
376 allowed);
377 if (allowed) {
378 mPermissionView.setVisibility(GONE);
379 mHeaderView.setVisibility(VISIBLE);
380 } else if (mOnBubbleBlockedListener != null) {
381 mOnBubbleBlockedListener.onBubbleBlocked(mEntry);
382 }
Steven Wub00225b2019-02-08 14:27:42 -0500383 logBubbleClickEvent(mEntry.notification,
384 allowed ? StatsLog.BUBBLE_UICHANGED__ACTION__PERMISSION_OPT_IN :
385 StatsLog.BUBBLE_UICHANGED__ACTION__PERMISSION_OPT_OUT);
Mady Mellore8e07712019-01-23 12:45:33 -0800386 } catch (RemoteException e) {
387 Log.w(TAG, e);
Mady Mellor9801e852019-01-22 14:50:28 -0800388 }
Mady Mellordea7ecf2018-12-10 15:47:40 -0800389 }
390
391 /**
Mady Mellor3dff9e62019-02-05 18:12:53 -0800392 * Update appearance of the expanded view being displayed.
393 */
394 public void updateView() {
395 if (usingActivityView()
396 && mActivityView.getVisibility() == VISIBLE
397 && mActivityView.isAttachedToWindow()) {
398 mActivityView.onLocationChanged();
399 } else if (mNotifRow != null) {
400 applyRowState(mNotifRow);
401 }
402 }
403
404 /**
Mady Mellordea7ecf2018-12-10 15:47:40 -0800405 * Set the x position that the tip of the triangle should point to.
406 */
Mady Mellor3dff9e62019-02-05 18:12:53 -0800407 public void setPointerPosition(float x) {
Mady Mellordea7ecf2018-12-10 15:47:40 -0800408 // Adjust for the pointer size
Mady Mellor3dff9e62019-02-05 18:12:53 -0800409 x -= (mPointerView.getWidth() / 2f);
Mady Mellordea7ecf2018-12-10 15:47:40 -0800410 mPointerView.setTranslationX(x);
411 }
412
413 /**
Mady Mellor3dff9e62019-02-05 18:12:53 -0800414 * Removes and releases an ActivityView if one was previously created for this bubble.
Mady Mellordea7ecf2018-12-10 15:47:40 -0800415 */
Mady Mellor3dff9e62019-02-05 18:12:53 -0800416 public void destroyActivityView(ViewGroup tmpParent) {
417 if (mActivityView == null) {
Mark Renouf89b1a4a2018-12-04 14:59:45 -0500418 return;
419 }
Mady Mellor3dff9e62019-02-05 18:12:53 -0800420 if (!mActivityViewReady) {
421 // release not needed, never initialized?
422 mActivityView = null;
423 return;
Mady Mellordea7ecf2018-12-10 15:47:40 -0800424 }
Mady Mellor3dff9e62019-02-05 18:12:53 -0800425 // HACK: release() will crash if the view is not attached.
426 if (!isAttachedToWindow()) {
427 mActivityView.setVisibility(View.GONE);
428 tmpParent.addView(this);
Mady Mellordea7ecf2018-12-10 15:47:40 -0800429 }
Mady Mellor3dff9e62019-02-05 18:12:53 -0800430
431 mActivityView.release();
432 ((ViewGroup) getParent()).removeView(this);
433 mActivityView = null;
434 mActivityViewReady = false;
Mady Mellordea7ecf2018-12-10 15:47:40 -0800435 }
436
Mady Mellor3dff9e62019-02-05 18:12:53 -0800437 private boolean usingActivityView() {
438 return mBubbleIntent != null;
439 }
440
441 private void applyRowState(ExpandableNotificationRow view) {
442 view.reset();
443 view.setHeadsUp(false);
444 view.resetTranslation();
445 view.setOnKeyguard(false);
446 view.setOnAmbient(false);
447 view.setClipBottomAmount(0);
448 view.setClipTopAmount(0);
449 view.setContentTransformationAmount(0, false);
450 view.setIconsVisible(true);
451
452 // TODO - Need to reset this (and others) when view goes back in shade, leave for now
453 // view.setTopRoundness(1, false);
454 // view.setBottomRoundness(1, false);
455
456 ExpandableViewState viewState = view.getViewState();
457 viewState = viewState == null ? new ExpandableViewState() : viewState;
458 viewState.height = view.getIntrinsicHeight();
459 viewState.gone = false;
460 viewState.hidden = false;
461 viewState.dimmed = false;
462 viewState.dark = false;
463 viewState.alpha = 1f;
464 viewState.notGoneIndex = -1;
465 viewState.xTranslation = 0;
466 viewState.yTranslation = 0;
467 viewState.zTranslation = 0;
468 viewState.scaleX = 1;
469 viewState.scaleY = 1;
470 viewState.inShelf = true;
471 viewState.headsUpIsVisible = false;
472 viewState.applyToView(view);
Mady Mellordea7ecf2018-12-10 15:47:40 -0800473 }
Mady Mellor9801e852019-01-22 14:50:28 -0800474
475 private Intent getSettingsIntent(String packageName, final int appUid) {
476 final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
477 intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName);
478 intent.putExtra(Settings.EXTRA_APP_UID, appUid);
479 intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
480 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
481 return intent;
482 }
Mady Mellore8e07712019-01-23 12:45:33 -0800483
Mady Mellor3dff9e62019-02-05 18:12:53 -0800484 @Nullable
485 private PendingIntent getBubbleIntent(NotificationEntry entry) {
486 Notification notif = entry.notification.getNotification();
487 String packageName = entry.notification.getPackageName();
488 Notification.BubbleMetadata data = notif.getBubbleMetadata();
489 if (data != null && canLaunchInActivityView(data.getIntent(), true /* enableLogging */,
490 packageName)) {
491 return data.getIntent();
492 } else if (BubbleController.shouldUseContentIntent(mContext)
493 && canLaunchInActivityView(notif.contentIntent, false /* enableLogging */,
494 packageName)) {
495 return notif.contentIntent;
496 }
497 return null;
498 }
499
500 /**
501 * Whether an intent is properly configured to display in an {@link android.app.ActivityView}.
502 *
503 * @param intent the pending intent of the bubble.
504 * @param enableLogging whether bubble developer error should be logged.
505 * @param packageName the notification package name for this bubble.
506 * @return
507 */
508 private boolean canLaunchInActivityView(PendingIntent intent, boolean enableLogging,
509 String packageName) {
510 if (intent == null) {
511 return false;
512 }
513 ActivityInfo info =
514 intent.getIntent().resolveActivityInfo(mContext.getPackageManager(), 0);
515 if (info == null) {
516 if (enableLogging) {
517 StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName,
518 BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_MISSING);
519 }
520 return false;
521 }
522 if (!ActivityInfo.isResizeableMode(info.resizeMode)) {
523 if (enableLogging) {
524 StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName,
525 BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_NOT_RESIZABLE);
526 }
527 return false;
528 }
529 if (info.documentLaunchMode != DOCUMENT_LAUNCH_ALWAYS) {
530 if (enableLogging) {
531 StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName,
532 BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__DOCUMENT_LAUNCH_NOT_ALWAYS);
533 }
534 return false;
535 }
536 return (info.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) != 0;
537 }
538
Mady Mellore8e07712019-01-23 12:45:33 -0800539 /**
540 * Listener that is notified when a bubble is blocked.
541 */
542 public interface OnBubbleBlockedListener {
543 /**
544 * Called when a bubble is blocked for the provided entry.
545 */
546 void onBubbleBlocked(NotificationEntry entry);
547 }
Steven Wub00225b2019-02-08 14:27:42 -0500548
549 /**
550 * Logs bubble UI click event.
551 *
552 * @param notification the bubble notification that user is interacting with.
553 * @param action the user interaction enum.
554 */
555 private void logBubbleClickEvent(StatusBarNotification notification, int action) {
556 StatsLog.write(StatsLog.BUBBLE_UI_CHANGED,
557 notification.getPackageName(),
558 notification.getNotification().getChannelId(),
559 notification.getId(),
560 mStackView.getBubbleIndex(mStackView.getExpandedBubble()),
561 mStackView.getBubbleCount(),
562 action,
563 mStackView.getNormalizedXPosition(),
564 mStackView.getNormalizedYPosition());
565 }
Mady Mellordea7ecf2018-12-10 15:47:40 -0800566}