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

Commit 93ae42b0 authored by Alex Chau's avatar Alex Chau
Browse files

Customize user switch dialog

- Introduced DevicePolicyManager to set messaging for switching out of and into user 0
- Introduced coressponeding API to get the message

Bug: 71787514
Test: Set start and end session message with TestDPC, change is reflected
Test: Restart the device, switch message is still enforced
Test: Clear the message with TestDPC, reverted back to default
Change-Id: I527eca6f151cee35459abad7ae9dcdeef486148f
parent 7d0e1f80
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -6397,6 +6397,7 @@ package android.app.admin {
    method public java.util.List<java.lang.String> getDelegatePackages(android.content.ComponentName, java.lang.String);
    method public java.util.List<java.lang.String> getDelegatedScopes(android.content.ComponentName, java.lang.String);
    method public java.lang.CharSequence getDeviceOwnerLockScreenInfo();
    method public java.lang.CharSequence getEndUserSessionMessage(android.content.ComponentName);
    method public java.util.List<byte[]> getInstalledCaCerts(android.content.ComponentName);
    method public java.util.List<java.lang.String> getKeepUninstalledPackages(android.content.ComponentName);
    method public int getKeyguardDisabledFeatures(android.content.ComponentName);
@@ -6432,6 +6433,7 @@ package android.app.admin {
    method public boolean getScreenCaptureDisabled(android.content.ComponentName);
    method public java.util.List<android.os.UserHandle> getSecondaryUsers(android.content.ComponentName);
    method public java.lang.CharSequence getShortSupportMessage(android.content.ComponentName);
    method public java.lang.CharSequence getStartUserSessionMessage(android.content.ComponentName);
    method public boolean getStorageEncryption(android.content.ComponentName);
    method public int getStorageEncryptionStatus();
    method public android.app.admin.SystemUpdatePolicy getSystemUpdatePolicy();
@@ -6494,6 +6496,7 @@ package android.app.admin {
    method public void setCrossProfileContactsSearchDisabled(android.content.ComponentName, boolean);
    method public void setDelegatedScopes(android.content.ComponentName, java.lang.String, java.util.List<java.lang.String>);
    method public void setDeviceOwnerLockScreenInfo(android.content.ComponentName, java.lang.CharSequence);
    method public void setEndUserSessionMessage(android.content.ComponentName, java.lang.CharSequence);
    method public void setGlobalSetting(android.content.ComponentName, java.lang.String, java.lang.String);
    method public void setKeepUninstalledPackages(android.content.ComponentName, java.util.List<java.lang.String>);
    method public boolean setKeyPairCertificate(android.content.ComponentName, java.lang.String, java.util.List<java.security.cert.Certificate>, boolean);
@@ -6537,6 +6540,7 @@ package android.app.admin {
    method public void setSecureSetting(android.content.ComponentName, java.lang.String, java.lang.String);
    method public void setSecurityLoggingEnabled(android.content.ComponentName, boolean);
    method public void setShortSupportMessage(android.content.ComponentName, java.lang.CharSequence);
    method public void setStartUserSessionMessage(android.content.ComponentName, java.lang.CharSequence);
    method public boolean setStatusBarDisabled(android.content.ComponentName, boolean);
    method public int setStorageEncryption(android.content.ComponentName, boolean);
    method public void setSystemSetting(android.content.ComponentName, java.lang.String, java.lang.String);
+10 −0
Original line number Diff line number Diff line
@@ -324,4 +324,14 @@ public abstract class ActivityManagerInternal {
     * Returns if more users can be started without stopping currently running users.
     */
    public abstract boolean canStartMoreUsers();

    /**
     * Sets the user switcher message for switching from {@link android.os.UserHandle#SYSTEM}.
     */
    public abstract void setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage);

    /**
     * Sets the user switcher message for switching to {@link android.os.UserHandle#SYSTEM}.
     */
    public abstract void setSwitchingToSystemUserMessage(String switchingToSystemUserMessage);
}
+80 −0
Original line number Diff line number Diff line
@@ -9124,4 +9124,84 @@ public class DevicePolicyManager {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Called by a device owner to specify the user session start message. This may be displayed
     * during a user switch.
     * <p>
     * The message should be limited to a short statement or it may be truncated.
     * <p>
     * If the message needs to be localized, it is the responsibility of the
     * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
     * and set a new version of this message accordingly.
     *
     * @param admin which {@link DeviceAdminReceiver} this request is associated with.
     * @param startUserSessionMessage message for starting user session, or {@code null} to use
     * system default message.
     * @throws SecurityException if {@code admin} is not a device owner.
     */
    public void setStartUserSessionMessage(
            @NonNull ComponentName admin, @Nullable CharSequence startUserSessionMessage) {
        throwIfParentInstance("setStartUserSessionMessage");
        try {
            mService.setStartUserSessionMessage(admin, startUserSessionMessage);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Called by a device owner to specify the user session end message. This may be displayed
     * during a user switch.
     * <p>
     * The message should be limited to a short statement or it may be truncated.
     * <p>
     * If the message needs to be localized, it is the responsibility of the
     * {@link DeviceAdminReceiver} to listen to the {@link Intent#ACTION_LOCALE_CHANGED} broadcast
     * and set a new version of this message accordingly.
     *
     * @param admin which {@link DeviceAdminReceiver} this request is associated with.
     * @param endUserSessionMessage message for ending user session, or {@code null} to use system
     * default message.
     * @throws SecurityException if {@code admin} is not a device owner.
     */
    public void setEndUserSessionMessage(
            @NonNull ComponentName admin, @Nullable CharSequence endUserSessionMessage) {
        throwIfParentInstance("setEndUserSessionMessage");
        try {
            mService.setEndUserSessionMessage(admin, endUserSessionMessage);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Returns the user session start message.
     *
     * @param admin which {@link DeviceAdminReceiver} this request is associated with.
     * @throws SecurityException if {@code admin} is not a device owner.
     */
    public CharSequence getStartUserSessionMessage(@NonNull ComponentName admin) {
        throwIfParentInstance("getStartUserSessionMessage");
        try {
            return mService.getStartUserSessionMessage(admin);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Returns the user session end message.
     *
     * @param admin which {@link DeviceAdminReceiver} this request is associated with.
     * @throws SecurityException if {@code admin} is not a device owner.
     */
    public CharSequence getEndUserSessionMessage(@NonNull ComponentName admin) {
        throwIfParentInstance("getEndUserSessionMessage");
        try {
            return mService.getEndUserSessionMessage(admin);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -391,4 +391,9 @@ interface IDevicePolicyManager {

    List<String> getDisallowedSystemApps(in ComponentName admin, int userId, String provisioningAction);
    void transferOwnership(in ComponentName admin, in ComponentName target, in PersistableBundle bundle);

    void setStartUserSessionMessage(in ComponentName admin, in CharSequence startUserSessionMessage);
    void setEndUserSessionMessage(in ComponentName admin, in CharSequence endUserSessionMessage);
    CharSequence getStartUserSessionMessage(in ComponentName admin);
    CharSequence getEndUserSessionMessage(in ComponentName admin);
}
+10 −0
Original line number Diff line number Diff line
@@ -25133,6 +25133,16 @@ public class ActivityManagerService extends IActivityManager.Stub
        public boolean canStartMoreUsers() {
            return mUserController.canStartMoreUsers();
        }
        @Override
        public void setSwitchingFromSystemUserMessage(String switchingFromSystemUserMessage) {
            mUserController.setSwitchingFromSystemUserMessage(switchingFromSystemUserMessage);
        }
        @Override
        public void setSwitchingToSystemUserMessage(String switchingToSystemUserMessage) {
            mUserController.setSwitchingToSystemUserMessage(switchingToSystemUserMessage);
        }
    }
    /**
Loading