Update WallpaperEffectsGeneration api, including annotations on data classes and allow the same uid process to call returnCinematicResponse API.

Test: Manual test on device
Bug: 218570612
Change-Id: Ie12b570f1e6400ab9e289b882e5821921a609e0a
(cherry picked from commit 1611a8d1c5)
Merged-In: Ie12b570f1e6400ab9e289b882e5821921a609e0a
This commit is contained in:
Sharon Su
2022-02-19 02:18:40 +00:00
parent 861759636b
commit bb146eff49
6 changed files with 85 additions and 46 deletions

View File

@@ -2636,18 +2636,18 @@ package android.app.wallpapereffectsgeneration {
method public int describeContents(); method public int describeContents();
method @NonNull public float[] getAnchorPointInOutputUvSpace(); method @NonNull public float[] getAnchorPointInOutputUvSpace();
method @NonNull public float[] getAnchorPointInWorldSpace(); method @NonNull public float[] getAnchorPointInWorldSpace();
method public float getCameraOrbitPitchDegrees(); method @FloatRange(from=-90.0F, to=90.0f) public float getCameraOrbitPitchDegrees();
method public float getCameraOrbitYawDegrees(); method @FloatRange(from=-180.0F, to=180.0f) public float getCameraOrbitYawDegrees();
method public float getDollyDistanceInWorldSpace(); method public float getDollyDistanceInWorldSpace();
method public float getFrustumFarInWorldSpace(); method @FloatRange(from=0.0f) public float getFrustumFarInWorldSpace();
method public float getFrustumNearInWorldSpace(); method @FloatRange(from=0.0f) public float getFrustumNearInWorldSpace();
method public float getVerticalFovDegrees(); method @FloatRange(from=0.0f, to=180.0f, fromInclusive=false) public float getVerticalFovDegrees();
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.app.wallpapereffectsgeneration.CameraAttributes> CREATOR; field @NonNull public static final android.os.Parcelable.Creator<android.app.wallpapereffectsgeneration.CameraAttributes> CREATOR;
} }
public static final class CameraAttributes.Builder { public static final class CameraAttributes.Builder {
ctor public CameraAttributes.Builder(@NonNull float[], @NonNull float[]); ctor public CameraAttributes.Builder(@NonNull @Size(3) float[], @NonNull @Size(2) float[]);
method @NonNull public android.app.wallpapereffectsgeneration.CameraAttributes build(); method @NonNull public android.app.wallpapereffectsgeneration.CameraAttributes build();
method @NonNull public android.app.wallpapereffectsgeneration.CameraAttributes.Builder setCameraOrbitPitchDegrees(@FloatRange(from=-90.0F, to=90.0f) float); method @NonNull public android.app.wallpapereffectsgeneration.CameraAttributes.Builder setCameraOrbitPitchDegrees(@FloatRange(from=-90.0F, to=90.0f) float);
method @NonNull public android.app.wallpapereffectsgeneration.CameraAttributes.Builder setCameraOrbitYawDegrees(@FloatRange(from=-180.0F, to=180.0f) float); method @NonNull public android.app.wallpapereffectsgeneration.CameraAttributes.Builder setCameraOrbitYawDegrees(@FloatRange(from=-180.0F, to=180.0f) float);
@@ -2675,12 +2675,11 @@ package android.app.wallpapereffectsgeneration {
method @NonNull public String getTaskId(); method @NonNull public String getTaskId();
method @NonNull public java.util.List<android.app.wallpapereffectsgeneration.TexturedMesh> getTexturedMeshes(); method @NonNull public java.util.List<android.app.wallpapereffectsgeneration.TexturedMesh> getTexturedMeshes();
method public void writeToParcel(@NonNull android.os.Parcel, int); method public void writeToParcel(@NonNull android.os.Parcel, int);
field public static final int CINEMATIC_EFFECT_STATUS_ERROR = 2; // 0x2 field public static final int CINEMATIC_EFFECT_STATUS_ERROR = 0; // 0x0
field public static final int CINEMATIC_EFFECT_STATUS_NOT_READY = 3; // 0x3 field public static final int CINEMATIC_EFFECT_STATUS_NOT_READY = 2; // 0x2
field public static final int CINEMATIC_EFFECT_STATUS_OK = 1; // 0x1 field public static final int CINEMATIC_EFFECT_STATUS_OK = 1; // 0x1
field public static final int CINEMATIC_EFFECT_STATUS_PENDING = 4; // 0x4 field public static final int CINEMATIC_EFFECT_STATUS_PENDING = 3; // 0x3
field public static final int CINEMATIC_EFFECT_STATUS_TOO_MANY_REQUESTS = 5; // 0x5 field public static final int CINEMATIC_EFFECT_STATUS_TOO_MANY_REQUESTS = 4; // 0x4
field public static final int CINEMATIC_EFFECT_STATUS_UNKNOWN = 0; // 0x0
field @NonNull public static final android.os.Parcelable.Creator<android.app.wallpapereffectsgeneration.CinematicEffectResponse> CREATOR; field @NonNull public static final android.os.Parcelable.Creator<android.app.wallpapereffectsgeneration.CinematicEffectResponse> CREATOR;
field public static final int IMAGE_CONTENT_TYPE_LANDSCAPE = 2; // 0x2 field public static final int IMAGE_CONTENT_TYPE_LANDSCAPE = 2; // 0x2
field public static final int IMAGE_CONTENT_TYPE_OTHER = 3; // 0x3 field public static final int IMAGE_CONTENT_TYPE_OTHER = 3; // 0x3
@@ -12041,8 +12040,9 @@ package android.service.wallpapereffectsgeneration {
public abstract class WallpaperEffectsGenerationService extends android.app.Service { public abstract class WallpaperEffectsGenerationService extends android.app.Service {
ctor public WallpaperEffectsGenerationService(); ctor public WallpaperEffectsGenerationService();
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 onGenerateCinematicEffect(@NonNull android.app.wallpapereffectsgeneration.CinematicEffectRequest); method @MainThread public abstract void onGenerateCinematicEffect(@NonNull android.app.wallpapereffectsgeneration.CinematicEffectRequest);
method public final void returnCinematicEffectResponse(@NonNull android.app.wallpapereffectsgeneration.CinematicEffectResponse); method public final void returnCinematicEffectResponse(@NonNull android.app.wallpapereffectsgeneration.CinematicEffectResponse);
field public static final String SERVICE_INTERFACE = "android.service.wallpapereffectsgeneration.WallpaperEffectsGenerationService";
} }
} }

View File

@@ -18,6 +18,7 @@ package android.app.wallpapereffectsgeneration;
import android.annotation.FloatRange; import android.annotation.FloatRange;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Size;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@@ -117,6 +118,7 @@ public final class CameraAttributes implements Parcelable {
/** /**
* Get the camera yaw orbit rotation. * Get the camera yaw orbit rotation.
*/ */
@FloatRange(from = -180.0f, to = 180.0f)
public float getCameraOrbitYawDegrees() { public float getCameraOrbitYawDegrees() {
return mCameraOrbitYawDegrees; return mCameraOrbitYawDegrees;
} }
@@ -124,6 +126,7 @@ public final class CameraAttributes implements Parcelable {
/** /**
* Get the camera pitch orbit rotation. * Get the camera pitch orbit rotation.
*/ */
@FloatRange(from = -90.0f, to = 90.0f)
public float getCameraOrbitPitchDegrees() { public float getCameraOrbitPitchDegrees() {
return mCameraOrbitPitchDegrees; return mCameraOrbitPitchDegrees;
} }
@@ -138,6 +141,7 @@ public final class CameraAttributes implements Parcelable {
/** /**
* Get the camera vertical fov degrees. * Get the camera vertical fov degrees.
*/ */
@FloatRange(from = 0.0f, to = 180.0f, fromInclusive = false)
public float getVerticalFovDegrees() { public float getVerticalFovDegrees() {
return mVerticalFovDegrees; return mVerticalFovDegrees;
} }
@@ -145,6 +149,7 @@ public final class CameraAttributes implements Parcelable {
/** /**
* Get the frustum in near plane. * Get the frustum in near plane.
*/ */
@FloatRange(from = 0.0f)
public float getFrustumNearInWorldSpace() { public float getFrustumNearInWorldSpace() {
return mFrustumNearInWorldSpace; return mFrustumNearInWorldSpace;
} }
@@ -152,6 +157,7 @@ public final class CameraAttributes implements Parcelable {
/** /**
* Get the frustum in far plane. * Get the frustum in far plane.
*/ */
@FloatRange(from = 0.0f)
public float getFrustumFarInWorldSpace() { public float getFrustumFarInWorldSpace() {
return mFrustumFarInWorldSpace; return mFrustumFarInWorldSpace;
} }
@@ -217,8 +223,8 @@ public final class CameraAttributes implements Parcelable {
* @hide * @hide
*/ */
@SystemApi @SystemApi
public Builder(@NonNull float[] anchorPointInWorldSpace, public Builder(@NonNull @Size(3) float[] anchorPointInWorldSpace,
@NonNull float[] anchorPointInOutputUvSpace) { @NonNull @Size(2) float[] anchorPointInOutputUvSpace) {
mAnchorPointInWorldSpace = anchorPointInWorldSpace; mAnchorPointInWorldSpace = anchorPointInWorldSpace;
mAnchorPointInOutputUvSpace = anchorPointInOutputUvSpace; mAnchorPointInOutputUvSpace = anchorPointInOutputUvSpace;
} }

View File

@@ -39,27 +39,31 @@ import java.util.Objects;
public final class CinematicEffectResponse implements Parcelable { public final class CinematicEffectResponse implements Parcelable {
/** @hide */ /** @hide */
@IntDef(prefix = {"CINEMATIC_EFFECT_STATUS_"}, @IntDef(prefix = {"CINEMATIC_EFFECT_STATUS_"},
value = {CINEMATIC_EFFECT_STATUS_UNKNOWN, value = {CINEMATIC_EFFECT_STATUS_ERROR,
CINEMATIC_EFFECT_STATUS_OK, CINEMATIC_EFFECT_STATUS_OK,
CINEMATIC_EFFECT_STATUS_ERROR,
CINEMATIC_EFFECT_STATUS_NOT_READY, CINEMATIC_EFFECT_STATUS_NOT_READY,
CINEMATIC_EFFECT_STATUS_PENDING, CINEMATIC_EFFECT_STATUS_PENDING,
CINEMATIC_EFFECT_STATUS_TOO_MANY_REQUESTS}) CINEMATIC_EFFECT_STATUS_TOO_MANY_REQUESTS
})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface CinematicEffectStatusCode {} public @interface CinematicEffectStatusCode {}
/** Cinematic effect generation unknown status. */ /** Cinematic effect generation failure with internal error. */
public static final int CINEMATIC_EFFECT_STATUS_UNKNOWN = 0; public static final int CINEMATIC_EFFECT_STATUS_ERROR = 0;
/** Cinematic effect generation success. */ /** Cinematic effect generation success. */
public static final int CINEMATIC_EFFECT_STATUS_OK = 1; public static final int CINEMATIC_EFFECT_STATUS_OK = 1;
/** Cinematic effect generation failure. */
public static final int CINEMATIC_EFFECT_STATUS_ERROR = 2;
/** Service not ready for cinematic effect generation. */ /** Service not ready for cinematic effect generation. */
public static final int CINEMATIC_EFFECT_STATUS_NOT_READY = 3; public static final int CINEMATIC_EFFECT_STATUS_NOT_READY = 2;
/** Cienmatic effect generation process is pending. */ /**
public static final int CINEMATIC_EFFECT_STATUS_PENDING = 4; * There is already a task being processed for the same task id.
/** Too manay requests for server to handle. */ * Client should wait for the response and not send the same request
public static final int CINEMATIC_EFFECT_STATUS_TOO_MANY_REQUESTS = 5; * again.
*/
public static final int CINEMATIC_EFFECT_STATUS_PENDING = 3;
/** Too many requests for server to handle. */
public static final int CINEMATIC_EFFECT_STATUS_TOO_MANY_REQUESTS = 4;
/** @hide */ /** @hide */
@IntDef(prefix = {"IMAGE_CONTENT_TYPE_"}, @IntDef(prefix = {"IMAGE_CONTENT_TYPE_"},
@@ -71,13 +75,13 @@ public final class CinematicEffectResponse implements Parcelable {
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface ImageContentType {} public @interface ImageContentType {}
/** Image content unknown. */ /** Unable to determine image type. */
public static final int IMAGE_CONTENT_TYPE_UNKNOWN = 0; public static final int IMAGE_CONTENT_TYPE_UNKNOWN = 0;
/** Image content is people portrait. */ /** Image content is people portrait. */
public static final int IMAGE_CONTENT_TYPE_PEOPLE_PORTRAIT = 1; public static final int IMAGE_CONTENT_TYPE_PEOPLE_PORTRAIT = 1;
/** Image content is landscape. */ /** Image content is landscape. */
public static final int IMAGE_CONTENT_TYPE_LANDSCAPE = 2; public static final int IMAGE_CONTENT_TYPE_LANDSCAPE = 2;
/** Image content is doesn't belong to other types. */ /** Image content is not people portrait or landscape. */
public static final int IMAGE_CONTENT_TYPE_OTHER = 3; public static final int IMAGE_CONTENT_TYPE_OTHER = 3;

View File

@@ -19,6 +19,7 @@ package android.service.wallpapereffectsgeneration;
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage; import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
import android.annotation.CallSuper; import android.annotation.CallSuper;
import android.annotation.MainThread;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.app.Service; import android.app.Service;
@@ -69,7 +70,6 @@ public abstract class WallpaperEffectsGenerationService extends Service {
* {@link android.permission#MANAGE_WALLPAPER_EFFECTS_GENERATION} * {@link android.permission#MANAGE_WALLPAPER_EFFECTS_GENERATION}
* permission. * permission.
* *
* @hide
*/ */
public static final String SERVICE_INTERFACE = public static final String SERVICE_INTERFACE =
"android.service.wallpapereffectsgeneration.WallpaperEffectsGenerationService"; "android.service.wallpapereffectsgeneration.WallpaperEffectsGenerationService";
@@ -97,6 +97,7 @@ public abstract class WallpaperEffectsGenerationService extends Service {
* *
* @param request the cinematic effect request passed from the client. * @param request the cinematic effect request passed from the client.
*/ */
@MainThread
public abstract void onGenerateCinematicEffect(@NonNull CinematicEffectRequest request); public abstract void onGenerateCinematicEffect(@NonNull CinematicEffectRequest request);
/** /**

View File

@@ -108,7 +108,7 @@ public class WallpaperEffectsGenerationManagerService extends
@Override @Override
public void generateCinematicEffect(@NonNull CinematicEffectRequest request, public void generateCinematicEffect(@NonNull CinematicEffectRequest request,
@NonNull ICinematicEffectListener listener) { @NonNull ICinematicEffectListener listener) {
if (!runForUserLocked("generateCinematicEffect", (service) -> if (!runForUser("generateCinematicEffect", true, (service) ->
service.onGenerateCinematicEffectLocked(request, listener))) { service.onGenerateCinematicEffectLocked(request, listener))) {
try { try {
listener.onCinematicEffectGenerated( listener.onCinematicEffectGenerated(
@@ -126,7 +126,7 @@ public class WallpaperEffectsGenerationManagerService extends
@Override @Override
public void returnCinematicEffectResponse(@NonNull CinematicEffectResponse response) { public void returnCinematicEffectResponse(@NonNull CinematicEffectResponse response) {
runForUserLocked("returnCinematicResponse", (service) -> runForUser("returnCinematicResponse", false, (service) ->
service.onReturnCinematicEffectResponseLocked(response)); service.onReturnCinematicEffectResponseLocked(response));
} }
@@ -140,30 +140,42 @@ public class WallpaperEffectsGenerationManagerService extends
} }
/** /**
* Execute the operation for the user locked. Return true if * Execute the operation for the user.
* WallpaperEffectsGenerationPerUserService is found for the user. *
* Otherwise return false. * @param func The name of function for logging purpose.
* @param checkManageWallpaperEffectsPermission whether to check if caller has
* MANAGE_WALLPAPER_EFFECTS_GENERATION.
* If false, check the uid of caller matching bind service.
* @param c WallpaperEffectsGenerationPerUserService operation.
* @return whether WallpaperEffectsGenerationPerUserService is found.
*/ */
private boolean runForUserLocked(@NonNull final String func, private boolean runForUser(@NonNull final String func,
@NonNull final boolean checkManageWallpaperEffectsPermission,
@NonNull final Consumer<WallpaperEffectsGenerationPerUserService> c) { @NonNull final Consumer<WallpaperEffectsGenerationPerUserService> c) {
ActivityManagerInternal am = LocalServices.getService(ActivityManagerInternal.class); ActivityManagerInternal am = LocalServices.getService(ActivityManagerInternal.class);
final int userId = am.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), final int userId = am.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
Binder.getCallingUserHandle().getIdentifier(), false, ALLOW_NON_FULL, Binder.getCallingUserHandle().getIdentifier(), false, ALLOW_NON_FULL,
null, null); null, null);
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "runForUserLocked:" + func + " from pid=" + Binder.getCallingPid() Slog.d(TAG, "runForUser:" + func + " from pid=" + Binder.getCallingPid()
+ ", uid=" + Binder.getCallingUid()); + ", uid=" + Binder.getCallingUid());
} }
Context ctx = getContext(); if (checkManageWallpaperEffectsPermission) {
if (!(ctx.checkCallingPermission(MANAGE_WALLPAPER_EFFECTS_GENERATION) // MANAGE_WALLPAPER_EFFECTS_GENERATION is required for all functions except for
== PERMISSION_GRANTED // "returnCinematicResponse", whose calling permission checked in
|| mServiceNameResolver.isTemporary(userId) // WallpaperEffectsGenerationPerUserService against remote binding.
|| mActivityTaskManagerInternal.isCallerRecents(Binder.getCallingUid()))) { Context ctx = getContext();
String msg = "Permission Denial: Cannot call " + func + " from pid=" if (!(ctx.checkCallingPermission(MANAGE_WALLPAPER_EFFECTS_GENERATION)
+ Binder.getCallingPid() + ", uid=" + Binder.getCallingUid(); == PERMISSION_GRANTED
Slog.w(TAG, msg); || mServiceNameResolver.isTemporary(userId)
throw new SecurityException(msg); || mActivityTaskManagerInternal.isCallerRecents(Binder.getCallingUid()))) {
String msg = "Permission Denial: Cannot call " + func + " from pid="
+ Binder.getCallingPid() + ", uid=" + Binder.getCallingUid();
Slog.w(TAG, msg);
throw new SecurityException(msg);
}
} }
final int origCallingUid = Binder.getCallingUid();
final long origId = Binder.clearCallingIdentity(); final long origId = Binder.clearCallingIdentity();
boolean accepted = false; boolean accepted = false;
try { try {
@@ -171,6 +183,16 @@ public class WallpaperEffectsGenerationManagerService extends
final WallpaperEffectsGenerationPerUserService service = final WallpaperEffectsGenerationPerUserService service =
getServiceForUserLocked(userId); getServiceForUserLocked(userId);
if (service != null) { if (service != null) {
// Check uid of caller matches bind service implementation if
// MANAGE_WALLPAPER_EFFECTS_GENERATION is skipped. This is useful
// for service implementation to return response.
if (!checkManageWallpaperEffectsPermission
&& !service.isCallingUidAllowed(origCallingUid)) {
String msg = "Permission Denial: cannot call " + func + ", uid["
+ origCallingUid + "] doesn't match service implementation";
Slog.w(TAG, msg);
throw new SecurityException(msg);
}
accepted = true; accepted = true;
c.accept(service); c.accept(service);
} }

View File

@@ -141,6 +141,13 @@ public class WallpaperEffectsGenerationPerUserService extends
invokeCinematicListenerAndCleanup(cinematicEffectResponse); invokeCinematicListenerAndCleanup(cinematicEffectResponse);
} }
/**
* Checks whether the calling uid matches the bind service uid.
*/
public boolean isCallingUidAllowed(int callingUid) {
return getServiceUidLocked() == callingUid;
}
@GuardedBy("mLock") @GuardedBy("mLock")
private void updateRemoteServiceLocked() { private void updateRemoteServiceLocked() {
if (mRemoteService != null) { if (mRemoteService != null) {
@@ -152,7 +159,6 @@ public class WallpaperEffectsGenerationPerUserService extends
invokeCinematicListenerAndCleanup( invokeCinematicListenerAndCleanup(
createErrorCinematicEffectResponse(mCinematicEffectListenerWrapper.mTaskId)); createErrorCinematicEffectResponse(mCinematicEffectListenerWrapper.mTaskId));
} }
} }
void onPackageUpdatedLocked() { void onPackageUpdatedLocked() {