SetupWizard: Add backup restore
Change-Id: Ide7149eee903cce11dfeb7fb919b707c614c8735
This commit is contained in:
@@ -38,10 +38,13 @@ public class SetupWizardApp extends Application {
|
||||
public static final String EXTRA_AUTO_FINISH = "wifi_auto_finish_on_connect";
|
||||
public static final String EXTRA_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
|
||||
public static final String EXTRA_USE_IMMERSIVE = "useImmersiveMode";
|
||||
public static final String EXTRA_THEME = "theme";
|
||||
public static final String EXTRA_MATERIAL_LIGHT = "material_light";
|
||||
|
||||
public static final int REQUEST_CODE_SETUP_WIFI = 0;
|
||||
public static final int REQUEST_CODE_SETUP_GMS= 1;
|
||||
public static final int REQUEST_CODE_SETUP_CYANOGEN= 2;
|
||||
public static final int REQUEST_CODE_RESTORE_GMS= 2;
|
||||
public static final int REQUEST_CODE_SETUP_CYANOGEN= 3;
|
||||
|
||||
private StatusBarManager mStatusBarManager;
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class CMSetupWizardData extends AbstractSetupData {
|
||||
}
|
||||
pages.add(new CyanogenServicesPage(mContext, this));
|
||||
pages.add(new CyanogenSettingsPage(mContext, this));
|
||||
pages.add(new LocationSettingsPage(mContext, this));
|
||||
pages.add(new OtherSettingsPage(mContext, this));
|
||||
pages.add(new DateTimePage(mContext, this));
|
||||
pages.add(new FinishPage(mContext, this));
|
||||
return new PageList(pages.toArray(new SetupPage[pages.size()]));
|
||||
|
||||
@@ -25,9 +25,13 @@ 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.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.cyanogenmod.setupwizard.R;
|
||||
import com.cyanogenmod.setupwizard.SetupWizardApp;
|
||||
@@ -35,13 +39,37 @@ 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 {
|
||||
|
||||
public static final String TAG = "GmsAccountPage";
|
||||
|
||||
public GmsAccountPage(Context context, SetupDataCallbacks callbacks) {
|
||||
public static final String ACTION_RESTORE = "com.google.android.setupwizard.RESTORE";
|
||||
|
||||
private ContentQueryMap mContentQueryMap;
|
||||
private Observer mSettingsObserver;
|
||||
|
||||
private boolean mBackupEnabled = false;
|
||||
|
||||
public GmsAccountPage(final Context context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
final ContentResolver res = context.getContentResolver();
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,19 +113,52 @@ public class GmsAccountPage extends SetupPage {
|
||||
@Override
|
||||
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS) {
|
||||
if (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_FIRST_USER) {
|
||||
if (SetupWizardUtils.accountExists(mContext, SetupWizardApp.ACCOUNT_TYPE_GMS)) {
|
||||
setHidden(true);
|
||||
}
|
||||
getCallbacks().onNextPage();
|
||||
} else if (resultCode == Activity.RESULT_CANCELED) {
|
||||
getCallbacks().onPreviousPage();
|
||||
if (!mBackupEnabled) {
|
||||
launchGmsRestorePage((Activity) mContext);
|
||||
} else {
|
||||
handleResult(resultCode);
|
||||
}
|
||||
} else if (requestCode == SetupWizardApp.REQUEST_CODE_RESTORE_GMS) {
|
||||
handleResult(resultCode);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void launchGmsAccountSetup(final Activity activity) {
|
||||
@Override
|
||||
public void onFinishSetup() {
|
||||
if (mContentQueryMap != null) {
|
||||
mContentQueryMap.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handleResult(int resultCode) {
|
||||
if (resultCode == Activity.RESULT_CANCELED) {
|
||||
getCallbacks().onPreviousPage();
|
||||
} else {
|
||||
if (SetupWizardUtils.accountExists(mContext, SetupWizardApp.ACCOUNT_TYPE_GMS)) {
|
||||
setHidden(true);
|
||||
}
|
||||
getCallbacks().onNextPage();
|
||||
}
|
||||
}
|
||||
|
||||
private static void launchGmsRestorePage(final Activity activity) {
|
||||
Intent intent = new Intent(ACTION_RESTORE);
|
||||
intent.putExtra(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
|
||||
intent.putExtra(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
|
||||
intent.putExtra(SetupWizardApp.EXTRA_FIRST_RUN, true);
|
||||
intent.putExtra(SetupWizardApp.EXTRA_THEME, SetupWizardApp.EXTRA_MATERIAL_LIGHT);
|
||||
ActivityOptions options =
|
||||
ActivityOptions.makeCustomAnimation(activity,
|
||||
android.R.anim.fade_in,
|
||||
android.R.anim.fade_out);
|
||||
activity.startActivityForResult(
|
||||
intent,
|
||||
SetupWizardApp.REQUEST_CODE_RESTORE_GMS, options.toBundle());
|
||||
}
|
||||
|
||||
private void launchGmsAccountSetup(final Activity activity) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(SetupWizardApp.EXTRA_FIRST_RUN, true);
|
||||
bundle.putBoolean(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
|
||||
|
||||
@@ -18,12 +18,15 @@ package com.cyanogenmod.setupwizard.setup;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.backup.IBackupManager;
|
||||
import android.content.ContentQueryMap;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
@@ -34,11 +37,11 @@ import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
public class LocationSettingsPage extends SetupPage {
|
||||
public class OtherSettingsPage extends SetupPage {
|
||||
|
||||
private static final String TAG = "LocationSettingsPage";
|
||||
private static final String TAG = "OtherSettingsPage";
|
||||
|
||||
public LocationSettingsPage(Context context, SetupDataCallbacks callbacks) {
|
||||
public OtherSettingsPage(Context context, SetupDataCallbacks callbacks) {
|
||||
super(context, callbacks);
|
||||
}
|
||||
|
||||
@@ -49,7 +52,7 @@ public class LocationSettingsPage extends SetupPage {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
|
||||
args.putInt(Page.KEY_PAGE_ACTION, action);
|
||||
fragment = new LocationSettingsFragment();
|
||||
fragment = new OtherSettingsFragment();
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
return fragment;
|
||||
@@ -62,20 +65,24 @@ public class LocationSettingsPage extends SetupPage {
|
||||
|
||||
@Override
|
||||
public int getTitleResId() {
|
||||
return R.string.setup_location;
|
||||
return R.string.setup_other;
|
||||
}
|
||||
|
||||
public static class LocationSettingsFragment extends SetupPageFragment {
|
||||
public static class OtherSettingsFragment extends SetupPageFragment {
|
||||
|
||||
private View mBackupRow;
|
||||
private View mLocationRow;
|
||||
private View mGpsRow;
|
||||
private View mNetworkRow;
|
||||
private CheckBox mBackup;
|
||||
private CheckBox mNetwork;
|
||||
private CheckBox mGps;
|
||||
private CheckBox mLocationAccess;
|
||||
|
||||
private ContentResolver mContentResolver;
|
||||
|
||||
private IBackupManager mBackupManager;
|
||||
|
||||
// These provide support for receiving notification when Location Manager settings change.
|
||||
// This is necessary because the Network Location Provider can change settings
|
||||
// if the user does not confirm enabling the provider.
|
||||
@@ -83,6 +90,13 @@ public class LocationSettingsPage extends SetupPage {
|
||||
private Observer mSettingsObserver;
|
||||
|
||||
|
||||
private View.OnClickListener mBackupClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
onToggleBackup(!mBackup.isChecked());
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnClickListener mLocationClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -110,11 +124,16 @@ public class LocationSettingsPage extends SetupPage {
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mContentResolver = getActivity().getContentResolver();
|
||||
mBackupManager = IBackupManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.BACKUP_SERVICE));
|
||||
getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializePage() {
|
||||
mBackupRow = mRootView.findViewById(R.id.backup);
|
||||
mBackupRow.setOnClickListener(mBackupClickListener);
|
||||
mBackup = (CheckBox) mRootView.findViewById(R.id.backup_checkbox);
|
||||
mLocationRow = mRootView.findViewById(R.id.location);
|
||||
mLocationRow.setOnClickListener(mLocationClickListener);
|
||||
mLocationAccess = (CheckBox) mRootView.findViewById(R.id.location_checkbox);
|
||||
@@ -135,10 +154,12 @@ public class LocationSettingsPage extends SetupPage {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateLocationToggles();
|
||||
updateBackupToggle();
|
||||
if (mSettingsObserver == null) {
|
||||
mSettingsObserver = new Observer() {
|
||||
public void update(Observable o, Object arg) {
|
||||
updateLocationToggles();
|
||||
updateBackupToggle();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -166,6 +187,24 @@ public class LocationSettingsPage extends SetupPage {
|
||||
mContentQueryMap.close();
|
||||
}
|
||||
|
||||
private boolean isBackupRestoreEnabled() {
|
||||
try {
|
||||
return mBackupManager.isBackupEnabled();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBackupToggle() {
|
||||
mBackup.setChecked(isBackupRestoreEnabled());
|
||||
}
|
||||
|
||||
private void onToggleBackup(boolean checked) {
|
||||
try {
|
||||
mBackupManager.setBackupEnabled(checked);
|
||||
} catch (RemoteException e) {}
|
||||
updateBackupToggle();
|
||||
}
|
||||
|
||||
private void updateLocationToggles() {
|
||||
boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled(
|
||||
@@ -58,7 +58,7 @@ public class SetupWizardUtils {
|
||||
intent.putExtra(SetupWizardApp.EXTRA_FIRST_RUN, true);
|
||||
intent.putExtra(SetupWizardApp.EXTRA_ALLOW_SKIP, true);
|
||||
intent.putExtra(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
|
||||
intent.putExtra("theme", "material_light");
|
||||
intent.putExtra(SetupWizardApp.EXTRA_THEME, SetupWizardApp.EXTRA_MATERIAL_LIGHT);
|
||||
intent.putExtra(SetupWizardApp.EXTRA_AUTO_FINISH, false);
|
||||
ActivityOptions options =
|
||||
ActivityOptions.makeCustomAnimation(context,
|
||||
|
||||
Reference in New Issue
Block a user