Add getter to retrieve interval between requests.

Added a getter instead of getting the interval between requests data
from the xml file. This was in response to API council feedback

Test: DisplayHashManagerTest
Fixes: 184890915
Change-Id: I8f903cada26b6fc4cd8c12a5c97089705bc821e3
This commit is contained in:
chaviw
2021-05-12 17:48:00 -05:00
parent ef6d7c0278
commit 566d81d802
6 changed files with 56 additions and 94 deletions

View File

@@ -317,7 +317,6 @@ 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
@@ -9888,9 +9887,9 @@ package android.service.displayhash {
method @NonNull public final android.os.IBinder onBind(@NonNull android.content.Intent);
method public abstract void onGenerateDisplayHash(@NonNull byte[], @NonNull android.hardware.HardwareBuffer, @NonNull android.graphics.Rect, @NonNull String, @NonNull android.view.displayhash.DisplayHashResultCallback);
method @NonNull public abstract java.util.Map<java.lang.String,android.service.displayhash.DisplayHashParams> onGetDisplayHashAlgorithms();
method public abstract int onGetIntervalBetweenRequestsMillis();
method @Nullable public abstract android.view.displayhash.VerifiedDisplayHash onVerifyDisplayHash(@NonNull byte[], @NonNull android.view.displayhash.DisplayHash);
field public static final String SERVICE_INTERFACE = "android.service.displayhash.DisplayHashingService";
field public static final String SERVICE_META_DATA = "android.displayhash.display_hashing_service";
}
}

View File

