summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdnan Begovic <adnan@cyngn.com>2016-03-16 10:40:43 -0700
committerAdnan Begovic <adnan@cyngn.com>2016-03-16 11:04:23 -0700
commit0d83f7c0625c522bdf34b7a695892991f01e2f7c (patch)
tree63b1275bebb60d2807b1b11039e6ab93aa4acae1
parent2009ae2ec4274902b62030e7ac8d5fc47fef1c69 (diff)
downloadpackages_apps_SetupWizard-0d83f7c0625c522bdf34b7a695892991f01e2f7c.zip
packages_apps_SetupWizard-0d83f7c0625c522bdf34b7a695892991f01e2f7c.tar.gz
packages_apps_SetupWizard-0d83f7c0625c522bdf34b7a695892991f01e2f7c.tar.bz2
SetupWizard: Fixup backup/restore for Marshmallow.
Since Marshmallow broke the ability to utilize complex matrix queries against the SettingsProvider because it is now backed by XML, rewrite the logic for the backup enabled flag to work within the new constraints. Change-Id: I8ad993564184fa14b5a3267689c69af2f7e8638e TICKET: CYNGNOS-2233
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java55
1 files changed, 24 insertions, 31 deletions
diff --git a/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java b/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java
index 34a344c..2fc1243 100644
--- a/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/GmsAccountPage.java
@@ -25,12 +25,12 @@ import android.app.Activity;
import android.app.ActivityOptions;
import android.app.Fragment;
import android.app.FragmentManager;
-import android.content.ContentQueryMap;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
-import android.database.Cursor;
+import android.database.ContentObserver;
import android.os.Bundle;
+import android.os.Handler;
import android.provider.Settings;
import android.service.persistentdata.PersistentDataBlockManager;
import android.util.Log;
@@ -42,8 +42,6 @@ import com.cyanogenmod.setupwizard.ui.LoadingFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.io.IOException;
-import java.util.Observable;
-import java.util.Observer;
public class GmsAccountPage extends SetupPage {
@@ -53,32 +51,33 @@ public class GmsAccountPage extends SetupPage {
private static final String RESTORE_WIZARD_SCRIPT =
"android.resource://com.google.android.setupwizard/xml/wizard_script";
- private ContentQueryMap mContentQueryMap;
- private Observer mSettingsObserver;
-
private boolean mBackupEnabled = false;
private Fragment mFragment;
+ private ContentResolver mContentResolver;
public GmsAccountPage(final Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
- final ContentResolver res = context.getContentResolver();
- mBackupEnabled = Settings.Secure.getInt(res,
- Settings.Secure.BACKUP_ENABLED, 0) == 1;
- mSettingsObserver = new Observer() {
- public void update(Observable o, Object arg) {
- mBackupEnabled = (Settings.Secure.getInt(res,
- Settings.Secure.BACKUP_AUTO_RESTORE, 0) == 1) ||
- (Settings.Secure.getInt(res,
- Settings.Secure.BACKUP_ENABLED, 0) == 1);
- }
- };
- //Cursor settingsCursor = res.query(Settings.Secure.CONTENT_URI, null,
- // "(" + Settings.System.NAME + "=? OR " + Settings.System.NAME + "=?)",
- // new String[]{Settings.Secure.BACKUP_AUTO_RESTORE, Settings.Secure.BACKUP_ENABLED},
- // null);
- //mContentQueryMap = new ContentQueryMap(settingsCursor, Settings.System.NAME, true, null);
- //mContentQueryMap.addObserver(mSettingsObserver);
+ mContentResolver = context.getContentResolver();
+ mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
+ Settings.Secure.BACKUP_AUTO_RESTORE), false, mSettingsObserver);
+ mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
+ Settings.Secure.BACKUP_ENABLED), false, mSettingsObserver);
+ }
+
+ private ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ onBackupEnabledChanged();
+ }
+ };
+
+ private void onBackupEnabledChanged() {
+ mBackupEnabled = (Settings.Secure.getInt(mContentResolver,
+ Settings.Secure.BACKUP_AUTO_RESTORE, 0) == 1) ||
+ (Settings.Secure.getInt(mContentResolver,
+ Settings.Secure.BACKUP_ENABLED, 0) == 1);
}
@Override
@@ -139,13 +138,7 @@ public class GmsAccountPage extends SetupPage {
@Override
public void onFinishSetup() {
- try {
- if (mContentQueryMap != null) {
- mContentQueryMap.close();
- }
- } catch (Exception e) {
- Log.wtf(TAG, e.toString());
- }
+ mContentResolver.unregisterContentObserver(mSettingsObserver);
}
private void handleResult(int requestCode, int resultCode) {