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

Commit b64e46b3 authored by Pavel Kirpichyov's avatar Pavel Kirpichyov Committed by d34d
Browse files

Provide upgrade path for cm12.1 -> cm13.0

This just takes care of making the database is up to date with
cm12.1

*Increasing alarm and switch to profile still need to be implemented.

Change-Id: Ibbb2b618ddeb6f93cd95a0fba3923bfd6d3fbbbb
parent 4a8d6862
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := android-opt-datetimepicker
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-gridlayout
LOCAL_STATIC_JAVA_LIBRARIES += org.cyanogenmod.platform.sdk

LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat
+34 −2
Original line number Diff line number Diff line
@@ -26,13 +26,16 @@ import android.database.Cursor;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Parcel;
import android.os.ParcelUuid;
import android.os.Parcelable;

import com.android.deskclock.R;
import cyanogenmod.app.ProfileManager;

import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;

public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
    /**
@@ -57,7 +60,9 @@ public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
            VIBRATE,
            LABEL,
            RINGTONE,
            DELETE_AFTER_USE
            DELETE_AFTER_USE,
            INCREASING_VOLUME,
            PROFILE
    };

    /**
@@ -73,8 +78,10 @@ public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
    private static final int LABEL_INDEX = 6;
    private static final int RINGTONE_INDEX = 7;
    private static final int DELETE_AFTER_USE_INDEX = 8;
    private static final int INCREASING_VOLUME_INDEX = 9;
    private static final int PROFILE_INDEX = 10;

    private static final int COLUMN_COUNT = DELETE_AFTER_USE_INDEX + 1;
    private static final int COLUMN_COUNT = PROFILE_INDEX + 1;

    public static ContentValues createContentValues(Alarm alarm) {
        ContentValues values = new ContentValues(COLUMN_COUNT);
@@ -89,12 +96,14 @@ public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
        values.put(VIBRATE, alarm.vibrate ? 1 : 0);
        values.put(LABEL, alarm.label);
        values.put(DELETE_AFTER_USE, alarm.deleteAfterUse);
        values.put(INCREASING_VOLUME, alarm.increasingVolume ? 1 : 0);
        if (alarm.alert == null) {
            // We want to put null, so default alarm changes
            values.putNull(RINGTONE);
        } else {
            values.put(RINGTONE, alarm.alert.toString());
        }
        values.put(PROFILE, alarm.profile.toString());

        return values;
    }
@@ -234,6 +243,8 @@ public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
    public String label;
    public Uri alert;
    public boolean deleteAfterUse;
    public boolean increasingVolume;
    public UUID profile;

    // Creates a default alarm at the current time.
    public Alarm() {
@@ -249,6 +260,8 @@ public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
        this.label = "";
        this.alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        this.deleteAfterUse = false;
        this.increasingVolume = false;
        this.profile = ProfileManager.NO_PROFILE;
    }

    public Alarm(Cursor c) {
@@ -260,6 +273,7 @@ public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
        vibrate = c.getInt(VIBRATE_INDEX) == 1;
        label = c.getString(LABEL_INDEX);
        deleteAfterUse = c.getInt(DELETE_AFTER_USE_INDEX) == 1;
        increasingVolume = c.getInt(INCREASING_VOLUME_INDEX) == 1;

        if (c.isNull(RINGTONE_INDEX)) {
            // Should we be saving this with the current ringtone or leave it null
@@ -268,6 +282,16 @@ public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
        } else {
            alert = Uri.parse(c.getString(RINGTONE_INDEX));
        }

        if (c.isNull(PROFILE_INDEX)) {
            profile = ProfileManager.NO_PROFILE;
        } else {
            try {
                profile = UUID.fromString(c.getString(PROFILE_INDEX));
            } catch (IllegalArgumentException ex) {
                profile = ProfileManager.NO_PROFILE;
            }
        }
    }

    Alarm(Parcel p) {
@@ -280,6 +304,8 @@ public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
        label = p.readString();
        alert = (Uri) p.readParcelable(null);
        deleteAfterUse = p.readInt() == 1;
        increasingVolume = p.readInt() == 1;
        profile = ParcelUuid.CREATOR.createFromParcel(p).getUuid();
    }

    public String getLabelOrDefault(Context context) {
@@ -299,6 +325,8 @@ public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
        p.writeString(label);
        p.writeParcelable(alert, flags);
        p.writeInt(deleteAfterUse ? 1 : 0);
        p.writeInt(increasingVolume ? 1 : 0);
        p.writeParcelable(new ParcelUuid(profile), 0);
    }

    public int describeContents() {
@@ -311,6 +339,8 @@ public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
        result.mVibrate = vibrate;
        result.mLabel = label;
        result.mRingtone = alert;
        result.mIncreasingVolume = increasingVolume;
        result.mProfile = profile;
        return result;
    }

@@ -385,6 +415,8 @@ public final class Alarm implements Parcelable, ClockContract.AlarmsColumns {
                ", vibrate=" + vibrate +
                ", label='" + label + '\'' +
                ", deleteAfterUse=" + deleteAfterUse +
                ", increasingVolume=" + increasingVolume +
                ", profile=" + profile +
                '}';
    }
}
+28 −2
Original line number Diff line number Diff line
@@ -29,10 +29,12 @@ import android.preference.PreferenceManager;
import com.android.deskclock.LogUtils;
import com.android.deskclock.R;
import com.android.deskclock.SettingsActivity;
import cyanogenmod.app.ProfileManager;

import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;

public final class AlarmInstance implements ClockContract.InstancesColumns {
    /**
@@ -71,7 +73,9 @@ public final class AlarmInstance implements ClockContract.InstancesColumns {
            VIBRATE,
            RINGTONE,
            ALARM_ID,
            ALARM_STATE
            ALARM_STATE,
            INCREASING_VOLUME,
            PROFILE
    };

    /**
@@ -89,8 +93,10 @@ public final class AlarmInstance implements ClockContract.InstancesColumns {
    private static final int RINGTONE_INDEX = 8;
    private static final int ALARM_ID_INDEX = 9;
    private static final int ALARM_STATE_INDEX = 10;
    private static final int INCREASING_VOLUME_INDEX = 11;
    private static final int PROFILE_INDEX = 12;

    private static final int COLUMN_COUNT = ALARM_STATE_INDEX + 1;
    private static final int COLUMN_COUNT = PROFILE_INDEX + 1;

    public static ContentValues createContentValues(AlarmInstance instance) {
        ContentValues values = new ContentValues(COLUMN_COUNT);
@@ -105,6 +111,9 @@ public final class AlarmInstance implements ClockContract.InstancesColumns {
        values.put(MINUTES, instance.mMinute);
        values.put(LABEL, instance.mLabel);
        values.put(VIBRATE, instance.mVibrate ? 1 : 0);
        values.put(INCREASING_VOLUME, instance.mIncreasingVolume ? 1 : 0);
        values.put(PROFILE, instance.mProfile.toString());

        if (instance.mRingtone == null) {
            // We want to put null in the database, so we'll be able
            // to pick up on changes to the default alarm
@@ -305,6 +314,8 @@ public final class AlarmInstance implements ClockContract.InstancesColumns {
    public Uri mRingtone;
    public Long mAlarmId;
    public int mAlarmState;
    public boolean mIncreasingVolume;
    public UUID mProfile;

    public AlarmInstance(Calendar calendar, Long alarmId) {
        this(calendar);
@@ -318,6 +329,8 @@ public final class AlarmInstance implements ClockContract.InstancesColumns {
        mVibrate = false;
        mRingtone = null;
        mAlarmState = SILENT_STATE;
        mIncreasingVolume = false;
        mProfile = ProfileManager.NO_PROFILE;
    }

    public AlarmInstance(Cursor c) {
@@ -341,6 +354,17 @@ public final class AlarmInstance implements ClockContract.InstancesColumns {
            mAlarmId = c.getLong(ALARM_ID_INDEX);
        }
        mAlarmState = c.getInt(ALARM_STATE_INDEX);

        mIncreasingVolume = c.getInt(INCREASING_VOLUME_INDEX) == 1;
        if (c.isNull(PROFILE_INDEX)) {
            mProfile = ProfileManager.NO_PROFILE;
        } else {
            try {
                mProfile = UUID.fromString(c.getString(PROFILE_INDEX));
            } catch (IllegalArgumentException ex) {
                mProfile = ProfileManager.NO_PROFILE;
            }
        }
    }

    public String getLabelOrDefault(Context context) {
@@ -452,6 +476,8 @@ public final class AlarmInstance implements ClockContract.InstancesColumns {
                ", mRingtone=" + mRingtone +
                ", mAlarmId=" + mAlarmId +
                ", mAlarmState=" + mAlarmState +
                ", mIncreasingVolume=" + mIncreasingVolume +
                ", mProfile=" + mProfile +
                '}';
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -83,6 +83,18 @@ public final class ClockContract {
         * <p>Type: STRING</p>
         */
        public static final String RINGTONE = "ringtone";

        /**
         * True if alarm should start off quiet and slowly increase volume
         * <P>Type: BOOLEAN</P>
         */
        public static final String INCREASING_VOLUME = "incvol";

        /**
         * Profile to change to when alarm triggers
         * <P>Type: STRING</P>
         */
        public static final String PROFILE = "profile";
    }

    /**
+63 −7
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.deskclock.provider;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
@@ -26,8 +27,10 @@ import android.net.Uri;
import android.text.TextUtils;

import com.android.deskclock.LogUtils;
import cyanogenmod.app.ProfileManager;

import java.util.Calendar;
import java.util.UUID;

/**
 * Helper class for opening the database from multiple providers.  Also provides
@@ -52,11 +55,23 @@ class ClockDatabaseHelper extends SQLiteOpenHelper {
     */
    private static final int VERSION_7 = 7;

    /**
     * Added increasing alarm volume mode
     */
    private static final int VERSION_8 = 10;

    /**
     * Added change profile
     */
    private static final int VERSION_9 = 11;

    // This creates a default alarm at 8:30 for every Mon,Tue,Wed,Thu,Fri
    private static final String DEFAULT_ALARM_1 = "(8, 30, 31, 0, 0, '', NULL, 0);";
    private static final String DEFAULT_ALARM_1 = "(8, 30, 31, 0, 0, '', NULL, 0, 0, '" +
            ProfileManager.NO_PROFILE.toString() + "');";

    // This creates a default alarm at 9:30 for every Sat,Sun
    private static final String DEFAULT_ALARM_2 = "(9, 00, 96, 0, 0, '', NULL, 0);";
    private static final String DEFAULT_ALARM_2 = "(9, 00, 96, 0, 0, '', NULL, 0, 0, '" +
            ProfileManager.NO_PROFILE.toString() + "');";

    // Database and table names
    static final String DATABASE_NAME = "alarms.db";
