summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author juquan <juquan@google.com> 2025-02-21 17:36:07 +0000
committer juquan <juquan@google.com> 2025-02-27 17:53:07 +0000
commit22928ac28e5509fbf5862431309da3c124f4b3c9 (patch)
tree2d8267ebc7ce5078047ac2a2b9476a4f9f56743d
parent543337c731654c712d080a2920c6863aa0a8e4e1 (diff)
[Device Supervision][base] Implement createConfirmSupervisionCredentialsIntent API.
Bug: 392961554 Flag: android.app.supervision.flags.enable_supervision_settings_screen Test: atest SupervisionServiceTest Change-Id: I5625ea388426c3d3603a7ecea96b456123397f39
-rw-r--r--core/java/android/app/supervision/SupervisionManager.java2
-rw-r--r--services/supervision/java/com/android/server/supervision/SupervisionService.java56
-rw-r--r--services/tests/servicestests/src/com/android/server/supervision/SupervisionServiceTest.kt8
3 files changed, 46 insertions, 20 deletions
diff --git a/core/java/android/app/supervision/SupervisionManager.java b/core/java/android/app/supervision/SupervisionManager.java
index 0270edf080a9..8217ca1953ab 100644
--- a/core/java/android/app/supervision/SupervisionManager.java
+++ b/core/java/android/app/supervision/SupervisionManager.java
@@ -97,7 +97,7 @@ public class SupervisionManager {
*
* @hide
*/
- @RequiresPermission(value = android.Manifest.permission.QUERY_USERS)
+ @RequiresPermission(anyOf = {MANAGE_USERS, QUERY_USERS})
@Nullable
public Intent createConfirmSupervisionCredentialsIntent() {
if (mService != null) {
diff --git a/services/supervision/java/com/android/server/supervision/SupervisionService.java b/services/supervision/java/com/android/server/supervision/SupervisionService.java
index f731b50d81b4..bb6339c79502 100644
--- a/services/supervision/java/com/android/server/supervision/SupervisionService.java
+++ b/services/supervision/java/com/android/server/supervision/SupervisionService.java
@@ -64,6 +64,18 @@ import java.util.List;
public class SupervisionService extends ISupervisionManager.Stub {
private static final String LOG_TAG = "SupervisionService";
+ /**
+ * Activity action: Requests user confirmation of supervision credentials.
+ *
+ * <p>Use {@link Activity#startActivityForResult} to launch this activity. The result will be
+ * {@link Activity#RESULT_OK} if credentials are valid.
+ *
+ * <p>If supervision credentials are not configured, this action initiates the setup flow.
+ */
+ @VisibleForTesting
+ static final String ACTION_CONFIRM_SUPERVISION_CREDENTIALS =
+ "android.app.supervision.action.CONFIRM_SUPERVISION_CREDENTIALS";
+
// TODO(b/362756788): Does this need to be a LockGuard lock?
private final Object mLockDoNoUseDirectly = new Object();
@@ -81,25 +93,6 @@ public class SupervisionService extends ISupervisionManager.Stub {
}
/**
- * Creates an {@link Intent} that can be used with {@link Context#startActivity(Intent)} to
- * launch the activity to verify supervision credentials.
- *
- * <p>A valid {@link Intent} is always returned if supervision is enabled at the time this
- * method is called, the launched activity still need to perform validity checks as the
- * supervision state can change when it's launched. A null intent is returned if supervision is
- * disabled at the time of this method call.
- *
- * <p>A result code of {@link android.app.Activity#RESULT_OK} indicates successful verification
- * of the supervision credentials.
- */
- @Override
- @Nullable
- public Intent createConfirmSupervisionCredentialsIntent() {
- // TODO(b/392961554): Implement createAuthenticationIntent API
- throw new UnsupportedOperationException();
- }
-
- /**
* Returns whether supervision is enabled for the given user.
*
* <p>Supervision is automatically enabled when the supervision app becomes the profile owner or
@@ -139,6 +132,31 @@ public class SupervisionService extends ISupervisionManager.Stub {
}
}
+ /**
+ * Creates an {@link Intent} that can be used with {@link Context#startActivity(Intent)} to
+ * launch the activity to verify supervision credentials.
+ *
+ * <p>A valid {@link Intent} is always returned if supervision is enabled at the time this
+ * method is called, the launched activity still need to perform validity checks as the
+ * supervision state can change when it's launched. A null intent is returned if supervision is
+ * disabled at the time of this method call.
+ *
+ * <p>A result code of {@link android.app.Activity#RESULT_OK} indicates successful verification
+ * of the supervision credentials.
+ */
+ @Override
+ @Nullable
+ public Intent createConfirmSupervisionCredentialsIntent() {
+ // TODO(b/392961554): (1) Return null if supervision is not enabled.
+ // (2) check if PIN exists before return a valid intent.
+ enforceAnyPermission(QUERY_USERS, MANAGE_USERS);
+ final Intent intent = new Intent(ACTION_CONFIRM_SUPERVISION_CREDENTIALS);
+ // explicitly set the package for security
+ intent.setPackage("com.android.settings");
+
+ return intent;
+ }
+
@Override
public void onShellCommand(
@Nullable FileDescriptor in,
diff --git a/services/tests/servicestests/src/com/android/server/supervision/SupervisionServiceTest.kt b/services/tests/servicestests/src/com/android/server/supervision/SupervisionServiceTest.kt
index da022780ea75..fbf906586e8b 100644
--- a/services/tests/servicestests/src/com/android/server/supervision/SupervisionServiceTest.kt
+++ b/services/tests/servicestests/src/com/android/server/supervision/SupervisionServiceTest.kt
@@ -39,6 +39,7 @@ import com.android.internal.R
import com.android.server.LocalServices
import com.android.server.SystemService.TargetUser
import com.android.server.pm.UserManagerInternal
+import com.android.server.supervision.SupervisionService.ACTION_CONFIRM_SUPERVISION_CREDENTIALS
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Rule
@@ -247,6 +248,13 @@ class SupervisionServiceTest {
assertThat(userData.supervisionLockScreenOptions).isNull()
}
+ @Test
+ fun createConfirmSupervisionCredentialsIntent() {
+ val intent = checkNotNull(service.createConfirmSupervisionCredentialsIntent())
+ assertThat(intent.action).isEqualTo(ACTION_CONFIRM_SUPERVISION_CREDENTIALS)
+ assertThat(intent.getPackage()).isEqualTo("com.android.settings")
+ }
+
private val systemSupervisionPackage: String
get() = context.getResources().getString(R.string.config_systemSupervision)