Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 440fe3d8 authored by Alex Salo's avatar Alex Salo
Browse files

Add a flags to AttentionManagerService

Additionally, simplify some flag names.

Test: manually tested, works as expected
Bug: 111939367
Change-Id: I8c2702dbbaf964096d6907cbcd6c90dfd38b7d07
parent e8d1eaa1
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -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 {
+22 −8
Original line number Diff line number Diff line
@@ -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";
    }

    /**
@@ -181,6 +179,22 @@ public final class DeviceConfig {
        String KEY_MAX_CACHED_PROCESSES = "max_cached_processes";
    }

    /**
     * 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.
     *
+18 −4
Original line number Diff line number Diff line
@@ -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)) {