@@ -51,15 +51,9 @@ public abstract class DisplayHashingService extends Service {
public static final String EXTRA_VERIFIED_DISPLAY_HASH =
"android.service.displayhash.extra.VERIFIED_DISPLAY_HASH";
/**
* Name under which a DisplayHashingService component publishes information
* about itself. This meta-data must reference an XML resource containing a
* {@link com.android.internal.R.styleable#DisplayHashingService} tag.
*
* @hide
*/
@SystemApi
public static final String SERVICE_META_DATA = "android.displayhash.display_hashing_service";
/** @hide **/
public static final String EXTRA_INTERVAL_BETWEEN_REQUESTS =
"android.service.displayhash.extra.INTERVAL_BETWEEN_REQUESTS";
/**
* The {@link Intent} action that must be declared as handled by a service in its manifest
@@ -149,6 +143,21 @@ public abstract class DisplayHashingService extends Service {
callback.sendResult(data);
}
/**
* Call to get the interval required between display hash requests. Requests made faster than
* this will be throttled.
*
* @return the interval value required between requests.
*/
public abstract int onGetIntervalBetweenRequestsMillis();
private void getDurationBetweenRequestsMillis(RemoteCallback callback) {
int durationBetweenRequestMillis = onGetIntervalBetweenRequestsMillis();
Bundle data = new Bundle();
data.putInt(EXTRA_INTERVAL_BETWEEN_REQUESTS, durationBetweenRequestMillis);
callback.sendResult(data);
}
private final class DisplayHashingServiceWrapper extends IDisplayHashingService.Stub {
@Override
public void generateDisplayHash(byte[] salt, HardwareBuffer buffer, Rect bounds,
@@ -187,5 +196,12 @@ public abstract class DisplayHashingService extends Service {
mHandler.sendMessage(obtainMessage(DisplayHashingService::getDisplayHashAlgorithms,
DisplayHashingService.this, callback));
}
@Override
public void getIntervalBetweenRequestsMillis(RemoteCallback callback) {
mHandler.sendMessage(
obtainMessage(DisplayHashingService::getDurationBetweenRequestsMillis,
DisplayHashingService.this, callback));
}
}
}

View File

@@ -58,4 +58,13 @@ oneway interface IDisplayHashingService {
* @param callback The callback invoked to send back the map of algorithms to DisplayHashParams.
*/
void getDisplayHashAlgorithms(in RemoteCallback callback);
/**
* Call to get the interval required between display hash requests. Requests made faster than
* this will be throttled. The result will be sent in the callback as an int with the key
* {@link #EXTRA_INTERVAL_BETWEEN_REQUESTS}.
*
* @param callback The callback invoked to send back the interval duration.
*/
void getIntervalBetweenRequestsMillis(in RemoteCallback callback);
}

View File

@@ -9568,11 +9568,4 @@
<attr name="iconfactoryBadgeSize" format="dimension"/>
<!-- Perceptual luminance of a color, in accessibility friendly color space. From 0 to 100. -->
<attr name="lStar" format="float"/>
<declare-styleable name="DisplayHashingService">
<!-- The interval required between display hash requests. Requests made faster than this
delay will be throttled."
@hide @SystemApi -->
<attr name="durationBetweenRequestsMillis" format="integer" />
</declare-styleable>
</resources>

View File

@@ -3095,8 +3095,6 @@
<!-- @hide @SystemApi -->
<public name="playHomeTransitionSound" />
<public name="lStar" />
<!-- @hide @SystemApi -->
<public name="durationBetweenRequestsMillis" />
<public name="showInInputMethodPicker" />
<public name="effectColor" />
<!-- @hide @TestApi -->

View File

@@ -16,8 +16,8 @@
package com.android.server.wm;
import static android.service.displayhash.DisplayHashingService.EXTRA_INTERVAL_BETWEEN_REQUESTS;
import static android.service.displayhash.DisplayHashingService.EXTRA_VERIFIED_DISPLAY_HASH;
import static android.service.displayhash.DisplayHashingService.SERVICE_META_DATA;
import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ERROR_INVALID_HASH_ALGORITHM;
import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ERROR_TOO_MANY_REQUESTS;
import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ERROR_UNKNOWN;
@@ -36,9 +36,6 @@ import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
@@ -54,22 +51,15 @@ import android.os.UserHandle;
import android.service.displayhash.DisplayHashParams;
import android.service.displayhash.DisplayHashingService;
import android.service.displayhash.IDisplayHashingService;
import android.util.AttributeSet;
import android.util.Size;
import android.util.Slog;
import android.util.Xml;
import android.view.MagnificationSpec;
import android.view.SurfaceControl;
import android.view.displayhash.DisplayHash;
import android.view.displayhash.VerifiedDisplayHash;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@@ -114,25 +104,18 @@ public class DisplayHashController {
private final Matrix mTmpMatrix = new Matrix();
private final RectF mTmpRectF = new RectF();
/**
* Lock used when retrieving xml metadata. Lock when retrieving the xml data the first time
* since it will be cached after that. Check if {@link #mParsedXml} is set to determine if the
* metadata needs to retrieved.
*/
private final Object mParseXmlLock = new Object();
/**
* Flag whether the xml metadata has been retrieved and parsed. Once this is set to true,
* there's no need to request metadata again.
* Lock used for the cached {@link #mIntervalBetweenRequestMillis}
*/
@GuardedBy("mParseXmlLock")
private boolean mParsedXml;
private final Object mIntervalBetweenRequestsLock = new Object();
/**
* Specified duration between requests to generate a display hash in milliseconds. Requests
* faster than this delay will be throttled.
*/
private int mDurationBetweenRequestMillis = 0;
@GuardedBy("mDurationBetweenRequestsLock")
private int mIntervalBetweenRequestMillis = -1;
/**
* The last time an app requested to generate a display hash in System time.
@@ -203,8 +186,8 @@ public class DisplayHashController {
return true;
}
int mDurationBetweenRequestsMs = getDurationBetweenRequestMillis();
if (currentTime - mLastRequestTimeMs < mDurationBetweenRequestsMs) {
int mIntervalBetweenRequestsMs = getIntervalBetweenRequestMillis();
if (currentTime - mLastRequestTimeMs < mIntervalBetweenRequestsMs) {
return false;
}
@@ -356,61 +339,25 @@ public class DisplayHashController {
}
}
private int getDurationBetweenRequestMillis() {
if (!parseXmlProperties()) {
return 0;
}
return mDurationBetweenRequestMillis;
}
private boolean parseXmlProperties() {
// We have a separate lock for the xml parsing since it doesn't need to make the
// request through the service connection. Instead, we have a lock to ensure we can
// properly cache the xml metadata so we don't need to call into the ExtServices
// process for each request.
synchronized (mParseXmlLock) {
if (mParsedXml) {
return true;
private int getIntervalBetweenRequestMillis() {
// We have a separate lock for the hashing params to ensure we can properly cache the
// hashing params so we don't need to call into the ExtServices process for each request.
synchronized (mIntervalBetweenRequestsLock) {
if (mIntervalBetweenRequestMillis != -1) {
return mIntervalBetweenRequestMillis;
}
final ServiceInfo serviceInfo = getServiceInfo();
if (serviceInfo == null) return false;
final PackageManager pm = mContext.getPackageManager();
XmlResourceParser parser;
parser = serviceInfo.loadXmlMetaData(pm, SERVICE_META_DATA);
if (parser == null) {
return false;
}
Resources res;
try {
res = pm.getResourcesForApplication(serviceInfo.applicationInfo);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while (true) {
final SyncCommand syncCommand = new SyncCommand();
Bundle results = syncCommand.run((service, remoteCallback) -> {
try {
if (!((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG)) {
break;
}
} catch (XmlPullParserException | IOException e) {
return false;
service.getIntervalBetweenRequestsMillis(remoteCallback);
} catch (RemoteException e) {
Slog.e(TAG, "Failed to invoke getDisplayHashAlgorithms command", e);
}
}
});
TypedArray sa = res.obtainAttributes(attrs, R.styleable.DisplayHashingService);
mDurationBetweenRequestMillis = sa.getInt(
R.styleable.DisplayHashingService_durationBetweenRequestsMillis, 0);
sa.recycle();
mParsedXml = true;
return true;
mIntervalBetweenRequestMillis = results.getInt(EXTRA_INTERVAL_BETWEEN_REQUESTS, 0);
return mIntervalBetweenRequestMillis;
}
}