Merge "Add package name to screenshot from overview" into sc-v2-dev am: a5cf02a4b9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15984245

Change-Id: I00f7377ca40ab1b7056e263155ff4bc2e216409d
This commit is contained in:
Miranda Kephart
2021-11-08 16:14:34 +00:00
committed by Automerger Merge Worker
3 changed files with 42 additions and 25 deletions

View File

@@ -266,6 +266,7 @@ public class ScreenshotController {
private Animator mScreenshotAnimation; private Animator mScreenshotAnimation;
private RequestCallback mCurrentRequestCallback; private RequestCallback mCurrentRequestCallback;
private String mPackageName = "";
private final Handler mScreenshotHandler = new Handler(Looper.getMainLooper()) { private final Handler mScreenshotHandler = new Handler(Looper.getMainLooper()) {
@Override @Override
@@ -275,7 +276,8 @@ public class ScreenshotController {
if (DEBUG_UI) { if (DEBUG_UI) {
Log.d(TAG, "Corner timeout hit"); Log.d(TAG, "Corner timeout hit");
} }
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_INTERACTION_TIMEOUT); mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_INTERACTION_TIMEOUT, 0,
mPackageName);
ScreenshotController.this.dismissScreenshot(false); ScreenshotController.this.dismissScreenshot(false);
break; break;
default: default:
@@ -354,12 +356,13 @@ public class ScreenshotController {
mCameraSound.load(MediaActionSound.SHUTTER_CLICK); mCameraSound.load(MediaActionSound.SHUTTER_CLICK);
} }
void takeScreenshotFullscreen(Consumer<Uri> finisher, RequestCallback requestCallback) { void takeScreenshotFullscreen(ComponentName topComponent, Consumer<Uri> finisher,
RequestCallback requestCallback) {
mCurrentRequestCallback = requestCallback; mCurrentRequestCallback = requestCallback;
DisplayMetrics displayMetrics = new DisplayMetrics(); DisplayMetrics displayMetrics = new DisplayMetrics();
getDefaultDisplay().getRealMetrics(displayMetrics); getDefaultDisplay().getRealMetrics(displayMetrics);
takeScreenshotInternal( takeScreenshotInternal(
finisher, topComponent, finisher,
new Rect(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels)); new Rect(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels));
} }
@@ -383,13 +386,15 @@ public class ScreenshotController {
screenshotScreenBounds.set(0, 0, screenshot.getWidth(), screenshot.getHeight()); screenshotScreenBounds.set(0, 0, screenshot.getWidth(), screenshot.getHeight());
} }
mCurrentRequestCallback = requestCallback; mCurrentRequestCallback = requestCallback;
saveScreenshot(screenshot, finisher, screenshotScreenBounds, visibleInsets, showFlash); saveScreenshot(screenshot, finisher, screenshotScreenBounds, visibleInsets, topComponent,
showFlash);
} }
/** /**
* Displays a screenshot selector * Displays a screenshot selector
*/ */
void takeScreenshotPartial(final Consumer<Uri> finisher, RequestCallback requestCallback) { void takeScreenshotPartial(ComponentName topComponent,
final Consumer<Uri> finisher, RequestCallback requestCallback) {
mScreenshotView.reset(); mScreenshotView.reset();
mCurrentRequestCallback = requestCallback; mCurrentRequestCallback = requestCallback;
@@ -398,7 +403,7 @@ public class ScreenshotController {
mScreenshotView.requestApplyInsets(); mScreenshotView.requestApplyInsets();
mScreenshotView.takePartialScreenshot( mScreenshotView.takePartialScreenshot(
rect -> takeScreenshotInternal(finisher, rect)); rect -> takeScreenshotInternal(topComponent, finisher, rect));
} }
/** /**
@@ -491,7 +496,8 @@ public class ScreenshotController {
/** /**
* Takes a screenshot of the current display and shows an animation. * Takes a screenshot of the current display and shows an animation.
*/ */
private void takeScreenshotInternal(Consumer<Uri> finisher, Rect crop) { private void takeScreenshotInternal(ComponentName topComponent, Consumer<Uri> finisher,
Rect crop) {
mScreenshotTakenInPortrait = mScreenshotTakenInPortrait =
mContext.getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT; mContext.getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT;
@@ -509,7 +515,7 @@ public class ScreenshotController {
return; return;
} }
saveScreenshot(screenshot, finisher, screenRect, Insets.NONE, true); saveScreenshot(screenshot, finisher, screenRect, Insets.NONE, topComponent, true);
} }
private Bitmap captureScreenshot(Rect crop) { private Bitmap captureScreenshot(Rect crop) {
@@ -539,7 +545,7 @@ public class ScreenshotController {
} }
private void saveScreenshot(Bitmap screenshot, Consumer<Uri> finisher, Rect screenRect, private void saveScreenshot(Bitmap screenshot, Consumer<Uri> finisher, Rect screenRect,
Insets screenInsets, boolean showFlash) { Insets screenInsets, ComponentName topComponent, boolean showFlash) {
if (mAccessibilityManager.isEnabled()) { if (mAccessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent event =
new AccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); new AccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
@@ -552,7 +558,7 @@ public class ScreenshotController {
if (mScreenshotView.isAttachedToWindow()) { if (mScreenshotView.isAttachedToWindow()) {
// if we didn't already dismiss for another reason // if we didn't already dismiss for another reason
if (!mScreenshotView.isDismissing()) { if (!mScreenshotView.isDismissing()) {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_REENTERED); mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_REENTERED, 0, mPackageName);
} }
if (DEBUG_WINDOW) { if (DEBUG_WINDOW) {
Log.d(TAG, "saveScreenshot: screenshotView is already attached, resetting. " Log.d(TAG, "saveScreenshot: screenshotView is already attached, resetting. "
@@ -560,6 +566,8 @@ public class ScreenshotController {
} }
mScreenshotView.reset(); mScreenshotView.reset();
} }
mPackageName = topComponent == null ? "" : topComponent.getPackageName();
mScreenshotView.setPackageName(mPackageName);
mScreenshotView.updateOrientation( mScreenshotView.updateOrientation(
mWindowManager.getCurrentWindowMetrics().getWindowInsets()); mWindowManager.getCurrentWindowMetrics().getWindowInsets());
@@ -790,11 +798,11 @@ public class ScreenshotController {
} }
finisher.accept(imageData.uri); finisher.accept(imageData.uri);
if (imageData.uri == null) { if (imageData.uri == null) {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_NOT_SAVED); mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_NOT_SAVED, 0, mPackageName);
mNotificationsController.notifyScreenshotError( mNotificationsController.notifyScreenshotError(
R.string.screenshot_failed_to_save_text); R.string.screenshot_failed_to_save_text);
} else { } else {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SAVED); mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SAVED, 0, mPackageName);
mScreenshotHandler.post(() -> Toast.makeText(mContext, mScreenshotHandler.post(() -> Toast.makeText(mContext,
R.string.screenshot_saved_title, Toast.LENGTH_SHORT).show()); R.string.screenshot_saved_title, Toast.LENGTH_SHORT).show());
} }
@@ -959,11 +967,11 @@ public class ScreenshotController {
*/ */
private void logSuccessOnActionsReady(ScreenshotController.SavedImageData imageData) { private void logSuccessOnActionsReady(ScreenshotController.SavedImageData imageData) {
if (imageData.uri == null) { if (imageData.uri == null) {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_NOT_SAVED); mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_NOT_SAVED, 0, mPackageName);
mNotificationsController.notifyScreenshotError( mNotificationsController.notifyScreenshotError(
R.string.screenshot_failed_to_save_text); R.string.screenshot_failed_to_save_text);
} else { } else {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SAVED); mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SAVED, 0, mPackageName);
} }
} }

