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

Commit 20af04ca authored by Adnan Begovic's avatar Adnan Begovic Committed by Roman Birg
Browse files

Implement linked volumes and add upgrade path.

Change-Id: Ibbeff656fcaaa4a2ff79de530b48b216df271b21
parent 7c3472dc
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1240,6 +1240,7 @@ public final class Settings {
            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_PING_DELAY_MS);
            MOVED_TO_SECURE.add(Secure.WIFI_WATCHDOG_PING_TIMEOUT_MS);
            MOVED_TO_SECURE.add(Secure.STATS_COLLECTION);
            MOVED_TO_SECURE.add(Secure.VOLUME_LINK_NOTIFICATION);

            // At one time in System, then Global, but now back in Secure
            MOVED_TO_SECURE.add(Secure.INSTALL_NON_MARKET_APPS);
@@ -5528,6 +5529,12 @@ public final class Settings {
         */
        public static final String STATS_COLLECTION = "stats_collection";

        /**
         * Boolean value whether to link ringtone and notification volume
         *
         * @hide
         */
        public static final String VOLUME_LINK_NOTIFICATION = "volume_link_notification";

        /**
         * Performance profile
+20 −0
Original line number Diff line number Diff line
@@ -361,6 +361,8 @@ public class AudioService extends IAudioService.Stub {
            "STREAM_TTS"
    };

    private boolean mLinkNotificationWithVolume;

    private final AudioSystem.ErrorCallback mAudioSystemCallback = new AudioSystem.ErrorCallback() {
        public void onError(int error) {
            switch (error) {
@@ -916,6 +918,13 @@ public class AudioService extends IAudioService.Stub {
        }

        mStreamVolumeAlias[AudioSystem.STREAM_DTMF] = dtmfStreamAlias;

        if (mLinkNotificationWithVolume) {
            mStreamVolumeAlias[AudioSystem.STREAM_NOTIFICATION] = AudioSystem.STREAM_RING;
        } else {
            mStreamVolumeAlias[AudioSystem.STREAM_NOTIFICATION] = AudioSystem.STREAM_NOTIFICATION;
        }

        if (updateVolumes) {
            mStreamStates[AudioSystem.STREAM_DTMF].setAllIndexes(mStreamStates[dtmfStreamAlias]);
            // apply stream mute states according to new value of mRingerModeAffectedStreams
@@ -990,6 +999,9 @@ public class AudioService extends IAudioService.Stub {
            readDockAudioSettings(cr);
        }

        mLinkNotificationWithVolume = Settings.Secure.getInt(cr,
                Settings.Secure.VOLUME_LINK_NOTIFICATION, 1) == 1;

        mMuteAffectedStreams = System.getIntForUser(cr,
                System.MUTE_STREAMS_AFFECTED,
                ((1 << AudioSystem.STREAM_MUSIC)|
@@ -4425,6 +4437,14 @@ public class AudioService extends IAudioService.Stub {
                    setRingerModeInt(getRingerMode(), false);
                }
                readDockAudioSettings(mContentResolver);

                mLinkNotificationWithVolume = Settings.System.getInt(mContentResolver,
                        Settings.Secure.VOLUME_LINK_NOTIFICATION, 1) == 1;
                if (mLinkNotificationWithVolume) {
                    mStreamVolumeAlias[AudioSystem.STREAM_NOTIFICATION] = AudioSystem.STREAM_RING;
                } else {
                    mStreamVolumeAlias[AudioSystem.STREAM_NOTIFICATION] = AudioSystem.STREAM_NOTIFICATION;
                }
            }
        }
    }
+10 −41
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
    // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
    // is properly propagated through your change.  Not doing so will result in a loss of user
    // settings.
    private static final int DATABASE_VERSION = 115;
    private static final int DATABASE_VERSION = 116;

    private Context mContext;
    private int mUserHandle;
@@ -1826,50 +1826,19 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 114;
        }

        // From here on out, we can assume the user is coming from CM and will have these rows
        if (upgradeVersion < 115) {
            db.beginTransaction();
            SQLiteStatement stmt = null;
            Cursor c = null;
            try {
                // The STATS_COLLECTION setting is becoming per-user rather
                // than device-system.
                try {
                    c = db.rawQuery("SELECT stats_collection from " + TABLE_SYSTEM, null);
                    // if this row exists, then we do work
                    if (c != null) {
                        if (c.moveToNext()) {
                            // The row exists so we can migrate the
                            // entry from there to the secure table, preserving its value.
                            String[] settingToSecure = {
                                    Settings.Secure.STATS_COLLECTION
                            };
            moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE,
                                    settingToSecure, true);
                        }
                    } else {
                        // Otherwise our dbs don't have STATS_COLLECTION in secure so institute the
                        // default.
                        stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
                                + " VALUES(?,?);");
                        loadBooleanSetting(stmt, Settings.Secure.STATS_COLLECTION,
                                R.bool.def_cm_stats_collection);
                    }
                } catch (SQLiteException ex) {
                    // This is bad, just bump the version and add the setting to secure
                    stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
                            + " VALUES(?,?);");
                    loadBooleanSetting(stmt, Settings.Secure.STATS_COLLECTION,
                            R.bool.def_cm_stats_collection);
                }
                db.setTransactionSuccessful();
            } finally {
                if (c != null) c.close();
                db.endTransaction();
                if (stmt != null) stmt.close();
            }
                    new String[] { Settings.Secure.STATS_COLLECTION }, true);
            upgradeVersion = 115;
        }

        if (upgradeVersion < 116) {
            moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE,
                    new String[] { Settings.Secure.VOLUME_LINK_NOTIFICATION }, true);
            upgradeVersion = 116;
        }

        // *** Remember to update DATABASE_VERSION above!

        if (upgradeVersion != currentVersion) {