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

Commit 70c874ba authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Restore GPS state and ringer/vibrate toggles.

Inform backup manager when sync flags change. Set ringer/vibrate mode.
parent 4492bcb8
Loading
Loading
Loading
Loading
+13 −1
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
import org.xmlpull.v1.XmlSerializer;


import android.backup.IBackupManager;
import android.database.Cursor;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteException;
@@ -35,6 +36,7 @@ import android.os.Message;
import android.os.Parcel;
import android.os.Parcel;
import android.os.RemoteCallbackList;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.Xml;
import android.util.Xml;
@@ -351,6 +353,16 @@ public class SyncStorageEngine extends Handler {
                }
                }
            }
            }
        }
        }
        // Inform the backup manager about a data change
        IBackupManager ibm = IBackupManager.Stub.asInterface(
                ServiceManager.getService(Context.BACKUP_SERVICE));
        if (ibm != null) {
            try {
                ibm.dataChanged("com.android.providers.settings");
            } catch (RemoteException e) {
                // Try again later
            }
        }
    }
    }


    public boolean getSyncProviderAutomatically(String account, String providerName) {
    public boolean getSyncProviderAutomatically(String account, String providerName) {
+6 −5
Original line number Original line Diff line number Diff line
@@ -166,11 +166,12 @@ public class SettingsBackupAgent extends BackupHelperAgent {
            pos += length;
            pos += length;
            if (!TextUtils.isEmpty(settingName) && !TextUtils.isEmpty(settingValue)) {
            if (!TextUtils.isEmpty(settingName) && !TextUtils.isEmpty(settingValue)) {
                //Log.i(TAG, "Restore " + settingName + " = " + settingValue);
                //Log.i(TAG, "Restore " + settingName + " = " + settingValue);
                if (mSettingsHelper.restoreValue(settingName, settingValue)) {
                    cv.clear();
                    cv.clear();
                    cv.put(Settings.NameValueTable.NAME, settingName);
                    cv.put(Settings.NameValueTable.NAME, settingName);
                    cv.put(Settings.NameValueTable.VALUE, settingValue);
                    cv.put(Settings.NameValueTable.VALUE, settingValue);
                    getContentResolver().insert(contentUri, cv);
                    getContentResolver().insert(contentUri, cv);
                mSettingsHelper.restoreValue(settingName, settingValue);
                }
            }
            }
        }
        }
    }
    }
+54 −14
Original line number Original line Diff line number Diff line
@@ -19,12 +19,13 @@ package com.android.providers.settings;
import android.backup.BackupDataInput;
import android.backup.BackupDataInput;
import android.content.ContentResolver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.IContentService;
import android.location.LocationManager;
import android.media.AudioManager;
import android.media.AudioManager;
import android.os.IHardwareService;
import android.os.IHardwareService;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.provider.Settings;
import android.provider.Settings;
import android.content.IContentService;
import android.util.Log;
import android.util.Log;


public class SettingsHelper {
public class SettingsHelper {
@@ -33,10 +34,10 @@ public class SettingsHelper {
    private Context mContext;
    private Context mContext;
    private AudioManager mAudioManager;
    private AudioManager mAudioManager;
    private IContentService mContentService;
    private IContentService mContentService;
    private static final String SYNC_AUTO = "auto_sync";
    private static final String[] PROVIDERS = { "gmail-ls", "calendar", "contacts" };
    private static final String SYNC_MAIL = "gmail-ls_sync";

    private static final String SYNC_CALENDAR = "calendar_sync";
    private boolean mSilent;
    private static final String SYNC_CONTACTS = "contacts_sync";
    private boolean mVibrate;


    public SettingsHelper(Context context) {
    public SettingsHelper(Context context) {
        mContext = context;
        mContext = context;
@@ -45,17 +46,45 @@ public class SettingsHelper {
        mContentService = ContentResolver.getContentService();
        mContentService = ContentResolver.getContentService();
    }
    }


    public void restoreValue(String name, String value) {
    /**
     * Sets the property via a call to the appropriate API, if any, and returns
     * whether or not the setting should be saved to the database as well.
     * @param name the name of the setting
     * @param value the string value of the setting
     * @return whether to continue with writing the value to the database. In
     * some cases the data will be written by the call to the appropriate API,
     * and in some cases the property value needs to be modified before setting.
     */
    public boolean restoreValue(String name, String value) {
        if (Settings.System.SCREEN_BRIGHTNESS.equals(name)) {
        if (Settings.System.SCREEN_BRIGHTNESS.equals(name)) {
            setBrightness(Integer.parseInt(value));
            setBrightness(Integer.parseInt(value));
        } else if (Settings.System.SOUND_EFFECTS_ENABLED.equals(name)) {
        } else if (Settings.System.SOUND_EFFECTS_ENABLED.equals(name)) {
            if (Integer.parseInt(value) == 1) {
            setSoundEffects(Integer.parseInt(value) == 1);
        } else if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name)) {
            setGpsLocation(value);
            return false;
        }
        return true;
    }

    private void setGpsLocation(String value) {
        final String GPS = LocationManager.GPS_PROVIDER;
        boolean enabled = 
                GPS.equals(value) ||
                value.startsWith(GPS + ",") ||
                value.endsWith("," + GPS) ||
                value.contains("," + GPS + ",");
        Settings.Secure.setLocationProviderEnabled(
                mContext.getContentResolver(), GPS, enabled);
    }

    private void setSoundEffects(boolean enable) {
        if (enable) {
            mAudioManager.loadSoundEffects();
            mAudioManager.loadSoundEffects();
        } else {
        } else {
            mAudioManager.unloadSoundEffects();
            mAudioManager.unloadSoundEffects();
        }
        }
    }
    }
    }


    private void setBrightness(int brightness) {
    private void setBrightness(int brightness) {
        try {
        try {
@@ -69,8 +98,19 @@ public class SettingsHelper {
        }
        }
    }
    }


    static final String[] PROVIDERS = { "gmail-ls", "calendar", "contacts" };
    private void setRingerMode() {
        if (mSilent) {
            mAudioManager.setRingerMode(mVibrate ? AudioManager.RINGER_MODE_VIBRATE :
                AudioManager.RINGER_MODE_SILENT);
        } else {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
                    mVibrate ? AudioManager.VIBRATE_SETTING_ON
                            : AudioManager.VIBRATE_SETTING_OFF);
        }
    }


    /* TODO: Get a list of all sync providers and save/restore the settings */
    byte[] getSyncProviders() {
    byte[] getSyncProviders() {
        byte[] sync = new byte[1 + PROVIDERS.length];
        byte[] sync = new byte[1 + PROVIDERS.length];
        try {
        try {