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

Commit 4b116044 authored by Steve Kondik's avatar Steve Kondik
Browse files

profiles: Add support for disabling screen lock

 * We can now have the option of disabling lockscreen security as part
   of the profile. A good use case for this is to create "Car" profile.
   You certainly don't want to input a pattern, or worse, face-unlock if
   you should happen to break the law and use your phone whilst driving.
 * Profile system now permits insecure mode or entirely disabling
   lockscreen as an override.
 * Fix issue where changes aren't applied if the active profile is
   modified.
 * Also fix a couple of string-comparison derps.

Change-Id: I07a09b7011bad4f32cdd7bfa576e3befa71193ea
parent 9e74c148
Loading
Loading
Loading
Loading
+33 −2
Original line number Diff line number Diff line
@@ -64,6 +64,15 @@ public final class Profile implements Parcelable, Comparable {

    private Map<Integer, ConnectionSettings> connections = new HashMap<Integer, ConnectionSettings>();

    private int mScreenLockMode = LockMode.DEFAULT;

    /** @hide */
    public static class LockMode {
        public static final int DEFAULT = 0;
        public static final int INSECURE = 1;
        public static final int DISABLE = 2;
    }

    /** @hide */
    public static final Parcelable.Creator<Profile> CREATOR = new Parcelable.Creator<Profile>() {
        public Profile createFromParcel(Parcel in) {
@@ -159,6 +168,7 @@ public final class Profile implements Parcelable, Comparable {
                streams.values().toArray(new Parcelable[streams.size()]), flags);
        dest.writeParcelableArray(
                connections.values().toArray(new Parcelable[connections.size()]), flags);
        dest.writeInt(mScreenLockMode);
    }

    /** @hide */
@@ -184,6 +194,7 @@ public final class Profile implements Parcelable, Comparable {
            ConnectionSettings connection = (ConnectionSettings) parcel;
            connections.put(connection.getConnectionId(), connection);
        }
        mScreenLockMode = in.readInt();
    }

    public String getName() {
@@ -230,6 +241,19 @@ public final class Profile implements Parcelable, Comparable {
        mDirty = true;
    }

    public int getScreenLockMode() {
        return mScreenLockMode;
    }

    public void setScreenLockMode(int screenLockMode) {
        if (screenLockMode < LockMode.DEFAULT || screenLockMode > LockMode.INSECURE) {
            mScreenLockMode = LockMode.DEFAULT;
        } else {
            mScreenLockMode = screenLockMode;
        }
        mDirty = true;
    }

    /** @hide */
    public boolean isDirty() {
        if (mDirty) {
@@ -275,6 +299,10 @@ 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>");

        for (ProfileGroup pGroup : profileGroups.values()) {
            pGroup.getXmlString(builder, context);
        }
@@ -331,10 +359,13 @@ public final class Profile implements Parcelable, Comparable {
            if (event == XmlPullParser.START_TAG) {
                String name = xpp.getName();
                if (name.equals("statusbar")) {
                    profile.setStatusBarIndicator(xpp.nextText() == "yes");
                    profile.setStatusBarIndicator(xpp.nextText().equals("yes"));
                }
                if (name.equals("profiletype")) {
                    profile.setProfileType(xpp.nextText() == "toggle" ? TOGGLE_TYPE : CONDITIONAL_TYPE);
                    profile.setProfileType(xpp.nextText().equals("toggle") ? TOGGLE_TYPE : CONDITIONAL_TYPE);
                }
                if (name.equals("screen-lock-mode")) {
                    profile.setScreenLockMode(Integer.valueOf(xpp.nextText()));
                }
                if (name.equals("profileGroup")) {
                    ProfileGroup pg = ProfileGroup.fromXml(xpp, context);
+13 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import com.android.internal.widget.LockPatternUtils;
import android.app.ActivityManagerNative;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Profile;
import android.app.ProfileManager;
import android.app.StatusBarManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
@@ -265,6 +267,8 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
    private int mLockSoundStreamId;
    private int mMasterStreamMaxVolume;

    private ProfileManager mProfileManager;

    public KeyguardViewMediator(Context context, PhoneWindowManager callback,
            LocalPowerManager powerManager) {
        mContext = context;
@@ -283,6 +287,8 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
                "keyguardWakeAndHandOff");
        mWakeAndHandOff.setReferenceCounted(false);

        mProfileManager = (ProfileManager) context.getSystemService(Context.PROFILE_SERVICE);

        IntentFilter filter = new IntentFilter();
        filter.addAction(DELAYED_KEYGUARD_ACTION);
        filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
@@ -630,6 +636,13 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
            return;
        }

        // if the current profile has disabled us, don't show
        if (!lockedOrMissing
                && mProfileManager.getActiveProfile().getScreenLockMode() == Profile.LockMode.DISABLE) {
            if (DEBUG) Log.d(TAG, "doKeyguard: not showing because of profile override");
            return;
        }

        if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
        showLocked();
    }
+10 −2
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.AlertDialog;
import android.app.Profile;
import android.app.ProfileManager;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
@@ -148,6 +150,9 @@ public class LockPatternKeyguardView extends KeyguardViewBase implements Handler
    //This resets when the phone is turned off with no current call
    private boolean mHasOverlay;

    // We can use the profile manager to override security
    private ProfileManager mProfileManager;


    /**
     * Either a lock screen (an informational keyguard screen), or an unlock
@@ -309,6 +314,7 @@ public class LockPatternKeyguardView extends KeyguardViewBase implements Handler
        mLockPatternUtils = lockPatternUtils;
        mWindowController = controller;
        mHasOverlay = false;
        mProfileManager = (ProfileManager) context.getSystemService(Context.PROFILE_SERVICE);

        mUpdateMonitor.registerInfoCallback(this);

@@ -823,7 +829,8 @@ public class LockPatternKeyguardView extends KeyguardViewBase implements Handler
        boolean secure = false;
        switch (unlockMode) {
            case Pattern:
                secure = mLockPatternUtils.isLockPatternEnabled();
                secure = mLockPatternUtils.isLockPatternEnabled() &&
                        mProfileManager.getActiveProfile().getScreenLockMode() != Profile.LockMode.INSECURE;
                break;
            case SimPin:
                secure = mUpdateMonitor.getSimState() == IccCard.State.PIN_REQUIRED;
@@ -835,7 +842,8 @@ public class LockPatternKeyguardView extends KeyguardViewBase implements Handler
                secure = true;
                break;
            case Password:
                secure = mLockPatternUtils.isLockPasswordEnabled();
                secure = mLockPatternUtils.isLockPasswordEnabled() &&
                        mProfileManager.getActiveProfile().getScreenLockMode() != Profile.LockMode.INSECURE;
                break;
            default:
                throw new IllegalStateException("unknown unlock mode " + unlockMode);
+5 −0
Original line number Diff line number Diff line
@@ -318,6 +318,11 @@ public class ProfileManagerService extends IProfileManager.Stub {
            /* no need to set mDirty, if the profile was actually changed,
             * it's marked as dirty by itself */
            persistIfDirty();

            // Also update we changed the active profile
            if (mActiveProfile != null && mActiveProfile.getUuid().equals(profile.getUuid())) {
                setActiveProfile(profile, true);
            }
        }
    }