Merge "Pass the URI of the new screenshot instead of file name (framework). This better matches the recommended way to access on-device media." into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
16ee6e725f
@@ -130,11 +130,6 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
|
||||
Resources r = mContext.getResources();
|
||||
|
||||
try {
|
||||
CompletableFuture<List<Notification.Action>> smartActionsFuture =
|
||||
ScreenshotSmartActions.getSmartActionsFuture(
|
||||
mScreenshotId, mImageFileName, image, mSmartActionsProvider,
|
||||
mSmartActionsEnabled, isManagedProfile(mContext));
|
||||
|
||||
// Save the screenshot to the MediaStore
|
||||
final ContentValues values = new ContentValues();
|
||||
values.put(MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_PICTURES
|
||||
@@ -148,6 +143,11 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
final Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
||||
|
||||
CompletableFuture<List<Notification.Action>> smartActionsFuture =
|
||||
ScreenshotSmartActions.getSmartActionsFuture(
|
||||
mScreenshotId, uri, image, mSmartActionsProvider,
|
||||
mSmartActionsEnabled, isManagedProfile(mContext));
|
||||
|
||||
try {
|
||||
// First, write the actual data for our screenshot
|
||||
try (OutputStream out = resolver.openOutputStream(uri)) {
|
||||
@@ -203,7 +203,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
|
||||
1000);
|
||||
smartActions.addAll(buildSmartActions(
|
||||
ScreenshotSmartActions.getSmartActions(
|
||||
mScreenshotId, mImageFileName, smartActionsFuture, timeoutMs,
|
||||
mScreenshotId, smartActionsFuture, timeoutMs,
|
||||
mSmartActionsProvider),
|
||||
mContext));
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.systemui.screenshot;
|
||||
import android.app.Notification;
|
||||
import android.content.ComponentName;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -67,7 +68,7 @@ public class ScreenshotNotificationSmartActionsProvider {
|
||||
*/
|
||||
public CompletableFuture<List<Notification.Action>> getActions(
|
||||
String screenshotId,
|
||||
String screenshotFileName,
|
||||
Uri screenshotUri,
|
||||
Bitmap bitmap,
|
||||
ComponentName componentName,
|
||||
boolean isManagedProfile) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.app.Notification;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Slog;
|
||||
@@ -45,7 +46,7 @@ public class ScreenshotSmartActions {
|
||||
|
||||
@VisibleForTesting
|
||||
static CompletableFuture<List<Notification.Action>> getSmartActionsFuture(
|
||||
String screenshotId, String screenshotFileName, Bitmap image,
|
||||
String screenshotId, Uri screenshotUri, Bitmap image,
|
||||
ScreenshotNotificationSmartActionsProvider smartActionsProvider,
|
||||
boolean smartActionsEnabled, boolean isManagedProfile) {
|
||||
if (!smartActionsEnabled) {
|
||||
@@ -70,7 +71,7 @@ public class ScreenshotSmartActions {
|
||||
? runningTask.topActivity
|
||||
: new ComponentName("", "");
|
||||
smartActionsFuture = smartActionsProvider.getActions(
|
||||
screenshotId, screenshotFileName, image, componentName, isManagedProfile);
|
||||
screenshotId, screenshotUri, image, componentName, isManagedProfile);
|
||||
} catch (Throwable e) {
|
||||
long waitTimeMs = SystemClock.uptimeMillis() - startTimeMs;
|
||||
smartActionsFuture = CompletableFuture.completedFuture(Collections.emptyList());
|
||||
@@ -84,7 +85,7 @@ public class ScreenshotSmartActions {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static List<Notification.Action> getSmartActions(String screenshotId, String screenshotFileName,
|
||||
static List<Notification.Action> getSmartActions(String screenshotId,
|
||||
CompletableFuture<List<Notification.Action>> smartActionsFuture, int timeoutMs,
|
||||
ScreenshotNotificationSmartActionsProvider smartActionsProvider) {
|
||||
long startTimeMs = SystemClock.uptimeMillis();
|
||||
|
||||
@@ -83,8 +83,9 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
|
||||
eq(false))).thenThrow(
|
||||
RuntimeException.class);
|
||||
CompletableFuture<List<Notification.Action>> smartActionsFuture =
|
||||
ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap,
|
||||
smartActionsProvider, true, false);
|
||||
ScreenshotSmartActions.getSmartActionsFuture(
|
||||
"", Uri.parse("content://authority/data"), bitmap, smartActionsProvider,
|
||||
true, false);
|
||||
assertNotNull(smartActionsFuture);
|
||||
List<Notification.Action> smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS);
|
||||
assertEquals(Collections.emptyList(), smartActions);
|
||||
@@ -101,7 +102,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
|
||||
when(smartActionsFuture.get(timeoutMs, TimeUnit.MILLISECONDS)).thenThrow(
|
||||
RuntimeException.class);
|
||||
List<Notification.Action> actions = ScreenshotSmartActions.getSmartActions(
|
||||
"", "", smartActionsFuture, timeoutMs, mSmartActionsProvider);
|
||||
"", smartActionsFuture, timeoutMs, mSmartActionsProvider);
|
||||
assertEquals(Collections.emptyList(), actions);
|
||||
}
|
||||
|
||||
@@ -122,8 +123,9 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmap.getConfig()).thenReturn(Bitmap.Config.RGB_565);
|
||||
CompletableFuture<List<Notification.Action>> smartActionsFuture =
|
||||
ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap,
|
||||
mSmartActionsProvider, true, true);
|
||||
ScreenshotSmartActions.getSmartActionsFuture(
|
||||
"", Uri.parse("content://autority/data"), bitmap, mSmartActionsProvider,
|
||||
true, true);
|
||||
verify(mSmartActionsProvider, never()).getActions(any(), any(), any(), any(),
|
||||
eq(false));
|
||||
assertNotNull(smartActionsFuture);
|
||||
@@ -136,8 +138,9 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
|
||||
public void testScreenshotNotificationSmartActionsProviderInvokedOnce() {
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmap.getConfig()).thenReturn(Bitmap.Config.HARDWARE);
|
||||
ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap, mSmartActionsProvider,
|
||||
true, true);
|
||||
ScreenshotSmartActions.getSmartActionsFuture(
|
||||
"", Uri.parse("content://autority/data"), bitmap, mSmartActionsProvider, true,
|
||||
true);
|
||||
verify(mSmartActionsProvider, times(1))
|
||||
.getActions(any(), any(), any(), any(), eq(true));
|
||||
}
|
||||
@@ -152,7 +155,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
|
||||
SystemUIFactory.getInstance().createScreenshotNotificationSmartActionsProvider(
|
||||
mContext, null, mHandler);
|
||||
CompletableFuture<List<Notification.Action>> smartActionsFuture =
|
||||
ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap,
|
||||
ScreenshotSmartActions.getSmartActionsFuture("", null, bitmap,
|
||||
actionsProvider,
|
||||
true, true);
|
||||
assertNotNull(smartActionsFuture);
|
||||
|
||||
Reference in New Issue
Block a user