diff options
8 files changed, 154 insertions, 32 deletions
diff --git a/core/java/com/android/internal/util/ScreenshotHelper.java b/core/java/com/android/internal/util/ScreenshotHelper.java index ad6c7e8f7f60..adc7ba30c157 100644 --- a/core/java/com/android/internal/util/ScreenshotHelper.java +++ b/core/java/com/android/internal/util/ScreenshotHelper.java @@ -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); } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl index 734cc9502828..b71395ddd9a4 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl @@ -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 = 29 */ 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; @@ -148,12 +152,18 @@ interface ISystemUiProxy { void onQuickSwitchToNewTask(int rotation) = 25; /** - * Start the one-handed mode. - */ + * Start the one-handed mode. + */ void startOneHandedMode() = 26; /** - * Stop the one-handed mode. - */ + * Stop the one-handed mode. + */ void stopOneHandedMode() = 27; + + /** + * 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) = 28; } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/Task.aidl b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/Task.aidl new file mode 100644 index 000000000000..e7cad2acc645 --- /dev/null +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/Task.aidl @@ -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;
\ No newline at end of file diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/Task.java b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/Task.java index dcb134ec933e..186379af4b1d 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/Task.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/Task.java @@ -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_") diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java index f638053d963e..9410a3b72250 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java +++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java @@ -72,6 +72,7 @@ import com.android.systemui.recents.OverviewProxyService.OverviewProxyListener; 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.InputMonitorCompat; import com.android.systemui.shared.system.QuickStepContract; @@ -387,8 +388,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis @Override public void handleImageAsScreenshot(Bitmap screenImage, Rect locationInScreen, Insets visibleInsets, int taskId) { - mScreenshotHelper.provideScreenshot(screenImage, locationInScreen, visibleInsets, - taskId, SCREENSHOT_OVERVIEW, mHandler, null); + // Deprecated } @Override @@ -468,6 +468,21 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis } } + @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) { diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java index a9d3772a0fdb..9b1734d40674 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java @@ -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); } diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshotLegacy.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshotLegacy.java index 095c32f4a2ce..0017b1f79b74 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshotLegacy.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshotLegacy.java @@ -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); } diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java index 98030d45b05e..8322fe08d3c2 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java @@ -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: |