Merge "[DO NOT MERGE] Make GlobalScreenshot PendingIntents immutable" into oc-mr1-dev

This commit is contained in:
Miranda Kephart
2020-11-09 18:28:56 +00:00
committed by Android (Google) Code Review

View File

@@ -100,6 +100,7 @@ class SaveImageInBackgroundData {
imageUri = null; imageUri = null;
iconSize = 0; iconSize = 0;
} }
void clearContext() { void clearContext() {
context = null; context = null;
} }
@@ -348,7 +349,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
mPublicNotificationBuilder mPublicNotificationBuilder
.setContentTitle(r.getString(R.string.screenshot_saved_title)) .setContentTitle(r.getString(R.string.screenshot_saved_title))
.setContentText(r.getString(R.string.screenshot_saved_text)) .setContentText(r.getString(R.string.screenshot_saved_text))
.setContentIntent(PendingIntent.getActivity(mParams.context, 0, launchIntent, 0)) .setContentIntent(PendingIntent.getActivity(mParams.context, 0, launchIntent,
PendingIntent.FLAG_IMMUTABLE))
.setWhen(now) .setWhen(now)
.setAutoCancel(true) .setAutoCancel(true)
.setColor(context.getColor( .setColor(context.getColor(
@@ -356,7 +358,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
mNotificationBuilder mNotificationBuilder
.setContentTitle(r.getString(R.string.screenshot_saved_title)) .setContentTitle(r.getString(R.string.screenshot_saved_title))
.setContentText(r.getString(R.string.screenshot_saved_text)) .setContentText(r.getString(R.string.screenshot_saved_text))
.setContentIntent(PendingIntent.getActivity(mParams.context, 0, launchIntent, 0)) .setContentIntent(PendingIntent.getActivity(mParams.context, 0, launchIntent,
PendingIntent.FLAG_IMMUTABLE))
.setWhen(now) .setWhen(now)
.setAutoCancel(true) .setAutoCancel(true)
.setColor(context.getColor( .setColor(context.getColor(
@@ -463,7 +466,8 @@ class GlobalScreenshot {
// Inflate the screenshot layout // Inflate the screenshot layout
mDisplayMatrix = new Matrix(); mDisplayMatrix = new Matrix();
mScreenshotLayout = layoutInflater.inflate(R.layout.global_screenshot, null); mScreenshotLayout = layoutInflater.inflate(R.layout.global_screenshot, null);
mBackgroundView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_background); mBackgroundView = (ImageView) mScreenshotLayout.findViewById(
R.id.global_screenshot_background);
mScreenshotView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot); mScreenshotView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot);
mScreenshotFlash = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_flash); mScreenshotFlash = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_flash);
mScreenshotSelectorView = (ScreenshotSelectorView) mScreenshotLayout.findViewById( mScreenshotSelectorView = (ScreenshotSelectorView) mScreenshotLayout.findViewById(
@@ -491,6 +495,7 @@ class GlobalScreenshot {
mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mNotificationManager = mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mDisplay = mWindowManager.getDefaultDisplay(); mDisplay = mWindowManager.getDefaultDisplay();
mDisplayMetrics = new DisplayMetrics(); mDisplayMetrics = new DisplayMetrics();
mDisplay.getRealMetrics(mDisplayMetrics); mDisplay.getRealMetrics(mDisplayMetrics);
@@ -735,6 +740,7 @@ class GlobalScreenshot {
} }
}); });
} }
private ValueAnimator createScreenshotDropInAnimation() { private ValueAnimator createScreenshotDropInAnimation() {
final float flashPeakDurationPct = ((float) (SCREENSHOT_FLASH_TO_PEAK_DURATION) final float flashPeakDurationPct = ((float) (SCREENSHOT_FLASH_TO_PEAK_DURATION)
/ SCREENSHOT_DROP_IN_DURATION); / SCREENSHOT_DROP_IN_DURATION);
@@ -775,6 +781,7 @@ class GlobalScreenshot {
mScreenshotFlash.setAlpha(0f); mScreenshotFlash.setAlpha(0f);
mScreenshotFlash.setVisibility(View.VISIBLE); mScreenshotFlash.setVisibility(View.VISIBLE);
} }
@Override @Override
public void onAnimationEnd(android.animation.Animator animation) { public void onAnimationEnd(android.animation.Animator animation) {
mScreenshotFlash.setVisibility(View.GONE); mScreenshotFlash.setVisibility(View.GONE);
@@ -796,6 +803,7 @@ class GlobalScreenshot {
}); });
return anim; return anim;
} }
private ValueAnimator createScreenshotDropOutAnimation(int w, int h, boolean statusBarVisible, private ValueAnimator createScreenshotDropOutAnimation(int w, int h, boolean statusBarVisible,
boolean navBarVisible) { boolean navBarVisible) {
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f); ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
@@ -817,7 +825,8 @@ class GlobalScreenshot {
public void onAnimationUpdate(ValueAnimator animation) { public void onAnimationUpdate(ValueAnimator animation) {
float t = (Float) animation.getAnimatedValue(); float t = (Float) animation.getAnimatedValue();
float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale) float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale)
- t * (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_FAST_DROP_OUT_MIN_SCALE); - t * (SCREENSHOT_DROP_IN_MIN_SCALE
- SCREENSHOT_FAST_DROP_OUT_MIN_SCALE);
mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA); mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
mScreenshotView.setAlpha(1f - t); mScreenshotView.setAlpha(1f - t);
mScreenshotView.setScaleX(scaleT); mScreenshotView.setScaleX(scaleT);
@@ -844,8 +853,10 @@ class GlobalScreenshot {
float halfScreenHeight = (h - 2f * mBgPadding) / 2f; float halfScreenHeight = (h - 2f * mBgPadding) / 2f;
final float offsetPct = SCREENSHOT_DROP_OUT_MIN_SCALE_OFFSET; final float offsetPct = SCREENSHOT_DROP_OUT_MIN_SCALE_OFFSET;
final PointF finalPos = new PointF( final PointF finalPos = new PointF(
-halfScreenWidth + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenWidth, -halfScreenWidth
-halfScreenHeight + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenHeight); + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenWidth,
-halfScreenHeight
+ (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenHeight);
// Animate the screenshot to the status bar // Animate the screenshot to the status bar
anim.setDuration(SCREENSHOT_DROP_OUT_DURATION); anim.setDuration(SCREENSHOT_DROP_OUT_DURATION);
@@ -890,7 +901,7 @@ class GlobalScreenshot {
DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE); DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE);
if (intent != null) { if (intent != null) {
final PendingIntent pendingIntent = PendingIntent.getActivityAsUser( final PendingIntent pendingIntent = PendingIntent.getActivityAsUser(
context, 0, intent, 0, null, UserHandle.CURRENT); context, 0, intent, PendingIntent.FLAG_IMMUTABLE, null, UserHandle.CURRENT);
b.setContentIntent(pendingIntent); b.setContentIntent(pendingIntent);
} }