blob: 38456eb4a096b5ede337319991efee4791cf939a [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);
Steven Wua62cb6a2019-02-15 17:12:51 -0500307 logBubbleClickEvent(mEntry.notification,
308 StatsLog.BUBBLE_UICHANGED__ACTION__PERMISSION_DIALOG_SHOWN);
Mady Mellor9801e852019-01-22 14:50:28 -0800309 }
310 }
311
Mady Mellor3dff9e62019-02-05 18:12:53 -0800312 private void updateExpandedView() {
313 mBubbleIntent = getBubbleIntent(mEntry);
314 if (mBubbleIntent != null) {
315 if (mNotifRow != null) {
316 // Clear out the row if we had it previously
317 removeView(mNotifRow);
318 mNotifRow = null;
319 }
320 Notification.BubbleMetadata data = mEntry.getBubbleMetadata();
321 mBubbleHeight = data != null && data.getDesiredHeight() > 0
322 ? data.getDesiredHeight()
323 : mDefaultHeight;
324 // XXX: enforce max / min height
325 LayoutParams lp = (LayoutParams) mActivityView.getLayoutParams();
326 lp.height = mBubbleHeight;
327 mActivityView.setLayoutParams(lp);
328 mActivityView.setVisibility(VISIBLE);
329 } else {
330 // Hide activity view if we had it previously
331 mActivityView.setVisibility(GONE);
332
333 // Use notification view
334 mNotifRow = mEntry.getRow();
335 addView(mNotifRow);
336 }
337 updateView();
338 }
339
Mady Mellor9801e852019-01-22 14:50:28 -0800340 @Override
341 public void onClick(View view) {
342 if (mEntry == null) {
343 return;
344 }
345 Notification n = mEntry.notification.getNotification();
346 int id = view.getId();
347 if (id == R.id.deep_link_button) {
348 mStackView.collapseStack(() -> {
349 try {
350 n.contentIntent.send();
Steven Wub00225b2019-02-08 14:27:42 -0500351 logBubbleClickEvent(mEntry.notification,
352 StatsLog.BUBBLE_UICHANGED__ACTION__HEADER_GO_TO_APP);
Mady Mellor9801e852019-01-22 14:50:28 -0800353 } catch (PendingIntent.CanceledException e) {
354 Log.w(TAG, "Failed to send intent for bubble with key: "
355 + (mEntry != null ? mEntry.key : " null entry"));
356 }
357 });
358 } else if (id == R.id.settings_button) {
359 Intent intent = getSettingsIntent(mEntry.notification.getPackageName(),
360 mEntry.notification.getUid());
Steven Wub00225b2019-02-08 14:27:42 -0500361 mStackView.collapseStack(() -> {
362 mContext.startActivity(intent);
363 logBubbleClickEvent(mEntry.notification,
364 StatsLog.BUBBLE_UICHANGED__ACTION__HEADER_GO_TO_SETTINGS);
365 });
Mady Mellore8e07712019-01-23 12:45:33 -0800366 } else if (id == R.id.no_bubbles_button) {
367 setBubblesAllowed(false);
368 } else if (id == R.id.yes_bubbles_button) {
369 setBubblesAllowed(true);
370 }
371 }
372
373 private void setBubblesAllowed(boolean allowed) {
374 try {
375 mNotificationManagerService.setBubblesAllowed(
376 mEntry.notification.getPackageName(),
377 mEntry.notification.getUid(),
378 allowed);
379 if (allowed) {
380 mPermissionView.setVisibility(GONE);
381 mHeaderView.setVisibility(VISIBLE);
382 } else if (mOnBubbleBlockedListener != null) {
383 mOnBubbleBlockedListener.onBubbleBlocked(mEntry);
384 }
Steven Wub00225b2019-02-08 14:27:42 -0500385 logBubbleClickEvent(mEntry.notification,
386 allowed ? StatsLog.BUBBLE_UICHANGED__ACTION__PERMISSION_OPT_IN :
387 StatsLog.BUBBLE_UICHANGED__ACTION__PERMISSION_OPT_OUT);
Mady Mellore8e07712019-01-23 12:45:33 -0800388 } catch (RemoteException e) {
389 Log.w(TAG, e);
Mady Mellor9801e852019-01-22 14:50:28 -0800390 }
Mady Mellordea7ecf2018-12-10 15:47:40 -0800391 }
392
393 /**
Mady Mellor3dff9e62019-02-05 18:12:53 -0800394 * Update appearance of the expanded view being displayed.
395 */
396 public void updateView() {
397 if (usingActivityView()
398 && mActivityView.getVisibility() == VISIBLE
399 && mActivityView.isAttachedToWindow()) {
400 mActivityView.onLocationChanged();
401 } else if (mNotifRow != null) {
402 applyRowState(mNotifRow);
403 }
404 }
405
406 /**
Mady Mellordea7ecf2018-12-10 15:47:40 -0800407 * Set the x position that the tip of the triangle should point to.
408 */
Mady Mellor3dff9e62019-02-05 18:12:53 -0800409 public void setPointerPosition(float x) {
Mady Mellordea7ecf2018-12-10 15:47:40 -0800410 // Adjust for the pointer size
Mady Mellor3dff9e62019-02-05 18:12:53 -0800411 x -= (mPointerView.getWidth() / 2f);
Mady Mellordea7ecf2018-12-10 15:47:40 -0800412 mPointerView.setTranslationX(x);
413 }
414
415 /**
Mady Mellor3dff9e62019-02-05 18:12:53 -0800416 * Removes and releases an ActivityView if one was previously created for this bubble.
Mady Mellordea7ecf2018-12-10 15:47:40 -0800417 */
Mady Mellor3dff9e62019-02-05 18:12:53 -0800418 public void destroyActivityView(ViewGroup tmpParent) {
419 if (mActivityView == null) {
Mark Renouf89b1a4a2018-12-04 14:59:45 -0500420 return;
421 }
Mady Mellor3dff9e62019-02-05 18:12:53 -0800422 if (!mActivityViewReady) {
423 // release not needed, never initialized?
424 mActivityView = null;
425 return;
Mady Mellordea7ecf2018-12-10 15:47:40 -0800426 }
Mady Mellor3dff9e62019-02-05 18:12:53 -0800427 // HACK: release() will crash if the view is not attached.
428 if (!isAttachedToWindow()) {
429 mActivityView.setVisibility(View.GONE);
430 tmpParent.addView(this);
Mady Mellordea7ecf2018-12-10 15:47:40 -0800431 }
Mady Mellor3dff9e62019-02-05 18:12:53 -0800432
433 mActivityView.release();
434 ((ViewGroup) getParent()).removeView(this);
435 mActivityView = null;
436 mActivityViewReady = false;
Mady Mellordea7ecf2018-12-10 15:47:40 -0800437 }
438
Mady Mellor3dff9e62019-02-05 18:12:53 -0800439 private boolean usingActivityView() {
440 return mBubbleIntent != null;
441 }
442
443 private void applyRowState(ExpandableNotificationRow view) {
444 view.reset();
445 view.setHeadsUp(false);
446 view.resetTranslation();
447 view.setOnKeyguard(false);
448 view.setOnAmbient(false);
449 view.setClipBottomAmount(0);
450 view.setClipTopAmount(0);
451 view.setContentTransformationAmount(0, false);
452 view.setIconsVisible(true);
453
454 // TODO - Need to reset this (and others) when view goes back in shade, leave for now
455 // view.setTopRoundness(1, false);
456 // view.setBottomRoundness(1, false);
457
458 ExpandableViewState viewState = view.getViewState();
459 viewState = viewState == null ? new ExpandableViewState() : viewState;
460 viewState.height = view.getIntrinsicHeight();
461 viewState.gone = false;
462 viewState.hidden = false;
463 viewState.dimmed = false;
464 viewState.dark = false;
465 viewState.alpha = 1f;
466 viewState.notGoneIndex = -1;
467 viewState.xTranslation = 0;
468 viewState.yTranslation = 0;
469 viewState.zTranslation = 0;
470 viewState.scaleX = 1;
471 viewState.scaleY = 1;
472 viewState.inShelf = true;
473 viewState.headsUpIsVisible = false;
474 viewState.applyToView(view);
Mady Mellordea7ecf2018-12-10 15:47:40 -0800475 }
Mady Mellor9801e852019-01-22 14:50:28 -0800476
477 private Intent getSettingsIntent(String packageName, final int appUid) {
478 final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
479 intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName);
480 intent.putExtra(Settings.EXTRA_APP_UID, appUid);
481 intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
482 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
483 return intent;
484 }
Mady Mellore8e07712019-01-23 12:45:33 -0800485
Mady Mellor3dff9e62019-02-05 18:12:53 -0800486 @Nullable
487 private PendingIntent getBubbleIntent(NotificationEntry entry) {
488 Notification notif = entry.notification.getNotification();
489 String packageName = entry.notification.getPackageName();
490 Notification.BubbleMetadata data = notif.getBubbleMetadata();
491 if (data != null && canLaunchInActivityView(data.getIntent(), true /* enableLogging */,
492 packageName)) {
493 return data.getIntent();
494 } else if (BubbleController.shouldUseContentIntent(mContext)
495 && canLaunchInActivityView(notif.contentIntent, false /* enableLogging */,
496 packageName)) {
497 return notif.contentIntent;
498 }
499 return null;
500 }
501
502 /**
503 * Whether an intent is properly configured to display in an {@link android.app.ActivityView}.
504 *
505 * @param intent the pending intent of the bubble.
506 * @param enableLogging whether bubble developer error should be logged.
507 * @param packageName the notification package name for this bubble.
508 * @return
509 */
510 private boolean canLaunchInActivityView(PendingIntent intent, boolean enableLogging,
511 String packageName) {
512 if (intent == null) {
513 return false;
514 }
515 ActivityInfo info =
516 intent.getIntent().resolveActivityInfo(mContext.getPackageManager(), 0);
517 if (info == null) {
518 if (enableLogging) {
519 StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName,
520 BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_MISSING);
521 }
522 return false;
523 }
524 if (!ActivityInfo.isResizeableMode(info.resizeMode)) {
525 if (enableLogging) {
526 StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName,
527 BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_NOT_RESIZABLE);
528 }
529 return false;
530 }
531 if (info.documentLaunchMode != DOCUMENT_LAUNCH_ALWAYS) {
532 if (enableLogging) {
533 StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName,
534 BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__DOCUMENT_LAUNCH_NOT_ALWAYS);
535 }
536 return false;
537 }
538 return (info.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) != 0;
539 }
540
Mady Mellore8e07712019-01-23 12:45:33 -0800541 /**
542 * Listener that is notified when a bubble is blocked.
543 */
544 public interface OnBubbleBlockedListener {
545 /**
546 * Called when a bubble is blocked for the provided entry.
547 */
548 void onBubbleBlocked(NotificationEntry entry);
549 }
Steven Wub00225b2019-02-08 14:27:42 -0500550
551 /**
552 * Logs bubble UI click event.
553 *
554 * @param notification the bubble notification that user is interacting with.
555 * @param action the user interaction enum.
556 */
557 private void logBubbleClickEvent(StatusBarNotification notification, int action) {
558 StatsLog.write(StatsLog.BUBBLE_UI_CHANGED,
559 notification.getPackageName(),
560 notification.getNotification().getChannelId(),
561 notification.getId(),
562 mStackView.getBubbleIndex(mStackView.getExpandedBubble()),
563 mStackView.getBubbleCount(),
564 action,
565 mStackView.getNormalizedXPosition(),
566 mStackView.getNormalizedYPosition());
567 }
Mady Mellordea7ecf2018-12-10 15:47:40 -0800568}