summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author felkachang <felkachang@google.com> 2022-09-19 13:06:23 +0800
committer felkachang <felkachang@google.com> 2022-11-30 00:49:42 +0800
commit1cbf6fbbb4835f97b9fd6ad6814966c01bdeeba3 (patch)
treeff00252c8b40d5a345f65a7808e55de5daf0f82b
parent77eb98c8ac71097229bd95680c21b63ab6e388aa (diff)
Let self-targeting apps be able access OverlayManager
Self-targeting apps can't get an OverlayManager instance without the system privilege. This patch makes sure that the self-targeting application can get an OverlayManager instance via Context. ``` OverlayManager overlayManager = context.getSystemService(OverlayManager.class); ``` In order to make the self-targeting feature compatible in the future, this patch adds SELF_TARGETING_OVERLAY compatibility feature. Test: atest \ OverlayHostTests \ OverlayDeviceTests \ SelfTargetingOverlayDeviceTests \ OverlayRemountedTest \ FrameworksServicesTests:com.android.server.om \ CtsContentTestCases:android.content.om.cts \ idmap2_tests Bug: 205919743 Change-Id: Ib0b619a2a54e22d31e6c14bf700e421688b6f506
-rw-r--r--core/java/android/app/SystemServiceRegistry.java6
-rw-r--r--core/java/android/content/om/OverlayManager.java15
2 files changed, 20 insertions, 1 deletions
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java
index e54a0841dd26..5d87012ec7e7 100644
--- a/core/java/android/app/SystemServiceRegistry.java
+++ b/core/java/android/app/SystemServiceRegistry.java
@@ -58,6 +58,7 @@ import android.companion.CompanionDeviceManager;
import android.companion.ICompanionDeviceManager;
import android.companion.virtual.IVirtualDeviceManager;
import android.companion.virtual.VirtualDeviceManager;
+import android.compat.Compatibility;
import android.content.ClipboardManager;
import android.content.ContentCaptureOptions;
import android.content.Context;
@@ -1092,7 +1093,10 @@ public final class SystemServiceRegistry {
new CachedServiceFetcher<OverlayManager>() {
@Override
public OverlayManager createService(ContextImpl ctx) throws ServiceNotFoundException {
- IBinder b = ServiceManager.getServiceOrThrow(Context.OVERLAY_SERVICE);
+ final IBinder b =
+ (Compatibility.isChangeEnabled(OverlayManager.SELF_TARGETING_OVERLAY))
+ ? ServiceManager.getService(Context.OVERLAY_SERVICE)
+ : ServiceManager.getServiceOrThrow(Context.OVERLAY_SERVICE);
return new OverlayManager(ctx, IOverlayManager.Stub.asInterface(b));
}});
diff --git a/core/java/android/content/om/OverlayManager.java b/core/java/android/content/om/OverlayManager.java
index 94275aea0c4d..812f6b0fc34b 100644
--- a/core/java/android/content/om/OverlayManager.java
+++ b/core/java/android/content/om/OverlayManager.java
@@ -92,6 +92,21 @@ public class OverlayManager {
private static final long THROW_SECURITY_EXCEPTIONS = 147340954;
/**
+ * Applications can use OverlayManager to create overlays to overlay on itself resources. The
+ * overlay target is itself and the work range is only in caller application.
+ *
+ * <p>In {@link android.content.Context#getSystemService(String)}, it crashes because of {@link
+ * java.lang.NullPointerException} if the parameter is OverlayManager. if the self-targeting is
+ * enabled, the caller application can get the OverlayManager instance to use self-targeting
+ * functionality.
+ *
+ * @hide
+ */
+ @ChangeId
+ @EnabledSince(targetSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
+ public static final long SELF_TARGETING_OVERLAY = 205919743;
+
+ /**
* Creates a new instance.
*
* @param context The current context in which to operate.