From 286642aecd56d5c31bfeeb091f4de0c200d18976 Mon Sep 17 00:00:00 2001 From: chaviw Date: Wed, 28 Apr 2021 14:38:47 -0500 Subject: [PATCH] Updated DisplayHash APIs Test: DisplayHashingServiceImplTest Test: DisplayHashManagerTest Fixes: 185274179 Fixes: 185940192 Change-Id: I8562fc8f0f3b53d41214a80168be5d14b9eb4c10 --- core/api/system-current.txt | 6 ++-- .../displayhash/DisplayHashParams.java | 32 +++++++++---------- core/res/res/values/attrs.xml | 5 +-- core/res/res/values/public.xml | 2 +- .../server/wm/DisplayHashController.java | 20 ++++++------ 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 22af3f7ba12a4..7f4a07c573b27 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -317,6 +317,7 @@ package android { public static final class R.attr { field public static final int allowClearUserDataOnFailedRestore = 16844288; // 0x1010600 + field public static final int durationBetweenRequestsMillis; field public static final int hotwordDetectionService; field public static final int isVrOnly = 16844152; // 0x1010578 field public static final int minExtensionVersion = 16844305; // 0x1010611 @@ -325,7 +326,6 @@ package android { field public static final int requiredSystemPropertyValue = 16844134; // 0x1010566 field public static final int sdkVersion = 16844304; // 0x1010610 field public static final int supportsAmbientMode = 16844173; // 0x101058d - field public static final int throttleDurationMillis; field public static final int userRestriction = 16844164; // 0x1010584 } @@ -9867,7 +9867,7 @@ package android.service.displayhash { public final class DisplayHashParams implements android.os.Parcelable { method public int describeContents(); method @Nullable public android.util.Size getBufferSize(); - method public boolean isUseGrayscale(); + method public boolean isGrayscaleBuffer(); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator CREATOR; } @@ -9876,7 +9876,7 @@ package android.service.displayhash { ctor public DisplayHashParams.Builder(); method @NonNull public android.service.displayhash.DisplayHashParams build(); method @NonNull public android.service.displayhash.DisplayHashParams.Builder setBufferSize(int, int); - method @NonNull public android.service.displayhash.DisplayHashParams.Builder setUseGrayscale(boolean); + method @NonNull public android.service.displayhash.DisplayHashParams.Builder setGrayscaleBuffer(boolean); } public abstract class DisplayHashingService extends android.app.Service { diff --git a/core/java/android/service/displayhash/DisplayHashParams.java b/core/java/android/service/displayhash/DisplayHashParams.java index 2ec9d5d111011..123c209519b60 100644 --- a/core/java/android/service/displayhash/DisplayHashParams.java +++ b/core/java/android/service/displayhash/DisplayHashParams.java @@ -48,7 +48,7 @@ public final class DisplayHashParams implements Parcelable { /** * Whether the content will be captured in grayscale or color. */ - private final boolean mUseGrayscale; + private final boolean mGrayscaleBuffer; /** * A builder for {@link DisplayHashParams} @@ -56,7 +56,7 @@ public final class DisplayHashParams implements Parcelable { public static final class Builder { @Nullable private Size mBufferSize; - private boolean mUseGrayscale; + private boolean mGrayscaleBuffer; /** * Creates a new Builder. @@ -77,15 +77,15 @@ public final class DisplayHashParams implements Parcelable { * Whether the content will be captured in grayscale or color. */ @NonNull - public Builder setUseGrayscale(boolean useGrayscale) { - mUseGrayscale = useGrayscale; + public Builder setGrayscaleBuffer(boolean grayscaleBuffer) { + mGrayscaleBuffer = grayscaleBuffer; return this; } /** Builds the instance. This builder should not be touched after calling this! */ @NonNull public DisplayHashParams build() { - return new DisplayHashParams(mBufferSize, mUseGrayscale); + return new DisplayHashParams(mBufferSize, mGrayscaleBuffer); } } @@ -112,16 +112,16 @@ public final class DisplayHashParams implements Parcelable { * buffer given to the {@link DisplayHashingService#onGenerateDisplayHash(byte[], * HardwareBuffer, Rect, String, DisplayHashResultCallback)} will be stretched based on the * value set here. If {@code null}, the buffer size will not be changed. - * @param useGrayscale + * @param grayscaleBuffer * Whether the content will be captured in grayscale or color. * @hide */ @DataClass.Generated.Member public DisplayHashParams( @Nullable Size bufferSize, - boolean useGrayscale) { + boolean grayscaleBuffer) { this.mBufferSize = bufferSize; - this.mUseGrayscale = useGrayscale; + this.mGrayscaleBuffer = grayscaleBuffer; // onConstructed(); // You can define this method to get a callback } @@ -141,8 +141,8 @@ public final class DisplayHashParams implements Parcelable { * Whether the content will be captured in grayscale or color. */ @DataClass.Generated.Member - public boolean isUseGrayscale() { - return mUseGrayscale; + public boolean isGrayscaleBuffer() { + return mGrayscaleBuffer; } @Override @@ -153,7 +153,7 @@ public final class DisplayHashParams implements Parcelable { return "DisplayHashParams { " + "bufferSize = " + mBufferSize + ", " + - "useGrayscale = " + mUseGrayscale + + "grayscaleBuffer = " + mGrayscaleBuffer + " }"; } @@ -164,7 +164,7 @@ public final class DisplayHashParams implements Parcelable { // void parcelFieldName(Parcel dest, int flags) { ... } byte flg = 0; - if (mUseGrayscale) flg |= 0x2; + if (mGrayscaleBuffer) flg |= 0x2; if (mBufferSize != null) flg |= 0x1; dest.writeByte(flg); if (mBufferSize != null) dest.writeSize(mBufferSize); @@ -182,11 +182,11 @@ public final class DisplayHashParams implements Parcelable { // static FieldType unparcelFieldName(Parcel in) { ... } byte flg = in.readByte(); - boolean useGrayscale = (flg & 0x2) != 0; + boolean grayscaleBuffer = (flg & 0x2) != 0; Size bufferSize = (flg & 0x1) == 0 ? null : (Size) in.readSize(); this.mBufferSize = bufferSize; - this.mUseGrayscale = useGrayscale; + this.mGrayscaleBuffer = grayscaleBuffer; // onConstructed(); // You can define this method to get a callback } @@ -206,10 +206,10 @@ public final class DisplayHashParams implements Parcelable { }; @DataClass.Generated( - time = 1618436855096L, + time = 1619638159453L, codegenVersion = "1.0.23", sourceFile = "frameworks/base/core/java/android/service/displayhash/DisplayHashParams.java", - inputSignatures = "private final @android.annotation.Nullable android.util.Size mBufferSize\nprivate final boolean mUseGrayscale\nclass DisplayHashParams extends java.lang.Object implements [android.os.Parcelable]\nprivate @android.annotation.Nullable android.util.Size mBufferSize\nprivate boolean mUseGrayscale\npublic @android.annotation.NonNull android.service.displayhash.DisplayHashParams.Builder setBufferSize(int,int)\npublic @android.annotation.NonNull android.service.displayhash.DisplayHashParams.Builder setUseGrayscale(boolean)\npublic @android.annotation.NonNull android.service.displayhash.DisplayHashParams build()\nclass Builder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genAidl=true, genToString=true, genParcelable=true, genHiddenConstructor=true)") + inputSignatures = "private final @android.annotation.Nullable android.util.Size mBufferSize\nprivate final boolean mGrayscaleBuffer\nclass DisplayHashParams extends java.lang.Object implements [android.os.Parcelable]\nprivate @android.annotation.Nullable android.util.Size mBufferSize\nprivate boolean mGrayscaleBuffer\npublic @android.annotation.NonNull android.service.displayhash.DisplayHashParams.Builder setBufferSize(int,int)\npublic @android.annotation.NonNull android.service.displayhash.DisplayHashParams.Builder setGrayscaleBuffer(boolean)\npublic @android.annotation.NonNull android.service.displayhash.DisplayHashParams build()\nclass Builder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genAidl=true, genToString=true, genParcelable=true, genHiddenConstructor=true)") @Deprecated private void __metadata() {} diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index f097009f9a6e3..d4fa28531acdc 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -9576,8 +9576,9 @@ - - + diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index c716000742178..0e9526ab4e6c0 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -3097,7 +3097,7 @@ - + diff --git a/services/core/java/com/android/server/wm/DisplayHashController.java b/services/core/java/com/android/server/wm/DisplayHashController.java index af0c3e3f319e9..94d81fbb7cc99 100644 --- a/services/core/java/com/android/server/wm/DisplayHashController.java +++ b/services/core/java/com/android/server/wm/DisplayHashController.java @@ -129,10 +129,10 @@ public class DisplayHashController { private boolean mParsedXml; /** - * Specified throttle time in milliseconds. Don't allow an app to generate a display hash more - * than once per throttleTime + * Specified duration between requests to generate a display hash in milliseconds. Requests + * faster than this delay will be throttled. */ - private int mThrottleDurationMillis = 0; + private int mDurationBetweenRequestMillis = 0; /** * The last time an app requested to generate a display hash in System time. @@ -203,8 +203,8 @@ public class DisplayHashController { return true; } - int throttleDurationMs = getThrottleDurationMillis(); - if (currentTime - mLastRequestTimeMs < throttleDurationMs) { + int mDurationBetweenRequestsMs = getDurationBetweenRequestMillis(); + if (currentTime - mLastRequestTimeMs < mDurationBetweenRequestsMs) { return false; } @@ -233,7 +233,7 @@ public class DisplayHashController { (float) size.getHeight() / boundsInWindow.height()); } - args.setGrayscale(displayHashParams.isUseGrayscale()); + args.setGrayscale(displayHashParams.isGrayscaleBuffer()); SurfaceControl.ScreenshotHardwareBuffer screenshotHardwareBuffer = SurfaceControl.captureLayers(args.build()); @@ -356,11 +356,11 @@ public class DisplayHashController { } } - private int getThrottleDurationMillis() { + private int getDurationBetweenRequestMillis() { if (!parseXmlProperties()) { return 0; } - return mThrottleDurationMillis; + return mDurationBetweenRequestMillis; } private boolean parseXmlProperties() { @@ -406,8 +406,8 @@ public class DisplayHashController { } TypedArray sa = res.obtainAttributes(attrs, R.styleable.DisplayHashingService); - mThrottleDurationMillis = sa.getInt( - R.styleable.DisplayHashingService_throttleDurationMillis, 0); + mDurationBetweenRequestMillis = sa.getInt( + R.styleable.DisplayHashingService_durationBetweenRequestsMillis, 0); sa.recycle(); mParsedXml = true; return true;