Merge "Rename functions that disable status bar and keyguard" into mnc-dev
diff --git a/api/current.txt b/api/current.txt
index 8716381..a5a1af6 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -5791,8 +5791,8 @@
     method public void setCrossProfileCallerIdDisabled(android.content.ComponentName, boolean);
     method public boolean setDeviceInitializer(android.content.ComponentName, android.content.ComponentName, java.lang.String) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException;
     method public void setGlobalSetting(android.content.ComponentName, java.lang.String, java.lang.String);
+    method public boolean setKeyguardDisabled(android.content.ComponentName, boolean);
     method public void setKeyguardDisabledFeatures(android.content.ComponentName, int);
-    method public boolean setKeyguardEnabledState(android.content.ComponentName, boolean);
     method public void setLockTaskPackages(android.content.ComponentName, java.lang.String[]) throws java.lang.SecurityException;
     method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
     method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
@@ -5818,7 +5818,7 @@
     method public void setRestrictionsProvider(android.content.ComponentName, android.content.ComponentName);
     method public void setScreenCaptureDisabled(android.content.ComponentName, boolean);
     method public void setSecureSetting(android.content.ComponentName, java.lang.String, java.lang.String);
-    method public void setStatusBarEnabledState(android.content.ComponentName, boolean);
+    method public boolean setStatusBarDisabled(android.content.ComponentName, boolean);
     method public int setStorageEncryption(android.content.ComponentName, boolean);
     method public void setSystemUpdatePolicy(android.content.ComponentName, android.app.admin.SystemUpdatePolicy);
     method public void setTrustAgentConfiguration(android.content.ComponentName, android.content.ComponentName, android.os.PersistableBundle);
diff --git a/api/system-current.txt b/api/system-current.txt
index f11e113..2248444 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -5897,8 +5897,8 @@
     method public void setCrossProfileCallerIdDisabled(android.content.ComponentName, boolean);
     method public boolean setDeviceInitializer(android.content.ComponentName, android.content.ComponentName, java.lang.String) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException;
     method public void setGlobalSetting(android.content.ComponentName, java.lang.String, java.lang.String);
+    method public boolean setKeyguardDisabled(android.content.ComponentName, boolean);
     method public void setKeyguardDisabledFeatures(android.content.ComponentName, int);
-    method public boolean setKeyguardEnabledState(android.content.ComponentName, boolean);
     method public void setLockTaskPackages(android.content.ComponentName, java.lang.String[]) throws java.lang.SecurityException;
     method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
     method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
@@ -5924,7 +5924,7 @@
     method public void setRestrictionsProvider(android.content.ComponentName, android.content.ComponentName);
     method public void setScreenCaptureDisabled(android.content.ComponentName, boolean);
     method public void setSecureSetting(android.content.ComponentName, java.lang.String, java.lang.String);
-    method public void setStatusBarEnabledState(android.content.ComponentName, boolean);
+    method public boolean setStatusBarDisabled(android.content.ComponentName, boolean);
     method public int setStorageEncryption(android.content.ComponentName, boolean);
     method public void setSystemUpdatePolicy(android.content.ComponentName, android.app.admin.SystemUpdatePolicy);
     method public void setTrustAgentConfiguration(android.content.ComponentName, android.content.ComponentName, android.os.PersistableBundle);
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 4b72dc3..8009b6c 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -4294,14 +4294,14 @@
      * being disabled.
      *
      * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
-     * @param enabled New state of the keyguard.
+     * @param disabled {@code true} disables the keyguard, {@code false} reenables it.
      *
      * @return {@code false} if attempting to disable the keyguard while a lock password was in
-     * place. {@code true} otherwise."
+     * place. {@code true} otherwise.
      */
