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

Commit 22928ac2 authored by juquan's avatar juquan
Browse files

[Device Supervision][base] Implement createConfirmSupervisionCredentialsIntent API.

Bug: 392961554
Flag: android.app.supervision.flags.enable_supervision_settings_screen
Test: atest SupervisionServiceTest
Change-Id: I5625ea388426c3d3603a7ecea96b456123397f39
parent 543337c7
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -97,7 +97,7 @@ public class SupervisionManager {
     *
     *
     * @hide
     * @hide
     */
     */
    @RequiresPermission(value = android.Manifest.permission.QUERY_USERS)
    @RequiresPermission(anyOf = {MANAGE_USERS, QUERY_USERS})
    @Nullable
    @Nullable
    public Intent createConfirmSupervisionCredentialsIntent() {
    public Intent createConfirmSupervisionCredentialsIntent() {
        if (mService != null) {
        if (mService != null) {
+37 −19
Original line number Original line Diff line number Diff line
@@ -64,6 +64,18 @@ import java.util.List;
public class SupervisionService extends ISupervisionManager.Stub {
public class SupervisionService extends ISupervisionManager.Stub {
    private static final String LOG_TAG = "SupervisionService";
    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?
    // TODO(b/362756788): Does this need to be a LockGuard lock?
    private final Object mLockDoNoUseDirectly = new Object();
    private final Object mLockDoNoUseDirectly = new Object();


@@ -80,25 +92,6 @@ public class SupervisionService extends ISupervisionManager.Stub {
        mInjector.getUserManagerInternal().addUserLifecycleListener(new UserLifecycleListener());
        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.
     * 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
    @Override
    public void onShellCommand(
    public void onShellCommand(
            @Nullable FileDescriptor in,
            @Nullable FileDescriptor in,
+8 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.internal.R
import com.android.server.LocalServices
import com.android.server.LocalServices
import com.android.server.SystemService.TargetUser
import com.android.server.SystemService.TargetUser
import com.android.server.pm.UserManagerInternal
import com.android.server.pm.UserManagerInternal
import com.android.server.supervision.SupervisionService.ACTION_CONFIRM_SUPERVISION_CREDENTIALS
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Before
import org.junit.Rule
import org.junit.Rule
@@ -247,6 +248,13 @@ class SupervisionServiceTest {
        assertThat(userData.supervisionLockScreenOptions).isNull()
        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
    private val systemSupervisionPackage: String
        get() = context.getResources().getString(R.string.config_systemSupervision)
        get() = context.getResources().getString(R.string.config_systemSupervision)