@@ -75,7 +90,10 @@ class ClockDatabaseHelper extends SQLiteOpenHelper {
                ClockContract.AlarmsColumns.VIBRATE + " INTEGER NOT NULL, " +
                ClockContract.AlarmsColumns.LABEL + " TEXT NOT NULL, " +
                ClockContract.AlarmsColumns.RINGTONE + " TEXT, " +
                ClockContract.AlarmsColumns.DELETE_AFTER_USE + " INTEGER NOT NULL DEFAULT 0);");
                ClockContract.AlarmsColumns.DELETE_AFTER_USE + " INTEGER NOT NULL DEFAULT 0, " +
                ClockContract.AlarmsColumns.INCREASING_VOLUME + " INTEGER NOT NULL DEFAULT 0, " +
                ClockContract.AlarmsColumns.PROFILE + " TEXT NOT NULL DEFAULT '" +
                    ProfileManager.NO_PROFILE.toString() + "');");
        LogUtils.i("Alarms Table created");
    }

@@ -93,8 +111,10 @@ class ClockDatabaseHelper extends SQLiteOpenHelper {
                ClockContract.InstancesColumns.ALARM_STATE + " INTEGER NOT NULL, " +
                ClockContract.InstancesColumns.ALARM_ID + " INTEGER REFERENCES " +
                    ALARMS_TABLE_NAME + "(" + ClockContract.AlarmsColumns._ID + ") " +
                    "ON UPDATE CASCADE ON DELETE CASCADE" +
                ");");
                    "ON UPDATE CASCADE ON DELETE CASCADE, " +
                ClockContract.InstancesColumns.INCREASING_VOLUME + " INTEGER NOT NULL DEFAULT 0, " +
                ClockContract.InstancesColumns.PROFILE + " TEXT NOT NULL DEFAULT '" +
                    ProfileManager.NO_PROFILE.toString() + "');");
        LogUtils.i("Instance table created");
    }

