diff options
Diffstat (limited to 'adservices/framework/java/com/android')
-rw-r--r-- | adservices/framework/java/com/android/adservices/AdServicesCommon.java | 37 | ||||
-rw-r--r-- | adservices/framework/java/com/android/adservices/AndroidServiceBinder.java | 54 |
2 files changed, 90 insertions, 1 deletions
diff --git a/adservices/framework/java/com/android/adservices/AdServicesCommon.java b/adservices/framework/java/com/android/adservices/AdServicesCommon.java index 23275bf655..5fae085095 100644 --- a/adservices/framework/java/com/android/adservices/AdServicesCommon.java +++ b/adservices/framework/java/com/android/adservices/AdServicesCommon.java @@ -17,11 +17,15 @@ package com.android.adservices; import android.adservices.adid.AdIdProviderService; import android.adservices.appsetid.AppSetIdProviderService; +import android.adservices.cobalt.AdServicesCobaltUploadService; +import android.adservices.extdata.AdServicesExtDataStorageService; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import java.util.List; +// TODO(b/295321663): need to split constants into AdServicesCommonConstants so they can be used by +// host-side test artifacts. /** * Common constants for AdServices * @@ -41,6 +45,14 @@ public class AdServicesCommon { public static final String ACTION_AD_SELECTION_SERVICE = "android.adservices.adselection.AD_SELECTION_SERVICE"; + /** + * Intent action to discover the protected signals service in the APK. + * + * @hide + */ + public static final String ACTION_PROTECTED_SIGNALS_SERVICE = + "android.adservices.adselection.PROTECTED_SIGNALS_SERVICE"; + /** Intent action to discover the Measurement service in the APK. */ public static final String ACTION_MEASUREMENT_SERVICE = "android.adservices.MEASUREMENT_SERVICE"; @@ -58,10 +70,18 @@ public class AdServicesCommon { public static final String ACTION_APPSETID_PROVIDER_SERVICE = AppSetIdProviderService.SERVICE_INTERFACE; + /** Intent action to discover the AdServicesExtDataStorageService. */ + public static final String ACTION_AD_EXT_DATA_STORAGE_SERVICE = + AdServicesExtDataStorageService.SERVICE_INTERFACE; + /** Intent action to discover the AdServicesCommon service in the APK. */ public static final String ACTION_AD_SERVICES_COMMON_SERVICE = "android.adservices.AD_SERVICES_COMMON_SERVICE"; + /** Intent action to discover the AdServices Cobalt upload service. */ + public static final String ACTION_AD_SERVICES_COBALT_UPLOAD_SERVICE = + AdServicesCobaltUploadService.SERVICE_INTERFACE; + // Used to differentiate between AdServices APK package name and AdExtServices APK package name. // The AdExtServices APK package name suffix is android.ext.services. public static final String ADSERVICES_APK_PACKAGE_NAME_SUFFIX = "android.adservices.api"; @@ -74,6 +94,23 @@ public class AdServicesCommon { */ public static final String EXTSERVICES_APEX_NAME_SUFFIX = "android.extservices"; + /** + * Prefix for system properties used for debugging purposes (like simulating unsupported devices + * or change some behavior without changing a flag). + */ + public static final String SYSTEM_PROPERTY_FOR_DEBUGGING_PREFIX = "debug.adservices."; + + /** System property used to simulate AdServices behavior in a device that doesn't support it. */ + public static final String SYSTEM_PROPERTY_FOR_DEBUGGING_SUPPORTED_ON_DEVICE = + SYSTEM_PROPERTY_FOR_DEBUGGING_PREFIX + "supported"; + + /** System property used to simulate AdServices behavior on devices with low memory. */ + public static final String SYSTEM_PROPERTY_FOR_DEBUGGING_FEATURE_RAM_LOW = + SYSTEM_PROPERTY_FOR_DEBUGGING_PREFIX + "low_ram_device"; + + /** Path name for Adservice class names */ + public static final String ADSERVICES_CLASS_PATH_PREFIX = "com.android.adservices."; + /** The package name of the active AdServices APK on this device. */ public static ServiceInfo resolveAdServicesService( List<ResolveInfo> intentResolveInfos, String intentAction) { diff --git a/adservices/framework/java/com/android/adservices/AndroidServiceBinder.java b/adservices/framework/java/com/android/adservices/AndroidServiceBinder.java index e63d278c0e..280be9a2cf 100644 --- a/adservices/framework/java/com/android/adservices/AndroidServiceBinder.java +++ b/adservices/framework/java/com/android/adservices/AndroidServiceBinder.java @@ -19,13 +19,16 @@ import static android.adservices.common.AdServicesStatusUtils.ILLEGAL_STATE_EXCE import static com.android.adservices.AdServicesCommon.ACTION_ADID_PROVIDER_SERVICE; import static com.android.adservices.AdServicesCommon.ACTION_ADID_SERVICE; +import static com.android.adservices.AdServicesCommon.ACTION_AD_EXT_DATA_STORAGE_SERVICE; import static com.android.adservices.AdServicesCommon.ACTION_AD_SELECTION_SERVICE; +import static com.android.adservices.AdServicesCommon.ACTION_AD_SERVICES_COBALT_UPLOAD_SERVICE; import static com.android.adservices.AdServicesCommon.ACTION_AD_SERVICES_COMMON_SERVICE; import static com.android.adservices.AdServicesCommon.ACTION_APPSETID_PROVIDER_SERVICE; import static com.android.adservices.AdServicesCommon.ACTION_APPSETID_SERVICE; import static com.android.adservices.AdServicesCommon.ACTION_CUSTOM_AUDIENCE_SERVICE; import static com.android.adservices.AdServicesCommon.ACTION_MEASUREMENT_SERVICE; import static com.android.adservices.AdServicesCommon.ACTION_TOPICS_SERVICE; +import static com.android.adservices.AdServicesCommon.SYSTEM_PROPERTY_FOR_DEBUGGING_FEATURE_RAM_LOW; import android.annotation.Nullable; import android.content.ComponentName; @@ -35,7 +38,10 @@ import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; +import android.os.Build; import android.os.IBinder; +import android.os.SystemProperties; +import android.text.TextUtils; import com.android.internal.annotations.GuardedBy; @@ -74,14 +80,34 @@ class AndroidServiceBinder<T> extends ServiceBinder<T> { @GuardedBy("mLock") private ServiceConnection mServiceConnection; + private final boolean mSimulatingLowRamDevice; + protected AndroidServiceBinder( Context context, String serviceIntentAction, Function<IBinder, T> converter) { mServiceIntentAction = serviceIntentAction; mContext = context; mBinderConverter = converter; + if (!isDebuggable()) { + mSimulatingLowRamDevice = false; + } else { + String propValue = SystemProperties.get(SYSTEM_PROPERTY_FOR_DEBUGGING_FEATURE_RAM_LOW); + mSimulatingLowRamDevice = !TextUtils.isEmpty(propValue) && Boolean.valueOf(propValue); + } + if (mSimulatingLowRamDevice) { + LogUtil.w( + "Service %s disabled because of system property %s", + serviceIntentAction, SYSTEM_PROPERTY_FOR_DEBUGGING_FEATURE_RAM_LOW); + } } public T getService() { + if (mSimulatingLowRamDevice) { + throw new IllegalStateException( + "Service is not bound (because of SystemProperty " + + SYSTEM_PROPERTY_FOR_DEBUGGING_FEATURE_RAM_LOW + + ")"); + } + synchronized (mLock) { // If we already have a service, just return it. if (mService != null) { @@ -193,7 +219,9 @@ class AndroidServiceBinder<T> extends ServiceBinder<T> { && !mServiceIntentAction.equals(ACTION_ADID_PROVIDER_SERVICE) && !mServiceIntentAction.equals(ACTION_APPSETID_SERVICE) && !mServiceIntentAction.equals(ACTION_APPSETID_PROVIDER_SERVICE) - && !mServiceIntentAction.equals(ACTION_AD_SERVICES_COMMON_SERVICE)) { + && !mServiceIntentAction.equals(ACTION_AD_SERVICES_COBALT_UPLOAD_SERVICE) + && !mServiceIntentAction.equals(ACTION_AD_SERVICES_COMMON_SERVICE) + && !mServiceIntentAction.equals(ACTION_AD_EXT_DATA_STORAGE_SERVICE)) { LogUtil.e("Bad service intent action: " + mServiceIntentAction); return null; } @@ -213,6 +241,12 @@ class AndroidServiceBinder<T> extends ServiceBinder<T> { @Override public void unbindFromService() { + if (mSimulatingLowRamDevice) { + LogUtil.d( + "unbindFromService(): ignored because it's disabled by system property %s", + SYSTEM_PROPERTY_FOR_DEBUGGING_FEATURE_RAM_LOW); + return; + } synchronized (mLock) { if (mServiceConnection != null) { LogUtil.d("unbinding..."); @@ -222,4 +256,22 @@ class AndroidServiceBinder<T> extends ServiceBinder<T> { mService = null; } } + + // TODO(b/293894199, b/284744130): members below were adapted from BuildCompatUtils, it would + // be better to move BuildCompatUtils to this package + + private static final boolean IS_DEBUGGABLE = computeIsDebuggable(); + + private static boolean isDebuggable() { + return IS_DEBUGGABLE; + } + + private static boolean computeIsDebuggable() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + return Build.isDebuggable(); + } + + // Build.isDebuggable was added in S; duplicate that functionality for R. + return SystemProperties.getInt("ro.debuggable", 0) == 1; + } } |