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

Commit 1da632ed authored by Junchen Quan's avatar Junchen Quan Committed by Android (Google) Code Review
Browse files

Merge "[Device Supervision][base] Implement...

Merge "[Device Supervision][base] Implement createConfirmSupervisionCredentialsIntent API." into main
parents 9d9e4847 22928ac2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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) {
+37 −19
Original line number Diff line number Diff line
@@ -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();

@@ -80,25 +92,6 @@ public class SupervisionService extends ISupervisionManager.Stub {
        mInjector.getUserManagerInternal().addUserLifecycleListener(new UserLifecycleListener());
    }

    /**
     * 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.
     *
@@ -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,
+8 −0
Original line number Diff line number Diff line
@@ -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)