View File

@@ -163,6 +163,7 @@ public class ScreenshotView extends FrameLayout implements
private SwipeDismissHandler mSwipeDismissHandler; private SwipeDismissHandler mSwipeDismissHandler;
private InputMonitorCompat mInputMonitor; private InputMonitorCompat mInputMonitor;
private boolean mShowScrollablePreview; private boolean mShowScrollablePreview;
private String mPackageName = "";
private final ArrayList<ScreenshotActionChip> mSmartChips = new ArrayList<>(); private final ArrayList<ScreenshotActionChip> mSmartChips = new ArrayList<>();
private PendingInteraction mPendingInteraction; private PendingInteraction mPendingInteraction;
@@ -409,6 +410,10 @@ public class ScreenshotView extends FrameLayout implements
mScreenshotPreview.setImageDrawable(createScreenDrawable(mResources, bitmap, screenInsets)); mScreenshotPreview.setImageDrawable(createScreenDrawable(mResources, bitmap, screenInsets));
} }
void setPackageName(String packageName) {
mPackageName = packageName;
}
void updateInsets(WindowInsets insets) { void updateInsets(WindowInsets insets) {
int orientation = mContext.getResources().getConfiguration().orientation; int orientation = mContext.getResources().getConfiguration().orientation;
mOrientationPortrait = (orientation == ORIENTATION_PORTRAIT); mOrientationPortrait = (orientation == ORIENTATION_PORTRAIT);
@@ -585,7 +590,8 @@ public class ScreenshotView extends FrameLayout implements
if (DEBUG_INPUT) { if (DEBUG_INPUT) {
Log.d(TAG, "dismiss button clicked"); Log.d(TAG, "dismiss button clicked");
} }
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_EXPLICIT_DISMISSAL); mUiEventLogger.log(
ScreenshotEvent.SCREENSHOT_EXPLICIT_DISMISSAL, 0, mPackageName);
animateDismissal(); animateDismissal();
}); });
mDismissButton.setAlpha(1); mDismissButton.setAlpha(1);
@@ -698,24 +704,25 @@ public class ScreenshotView extends FrameLayout implements
void setChipIntents(ScreenshotController.SavedImageData imageData) { void setChipIntents(ScreenshotController.SavedImageData imageData) {
mShareChip.setOnClickListener(v -> { mShareChip.setOnClickListener(v -> {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SHARE_TAPPED); mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SHARE_TAPPED, 0, mPackageName);
startSharedTransition( startSharedTransition(
imageData.shareTransition.get()); imageData.shareTransition.get());
}); });
mEditChip.setOnClickListener(v -> { mEditChip.setOnClickListener(v -> {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_EDIT_TAPPED); mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_EDIT_TAPPED, 0, mPackageName);
startSharedTransition( startSharedTransition(
imageData.editTransition.get()); imageData.editTransition.get());
}); });
mScreenshotPreview.setOnClickListener(v -> { mScreenshotPreview.setOnClickListener(v -> {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_PREVIEW_TAPPED); mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_PREVIEW_TAPPED, 0, mPackageName);
startSharedTransition( startSharedTransition(
imageData.editTransition.get()); imageData.editTransition.get());
}); });
if (mQuickShareChip != null) { if (mQuickShareChip != null) {
mQuickShareChip.setPendingIntent(imageData.quickShareAction.actionIntent, mQuickShareChip.setPendingIntent(imageData.quickShareAction.actionIntent,
() -> { () -> {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SMART_ACTION_TAPPED); mUiEventLogger.log(
ScreenshotEvent.SCREENSHOT_SMART_ACTION_TAPPED, 0, mPackageName);
animateDismissal(); animateDismissal();
}); });
} }
@@ -745,7 +752,8 @@ public class ScreenshotView extends FrameLayout implements
actionChip.setIcon(smartAction.getIcon(), false); actionChip.setIcon(smartAction.getIcon(), false);
actionChip.setPendingIntent(smartAction.actionIntent, actionChip.setPendingIntent(smartAction.actionIntent,
() -> { () -> {
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SMART_ACTION_TAPPED); mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SMART_ACTION_TAPPED,
0, mPackageName);
animateDismissal(); animateDismissal();
}); });
actionChip.setAlpha(1); actionChip.setAlpha(1);
@@ -1121,7 +1129,7 @@ public class ScreenshotView extends FrameLayout implements
if (DEBUG_INPUT) { if (DEBUG_INPUT) {
Log.d(TAG, "dismiss triggered via swipe gesture"); Log.d(TAG, "dismiss triggered via swipe gesture");
} }
mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SWIPE_DISMISSED); mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_SWIPE_DISMISSED, 0, mPackageName);
animateDismissal(createSwipeDismissAnimation()); animateDismissal(createSwipeDismissAnimation());
} else { } else {
// if we've moved, but not past the threshold, start the return animation // if we've moved, but not past the threshold, start the return animation

View File

@@ -186,20 +186,22 @@ public class TakeScreenshotService extends Service {
ScreenshotHelper.ScreenshotRequest screenshotRequest = ScreenshotHelper.ScreenshotRequest screenshotRequest =
(ScreenshotHelper.ScreenshotRequest) msg.obj; (ScreenshotHelper.ScreenshotRequest) msg.obj;
mUiEventLogger.log(ScreenshotEvent.getScreenshotSource(screenshotRequest.getSource())); ComponentName topComponent = screenshotRequest.getTopComponent();
mUiEventLogger.log(ScreenshotEvent.getScreenshotSource(screenshotRequest.getSource()), 0,
topComponent == null ? "" : topComponent.getPackageName());
switch (msg.what) { switch (msg.what) {
case WindowManager.TAKE_SCREENSHOT_FULLSCREEN: case WindowManager.TAKE_SCREENSHOT_FULLSCREEN:
if (DEBUG_SERVICE) { if (DEBUG_SERVICE) {
Log.d(TAG, "handleMessage: TAKE_SCREENSHOT_FULLSCREEN"); Log.d(TAG, "handleMessage: TAKE_SCREENSHOT_FULLSCREEN");
} }
mScreenshot.takeScreenshotFullscreen(uriConsumer, requestCallback); mScreenshot.takeScreenshotFullscreen(topComponent, uriConsumer, requestCallback);
break; break;
case WindowManager.TAKE_SCREENSHOT_SELECTED_REGION: case WindowManager.TAKE_SCREENSHOT_SELECTED_REGION:
if (DEBUG_SERVICE) { if (DEBUG_SERVICE) {
Log.d(TAG, "handleMessage: TAKE_SCREENSHOT_SELECTED_REGION"); Log.d(TAG, "handleMessage: TAKE_SCREENSHOT_SELECTED_REGION");
} }
mScreenshot.takeScreenshotPartial(uriConsumer, requestCallback); mScreenshot.takeScreenshotPartial(topComponent, uriConsumer, requestCallback);
break; break;
case WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE: case WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE:
if (DEBUG_SERVICE) { if (DEBUG_SERVICE) {
@@ -211,7 +213,6 @@ public class TakeScreenshotService extends Service {
Insets insets = screenshotRequest.getInsets(); Insets insets = screenshotRequest.getInsets();
int taskId = screenshotRequest.getTaskId(); int taskId = screenshotRequest.getTaskId();
int userId = screenshotRequest.getUserId(); int userId = screenshotRequest.getUserId();
ComponentName topComponent = screenshotRequest.getTopComponent();
if (screenshot == null) { if (screenshot == null) {
Log.e(TAG, "Got null bitmap from screenshot message"); Log.e(TAG, "Got null bitmap from screenshot message");