aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/java/cyanogenmod/app/Profile.java42
-rw-r--r--src/java/cyanogenmod/profiles/LockSettings.java177
-rw-r--r--tests/src/org/cyanogenmod/tests/profiles/ProfileTest.java7
-rw-r--r--tests/src/org/cyanogenmod/tests/profiles/unit/ProfileTest.java26
4 files changed, 231 insertions, 21 deletions
diff --git a/src/java/cyanogenmod/app/Profile.java b/src/java/cyanogenmod/app/Profile.java
index 495ec41..ad718ec 100755
--- a/src/java/cyanogenmod/app/Profile.java
+++ b/src/java/cyanogenmod/app/Profile.java
@@ -30,6 +30,7 @@ import cyanogenmod.os.Build;
import cyanogenmod.profiles.AirplaneModeSettings;
import cyanogenmod.profiles.BrightnessSettings;
import cyanogenmod.profiles.ConnectionSettings;
+import cyanogenmod.profiles.LockSettings;
import cyanogenmod.profiles.RingModeSettings;
import cyanogenmod.profiles.StreamSettings;
@@ -86,7 +87,7 @@ public final class Profile implements Parcelable, Comparable {
private BrightnessSettings mBrightness = new BrightnessSettings();
- private int mScreenLockMode = LockMode.DEFAULT;
+ private LockSettings mScreenLockMode = new LockSettings();
private int mExpandedDesktopMode = ExpandedDesktopMode.DEFAULT;
@@ -591,7 +592,12 @@ public final class Profile implements Parcelable, Comparable {
} else {
dest.writeInt(0);
}
- dest.writeInt(mScreenLockMode);
+ if (mScreenLockMode != null) {
+ dest.writeInt(1);
+ mScreenLockMode.writeToParcel(dest, 0);
+ } else {
+ dest.writeInt(0);
+ }
dest.writeTypedArray(mTriggers.values().toArray(new ProfileTrigger[0]), flags);
dest.writeInt(mExpandedDesktopMode);
dest.writeInt(mDozeMode);
@@ -661,7 +667,9 @@ public final class Profile implements Parcelable, Comparable {
if (in.readInt() != 0) {
mBrightness = BrightnessSettings.CREATOR.createFromParcel(in);
}
- mScreenLockMode = in.readInt();
+ if (in.readInt() != 0) {
+ mScreenLockMode = LockSettings.CREATOR.createFromParcel(in);
+ }
for (ProfileTrigger trigger : in.createTypedArray(ProfileTrigger.CREATOR)) {
mTriggers.put(trigger.mId, trigger);
}
@@ -796,23 +804,19 @@ public final class Profile implements Parcelable, Comparable {
}
/**
- * Get the {@link LockMode} for the {@link Profile}
+ * Get the {@link LockSettings} for the {@link Profile}
* @return
*/
- public int getScreenLockMode() {
+ public LockSettings getScreenLockMode() {
return mScreenLockMode;
}
/**
- * Set the {@link LockMode} for the {@link Profile}
+ * Set the {@link LockSettings} for the {@link Profile}
* @param screenLockMode
*/
- public void setScreenLockMode(int screenLockMode) {
- if (screenLockMode < LockMode.DEFAULT || screenLockMode > LockMode.DISABLE) {
- mScreenLockMode = LockMode.DEFAULT;
- } else {
- mScreenLockMode = screenLockMode;
- }
+ public void setScreenLockMode(LockSettings screenLockMode) {
+ mScreenLockMode = screenLockMode;
mDirty = true;
}
@@ -956,9 +960,11 @@ public final class Profile implements Parcelable, Comparable {
builder.append(getStatusBarIndicator() ? "yes" : "no");
builder.append("</statusbar>\n");
- builder.append("<screen-lock-mode>");
- builder.append(mScreenLockMode);
- builder.append("</screen-lock-mode>\n");
+ if (mScreenLockMode != null) {
+ builder.append("<screen-lock-mode>");
+ mScreenLockMode.writeXmlString(builder, context);
+ builder.append("</screen-lock-mode>\n");
+ }
builder.append("<expanded-desktop-mode>");
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 0000000..1d5cf33
--- /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}
+ *
+ * <p>Example for disabling lockscreen security:
+ * <pre class="prettyprint">
+ * LockSettings lock = new LockSettings(Profile.LockMode.INSECURE);
+ * profile.setScreenLockMode(lock);
+ * </pre>
+ */
+public final class LockSettings implements Parcelable {
+
+ private int mValue;
+ private boolean mDirty;
+
+ /** @hide */
+ public static final Creator<LockSettings> CREATOR
+ = new Creator<LockSettings>() {
+ 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 29e7f2f..0d8d038 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 4639c4a..f48b805 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;
@@ -177,10 +178,32 @@ public class ProfileTest extends AndroidTestCase {
}
@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());
}