summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorMatt Pietal <mpietal@google.com>2021-10-21 10:33:09 -0400
committerMatt Pietal <mpietal@google.com>2021-11-01 13:55:52 -0400
commitd689c6ad2d0d7cbbd5a2cd9ea93bb61b261a3f5a (patch)
treedcd7d106ecec52361f4ab3af7f53b7ccf325f4ae /core/java
parent809adc7c21eddc2444d6527ea478e9b3841be72f (diff)
Controls API - Support action while device is locked
By default, all user interactions with a device control while the device is locked will require authorization. Add a new field to the Control class that allows the application that builds the control to determine if the device requires authorization or not. Fixes: 202978576 Test: atest ControlActionCoordinatorImplTest ControlProviderServiceTest Test: atest CtsControlsDeviceTestCases CtsControlBuilderTest CtsControlTemplateTest Change-Id: I294662b88637e18bf620aff2eed4749ae304ebd4
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/service/controls/Control.java37
-rw-r--r--core/java/android/service/controls/ControlsProviderService.java6
2 files changed, 40 insertions, 3 deletions
diff --git a/core/java/android/service/controls/Control.java b/core/java/android/service/controls/Control.java
index 2868f1bf3547..3b757d6e3dd3 100644
--- a/core/java/android/service/controls/Control.java
+++ b/core/java/android/service/controls/Control.java
@@ -121,6 +121,7 @@ public final class Control implements Parcelable {
private final @Status int mStatus;
private final @NonNull ControlTemplate mControlTemplate;
private final @NonNull CharSequence mStatusText;
+ private final boolean mAuthRequired;
/**
* @param controlId the unique persistent identifier for this object.
@@ -137,6 +138,8 @@ public final class Control implements Parcelable {
* @param status
* @param controlTemplate
* @param statusText
+ * @param authRequired true if the control can not be interacted with until the device is
+ * unlocked
*/
Control(@NonNull String controlId,
@DeviceTypes.DeviceType int deviceType,
@@ -149,7 +152,8 @@ public final class Control implements Parcelable {
@Nullable ColorStateList customColor,
@Status int status,
@NonNull ControlTemplate controlTemplate,
- @NonNull CharSequence statusText) {
+ @NonNull CharSequence statusText,
+ boolean authRequired) {
Preconditions.checkNotNull(controlId);
Preconditions.checkNotNull(title);
Preconditions.checkNotNull(subtitle);
@@ -180,6 +184,7 @@ public final class Control implements Parcelable {
}
mControlTemplate = controlTemplate;
mStatusText = statusText;
+ mAuthRequired = authRequired;
}
/**
@@ -219,6 +224,7 @@ public final class Control implements Parcelable {
ControlTemplateWrapper wrapper = ControlTemplateWrapper.CREATOR.createFromParcel(in);
mControlTemplate = wrapper.getWrappedTemplate();
mStatusText = in.readCharSequence();
+ mAuthRequired = in.readBoolean();
}
/**
@@ -336,6 +342,13 @@ public final class Control implements Parcelable {
return mStatusText;
}
+ /**
+ * @return true if the control can not be interacted with until the device is unlocked
+ */
+ public boolean isAuthRequired() {
+ return mAuthRequired;
+ }
+
@Override
public int describeContents() {
return 0;
@@ -376,6 +389,7 @@ public final class Control implements Parcelable {
dest.writeInt(mStatus);
new ControlTemplateWrapper(mControlTemplate).writeToParcel(dest, flags);
dest.writeCharSequence(mStatusText);
+ dest.writeBoolean(mAuthRequired);
}
public static final @NonNull Creator<Control> CREATOR = new Creator<Control>() {
@@ -409,6 +423,7 @@ public final class Control implements Parcelable {
* <li> Status: {@link Status#STATUS_UNKNOWN}
* <li> Control template: {@link ControlTemplate#getNoTemplateObject}
* <li> Status text: {@code ""}
+ * <li> Auth Required: {@code true}
* </ul>
*/
@SuppressLint("MutableBareField")
@@ -585,7 +600,8 @@ public final class Control implements Parcelable {
mCustomColor,
STATUS_UNKNOWN,
ControlTemplate.NO_TEMPLATE,
- "");
+ "",
+ true /* authRequired */);
}
}
@@ -607,6 +623,7 @@ public final class Control implements Parcelable {
* <li> Status: {@link Status#STATUS_UNKNOWN}
* <li> Control template: {@link ControlTemplate#getNoTemplateObject}
* <li> Status text: {@code ""}
+ * <li> Auth Required: {@code true}
* </ul>
*/
public static final class StatefulBuilder {
@@ -623,6 +640,7 @@ public final class Control implements Parcelable {
private @Status int mStatus = STATUS_UNKNOWN;
private @NonNull ControlTemplate mControlTemplate = ControlTemplate.NO_TEMPLATE;
private @NonNull CharSequence mStatusText = "";
+ private boolean mAuthRequired = true;
/**
* @param controlId the identifier for the {@link Control}.
@@ -655,6 +673,7 @@ public final class Control implements Parcelable {
mStatus = control.mStatus;
mControlTemplate = control.mControlTemplate;
mStatusText = control.mStatusText;
+ mAuthRequired = control.mAuthRequired;
}
/**
@@ -821,6 +840,17 @@ public final class Control implements Parcelable {
}
/**
+ * @param authRequired true if the control can not be interacted with until the device is
+ * unlocked
+ * @return {@code this}
+ */
+ @NonNull
+ public StatefulBuilder setAuthRequired(boolean authRequired) {
+ mAuthRequired = authRequired;
+ return this;
+ }
+
+ /**
* @return a valid {@link Control}
*/
@NonNull
@@ -836,7 +866,8 @@ public final class Control implements Parcelable {
mCustomColor,
mStatus,
mControlTemplate,
- mStatusText);
+ mStatusText,
+ mAuthRequired);
}
}
}
diff --git a/core/java/android/service/controls/ControlsProviderService.java b/core/java/android/service/controls/ControlsProviderService.java
index c5277ee0ed5e..47b16a351806 100644
--- a/core/java/android/service/controls/ControlsProviderService.java
+++ b/core/java/android/service/controls/ControlsProviderService.java
@@ -116,6 +116,9 @@ public abstract class ControlsProviderService extends Service {
* Calls to {@link Subscriber#onComplete} will not be expected. Instead, wait for the call from
* {@link Subscription#cancel} to indicate that updates are no longer required. It is expected
* that controls provided by this publisher were created using {@link Control.StatefulBuilder}.
+ *
+ * By default, all controls require the device to be unlocked in order for the user to interact
+ * with it. This can be modified per Control by {@link Control.StatefulBuilder#setAuthRequired}.
*/
@NonNull
public abstract Publisher<Control> createPublisherFor(@NonNull List<String> controlIds);
@@ -127,6 +130,9 @@ public abstract class ControlsProviderService extends Service {
* {@link ControlAction.ResponseResult}. The Integer should indicate whether the action
* was received successfully, or if additional prompts should be presented to
* the user. Any visual control updates should be sent via the Publisher.
+
+ * By default, all invocations of this method will require the device be unlocked. This can
+ * be modified per Control by {@link Control.StatefulBuilder#setAuthRequired}.
*/
public abstract void performControlAction(@NonNull String controlId,
@NonNull ControlAction action, @NonNull Consumer<Integer> consumer);