SetupWizard: Add backup restore

Change-Id: Ide7149eee903cce11dfeb7fb919b707c614c8735
This commit is contained in:
cretin45 2015-02-02 16:44:52 -08:00
parent 7e9af47d04
commit 3441abdd57
9 changed files with 177 additions and 22 deletions

View File

@ -44,6 +44,7 @@
<uses-permission android:name="android.permission.ACCESS_THEME_MANAGER"/>
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.HARDWARE_ABSTRACTION_ACCESS" />
<uses-permission android:name="android.permission.BACKUP" />
<uses-permission android:name="org.whispersystems.whisperpush.permissions.REGISTER" />
<permission

View File

@ -36,6 +36,53 @@
android:layout_height="match_parent"
style="@style/PageContent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:paddingLeft="@dimen/content_margin_left"
android:paddingRight="@dimen/content_margin_right"
style="@style/PageSummaryText"
android:text="@string/backup_data_title" />
<LinearLayout
android:id="@+id/backup"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/location_margin_left"
android:paddingRight="@dimen/content_margin_right"
android:background="?android:attr/selectableItemBackground"
android:clickable="true">
<CheckBox
android:id="@+id/backup_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="5dp"
android:duplicateParentState="true"
android:clickable="false" />
<TextView
android:id="@+id/backup_summary"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="15sp"
android:lineSpacingExtra="@dimen/setup_line_spacing"
android:gravity="top"
android:layout_marginLeft="@dimen/location_text_margin_left"
android:layout_marginRight="@dimen/location_text_margin_right"
android:paddingBottom="@dimen/content_margin_bottom"
android:text="@string/backup_data_summary"
android:maxLines="5" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -83,8 +83,8 @@
android:gravity="center_vertical"
android:duplicateParentState="true"
android:clickable="false"
android:textOff="@string/enable_mobile_off"
android:textOn="@string/enable_mobile_on"/>
android:textOff="@string/no"
android:textOn="@string/yes"/>
</LinearLayout>
<include layout="@layout/divider" />

View File

@ -42,6 +42,7 @@
<string name="setup_gms_account">GMS account</string>
<string name="setup_choose_data_sim">Choose a SIM for Data</string>
<string name="setup_location">Location Services</string>
<string name="setup_other">Other Services</string>
<string name="setup_datetime">Date &amp; time</string>
<string name="setup_current_date">Current date</string>
<string name="setup_current_time">Current time</string>
@ -51,6 +52,9 @@
<string name="date_time_summary">Set your time zone and adjust current date and time if needed</string>
<string name="backup_data_title">Back up my data</string>
<string name="backup_data_summary">Back up app data, Wi-Fi passwords, and other settings to Google servers</string>
<string name="location_services_summary">Location services allows Maps and other apps to gather and use data such as your approximate location. For example, Maps may use your approximate location to locate nearby coffee shops.</string>
<string name="location_access_summary"><b>Allow apps that have asked your permission</b> to use your location information. This may include your current location and past locations.</string>
<string name="location_gps"><b>Improve location accuracy</b> by allowing apps to use the GPS on your phone.</string>
@ -60,8 +64,8 @@
<string name="setup_mobile_data_no_service">No service</string>
<string name="setup_mobile_data_emergency_only">Emergency calls only</string>
<string name="enable_mobile_data_summary">Do you want to use mobile data during setup? Turning on mobile data may be subject to data charges.</string>
<string name="enable_mobile_off">No</string>
<string name="enable_mobile_on">Yes</string>
<string name="no">No</string>
<string name="yes">Yes</string>
<string name="data_sim_name">SIM <xliff:g id="sub">%d</xliff:g> - <xliff:g id="name">%s</xliff:g></string>

View File

@ -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;

View File

@ -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()]));

View File

@ -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);

View File

@ -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(

View File

@ -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,