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

Commit 0501cc6e authored by Kirill Rakhman's avatar Kirill Rakhman Committed by Steve Kondik
Browse files

Set expanded desktop through profiles (1/2)

Change-Id: I56df3c83b1e7b75004a6fe6ad160305774440a5a
parent 82b0dd81
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.media.AudioManager;
import android.os.Parcel;
import android.os.ParcelUuid;
import android.os.Parcelable;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

@@ -77,6 +79,8 @@ public final class Profile implements Parcelable, Comparable {

    private int mScreenLockMode = LockMode.DEFAULT;

    private int mExpandedDesktopMode = ExpandedDesktopMode.DEFAULT;

    /** @hide */
    public static class LockMode {
        public static final int DEFAULT = 0;
@@ -84,6 +88,13 @@ public final class Profile implements Parcelable, Comparable {
        public static final int DISABLE = 2;
    }

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

    /** @hide */
    public static class TriggerType {
        public static final int WIFI = 0;
@@ -346,6 +357,7 @@ public final class Profile implements Parcelable, Comparable {
        dest.writeParcelable(mAirplaneMode, flags);
        dest.writeInt(mScreenLockMode);
        dest.writeMap(mTriggers);
        dest.writeInt(mExpandedDesktopMode);
    }

    /** @hide */
@@ -379,6 +391,7 @@ public final class Profile implements Parcelable, Comparable {
        mAirplaneMode = (AirplaneModeSettings) in.readParcelable(null);
        mScreenLockMode = in.readInt();
        in.readMap(mTriggers, null);
        mExpandedDesktopMode = in.readInt();
    }

    public String getName() {
@@ -466,6 +479,20 @@ public final class Profile implements Parcelable, Comparable {
        mDirty = true;
    }

    public int getExpandedDesktopMode() {
        return mExpandedDesktopMode;
    }

    public void setExpandedDesktopMode(int expandedDesktopMode) {
        if (expandedDesktopMode < ExpandedDesktopMode.DEFAULT
                || expandedDesktopMode > ExpandedDesktopMode.DISABLE) {
            mExpandedDesktopMode = ExpandedDesktopMode.DEFAULT;
        } else {
            mExpandedDesktopMode = expandedDesktopMode;
        }
        mDirty = true;
    }

    public AirplaneModeSettings getAirplaneMode() {
        return mAirplaneMode;
    }
@@ -538,6 +565,10 @@ public final class Profile implements Parcelable, Comparable {
        builder.append(mScreenLockMode);
        builder.append("</screen-lock-mode>\n");

        builder.append("<expanded-desktop-mode>");
        builder.append(mExpandedDesktopMode);
        builder.append("</expanded-desktop-mode>\n");

        mAirplaneMode.getXmlString(builder, context);

        mRingMode.getXmlString(builder, context);
@@ -669,6 +700,9 @@ public final class Profile implements Parcelable, Comparable {
                if (name.equals("screen-lock-mode")) {
                    profile.setScreenLockMode(Integer.valueOf(xpp.nextText()));
                }
                if (name.equals("expanded-desktop-mode")) {
                    profile.setExpandedDesktopMode(Integer.valueOf(xpp.nextText()));
                }
                if (name.equals("profileGroup")) {
                    ProfileGroup pg = ProfileGroup.fromXml(xpp, context);
                    profile.addProfileGroup(pg);
@@ -713,6 +747,14 @@ public final class Profile implements Parcelable, Comparable {
        mRingMode.processOverride(context);
        // Set airplane mode
        mAirplaneMode.processOverride(context);

        // Set expanded desktop
        if (mExpandedDesktopMode != ExpandedDesktopMode.DEFAULT) {
            Settings.System.putIntForUser(context.getContentResolver(),
                    Settings.System.EXPANDED_DESKTOP_STATE,
                    mExpandedDesktopMode == ExpandedDesktopMode.ENABLE ? 1 : 0,
                    UserHandle.USER_CURRENT);
        }
    }

    /** @hide */