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

Commit 3a86bd81 authored by Zhou Liu's avatar Zhou Liu
Browse files

Add an API in SupervisionManager to create intent for launching the PIN verification activity

The intent is to be consumed by both Package Installer and KM.

Test: atest SupervisionServiceTest
Bug: 393468509
Flag: android.app.supervision.flags.enable_supervision_settings_screen
Change-Id: I2505cf97b71dcc3eadf52634a7dd7b51f9291c33
parent f7e95e04
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -16,11 +16,14 @@


package android.app.supervision;
package android.app.supervision;


import android.content.Intent;

/**
/**
 * Internal IPC interface to the supervision service.
 * Internal IPC interface to the supervision service.
 * {@hide}
 * {@hide}
 */
 */
interface ISupervisionManager {
interface ISupervisionManager {
    Intent createConfirmSupervisionCredentialsIntent();
    boolean isSupervisionEnabledForUser(int userId);
    boolean isSupervisionEnabledForUser(int userId);
    void setSupervisionEnabledForUser(int userId, boolean enabled);
    void setSupervisionEnabledForUser(int userId, boolean enabled);
    String getActiveSupervisionAppPackage(int userId);
    String getActiveSupervisionAppPackage(int userId);
+33 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.UserHandleAware;
import android.annotation.UserIdInt;
import android.annotation.UserIdInt;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.os.RemoteException;
import android.os.RemoteException;


/**
/**
@@ -71,6 +72,38 @@ public class SupervisionManager {
        mService = service;
        mService = service;
    }
    }


    /**
     * 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 API
     * is called, the launched activity still need to perform validity checks as the supervision
     * state can change when the activity is launched. A null intent is returned if supervision is
     * disabled at the time of this API call.
     *
     * <p>A result code of {@link android.app.Activity#RESULT_OK} indicates successful verification
     * of the supervision credentials.
     *
     * @hide
     */
    @RequiresPermission(value = android.Manifest.permission.QUERY_USERS)
    @Nullable
    public Intent createConfirmSupervisionCredentialsIntent() {
        if (mService != null) {
            try {
                Intent result = mService.createConfirmSupervisionCredentialsIntent();
                if (result != null) {
                    result.prepareToEnterProcess(
                            Intent.LOCAL_FLAG_FROM_SYSTEM, mContext.getAttributionSource());
                }
                return result;
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return null;
    }

    /**
    /**
     * Returns whether the device is supervised.
     * Returns whether the device is supervised.
     *
     *
+19 −0
Original line number Original line Diff line number Diff line
@@ -78,6 +78,25 @@ 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.
     *
     *