summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/system-current.txt10
-rw-r--r--core/java/android/provider/DeviceConfig.java30
-rw-r--r--services/core/java/com/android/server/attention/AttentionManagerService.java22
3 files changed, 48 insertions, 14 deletions
diff --git a/api/system-current.txt b/api/system-current.txt
index 328b6d277f0d..e0af359c999b 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -5743,6 +5743,12 @@ package android.provider {
field public static final String NAMESPACE = "activity_manager";
}
+ public static interface DeviceConfig.AttentionManagerService {
+ field public static final String NAMESPACE = "attention_manager_service";
+ field public static final String PROPERTY_COMPONENT_NAME = "component_name";
+ field public static final String PROPERTY_SERVICE_ENABLED = "service_enabled";
+ }
+
public static interface DeviceConfig.FsiBoot {
field public static final String NAMESPACE = "fsi_boot";
field public static final String OOB_ENABLED = "oob_enabled";
@@ -5751,8 +5757,8 @@ package android.provider {
public static interface DeviceConfig.IntelligenceAttention {
field public static final String NAMESPACE = "intelligence_attention";
- field public static final String PROPERTY_ATTENTION_CHECK_ENABLED = "attention_check_enabled";
- field public static final String PROPERTY_ATTENTION_CHECK_SETTINGS = "attention_check_settings";
+ field public static final String PROPERTY_ATTENTION_ENABLED = "attention_enabled";
+ field public static final String PROPERTY_ATTENTION_SETTINGS = "attention_settings";
}
public static interface DeviceConfig.OnPropertyChangedListener {
diff --git a/core/java/android/provider/DeviceConfig.java b/core/java/android/provider/DeviceConfig.java
index 148dd910ef69..d58e00af5054 100644
--- a/core/java/android/provider/DeviceConfig.java
+++ b/core/java/android/provider/DeviceConfig.java
@@ -112,14 +112,12 @@ public final class DeviceConfig {
@SystemApi
public interface IntelligenceAttention {
String NAMESPACE = "intelligence_attention";
- /**
- * If {@code true}, enables the attention check.
- */
- String PROPERTY_ATTENTION_CHECK_ENABLED = "attention_check_enabled";
- /**
- * Settings for performing the attention check.
- */
- String PROPERTY_ATTENTION_CHECK_SETTINGS = "attention_check_settings";
+
+ /** If {@code true}, enables the attention features. */
+ String PROPERTY_ATTENTION_ENABLED = "attention_enabled";
+
+ /** Settings for the attention features. */
+ String PROPERTY_ATTENTION_SETTINGS = "attention_settings";
}
/**
@@ -182,6 +180,22 @@ public final class DeviceConfig {
}
/**
+ * Namespace for {@link AttentionManagerService} related features.
+ *
+ * @hide
+ */
+ @SystemApi
+ public interface AttentionManagerService {
+ String NAMESPACE = "attention_manager_service";
+
+ /** If {@code true}, enables {@link AttentionManagerService} features. */
+ String PROPERTY_SERVICE_ENABLED = "service_enabled";
+
+ /** Allows a CTS to inject a fake implementation. */
+ String PROPERTY_COMPONENT_NAME = "component_name";
+ }
+
+ /**
* Namespace for storage-related features.
*
* @hide
diff --git a/services/core/java/com/android/server/attention/AttentionManagerService.java b/services/core/java/com/android/server/attention/AttentionManagerService.java
index b71a7517ab12..5b469fe2dc7a 100644
--- a/services/core/java/com/android/server/attention/AttentionManagerService.java
+++ b/services/core/java/com/android/server/attention/AttentionManagerService.java
@@ -16,6 +16,10 @@
package com.android.server.attention;
+import static android.provider.DeviceConfig.AttentionManagerService.NAMESPACE;
+import static android.provider.DeviceConfig.AttentionManagerService.PROPERTY_COMPONENT_NAME;
+import static android.provider.DeviceConfig.AttentionManagerService.PROPERTY_SERVICE_ENABLED;
+
import android.Manifest;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
@@ -40,6 +44,7 @@ import android.os.PowerManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
+import android.provider.DeviceConfig;
import android.service.attention.AttentionService;
import android.service.attention.AttentionService.AttentionFailureCodes;
import android.service.attention.IAttentionCallback;
@@ -66,6 +71,9 @@ import java.io.PrintWriter;
public class AttentionManagerService extends SystemService {
private static final String LOG_TAG = "AttentionManagerService";
+ /** Default value in absence of {@link DeviceConfig} override. */
+ private static final boolean DEFAULT_SERVICE_ENABLED = true;
+
/** Service will unbind if connection is not used for that amount of time. */
private static final long CONNECTION_TTL_MILLIS = 60_000;
@@ -105,7 +113,7 @@ public class AttentionManagerService extends SystemService {
super.onBootPhase(phase);
if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
mComponentName = resolveAttentionService(mContext);
- if (mComponentName != null) {
+ if (isAttentionServiceSupported()) {
// If the service is supported we want to keep receiving the screen off events.
mContext.registerReceiver(new ScreenStateReceiver(),
new IntentFilter(Intent.ACTION_SCREEN_OFF));
@@ -117,7 +125,12 @@ public class AttentionManagerService extends SystemService {
* Returns {@code true} if attention service is supported on this device.
*/
public boolean isAttentionServiceSupported() {
- return mComponentName != null;
+ return mComponentName != null && isServiceEnabled();
+ }
+
+ private boolean isServiceEnabled() {
+ final String enabled = DeviceConfig.getProperty(NAMESPACE, PROPERTY_SERVICE_ENABLED);
+ return enabled == null ? DEFAULT_SERVICE_ENABLED : "true".equals(enabled);
}
/**
@@ -266,8 +279,9 @@ public class AttentionManagerService extends SystemService {
* system.
*/
private static ComponentName resolveAttentionService(Context context) {
- // TODO(b/111939367): add a flag to turn on/off.
- final String componentNameString = context.getString(
+ final String flag = DeviceConfig.getProperty(NAMESPACE, PROPERTY_COMPONENT_NAME);
+
+ final String componentNameString = flag != null ? flag : context.getString(
R.string.config_defaultAttentionService);
if (TextUtils.isEmpty(componentNameString)) {