-    public boolean setKeyguardEnabledState(ComponentName admin, boolean enabled) {
+    public boolean setKeyguardDisabled(ComponentName admin, boolean disabled) {
         try {
-            return mService.setKeyguardEnabledState(admin, enabled);
+            return mService.setKeyguardDisabled(admin, disabled);
         } catch (RemoteException re) {
             Log.w(TAG, "Failed talking with device policy service", re);
             return false;
@@ -4309,18 +4309,22 @@
     }
 
     /**
-     * Called by device owner to set the enabled state of the status bar. Disabling the status
-     * bar blocks notifications, quick settings and other screen overlays that allow escaping from
+     * Called by device owner to disable the status bar. Disabling the status bar blocks
+     * notifications, quick settings and other screen overlays that allow escaping from
      * a single use device.
      *
      * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
-     * @param enabled New state of the status bar.
+     * @param disabled {@code true} disables the status bar, {@code false} reenables it.
+     *
+     * @return {@code false} if attempting to disable the status bar failed.
+     * {@code true} otherwise.
      */
-    public void setStatusBarEnabledState(ComponentName admin, boolean enabled) {
+    public boolean setStatusBarDisabled(ComponentName admin, boolean disabled) {
         try {
-            mService.setStatusBarEnabledState(admin, enabled);
+            return mService.setStatusBarDisabled(admin, disabled);
         } catch (RemoteException re) {
             Log.w(TAG, "Failed talking with device policy service", re);
+            return false;
         }
     }
 
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 833bc00..e81e7c1 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -224,8 +224,8 @@
     void setSystemUpdatePolicy(in ComponentName who, in PersistableBundle policy);
     PersistableBundle getSystemUpdatePolicy();
 
-    boolean setKeyguardEnabledState(in ComponentName admin, boolean enabled);
-    void setStatusBarEnabledState(in ComponentName who, boolean enabled);
+    boolean setKeyguardDisabled(in ComponentName admin, boolean disabled);
+    boolean setStatusBarDisabled(in ComponentName who, boolean disabled);
     boolean getDoNotAskCredentialsOnBoot();
 
     void notifyPendingSystemUpdate(in long updateReceivedTime);
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index a8ec867..6f01ca0 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -161,7 +161,7 @@
 
     private static final String TAG_STATUS_BAR = "statusbar";
 
-    private static final String ATTR_ENABLED = "enabled";
+    private static final String ATTR_DISABLED = "disabled";
 
     private static final String DO_NOT_ASK_CREDENTIALS_ON_BOOT_XML =
             "do-not-ask-credentials-on-boot";
@@ -313,7 +313,7 @@
         // This is the list of component allowed to start lock task mode.
         List<String> mLockTaskPackages = new ArrayList<>();
 
-        boolean mStatusBarEnabledState = true;
+        boolean mStatusBarDisabled = false;
 
         ComponentName mRestrictionsProvider;
 
@@ -1476,9 +1476,9 @@
                 out.endTag(null, TAG_LOCK_TASK_COMPONENTS);
             }
 
-            if (!policy.mStatusBarEnabledState) {
+            if (policy.mStatusBarDisabled) {
                 out.startTag(null, TAG_STATUS_BAR);
-                out.attribute(null, ATTR_ENABLED, Boolean.toString(policy.mStatusBarEnabledState));
+                out.attribute(null, ATTR_DISABLED, Boolean.toString(policy.mStatusBarDisabled));
                 out.endTag(null, TAG_STATUS_BAR);
             }
 
@@ -1615,8 +1615,8 @@
                 } else if (TAG_LOCK_TASK_COMPONENTS.equals(tag)) {
                     policy.mLockTaskPackages.add(parser.getAttributeValue(null, "name"));
                 } else if (TAG_STATUS_BAR.equals(tag)) {
-                    policy.mStatusBarEnabledState = Boolean.parseBoolean(
-                            parser.getAttributeValue(null, ATTR_ENABLED));
+                    policy.mStatusBarDisabled = Boolean.parseBoolean(
+                            parser.getAttributeValue(null, ATTR_DISABLED));
                 } else if (DO_NOT_ASK_CREDENTIALS_ON_BOOT_XML.equals(tag)) {
                     policy.doNotAskCredentialsOnBoot = true;
                 } else {
@@ -1678,8 +1678,8 @@
         updateMaximumTimeToLockLocked(policy);
         addDeviceInitializerToLockTaskPackagesLocked(userHandle);
         updateLockTaskPackagesLocked(policy.mLockTaskPackages, userHandle);
-        if (!policy.mStatusBarEnabledState) {
-            setStatusBarEnabledStateInternal(policy.mStatusBarEnabledState, userHandle);
+        if (policy.mStatusBarDisabled) {
+            setStatusBarDisabledInternal(policy.mStatusBarDisabled, userHandle);
         }
         updatePreferredSetupActivityLocked(userHandle);
     }
@@ -4275,7 +4275,7 @@
             DevicePolicyData policy = getUserData(userId);
             policy.mPermissionPolicy = DevicePolicyManager.PERMISSION_POLICY_PROMPT;
             policy.mDelegatedCertInstallerPackage = null;
-            policy.mStatusBarEnabledState = true;
+            policy.mStatusBarDisabled = false;
             saveSettingsLocked(userId);
 
             long ident = Binder.clearCallingIdentity();
@@ -6026,7 +6026,7 @@
     }
 
     @Override
-    public boolean setKeyguardEnabledState(ComponentName who, boolean enabled) {
+    public boolean setKeyguardDisabled(ComponentName who, boolean disabled) {
         Preconditions.checkNotNull(who, "ComponentName is null");
         synchronized (this) {
             getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
@@ -6037,10 +6037,10 @@
         long ident = Binder.clearCallingIdentity();
         try {
             // disallow disabling the keyguard if a password is currently set
-            if (!enabled && utils.isSecure(userId)) {
+            if (disabled && utils.isSecure(userId)) {
                 return false;
             }
-            utils.setLockScreenDisabled(!enabled, userId);
+            utils.setLockScreenDisabled(disabled, userId);
         } finally {
             Binder.restoreCallingIdentity(ident);
         }
@@ -6048,35 +6048,40 @@
     }
 
     @Override
-    public void setStatusBarEnabledState(ComponentName who, boolean enabled) {
+    public boolean setStatusBarDisabled(ComponentName who, boolean disabled) {
         int userId = UserHandle.getCallingUserId();
         synchronized (this) {
             getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
             DevicePolicyData policy = getUserData(userId);
-            if (policy.mStatusBarEnabledState != enabled) {
-                policy.mStatusBarEnabledState = enabled;
-                setStatusBarEnabledStateInternal(enabled, userId);
+            if (policy.mStatusBarDisabled != disabled) {
+                if (!setStatusBarDisabledInternal(disabled, userId)) {
+                    return false;
+                }
+                policy.mStatusBarDisabled = disabled;
                 saveSettingsLocked(userId);
             }
         }
+        return true;
     }
 
-    private void setStatusBarEnabledStateInternal(boolean enabled, int userId) {
+    private boolean setStatusBarDisabledInternal(boolean disabled, int userId) {
         long ident = Binder.clearCallingIdentity();
         try {
             IStatusBarService statusBarService = IStatusBarService.Stub.asInterface(
                     ServiceManager.checkService(Context.STATUS_BAR_SERVICE));
             if (statusBarService != null) {
-                int flags1 = enabled ? StatusBarManager.DISABLE_NONE : STATUS_BAR_DISABLE_MASK;
-                int flags2 = enabled ? StatusBarManager.DISABLE2_NONE : STATUS_BAR_DISABLE2_MASK;
+                int flags1 = disabled ? STATUS_BAR_DISABLE_MASK : StatusBarManager.DISABLE_NONE;
+                int flags2 = disabled ? STATUS_BAR_DISABLE2_MASK : StatusBarManager.DISABLE2_NONE;
                 statusBarService.disableForUser(flags1, mToken, mContext.getPackageName(), userId);
                 statusBarService.disable2ForUser(flags2, mToken, mContext.getPackageName(), userId);
+                return true;
             }
         } catch (RemoteException e) {
             Slog.e(LOG_TAG, "Failed to disable the status bar", e);
         } finally {
             Binder.restoreCallingIdentity(ident);
         }
+        return false;
     }
 
     /**