SetupWizard: Ensure compliance with GMS TOS

* Launches GMS TOS per documentation
* Filters out redundant location page if GMS present
* Uses setupwizardlib for some helper functions
* Hide notification icons

Issue-id: CYNGNOS-2599

Change-Id: I4b59592f0b84d0eb0eafe365eab3bad77c1f76ff
This commit is contained in:
cretin45 2016-04-26 13:43:22 -07:00
parent 941aa1e1e2
commit 8109277755
8 changed files with 58 additions and 150 deletions

View File

@ -28,4 +28,6 @@ LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dir))
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages com.google.android.gms
include frameworks/opt/setupwizard/library/common.mk
include $(BUILD_PACKAGE)

View File

@ -45,42 +45,6 @@
android:paddingRight="@dimen/content_margin_right"
style="@style/PageSummaryText" />
<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>
<LinearLayout
android:id="@+id/location"
android:orientation="horizontal"

View File

@ -75,6 +75,7 @@ public class SetupWizardApp extends Application {
public static final int REQUEST_CODE_SETUP_BLUETOOTH= 5;
public static final int REQUEST_CODE_UNLOCK = 6;
public static final int REQUEST_CODE_SETUP_FINGERPRINT = 7;
public static final int REQUEST_CODE_VENDOR_SETUP_GMS = 8;
public static final int RADIO_READY_TIMEOUT = 10 * 1000;
@ -150,9 +151,13 @@ public class SetupWizardApp extends Application {
}
public void disableStatusBar() {
mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND | StatusBarManager.DISABLE_NOTIFICATION_ALERTS
| StatusBarManager.DISABLE_NOTIFICATION_TICKER | StatusBarManager.DISABLE_RECENT | StatusBarManager.DISABLE_HOME
| StatusBarManager.DISABLE_SEARCH);
mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND |
StatusBarManager.DISABLE_NOTIFICATION_ALERTS |
StatusBarManager.DISABLE_NOTIFICATION_ICONS |
StatusBarManager.DISABLE_NOTIFICATION_TICKER |
StatusBarManager.DISABLE_RECENT |
StatusBarManager.DISABLE_HOME |
StatusBarManager.DISABLE_SEARCH);
}
public void enableStatusBar() {

View File

@ -113,8 +113,13 @@ public class CMSetupWizardData extends AbstractSetupData {
boolean isConnected = SetupWizardUtils.isNetworkConnected(mContext);
GmsAccountPage gmsAccountPage =
(GmsAccountPage) getPage(GmsAccountPage.TAG);
OtherSettingsPage otherSettingsPage = (OtherSettingsPage) getPage(OtherSettingsPage.TAG);
if (gmsAccountPage != null) {
gmsAccountPage.setHidden(!isConnected && gmsAccountPage.canSkip());
boolean hidden = !isConnected && gmsAccountPage.canSkip();
gmsAccountPage.setHidden(hidden);
if (otherSettingsPage != null) {
otherSettingsPage.setHidden(!hidden);
}
}
CyanogenServicesPage cyanogenServicesPage =
(CyanogenServicesPage) getPage(CyanogenServicesPage.TAG);

View File

@ -32,6 +32,7 @@ import android.os.Bundle;
import android.service.persistentdata.PersistentDataBlockManager;
import android.util.Log;
import com.android.setupwizardlib.util.ResultCodes;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
@ -46,6 +47,7 @@ public class GmsAccountPage extends SetupPage {
public static final String ACTION_RESTORE = "com.google.android.setupwizard.RESTORE";
public static final String ACTION_PROGRESS = "com.google.android.setupwizard.PROGRESS";
public static final String ACTION_VENDOR_SETUP = "com.google.android.setupwizard.VENDOR_SETUP";
public static final String RESTORE_ACTION_ID = "mfm_restore_start";
public static final String RESTORE_CHECK_ID = "restore_check";
public static final String FRAGMENT_START_RESTORE =
@ -128,7 +130,10 @@ public class GmsAccountPage extends SetupPage {
}
}
}
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS && data != null) {
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS &&
resultCode == ResultCodes.RESULT_SKIP) {
launchGmsVendorSetup();
} else if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS && data != null) {
if (SetupWizardUtils.isOwner() && resultCode == Activity.RESULT_OK) {
// If we don't have a restore token and a restore account, then we need to
@ -242,6 +247,31 @@ public class GmsAccountPage extends SetupPage {
}
}
private void launchGmsVendorSetup() {
if (SetupWizardApp.DEBUG) {
Log.d(TAG, "Launching gms vendor setup page");
}
try {
Intent intent = new Intent(ACTION_VENDOR_SETUP);
intent.setPackage(SetupWizardUtils.GOOGLE_SETUPWIZARD_PACKAGE);
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(mContext,
android.R.anim.fade_in,
android.R.anim.fade_out);
mFragment.startActivityForResult(
intent,
SetupWizardApp.REQUEST_CODE_VENDOR_SETUP_GMS, options.toBundle());
return;
} catch (Exception e) {
// Move on if the vendor setup activity is not found.
getCallbacks().onNextPage();
}
}
public boolean canSkip() {
final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
mContext.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);

View File

@ -16,40 +16,27 @@
package com.cyanogenmod.setupwizard.setup;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.backup.IBackupManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
public class OtherSettingsPage extends SetupPage {
private static final String TAG = "OtherSettingsPage";
private static final String PRIVACY_POLICY_URI =
"https://www.google.com/intl/en/policies/privacy/?fg=1";
public static final String TAG = "OtherSettingsPage";
public OtherSettingsPage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
@ -84,18 +71,15 @@ public class OtherSettingsPage extends SetupPage {
public static class OtherSettingsFragment extends SetupPageFragment {
private View mBackupRow;
private View mLocationRow;
private View mBatteryRow;
private View mNetworkRow;
private CheckBox mBackup;
private CheckBox mNetwork;
private CheckBox mBattery;
private CheckBox mLocationAccess;
private ContentResolver mContentResolver;
private IBackupManager mBackupManager;
/** Broadcast intent action when the location mode is about to change. */
private static final String MODE_CHANGING_ACTION =
@ -107,13 +91,6 @@ public class OtherSettingsPage extends SetupPage {
private BroadcastReceiver mReceiver;
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) {
@ -137,42 +114,10 @@ public class OtherSettingsPage extends SetupPage {
@Override
protected void initializePage() {
final boolean hasGms = SetupWizardUtils.hasGMS(getActivity());
final boolean hasTelephony = SetupWizardUtils.hasTelephony(getActivity());
mContentResolver = getActivity().getContentResolver();
mBackupManager = IBackupManager.Stub.asInterface(
ServiceManager.getService(Context.BACKUP_SERVICE));
TextView summaryView = (TextView) mRootView.findViewById(android.R.id.summary);
if (hasGms) {
String privacy_policy = getString(R.string.services_privacy_policy);
String otherSummary = getString(R.string.other_services_summary, privacy_policy);
SpannableString ss = new SpannableString(otherSummary);
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
final Intent intent = new Intent(SetupWizardApp.ACTION_VIEW_LEGAL);
intent.setData(Uri.parse(PRIVACY_POLICY_URI));
try {
getActivity().startActivity(intent);
} catch (Exception e) {
Log.e(TAG, "Unable to start activity " + intent.toString());
}
}
};
ss.setSpan(clickableSpan,
otherSummary.length() - privacy_policy.length() - 1,
otherSummary.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
summaryView.setMovementMethod(LinkMovementMethod.getInstance());
summaryView.setText(ss);
} else {
summaryView.setText(R.string.location_services_summary);
}
mBackupRow = mRootView.findViewById(R.id.backup);
mBackupRow.setOnClickListener(mBackupClickListener);
boolean backupVisible = hasGms &&
SetupWizardUtils.accountExists(getActivity(), SetupWizardApp.ACCOUNT_TYPE_GMS);
mBackupRow.setVisibility(backupVisible ? View.VISIBLE : View.GONE);
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);
@ -183,9 +128,7 @@ public class OtherSettingsPage extends SetupPage {
mNetworkRow.setOnClickListener(mNetworkClickListener);
mNetwork = (CheckBox) mRootView.findViewById(R.id.network_checkbox);
TextView networkSummary = (TextView) mRootView.findViewById(R.id.network_summary);
if (hasGms) {
networkSummary.setText(R.string.location_network_gms);
} else if (hasTelephony) {
if (hasTelephony) {
networkSummary.setText(R.string.location_network_telephony);
} else {
networkSummary.setText(R.string.location_network);
@ -201,7 +144,6 @@ public class OtherSettingsPage extends SetupPage {
public void onResume() {
super.onResume();
refreshLocationMode();
updateBackupToggle();
}
@Override
@ -218,28 +160,6 @@ public class OtherSettingsPage extends SetupPage {
};
}
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);
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.ENABLE_BACKUP,
SetupStats.Label.CHECKED, String.valueOf(checked));
} catch (RemoteException e) {}
updateBackupToggle();
}
private void setLocationMode(int mode) {
Intent intent = new Intent(MODE_CHANGING_ACTION);
intent.putExtra(CURRENT_MODE_KEY, mCurrentMode);

View File

@ -42,6 +42,7 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import com.android.setupwizardlib.util.SystemBarHelper;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
@ -64,11 +65,6 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks,
private static final String TAG = SetupWizardActivity.class.getSimpleName();
private static final String KEY_LAST_PAGE_TAG = "last_page_tag";
private static final int UI_FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
private View mRootView;
private View mButtonBar;
@ -95,25 +91,13 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks,
if (!isOwner) {
finish();
}
final View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(UI_FLAGS);
decorView.setOnSystemUiVisibilityChangeListener(
new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
decorView.setSystemUiVisibility(UI_FLAGS);
}
}
});
SystemBarHelper.hideSystemBars(getWindow());
if (sLaunchTime == 0) {
SetupStats.addEvent(SetupStats.Categories.APP_LAUNCH, TAG);
sLaunchTime = System.nanoTime();
}
setContentView(R.layout.setup_main);
mRootView = findViewById(R.id.root);
mRootView.setSystemUiVisibility(UI_FLAGS);
mReveal = (ImageView)mRootView.findViewById(R.id.reveal);
mButtonBar = findViewById(R.id.button_bar);
mFinishingProgressBar = (ProgressBar)findViewById(R.id.finishing_bar);
@ -186,8 +170,6 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks,
@Override
protected void onResume() {
final View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(UI_FLAGS);
super.onResume();
if (isFinishing()) {
return;

View File

@ -51,7 +51,7 @@ public class SetupWizardUtils {
private static final String TAG = SetupWizardUtils.class.getSimpleName();
private static final String GOOGLE_SETUPWIZARD_PACKAGE = "com.google.android.setupwizard";
public static final String GOOGLE_SETUPWIZARD_PACKAGE = "com.google.android.setupwizard";
private SetupWizardUtils(){}