@@ -110,7 +130,7 @@ class ClockDatabaseHelper extends SQLiteOpenHelper {
    private Context mContext;

    public ClockDatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, VERSION_7);
        super(context, DATABASE_NAME, null, VERSION_9);
        mContext = context;
    }

@@ -131,7 +151,9 @@ class ClockDatabaseHelper extends SQLiteOpenHelper {
                ClockContract.AlarmsColumns.VIBRATE + cs +
                ClockContract.AlarmsColumns.LABEL + cs +
                ClockContract.AlarmsColumns.RINGTONE + cs +
                ClockContract.AlarmsColumns.DELETE_AFTER_USE + ") VALUES ";
                ClockContract.AlarmsColumns.DELETE_AFTER_USE + cs +
                ClockContract.AlarmsColumns.INCREASING_VOLUME + cs +
                ClockContract.AlarmsColumns.PROFILE + ") VALUES ";
        db.execSQL(insertMe + DEFAULT_ALARM_1);
        db.execSQL(insertMe + DEFAULT_ALARM_2);
    }
@@ -161,6 +183,8 @@ class ClockDatabaseHelper extends SQLiteOpenHelper {
                    "vibrate",
                    "message",
                    "alert",
                    "incvol",
                    "profile"
            };
            Cursor cursor = db.query(OLD_ALARMS_TABLE_NAME, OLD_TABLE_COLUMNS,
                    null, null, null, null, null);
