public abstract class AttentionService extends android.app.Service {
ctor public AttentionService();
+ method public final void disableSelf();
method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
method public abstract void onCancelAttentionCheck(int);
method public abstract void onCheckAttention(int, @NonNull android.service.attention.AttentionService.AttentionCallback);
- field public static final int ATTENTION_FAILURE_PREEMPTED = 2; // 0x2
- field public static final int ATTENTION_FAILURE_TIMED_OUT = 3; // 0x3
- field public static final int ATTENTION_FAILURE_UNKNOWN = 4; // 0x4
+ field public static final int ATTENTION_FAILURE_CAMERA_PERMISSION_ABSENT = 6; // 0x6
+ field public static final int ATTENTION_FAILURE_CANCELLED = 3; // 0x3
+ field public static final int ATTENTION_FAILURE_PREEMPTED = 4; // 0x4
+ field public static final int ATTENTION_FAILURE_TIMED_OUT = 5; // 0x5
+ field public static final int ATTENTION_FAILURE_UNKNOWN = 2; // 0x2
field public static final int ATTENTION_SUCCESS_ABSENT = 0; // 0x0
field public static final int ATTENTION_SUCCESS_PRESENT = 1; // 0x1
field public static final String SERVICE_INTERFACE = "android.service.attention.AttentionService";
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.Service;
+import android.attention.AttentionManagerInternal;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import com.android.internal.util.Preconditions;
+import com.android.server.LocalServices;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/** Attention is present. */
public static final int ATTENTION_SUCCESS_PRESENT = 1;
+ /** Unknown reasons for failing to determine the attention. */
+ public static final int ATTENTION_FAILURE_UNKNOWN = 2;
+
+ /** Request has been cancelled. */
+ public static final int ATTENTION_FAILURE_CANCELLED = 3;
+
/** Preempted by other client. */
- public static final int ATTENTION_FAILURE_PREEMPTED = 2;
+ public static final int ATTENTION_FAILURE_PREEMPTED = 4;
/** Request timed out. */
- public static final int ATTENTION_FAILURE_TIMED_OUT = 3;
+ public static final int ATTENTION_FAILURE_TIMED_OUT = 5;
- /** Unknown reasons for failing to determine the attention. */
- public static final int ATTENTION_FAILURE_UNKNOWN = 4;
+ /** Camera permission is not granted. */
+ public static final int ATTENTION_FAILURE_CAMERA_PERMISSION_ABSENT = 6;
/**
* Result codes for when attention check was successful.
*
* @hide
*/
- @IntDef(prefix = {"ATTENTION_FAILURE_"}, value = {ATTENTION_FAILURE_PREEMPTED,
- ATTENTION_FAILURE_TIMED_OUT, ATTENTION_FAILURE_UNKNOWN})
+ @IntDef(prefix = {"ATTENTION_FAILURE_"}, value = {ATTENTION_FAILURE_UNKNOWN,
+ ATTENTION_FAILURE_CANCELLED, ATTENTION_FAILURE_PREEMPTED, ATTENTION_FAILURE_TIMED_OUT,
+ ATTENTION_FAILURE_CAMERA_PERMISSION_ABSENT})
@Retention(RetentionPolicy.SOURCE)
public @interface AttentionFailureCodes {
}
}
/**
+ * Disables the dependants.
+ *
+ * Example: called if the service does not have sufficient permissions to perform the task.
+ */
+ public final void disableSelf() {
+ AttentionManagerInternal attentionManager = LocalServices.getService(
+ AttentionManagerInternal.class);
+ if (attentionManager != null) {
+ attentionManager.disableSelf();
+ }
+ }
+
+ /**
* Checks the user attention and calls into the provided callback.
*
* @param requestCode an identifier that could be used to cancel the request
/** Cancels the attention check for a given request code. */
public abstract void onCancelAttentionCheck(int requestCode);
-
/** Callbacks for AttentionService results. */
public static final class AttentionCallback {
private final IAttentionCallback mCallback;
package com.android.server.attention;
import static android.provider.DeviceConfig.NAMESPACE_ATTENTION_MANAGER_SERVICE;
+import static android.provider.Settings.System.ADAPTIVE_SLEEP;
import android.Manifest;
import android.annotation.Nullable;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.DeviceConfig;
+import android.provider.Settings;
import android.service.attention.AttentionService;
import android.service.attention.AttentionService.AttentionFailureCodes;
import android.service.attention.IAttentionCallback;
}
}
+ /** Disables service dependants. */
+ private void disableSelf() {
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ Settings.System.putInt(mContext.getContentResolver(), ADAPTIVE_SLEEP, 0);
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+ }
+
@GuardedBy("mLock")
private void freeIfInactiveLocked() {
// If we are called here, it means someone used the API again - reset the timer then.
public void cancelAttentionCheck(int requestCode) {
AttentionManagerService.this.cancelAttentionCheck(requestCode);
}
+
+ @Override
+ public void disableSelf() {
+ AttentionManagerService.this.disableSelf();
+ }
}
private static final class AttentionCheckCache {