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