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
This commit is contained in:
parent
2009ae2ec4
commit
0d83f7c062
@ -25,12 +25,12 @@ import android.app.Activity;
|
|||||||
import android.app.ActivityOptions;
|
import android.app.ActivityOptions;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
import android.content.ContentQueryMap;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.ContentObserver;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.service.persistentdata.PersistentDataBlockManager;
|
import android.service.persistentdata.PersistentDataBlockManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -42,8 +42,6 @@ import com.cyanogenmod.setupwizard.ui.LoadingFragment;
|
|||||||
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
|
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Observable;
|
|
||||||
import java.util.Observer;
|
|
||||||
|
|
||||||
public class GmsAccountPage extends SetupPage {
|
public class GmsAccountPage extends SetupPage {
|
||||||
|
|
||||||
@ -53,32 +51,33 @@ public class GmsAccountPage extends SetupPage {
|
|||||||
private static final String RESTORE_WIZARD_SCRIPT =
|
private static final String RESTORE_WIZARD_SCRIPT =
|
||||||
"android.resource://com.google.android.setupwizard/xml/wizard_script";
|
"android.resource://com.google.android.setupwizard/xml/wizard_script";
|
||||||
|
|
||||||
private ContentQueryMap mContentQueryMap;
|
|
||||||
private Observer mSettingsObserver;
|
|
||||||
|
|
||||||
private boolean mBackupEnabled = false;
|
private boolean mBackupEnabled = false;
|
||||||
|
|
||||||
private Fragment mFragment;
|
private Fragment mFragment;
|
||||||
|
private ContentResolver mContentResolver;
|
||||||
|
|
||||||
public GmsAccountPage(final Context context, SetupDataCallbacks callbacks) {
|
public GmsAccountPage(final Context context, SetupDataCallbacks callbacks) {
|
||||||
super(context, callbacks);
|
super(context, callbacks);
|
||||||
final ContentResolver res = context.getContentResolver();
|
mContentResolver = context.getContentResolver();
|
||||||
mBackupEnabled = Settings.Secure.getInt(res,
|
mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||||
Settings.Secure.BACKUP_ENABLED, 0) == 1;
|
Settings.Secure.BACKUP_AUTO_RESTORE), false, mSettingsObserver);
|
||||||
mSettingsObserver = new Observer() {
|
mContentResolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||||
public void update(Observable o, Object arg) {
|
Settings.Secure.BACKUP_ENABLED), false, mSettingsObserver);
|
||||||
mBackupEnabled = (Settings.Secure.getInt(res,
|
}
|
||||||
Settings.Secure.BACKUP_AUTO_RESTORE, 0) == 1) ||
|
|
||||||
(Settings.Secure.getInt(res,
|
private ContentObserver mSettingsObserver = new ContentObserver(new Handler()) {
|
||||||
Settings.Secure.BACKUP_ENABLED, 0) == 1);
|
@Override
|
||||||
}
|
public void onChange(boolean selfChange) {
|
||||||
};
|
super.onChange(selfChange);
|
||||||
//Cursor settingsCursor = res.query(Settings.Secure.CONTENT_URI, null,
|
onBackupEnabledChanged();
|
||||||
// "(" + 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);
|
private void onBackupEnabledChanged() {
|
||||||
//mContentQueryMap.addObserver(mSettingsObserver);
|
mBackupEnabled = (Settings.Secure.getInt(mContentResolver,
|
||||||
|
Settings.Secure.BACKUP_AUTO_RESTORE, 0) == 1) ||
|
||||||
|
(Settings.Secure.getInt(mContentResolver,
|
||||||
|
Settings.Secure.BACKUP_ENABLED, 0) == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -139,13 +138,7 @@ public class GmsAccountPage extends SetupPage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFinishSetup() {
|
public void onFinishSetup() {
|
||||||
try {
|
mContentResolver.unregisterContentObserver(mSettingsObserver);
|
||||||
if (mContentQueryMap != null) {
|
|
||||||
mContentQueryMap.close();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.wtf(TAG, e.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleResult(int requestCode, int resultCode) {
|
private void handleResult(int requestCode, int resultCode) {
|
||||||
|
Loading…
Reference in New Issue
Block a user