Merge "Add getter to retrieve interval between requests." into sc-dev

This commit is contained in:
Chavi Weingarten
2021-05-18 15:02:06 +00:00
committed by Android (Google) Code Review
6 changed files with 56 additions and 94 deletions

View File

@@ -318,7 +318,6 @@ 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
@@ -9894,9 +9893,9 @@ package android.service.displayhash {
method @NonNull public final android.os.IBinder onBind(@NonNull android.content.Intent); 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 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 @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); 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_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 = public static final String EXTRA_VERIFIED_DISPLAY_HASH =
"android.service.displayhash.extra.VERIFIED_DISPLAY_HASH"; "android.service.displayhash.extra.VERIFIED_DISPLAY_HASH";
/** /** @hide **/
* Name under which a DisplayHashingService component publishes information public static final String EXTRA_INTERVAL_BETWEEN_REQUESTS =
* about itself. This meta-data must reference an XML resource containing a "android.service.displayhash.extra.INTERVAL_BETWEEN_REQUESTS";
* {@link com.android.internal.R.styleable#DisplayHashingService} tag.
*
* @hide
*/
@SystemApi
public static final String SERVICE_META_DATA = "android.displayhash.display_hashing_service";
/** /**
* The {@link Intent} action that must be declared as handled by a service in its manifest * 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); 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 { private final class DisplayHashingServiceWrapper extends IDisplayHashingService.Stub {
@Override @Override
public void generateDisplayHash(byte[] salt, HardwareBuffer buffer, Rect bounds, public void generateDisplayHash(byte[] salt, HardwareBuffer buffer, Rect bounds,
@@ -187,5 +196,12 @@ public abstract class DisplayHashingService extends Service {
mHandler.sendMessage(obtainMessage(DisplayHashingService::getDisplayHashAlgorithms, mHandler.sendMessage(obtainMessage(DisplayHashingService::getDisplayHashAlgorithms,
DisplayHashingService.this, callback)); 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. * @param callback The callback invoked to send back the map of algorithms to DisplayHashParams.
*/ */
void getDisplayHashAlgorithms(in RemoteCallback callback); 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"/> <attr name="iconfactoryBadgeSize" format="dimension"/>
<!-- Perceptual luminance of a color, in accessibility friendly color space. From 0 to 100. --> <!-- Perceptual luminance of a color, in accessibility friendly color space. From 0 to 100. -->
<attr name="lStar" format="float"/> <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> </resources>

View File

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

View File

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