aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman Birg <roman@cyngn.com>2015-07-28 00:37:33 -0700
committerAdnan Begovic <adnan@cyngn.com>2015-07-31 14:09:33 -0700
commite84d6568ab8198f65489a672a1995eacd2dd94a7 (patch)
treed5a36ad3fdaaa2a7a4989a8933759dd166e30211 /src
parentbd5230afe0995625936901a189811bc8f5cceb80 (diff)
downloadvendor_cmsdk-e84d6568ab8198f65489a672a1995eacd2dd94a7.zip
vendor_cmsdk-e84d6568ab8198f65489a672a1995eacd2dd94a7.tar.gz
vendor_cmsdk-e84d6568ab8198f65489a672a1995eacd2dd94a7.tar.bz2
Profiles: add LockModeSettings
Splits out the lockmode into its own LockSettings, primarly so it has its own processOverride() - so it will respect the LockMode.DEFAULT setting. Ref: CYNGNOS-620 Change-Id: I6183492facebed37133e84d45a6bb2f91f76d5ea Signed-off-by: Roman Birg <roman@cyngn.com> Signed-off-by: Adnan Begovic <adnan@cyngn.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/java/cyanogenmod/app/Profile.java42
-rw-r--r--src/java/cyanogenmod/profiles/LockSettings.java177
2 files changed, 203 insertions, 16 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);
+ }
+}