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

Commit 57b09882 authored by Daisuke Miyakawa's avatar Daisuke Miyakawa Committed by Android (Google) Code Review
Browse files

Merge "Have a new constant for "vibrate when ringing" setting" into jb-dev

parents d422ade3 3c60eeb1
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -1748,6 +1748,20 @@ public final class Settings {
         */
        public static final String USER_ROTATION = "user_rotation";

        /**
         * Whether the phone vibrates when it is ringing due to an incoming call. This will
         * be used by Phone and Setting apps; it shouldn't affect other apps.
         * The value is boolean (1 or 0).
         *
         * Note: this is not same as "vibrate on ring", which had been available until ICS.
         * It was about AudioManager's setting and thus affected all the applications which
         * relied on the setting, while this is purely about the vibration setting for incoming
         * calls.
         *
         * @hide
         */
        public static final String VIBRATE_WHEN_RINGING = "vibrate_when_ringing";

        /**
         * Whether the audible DTMF tones are played by the dialer when dialing. The value is
         * boolean (1 or 0).
@@ -2030,6 +2044,7 @@ public final class Settings {
            SIP_CALL_OPTIONS,
            SIP_RECEIVE_CALLS,
            POINTER_SPEED,
            VIBRATE_WHEN_RINGING
        };

        // Settings moved to Settings.Secure
+66 −40
Original line number Diff line number Diff line
@@ -63,7 +63,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 = 77;
    private static final int DATABASE_VERSION = 78;

    private Context mContext;

@@ -1047,6 +1047,12 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 77;
        }

        if (upgradeVersion == 77) {
            // Introduce "vibrate when ringing" setting
            loadVibrateWhenRingingSetting(db);

            upgradeVersion = 78;
        }

        // *** Remember to update DATABASE_VERSION above!

@@ -1352,6 +1358,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
        } finally {
            if (stmt != null) stmt.close();
        }

        loadVibrateWhenRingingSetting(db);
    }

    private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
@@ -1377,6 +1385,24 @@ public class DatabaseHelper extends SQLiteOpenHelper {
        }
    }

    private void loadVibrateWhenRingingSetting(SQLiteDatabase db) {
        // The default should be off. VIBRATE_SETTING_ONLY_SILENT should also be ignored here.
        // Phone app should separately check whether AudioManager#getRingerMode() returns
        // RINGER_MODE_VIBRATE, with which the device should vibrate anyway.
        int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON,
                AudioManager.VIBRATE_SETTING_OFF);
        boolean vibrateWhenRinging = ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_ON);

        SQLiteStatement stmt = null;
        try {
            stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                    + " VALUES(?,?);");
            loadSetting(stmt, Settings.System.VIBRATE_WHEN_RINGING, vibrateWhenRinging ? 1 : 0);
        } finally {
            if (stmt != null) stmt.close();
        }
    }

    private void loadSettings(SQLiteDatabase db) {
        loadSystemSettings(db);
        loadSecureSettings(db);