Merge "Screenshot - pass bitmap as bundled hardware buffer from Launcher" into rvc-dev
This commit is contained in:
@@ -8,10 +8,10 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Insets;
|
||||
import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
@@ -37,10 +37,12 @@ public class ScreenshotHelper {
|
||||
private int mSource;
|
||||
private boolean mHasStatusBar;
|
||||
private boolean mHasNavBar;
|
||||
private Bitmap mBitmap;
|
||||
private Bundle mBitmapBundle;
|
||||
private Rect mBoundsInScreen;
|
||||
private Insets mInsets;
|
||||
private int mTaskId;
|
||||
private int mUserId;
|
||||
private ComponentName mTopComponent;
|
||||
|
||||
ScreenshotRequest(int source, boolean hasStatus, boolean hasNav) {
|
||||
mSource = source;
|
||||
@@ -48,24 +50,29 @@ public class ScreenshotHelper {
|
||||
mHasNavBar = hasNav;
|
||||
}
|
||||
|
||||
ScreenshotRequest(
|
||||
int source, Bitmap bitmap, Rect boundsInScreen, Insets insets, int taskId) {
|
||||
ScreenshotRequest(int source, Bundle bitmapBundle, Rect boundsInScreen, Insets insets,
|
||||
int taskId, int userId, ComponentName topComponent) {
|
||||
mSource = source;
|
||||
mBitmap = bitmap;
|
||||
mBitmapBundle = bitmapBundle;
|
||||
mBoundsInScreen = boundsInScreen;
|
||||
mInsets = insets;
|
||||
mTaskId = taskId;
|
||||
mUserId = userId;
|
||||
mTopComponent = topComponent;
|
||||
}
|
||||
|
||||
ScreenshotRequest(Parcel in) {
|
||||
mSource = in.readInt();
|
||||
mHasStatusBar = in.readBoolean();
|
||||
mHasNavBar = in.readBoolean();
|
||||
|
||||
if (in.readInt() == 1) {
|
||||
mBitmap = in.readParcelable(Bitmap.class.getClassLoader());
|
||||
mBitmapBundle = in.readBundle(getClass().getClassLoader());
|
||||
mBoundsInScreen = in.readParcelable(Rect.class.getClassLoader());
|
||||
mInsets = in.readParcelable(Insets.class.getClassLoader());
|
||||
mTaskId = in.readInt();
|
||||
mUserId = in.readInt();
|
||||
mTopComponent = in.readParcelable(ComponentName.class.getClassLoader());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,8 +88,8 @@ public class ScreenshotHelper {
|
||||
return mHasNavBar;
|
||||
}
|
||||
|
||||
public Bitmap getBitmap() {
|
||||
return mBitmap;
|
||||
public Bundle getBitmapBundle() {
|
||||
return mBitmapBundle;
|
||||
}
|
||||
|
||||
public Rect getBoundsInScreen() {
|
||||
@@ -97,6 +104,15 @@ public class ScreenshotHelper {
|
||||
return mTaskId;
|
||||
}
|
||||
|
||||
|
||||
public int getUserId() {
|
||||
return mUserId;
|
||||
}
|
||||
|
||||
public ComponentName getTopComponent() {
|
||||
return mTopComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
@@ -107,14 +123,16 @@ public class ScreenshotHelper {
|
||||
dest.writeInt(mSource);
|
||||
dest.writeBoolean(mHasStatusBar);
|
||||
dest.writeBoolean(mHasNavBar);
|
||||
if (mBitmap == null) {
|
||||
if (mBitmapBundle == null) {
|
||||
dest.writeInt(0);
|
||||
} else {
|
||||
dest.writeInt(1);
|
||||
dest.writeParcelable(mBitmap, 0);
|
||||
dest.writeBundle(mBitmapBundle);
|
||||
dest.writeParcelable(mBoundsInScreen, 0);
|
||||
dest.writeParcelable(mInsets, 0);
|
||||
dest.writeInt(mTaskId);
|
||||
dest.writeInt(mUserId);
|
||||
dest.writeParcelable(mTopComponent, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,19 +252,22 @@ public class ScreenshotHelper {
|
||||
/**
|
||||
* Request that provided image be handled as if it was a screenshot.
|
||||
*
|
||||
* @param screenshot The bitmap to treat as the screen shot.
|
||||
* @param screenshotBundle Bundle containing the buffer and color space of the screenshot.
|
||||
* @param boundsInScreen The bounds in screen coordinates that the bitmap orginated from.
|
||||
* @param insets The insets that the image was shown with, inside the screenbounds.
|
||||
* @param taskId The taskId of the task that the screen shot was taken of.
|
||||
* @param userId The userId of user running the task provided in taskId.
|
||||
* @param topComponent The component name of the top component running in the task.
|
||||
* @param handler A handler used in case the screenshot times out
|
||||
* @param completionConsumer Consumes `false` if a screenshot was not taken, and `true` if the
|
||||
* screenshot was taken.
|
||||
*/
|
||||
public void provideScreenshot(@NonNull Bitmap screenshot, @NonNull Rect boundsInScreen,
|
||||
@NonNull Insets insets, int taskId, int source,
|
||||
public void provideScreenshot(@NonNull Bundle screenshotBundle, @NonNull Rect boundsInScreen,
|
||||
@NonNull Insets insets, int taskId, int userId, ComponentName topComponent, int source,
|
||||
@NonNull Handler handler, @Nullable Consumer<Uri> completionConsumer) {
|
||||
ScreenshotRequest screenshotRequest =
|
||||
new ScreenshotRequest(source, screenshot, boundsInScreen, insets, taskId);
|
||||
new ScreenshotRequest(source, screenshotBundle, boundsInScreen, insets, taskId,
|
||||
userId, topComponent);
|
||||
takeScreenshot(WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE, SCREENSHOT_TIMEOUT_MS,
|
||||
handler, screenshotRequest, completionConsumer);
|
||||
}
|
||||
|
||||
@@ -23,10 +23,11 @@ import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.android.systemui.shared.recents.IPinnedStackAnimationListener;
|
||||
import com.android.systemui.shared.recents.model.Task;
|
||||
|
||||
/**
|
||||
* Temporary callbacks into SystemUI.
|
||||
* Next id = 26
|
||||
* Next id = 27
|
||||
*/
|
||||
interface ISystemUiProxy {
|
||||
|
||||
@@ -122,6 +123,9 @@ interface ISystemUiProxy {
|
||||
|
||||
/**
|
||||
* Handle the provided image as if it was a screenshot.
|
||||
*
|
||||
* Deprecated, use handleImageBundleAsScreenshot with image bundle and UserTask
|
||||
* @deprecated
|
||||
*/
|
||||
void handleImageAsScreenshot(in Bitmap screenImage, in Rect locationInScreen,
|
||||
in Insets visibleInsets, int taskId) = 21;
|
||||
@@ -146,4 +150,10 @@ interface ISystemUiProxy {
|
||||
* @param rotation indicates which Surface.Rotation the gesture was started in
|
||||
*/
|
||||
void onQuickSwitchToNewTask(int rotation) = 25;
|
||||
|
||||
/**
|
||||
* Handle the provided image as if it was a screenshot.
|
||||
*/
|
||||
void handleImageBundleAsScreenshot(in Bundle screenImageBundle, in Rect locationInScreen,
|
||||
in Insets visibleInsets, in Task.TaskKey task) = 26;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.shared.recents.model;
|
||||
|
||||
parcelable Task.TaskKey;
|
||||
@@ -26,6 +26,8 @@ import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.view.ViewDebug;
|
||||
|
||||
import com.android.systemui.shared.recents.utilities.Utilities;
|
||||
@@ -52,8 +54,10 @@ public class Task {
|
||||
void onTaskWindowingModeChanged();
|
||||
}
|
||||
|
||||
/* The Task Key represents the unique primary key for the task */
|
||||
public static class TaskKey {
|
||||
/**
|
||||
* The Task Key represents the unique primary key for the task
|
||||
*/
|
||||
public static class TaskKey implements Parcelable {
|
||||
@ViewDebug.ExportedProperty(category="recents")
|
||||
public final int id;
|
||||
@ViewDebug.ExportedProperty(category="recents")
|
||||
@@ -157,6 +161,48 @@ public class Task {
|
||||
private void updateHashCode() {
|
||||
mHashCode = Objects.hash(id, windowingMode, userId);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<TaskKey> CREATOR =
|
||||
new Parcelable.Creator<TaskKey>() {
|
||||
@Override
|
||||
public TaskKey createFromParcel(Parcel source) {
|
||||
return TaskKey.readFromParcel(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskKey[] newArray(int size) {
|
||||
return new TaskKey[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public final void writeToParcel(Parcel parcel, int flags) {
|
||||
parcel.writeInt(id);
|
||||
parcel.writeInt(windowingMode);
|
||||
parcel.writeTypedObject(baseIntent, flags);
|
||||
parcel.writeInt(userId);
|
||||
parcel.writeLong(lastActiveTime);
|
||||
parcel.writeInt(displayId);
|
||||
parcel.writeTypedObject(sourceComponent, flags);
|
||||
}
|
||||
|
||||
private static TaskKey readFromParcel(Parcel parcel) {
|
||||
int id = parcel.readInt();
|
||||
int windowingMode = parcel.readInt();
|
||||
Intent baseIntent = parcel.readTypedObject(Intent.CREATOR);
|
||||
int userId = parcel.readInt();
|
||||
long lastActiveTime = parcel.readLong();
|
||||
int displayId = parcel.readInt();
|
||||
ComponentName sourceComponent = parcel.readTypedObject(ComponentName.CREATOR);
|
||||
|
||||
return new TaskKey(id, windowingMode, baseIntent, sourceComponent, userId,
|
||||
lastActiveTime, displayId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ViewDebug.ExportedProperty(deepExport=true, prefix="key_")
|
||||
|
||||
@@ -73,6 +73,7 @@ import com.android.systemui.settings.CurrentUserTracker;
|
||||
import com.android.systemui.shared.recents.IOverviewProxy;
|
||||
import com.android.systemui.shared.recents.IPinnedStackAnimationListener;
|
||||
import com.android.systemui.shared.recents.ISystemUiProxy;
|
||||
import com.android.systemui.shared.recents.model.Task;
|
||||
import com.android.systemui.shared.system.ActivityManagerWrapper;
|
||||
import com.android.systemui.shared.system.QuickStepContract;
|
||||
import com.android.systemui.stackdivider.Divider;
|
||||
@@ -383,8 +384,7 @@ public class OverviewProxyService extends CurrentUserTracker implements
|
||||
@Override
|
||||
public void handleImageAsScreenshot(Bitmap screenImage, Rect locationInScreen,
|
||||
Insets visibleInsets, int taskId) {
|
||||
mScreenshotHelper.provideScreenshot(screenImage, locationInScreen, visibleInsets,
|
||||
taskId, SCREENSHOT_OVERVIEW, mHandler, null);
|
||||
// Deprecated
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -434,6 +434,21 @@ public class OverviewProxyService extends CurrentUserTracker implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleImageBundleAsScreenshot(Bundle screenImageBundle, Rect locationInScreen,
|
||||
Insets visibleInsets, Task.TaskKey task) {
|
||||
mScreenshotHelper.provideScreenshot(
|
||||
screenImageBundle,
|
||||
locationInScreen,
|
||||
visibleInsets,
|
||||
task.id,
|
||||
task.userId,
|
||||
task.sourceComponent,
|
||||
SCREENSHOT_OVERVIEW,
|
||||
mHandler,
|
||||
null);
|
||||
}
|
||||
|
||||
private boolean verifyCaller(String reason) {
|
||||
final int callerId = Binder.getCallingUserHandle().getIdentifier();
|
||||
if (callerId != mCurrentBoundedUserId) {
|
||||
|
||||
@@ -35,6 +35,7 @@ import android.app.ActivityOptions;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
@@ -494,8 +495,10 @@ public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInset
|
||||
}
|
||||
|
||||
void handleImageAsScreenshot(Bitmap screenshot, Rect screenshotScreenBounds,
|
||||
Insets visibleInsets, int taskId, Consumer<Uri> finisher, Runnable onComplete) {
|
||||
// TODO use taskId and visibleInsets
|
||||
Insets visibleInsets, int taskId, int userId, ComponentName topComponent,
|
||||
Consumer<Uri> finisher, Runnable onComplete) {
|
||||
// TODO: use task Id, userId, topComponent for smart handler
|
||||
// TODO: use visibleInsets for animation
|
||||
mOnCompleteRunnable = onComplete;
|
||||
takeScreenshot(screenshot, finisher, screenshotScreenBounds);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.animation.AnimatorSet;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.animation.ValueAnimator.AnimatorUpdateListener;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
@@ -234,8 +235,10 @@ public class GlobalScreenshotLegacy {
|
||||
}
|
||||
|
||||
void handleImageAsScreenshot(Bitmap screenshot, Rect screenshotScreenBounds,
|
||||
Insets visibleInsets, int taskId, Consumer<Uri> finisher) {
|
||||
// TODO use taskId and visibleInsets
|
||||
Insets visibleInsets, int taskId, int userId, ComponentName topComponent,
|
||||
Consumer<Uri> finisher) {
|
||||
// TODO: use task Id, userId, topComponent for smart handler
|
||||
// TODO: use visibleInsets for animation
|
||||
takeScreenshot(screenshot, finisher, false, false, screenshotScreenBounds);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import static com.android.internal.util.ScreenshotHelper.SCREENSHOT_MSG_PROCESS_
|
||||
import static com.android.internal.util.ScreenshotHelper.SCREENSHOT_MSG_URI;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Insets;
|
||||
@@ -37,6 +38,7 @@ import android.view.WindowManager;
|
||||
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.internal.util.ScreenshotHelper;
|
||||
import com.android.systemui.shared.recents.utilities.BitmapUtil;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -107,16 +109,19 @@ public class TakeScreenshotService extends Service {
|
||||
}
|
||||
break;
|
||||
case WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE:
|
||||
Bitmap screenshot = screenshotRequest.getBitmap();
|
||||
Bitmap screenshot = BitmapUtil.bundleToHardwareBitmap(
|
||||
screenshotRequest.getBitmapBundle());
|
||||
Rect screenBounds = screenshotRequest.getBoundsInScreen();
|
||||
Insets insets = screenshotRequest.getInsets();
|
||||
int taskId = screenshotRequest.getTaskId();
|
||||
int userId = screenshotRequest.getUserId();
|
||||
ComponentName topComponent = screenshotRequest.getTopComponent();
|
||||
if (useCornerFlow) {
|
||||
mScreenshot.handleImageAsScreenshot(
|
||||
screenshot, screenBounds, insets, taskId, uriConsumer, onComplete);
|
||||
mScreenshot.handleImageAsScreenshot(screenshot, screenBounds, insets,
|
||||
taskId, userId, topComponent, uriConsumer, onComplete);
|
||||
} else {
|
||||
mScreenshotLegacy.handleImageAsScreenshot(
|
||||
screenshot, screenBounds, insets, taskId, uriConsumer);
|
||||
mScreenshotLegacy.handleImageAsScreenshot(screenshot, screenBounds, insets,
|
||||
taskId, userId, topComponent, uriConsumer);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user