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

Commit d795827c authored by Alex Chau's avatar Alex Chau
Browse files

API Review: Drop "Button" in is/setLogoutEnabled method

Bug: 70336452
Test: Logout button can still be controlled

Change-Id: I2ac24c4dec1ce90a77037a6415b4a6f77e959965
parent a044c1d2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -6392,7 +6392,7 @@ package android.app.admin {
    method public deprecated boolean isCallerApplicationRestrictionsManagingPackage();
    method public boolean isDeviceOwnerApp(java.lang.String);
    method public boolean isLockTaskPermitted(java.lang.String);
    method public boolean isLogoutButtonEnabled();
    method public boolean isLogoutEnabled();
    method public boolean isManagedProfile(android.content.ComponentName);
    method public boolean isMasterVolumeMuted(android.content.ComponentName);
    method public boolean isNetworkLoggingEnabled(android.content.ComponentName);
@@ -6436,7 +6436,7 @@ package android.app.admin {
    method public void setKeyguardDisabledFeatures(android.content.ComponentName, int);
    method public void setLockTaskFeatures(android.content.ComponentName, int);
    method public void setLockTaskPackages(android.content.ComponentName, java.lang.String[]) throws java.lang.SecurityException;
    method public void setLogoutButtonEnabled(android.content.ComponentName, boolean);
    method public void setLogoutEnabled(android.content.ComponentName, boolean);
    method public void setLongSupportMessage(android.content.ComponentName, java.lang.CharSequence);
    method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
    method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
+11 −12
Original line number Diff line number Diff line
@@ -8535,32 +8535,31 @@ public class DevicePolicyManager {
    }

    /**
     * Called by a device owner to specify whether a logout button is enabled for all secondary
     * users. The system may show a logout button that stops the user and switches back to the
     * primary user.
     * Called by a device owner to specify whether logout is enabled for all secondary users. The
     * system may show a logout button that stops the user and switches back to the primary user.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param enabled whether logout button should be enabled or not.
     * @param enabled whether logout should be enabled or not.
     * @throws SecurityException if {@code admin} is not a device owner.
     */
    public void setLogoutButtonEnabled(@NonNull ComponentName admin, boolean enabled) {
        throwIfParentInstance("setLogoutButtonEnabled");
    public void setLogoutEnabled(@NonNull ComponentName admin, boolean enabled) {
        throwIfParentInstance("setLogoutEnabled");
        try {
            mService.setLogoutButtonEnabled(admin, enabled);
            mService.setLogoutEnabled(admin, enabled);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Returns whether logout button is enabled by a device owner.
     * Returns whether logout is enabled by a device owner.
     *
     * @return {@code true} if logout button is enabled by device owner, {@code false} otherwise.
     * @return {@code true} if logout is enabled by device owner, {@code false} otherwise.
     */
    public boolean isLogoutButtonEnabled() {
        throwIfParentInstance("isLogoutButtonEnabled");
    public boolean isLogoutEnabled() {
        throwIfParentInstance("isLogoutEnabled");
        try {
            return mService.isLogoutButtonEnabled();
            return mService.isLogoutEnabled();
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
+2 −2
Original line number Diff line number Diff line
@@ -370,6 +370,6 @@ interface IDevicePolicyManager {

    boolean clearApplicationUserData(in ComponentName admin, in String packageName, in IPackageDataObserver callback);

    void setLogoutButtonEnabled(in ComponentName admin, boolean enabled);
    boolean isLogoutButtonEnabled();
    void setLogoutEnabled(in ComponentName admin, boolean enabled);
    boolean isLogoutEnabled();
}
+1 −1
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener,
            } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
                mItems.add(new RestartAction());
            } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
                if (mDevicePolicyManager.isLogoutButtonEnabled()
                if (mDevicePolicyManager.isLogoutEnabled()
                        && getCurrentUser().id != UserHandle.USER_SYSTEM) {
                    mItems.add(new LogoutAction());
                    mHasLogoutButton = true;
+15 −16
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ import android.app.admin.DeviceAdminInfo;
import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.admin.IDevicePolicyManager;
import android.app.admin.NetworkEvent;
import android.app.admin.PasswordMetrics;
import android.app.admin.SecurityLog;
@@ -737,7 +736,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        private static final String TAG_ORGANIZATION_NAME = "organization-name";
        private static final String ATTR_LAST_NETWORK_LOGGING_NOTIFICATION = "last-notification";
        private static final String ATTR_NUM_NETWORK_LOGGING_NOTIFICATIONS = "num-notifications";
        private static final String TAG_IS_LOGOUT_BUTTON_ENABLED = "is_logout_button_enabled";
        private static final String TAG_IS_LOGOUT_ENABLED = "is_logout_enabled";

        final DeviceAdminInfo info;

@@ -787,7 +786,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        boolean requireAutoTime = false; // Can only be set by a device owner.
        boolean forceEphemeralUsers = false; // Can only be set by a device owner.
        boolean isNetworkLoggingEnabled = false; // Can only be set by a device owner.
        boolean isLogoutButtonEnabled = false; // Can only be set by a device owner.
        boolean isLogoutEnabled = false; // Can only be set by a device owner.

        // one notification after enabling + one more after reboots
        static final int DEF_MAXIMUM_NETWORK_LOGGING_NOTIFICATIONS_SHOWN = 2;
@@ -1105,10 +1104,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                out.text(organizationName);
                out.endTag(null, TAG_ORGANIZATION_NAME);
            }
            if (isLogoutButtonEnabled) {
                out.startTag(null, TAG_IS_LOGOUT_BUTTON_ENABLED);
                out.attribute(null, ATTR_VALUE, Boolean.toString(isLogoutButtonEnabled));
                out.endTag(null, TAG_IS_LOGOUT_BUTTON_ENABLED);
            if (isLogoutEnabled) {
                out.startTag(null, TAG_IS_LOGOUT_ENABLED);
                out.attribute(null, ATTR_VALUE, Boolean.toString(isLogoutEnabled));
                out.endTag(null, TAG_IS_LOGOUT_ENABLED);
            }
        }

@@ -1283,8 +1282,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    } else {
                        Log.w(LOG_TAG, "Missing text when loading organization name");
                    }
                } else if (TAG_IS_LOGOUT_BUTTON_ENABLED.equals(tag)) {
                    isLogoutButtonEnabled = Boolean.parseBoolean(
                } else if (TAG_IS_LOGOUT_ENABLED.equals(tag)) {
                    isLogoutEnabled = Boolean.parseBoolean(
                            parser.getAttributeValue(null, ATTR_VALUE));
                } else {
                    Slog.w(LOG_TAG, "Unknown admin tag: " + tag);
@@ -11530,35 +11529,35 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }

    @Override
    public synchronized void setLogoutButtonEnabled(ComponentName admin, boolean enabled) {
    public synchronized void setLogoutEnabled(ComponentName admin, boolean enabled) {
        if (!mHasFeature) {
            return;
        }
        Preconditions.checkNotNull(admin);
        getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);

        if (enabled == isLogoutButtonEnabledInternalLocked()) {
        if (enabled == isLogoutEnabledInternalLocked()) {
            // already in the requested state
            return;
        }
        ActiveAdmin deviceOwner = getDeviceOwnerAdminLocked();
        deviceOwner.isLogoutButtonEnabled = enabled;
        deviceOwner.isLogoutEnabled = enabled;
        saveSettingsLocked(mInjector.userHandleGetCallingUserId());
    }

    @Override
    public boolean isLogoutButtonEnabled() {
    public boolean isLogoutEnabled() {
        if (!mHasFeature) {
            return false;
        }
        synchronized (this) {
            return isLogoutButtonEnabledInternalLocked();
            return isLogoutEnabledInternalLocked();
        }
    }

    private boolean isLogoutButtonEnabledInternalLocked() {
    private boolean isLogoutEnabledInternalLocked() {
        ActiveAdmin deviceOwner = getDeviceOwnerAdminLocked();
        return (deviceOwner != null) && deviceOwner.isLogoutButtonEnabled;
        return (deviceOwner != null) && deviceOwner.isLogoutEnabled;
    }

}