Merge "Updated DisplayHash APIs" into sc-dev

This commit is contained in:
Chavi Weingarten
2021-04-29 15:31:20 +00:00
committed by Android (Google) Code Review
5 changed files with 33 additions and 32 deletions

View File

@@ -317,6 +317,7 @@ package android {
public static final class R.attr { public static final class R.attr {
field public static final int allowClearUserDataOnFailedRestore = 16844288; // 0x1010600 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 hotwordDetectionService;
field public static final int isVrOnly = 16844152; // 0x1010578 field public static final int isVrOnly = 16844152; // 0x1010578
field public static final int minExtensionVersion = 16844305; // 0x1010611 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 requiredSystemPropertyValue = 16844134; // 0x1010566
field public static final int sdkVersion = 16844304; // 0x1010610 field public static final int sdkVersion = 16844304; // 0x1010610
field public static final int supportsAmbientMode = 16844173; // 0x101058d field public static final int supportsAmbientMode = 16844173; // 0x101058d
field public static final int throttleDurationMillis;
field public static final int userRestriction = 16844164; // 0x1010584 field public static final int userRestriction = 16844164; // 0x1010584
} }
@@ -9867,7 +9867,7 @@ package android.service.displayhash {
public final class DisplayHashParams implements android.os.Parcelable { public final class DisplayHashParams implements android.os.Parcelable {
method public int describeContents(); method public int describeContents();
method @Nullable public android.util.Size getBufferSize(); method @Nullable public android.util.Size getBufferSize();
method public boolean isUseGrayscale(); method public boolean isGrayscaleBuffer();
method public void writeToParcel(@NonNull android.os.Parcel, int); method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.service.displayhash.DisplayHashParams> CREATOR; field @NonNull public static final android.os.Parcelable.Creator<android.service.displayhash.DisplayHashParams> CREATOR;
} }
@@ -9876,7 +9876,7 @@ package android.service.displayhash {
ctor public DisplayHashParams.Builder(); ctor public DisplayHashParams.Builder();
method @NonNull public android.service.displayhash.DisplayHashParams build(); 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 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 { public abstract class DisplayHashingService extends android.app.Service {

View File

@@ -48,7 +48,7 @@ public final class DisplayHashParams implements Parcelable {
/** /**
* Whether the content will be captured in grayscale or color. * Whether the content will be captured in grayscale or color.
*/ */
private final boolean mUseGrayscale; private final boolean mGrayscaleBuffer;
/** /**
* A builder for {@link DisplayHashParams} * A builder for {@link DisplayHashParams}
@@ -56,7 +56,7 @@ public final class DisplayHashParams implements Parcelable {
public static final class Builder { public static final class Builder {
@Nullable @Nullable
private Size mBufferSize; private Size mBufferSize;
private boolean mUseGrayscale; private boolean mGrayscaleBuffer;
/** /**
* Creates a new Builder. * Creates a new Builder.
@@ -77,15 +77,15 @@ public final class DisplayHashParams implements Parcelable {
* Whether the content will be captured in grayscale or color. * Whether the content will be captured in grayscale or color.
*/ */
@NonNull @NonNull
public Builder setUseGrayscale(boolean useGrayscale) { public Builder setGrayscaleBuffer(boolean grayscaleBuffer) {
mUseGrayscale = useGrayscale; mGrayscaleBuffer = grayscaleBuffer;
return this; return this;
} }
/** Builds the instance. This builder should not be touched after calling this! */ /** Builds the instance. This builder should not be touched after calling this! */
@NonNull @NonNull
public DisplayHashParams build() { 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[], * buffer given to the {@link DisplayHashingService#onGenerateDisplayHash(byte[],
* HardwareBuffer, Rect, String, DisplayHashResultCallback)} will be stretched based on the * HardwareBuffer, Rect, String, DisplayHashResultCallback)} will be stretched based on the
* value set here. If {@code null}, the buffer size will not be changed. * 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. * Whether the content will be captured in grayscale or color.
* @hide * @hide
*/ */
@DataClass.Generated.Member @DataClass.Generated.Member
public DisplayHashParams( public DisplayHashParams(
@Nullable Size bufferSize, @Nullable Size bufferSize,
boolean useGrayscale) { boolean grayscaleBuffer) {
this.mBufferSize = bufferSize; this.mBufferSize = bufferSize;
this.mUseGrayscale = useGrayscale; this.mGrayscaleBuffer = grayscaleBuffer;
// onConstructed(); // You can define this method to get a callback // 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. * Whether the content will be captured in grayscale or color.
*/ */
@DataClass.Generated.Member @DataClass.Generated.Member
public boolean isUseGrayscale() { public boolean isGrayscaleBuffer() {
return mUseGrayscale; return mGrayscaleBuffer;
} }
@Override @Override
@@ -153,7 +153,7 @@ public final class DisplayHashParams implements Parcelable {
return "DisplayHashParams { " + return "DisplayHashParams { " +
"bufferSize = " + mBufferSize + ", " + "bufferSize = " + mBufferSize + ", " +
"useGrayscale = " + mUseGrayscale + "grayscaleBuffer = " + mGrayscaleBuffer +
" }"; " }";
} }
@@ -164,7 +164,7 @@ public final class DisplayHashParams implements Parcelable {
// void parcelFieldName(Parcel dest, int flags) { ... } // void parcelFieldName(Parcel dest, int flags) { ... }
byte flg = 0; byte flg = 0;
if (mUseGrayscale) flg |= 0x2; if (mGrayscaleBuffer) flg |= 0x2;
if (mBufferSize != null) flg |= 0x1; if (mBufferSize != null) flg |= 0x1;
dest.writeByte(flg); dest.writeByte(flg);
if (mBufferSize != null) dest.writeSize(mBufferSize); if (mBufferSize != null) dest.writeSize(mBufferSize);
@@ -182,11 +182,11 @@ public final class DisplayHashParams implements Parcelable {
// static FieldType unparcelFieldName(Parcel in) { ... } // static FieldType unparcelFieldName(Parcel in) { ... }
byte flg = in.readByte(); byte flg = in.readByte();
boolean useGrayscale = (flg & 0x2) != 0; boolean grayscaleBuffer = (flg & 0x2) != 0;
Size bufferSize = (flg & 0x1) == 0 ? null : (Size) in.readSize(); Size bufferSize = (flg & 0x1) == 0 ? null : (Size) in.readSize();
this.mBufferSize = bufferSize; this.mBufferSize = bufferSize;
this.mUseGrayscale = useGrayscale; this.mGrayscaleBuffer = grayscaleBuffer;
// onConstructed(); // You can define this method to get a callback // onConstructed(); // You can define this method to get a callback
} }
@@ -206,10 +206,10 @@ public final class DisplayHashParams implements Parcelable {
}; };
@DataClass.Generated( @DataClass.Generated(
time = 1618436855096L, time = 1619638159453L,
codegenVersion = "1.0.23", codegenVersion = "1.0.23",
sourceFile = "frameworks/base/core/java/android/service/displayhash/DisplayHashParams.java", 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 @Deprecated
private void __metadata() {} private void __metadata() {}

View File

@@ -9576,8 +9576,9 @@
<attr name="lStar" format="float"/> <attr name="lStar" format="float"/>
<declare-styleable name="DisplayHashingService"> <declare-styleable name="DisplayHashingService">
<!-- The throttle duration for display hash requests <!-- The interval required between display hash requests. Requests made faster than this
delay will be throttled."
@hide @SystemApi --> @hide @SystemApi -->
<attr name="throttleDurationMillis" format="integer" /> <attr name="durationBetweenRequestsMillis" format="integer" />
</declare-styleable> </declare-styleable>
</resources> </resources>

View File

@@ -3097,7 +3097,7 @@
<public name="playHomeTransitionSound" /> <public name="playHomeTransitionSound" />
<public name="lStar" /> <public name="lStar" />
<!-- @hide @SystemApi --> <!-- @hide @SystemApi -->
<public name="throttleDurationMillis" /> <public name="durationBetweenRequestsMillis" />
<public name="showInInputMethodPicker" /> <public name="showInInputMethodPicker" />
<public name="effectColor" /> <public name="effectColor" />
</staging-public-group> </staging-public-group>

View File

@@ -129,10 +129,10 @@ public class DisplayHashController {
private boolean mParsedXml; private boolean mParsedXml;
/** /**
* Specified throttle time in milliseconds. Don't allow an app to generate a display hash more * Specified duration between requests to generate a display hash in milliseconds. Requests
* than once per throttleTime * 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. * The last time an app requested to generate a display hash in System time.
@@ -203,8 +203,8 @@ public class DisplayHashController {
return true; return true;
} }
int throttleDurationMs = getThrottleDurationMillis(); int mDurationBetweenRequestsMs = getDurationBetweenRequestMillis();
if (currentTime - mLastRequestTimeMs < throttleDurationMs) { if (currentTime - mLastRequestTimeMs < mDurationBetweenRequestsMs) {
return false; return false;
} }
@@ -233,7 +233,7 @@ public class DisplayHashController {
(float) size.getHeight() / boundsInWindow.height()); (float) size.getHeight() / boundsInWindow.height());
} }
args.setGrayscale(displayHashParams.isUseGrayscale()); args.setGrayscale(displayHashParams.isGrayscaleBuffer());
SurfaceControl.ScreenshotHardwareBuffer screenshotHardwareBuffer = SurfaceControl.ScreenshotHardwareBuffer screenshotHardwareBuffer =
SurfaceControl.captureLayers(args.build()); SurfaceControl.captureLayers(args.build());
@@ -356,11 +356,11 @@ public class DisplayHashController {
} }
} }
private int getThrottleDurationMillis() { private int getDurationBetweenRequestMillis() {
if (!parseXmlProperties()) { if (!parseXmlProperties()) {
return 0; return 0;
} }
return mThrottleDurationMillis; return mDurationBetweenRequestMillis;
} }
private boolean parseXmlProperties() { private boolean parseXmlProperties() {
@@ -406,8 +406,8 @@ public class DisplayHashController {
} }
TypedArray sa = res.obtainAttributes(attrs, R.styleable.DisplayHashingService); TypedArray sa = res.obtainAttributes(attrs, R.styleable.DisplayHashingService);
mThrottleDurationMillis = sa.getInt( mDurationBetweenRequestMillis = sa.getInt(
R.styleable.DisplayHashingService_throttleDurationMillis, 0); R.styleable.DisplayHashingService_durationBetweenRequestsMillis, 0);
sa.recycle(); sa.recycle();
mParsedXml = true; mParsedXml = true;
return true; return true;