@@ -182,6 +206,18 @@ class ClockDatabaseHelper extends SQLiteOpenHelper {
                    alarm.alert = TextUtils.isEmpty(alertString) ? null : Uri.parse(alertString);
                }

                alarm.increasingVolume = cursor.getInt(8) == 1;

                if (cursor.isNull(9)) {
                    alarm.profile = ProfileManager.NO_PROFILE;
                } else {
                    try {
                        alarm.profile = UUID.fromString(cursor.getString(9));
                    } catch (IllegalArgumentException ex) {
                        alarm.profile = ProfileManager.NO_PROFILE;
                    }
                }

                // Save new version of alarm and create alarminstance for it
                db.insert(ALARMS_TABLE_NAME, null, Alarm.createContentValues(alarm));
                if (alarm.enabled) {
@@ -194,6 +230,26 @@ class ClockDatabaseHelper extends SQLiteOpenHelper {

            LogUtils.i("Dropping old alarm table");
            db.execSQL("DROP TABLE IF EXISTS " + OLD_ALARMS_TABLE_NAME + ";");
        } else {
            // Update the database tables according the old version

            if (oldVersion < VERSION_8) {
                db.execSQL("ALTER TABLE " + ALARMS_TABLE_NAME
                        + " ADD COLUMN " + ClockContract.AlarmsColumns.INCREASING_VOLUME
                        + " INTEGER NOT NULL DEFAULT 0;");
                db.execSQL("ALTER TABLE " + INSTANCES_TABLE_NAME
                        + " ADD COLUMN " + ClockContract.InstancesColumns.INCREASING_VOLUME
                        + " INTEGER NOT NULL DEFAULT 0;");
            }

            if (oldVersion < VERSION_9) {
                db.execSQL("ALTER TABLE " + ALARMS_TABLE_NAME
                        + " ADD COLUMN " + ClockContract.AlarmsColumns.PROFILE
                        + " TEXT NOT NULL DEFAULT '" + ProfileManager.NO_PROFILE + "';");
                db.execSQL("ALTER TABLE " + INSTANCES_TABLE_NAME
                        + " ADD COLUMN " + ClockContract.InstancesColumns.PROFILE
                        + " TEXT NOT NULL DEFAULT '" + ProfileManager.NO_PROFILE + "';");
            }
        }
    }