");
builder.append(mExpandedDesktopMode);
@@ -1107,7 +1113,8 @@ public final class Profile implements Parcelable, Comparable {
profile.setBrightness(bd);
}
if (name.equals("screen-lock-mode")) {
- profile.setScreenLockMode(Integer.valueOf(xpp.nextText()));
+ LockSettings lockMode = new LockSettings(Integer.valueOf(xpp.nextText()));
+ profile.setScreenLockMode(lockMode);
}
if (name.equals("expanded-desktop-mode")) {
profile.setExpandedDesktopMode(Integer.valueOf(xpp.nextText()));
@@ -1165,6 +1172,9 @@ public final class Profile implements Parcelable, Comparable {
// Set brightness
mBrightness.processOverride(context);
+ // Set lock screen mode
+ mScreenLockMode.processOverride(context);
+
// Set expanded desktop
// if (mExpandedDesktopMode != ExpandedDesktopMode.DEFAULT) {
// Settings.System.putIntForUser(context.getContentResolver(),
diff --git a/src/java/cyanogenmod/profiles/LockSettings.java b/src/java/cyanogenmod/profiles/LockSettings.java
new file mode 100644
index 00000000..1d5cf33b
--- /dev/null
+++ b/src/java/cyanogenmod/profiles/LockSettings.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2015 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cyanogenmod.profiles;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.view.WindowManagerPolicy;
+import com.android.internal.policy.PolicyManager;
+import cyanogenmod.app.Profile;
+import cyanogenmod.os.Build;
+
+/**
+ * The {@link LockSettings} class allows for overriding and setting the
+ * current Lock screen state/security level. Value should be one a constant from
+ * of {@link Profile.LockMode}
+ *
+ * Example for disabling lockscreen security:
+ *
+ * LockSettings lock = new LockSettings(Profile.LockMode.INSECURE);
+ * profile.setScreenLockMode(lock);
+ *
+ */
+public final class LockSettings implements Parcelable {
+
+ private int mValue;
+ private boolean mDirty;
+
+ /** @hide */
+ public static final Creator CREATOR
+ = new Creator() {
+ public LockSettings createFromParcel(Parcel in) {
+ return new LockSettings(in);
+ }
+
+ @Override
+ public LockSettings[] newArray(int size) {
+ return new LockSettings[size];
+ }
+ };
+
+ /**
+ * Unwrap {@link LockSettings} from a parcel.
+ * @param parcel
+ */
+ public LockSettings(Parcel parcel) {
+ readFromParcel(parcel);
+ }
+
+ /**
+ * Construct a {@link LockSettings} with a default value of {@link Profile.LockMode.DEFAULT}.
+ */
+ public LockSettings() {
+ this(Profile.LockMode.DEFAULT);
+ }
+
+ /**
+ * Construct a {@link LockSettings} with a default value.
+ */
+ public LockSettings(int value) {
+ mValue = value;
+ mDirty = false;
+ }
+
+ /**
+ * Get the value for the {@link LockSettings}
+ * @return a constant from {@link Profile.LockMode}
+ */
+ public int getValue() {
+ return mValue;
+ }
+
+ /**
+ * Set the value for the {@link LockSettings}
+ *
+ * see {@link Profile.LockMode}
+ */
+ public void setValue(int value) {
+ mValue = value;
+ mDirty = true;
+ }
+
+ /** @hide */
+ public boolean isDirty() {
+ return mDirty;
+ }
+
+ /** @hide */
+ public void processOverride(Context context) {
+ final DevicePolicyManager devicePolicyManager =
+ (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
+ final WindowManagerPolicy policy = PolicyManager.makeNewWindowManager();
+
+ if (devicePolicyManager != null && devicePolicyManager.requireSecureKeyguard()) {
+ policy.enableKeyguard(true);
+ return;
+ }
+
+ switch (mValue) {
+ case Profile.LockMode.DEFAULT:
+ case Profile.LockMode.INSECURE:
+ policy.enableKeyguard(true);
+ break;
+ case Profile.LockMode.DISABLE:
+ policy.enableKeyguard(false);
+ break;
+ }
+ }
+
+ /** @hide */
+ public void writeXmlString(StringBuilder builder, Context context) {
+ builder.append(mValue);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /** @hide */
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ // Write parcelable version, make sure to define explicit changes
+ // within {@link Build.PARCELABLE_VERSION);
+ dest.writeInt(Build.PARCELABLE_VERSION);
+
+ // Inject a placeholder that will store the parcel size from this point on
+ // (not including the size itself).
+ int sizePosition = dest.dataPosition();
+ dest.writeInt(0);
+ int startPosition = dest.dataPosition();
+
+ // === BOYSENBERRY ===
+ dest.writeInt(mValue);
+ dest.writeInt(mDirty ? 1 : 0);
+
+ // Go back and write size
+ int parcelableSize = dest.dataPosition() - startPosition;
+ dest.setDataPosition(sizePosition);
+ dest.writeInt(parcelableSize);
+ dest.setDataPosition(startPosition + parcelableSize);
+ }
+
+ /** @hide */
+ public void readFromParcel(Parcel in) {
+ // Read parcelable version, make sure to define explicit changes
+ // within {@link Build.PARCELABLE_VERSION);
+ int parcelableVersion = in.readInt();
+ int parcelableSize = in.readInt();
+ int startPosition = in.dataPosition();
+
+ // Pattern here is that all new members should be added to the end of
+ // the writeToParcel method. Then we step through each version, until the latest
+ // API release to help unravel this parcel
+ if (parcelableVersion >= Build.CM_VERSION_CODES.BOYSENBERRY) {
+ mValue = in.readInt();
+ mDirty = in.readInt() != 0;
+ }
+
+ in.setDataPosition(startPosition + parcelableSize);
+ }
+}
diff --git a/tests/src/org/cyanogenmod/tests/profiles/ProfileTest.java b/tests/src/org/cyanogenmod/tests/profiles/ProfileTest.java
index 29e7f2f1..0d8d0386 100644
--- a/tests/src/org/cyanogenmod/tests/profiles/ProfileTest.java
+++ b/tests/src/org/cyanogenmod/tests/profiles/ProfileTest.java
@@ -26,6 +26,7 @@ import cyanogenmod.app.ProfileManager;
import cyanogenmod.profiles.AirplaneModeSettings;
import cyanogenmod.profiles.BrightnessSettings;
import cyanogenmod.profiles.ConnectionSettings;
+import cyanogenmod.profiles.LockSettings;
import cyanogenmod.profiles.RingModeSettings;
import cyanogenmod.profiles.StreamSettings;
import org.cyanogenmod.tests.TestActivity;
@@ -64,7 +65,7 @@ public class ProfileTest extends TestActivity {
profile.setProfileType(Type.TOGGLE);
profile.setExpandedDesktopMode(Profile.ExpandedDesktopMode.ENABLE);
profile.setDozeMode(Profile.DozeMode.DEFAULT);
- profile.setScreenLockMode(Profile.LockMode.DISABLE);
+ profile.setScreenLockMode(new LockSettings(Profile.LockMode.DISABLE));
mProfileUuidList.add(profile.getUuid());
mProfileManager.addProfile(profile);
}
@@ -76,7 +77,7 @@ public class ProfileTest extends TestActivity {
profile.setProfileType(Type.TOGGLE);
profile.setExpandedDesktopMode(Profile.ExpandedDesktopMode.ENABLE);
profile.setDozeMode(Profile.DozeMode.DEFAULT);
- profile.setScreenLockMode(Profile.LockMode.DISABLE);
+ profile.setScreenLockMode(new LockSettings(Profile.LockMode.DISABLE));
mProfileUuidList.add(profile.getUuid());
mProfileManager.addProfile(profile);
mProfileManager.setActiveProfile(profile.getUuid());
@@ -94,7 +95,7 @@ public class ProfileTest extends TestActivity {
profile.setProfileType(Type.TOGGLE);
profile.setExpandedDesktopMode(Profile.ExpandedDesktopMode.ENABLE);
profile.setDozeMode(Profile.DozeMode.DEFAULT);
- profile.setScreenLockMode(Profile.LockMode.DISABLE);
+ profile.setScreenLockMode(new LockSettings(Profile.LockMode.DISABLE));
mProfileUuidList.add(profile.getUuid());
mProfileManager.addProfile(profile);
mProfileManager.setActiveProfile(profile.getUuid());
diff --git a/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileTest.java b/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileTest.java
index 4639c4aa..f48b8059 100644
--- a/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileTest.java
+++ b/tests/src/org/cyanogenmod/tests/profiles/unit/ProfileTest.java
@@ -27,6 +27,7 @@ import cyanogenmod.app.Profile;
import cyanogenmod.profiles.AirplaneModeSettings;
import cyanogenmod.profiles.BrightnessSettings;
import cyanogenmod.profiles.ConnectionSettings;
+import cyanogenmod.profiles.LockSettings;
import cyanogenmod.profiles.RingModeSettings;
import cyanogenmod.profiles.StreamSettings;
@@ -176,11 +177,33 @@ public class ProfileTest extends AndroidTestCase {
assertEquals(expectedStreamSettings.isDirty(), actualStreamSettings.isDirty());
}
+ @MediumTest
+ public void testProfileLockSettingsUnravelFromParcel() {
+ Profile profile = new Profile("Lock Profile");
+ LockSettings expectedLockSettings = new LockSettings(Profile.LockMode.INSECURE);
+ profile.setScreenLockMode(expectedLockSettings);
+
+ // Write to parcel
+ Parcel parcel = Parcel.obtain();
+ profile.writeToParcel(parcel, 0);
+
+ // Rewind
+ parcel.setDataPosition(0);
+
+ // Verify data when unraveling
+ Profile fromParcel = Profile.CREATOR.createFromParcel(parcel);
+
+ LockSettings actualLockSettings = fromParcel.getScreenLockMode();
+
+ assertNotNull(fromParcel);
+ assertEquals(expectedLockSettings.getValue(), actualLockSettings.getValue());
+ assertEquals(expectedLockSettings.isDirty(), actualLockSettings.isDirty());
+ }
+
@MediumTest
public void testProfileUnravelFromParcel() {
Profile profile = new Profile("Single Profile");
profile.setProfileType(Profile.Type.TOGGLE);
- profile.setScreenLockMode(Profile.LockMode.DISABLE);
profile.setDozeMode(Profile.DozeMode.ENABLE);
profile.setStatusBarIndicator(true);
@@ -197,7 +220,6 @@ public class ProfileTest extends AndroidTestCase {
assertNotNull(fromParcel);
assertEquals(profile.getName(), fromParcel.getName());
assertEquals(profile.getProfileType(), fromParcel.getProfileType());
- assertEquals(profile.getScreenLockMode(), fromParcel.getScreenLockMode());
assertEquals(profile.getDozeMode(), fromParcel.getDozeMode());
assertEquals(profile.getStatusBarIndicator(), fromParcel.getStatusBarIndicator());
}