Updated DisplayHash APIs
Test: DisplayHashingServiceImplTest Test: DisplayHashManagerTest Fixes: 185274179 Fixes: 185940192 Change-Id: I8562fc8f0f3b53d41214a80168be5d14b9eb4c10
This commit is contained in:
@@ -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<android.service.displayhash.DisplayHashParams> 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 {
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
|
||||
@@ -9576,8 +9576,9 @@
|
||||
<attr name="lStar" format="float"/>
|
||||
|
||||
<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 -->
|
||||
<attr name="throttleDurationMillis" format="integer" />
|
||||
<attr name="durationBetweenRequestsMillis" format="integer" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
|
||||
@@ -3097,7 +3097,7 @@
|
||||
<public name="playHomeTransitionSound" />
|
||||
<public name="lStar" />
|
||||
<!-- @hide @SystemApi -->
|
||||
<public name="throttleDurationMillis" />
|
||||
<public name="durationBetweenRequestsMillis" />
|
||||
<public name="showInInputMethodPicker" />
|
||||
<public name="effectColor" />
|
||||
</staging-public-group>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user