summaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod/setupwizard/setup
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2015-05-07 16:21:10 -0700
committercretin45 <cretin45@gmail.com>2015-05-08 11:44:34 -0700
commit7710855b726a921d7fd1e85aeeb4b20fee998923 (patch)
treea7203ba380b5189a47ae6cf25be9ffe3c46294d3 /src/com/cyanogenmod/setupwizard/setup
parent4d08b90df38a90a0ec077412f92b0dabb594e056 (diff)
downloadpackages_apps_SetupWizard-7710855b726a921d7fd1e85aeeb4b20fee998923.zip
packages_apps_SetupWizard-7710855b726a921d7fd1e85aeeb4b20fee998923.tar.gz
packages_apps_SetupWizard-7710855b726a921d7fd1e85aeeb4b20fee998923.tar.bz2
SetupWizard: Add kill switch implementation
Change-Id: I1335cddf0dcc94eb8d2defeebdc47cb61abffd06
Diffstat (limited to 'src/com/cyanogenmod/setupwizard/setup')
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/CyanogenServicesPage.java3
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/CyanogenSettingsPage.java23
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/WelcomePage.java79
3 files changed, 100 insertions, 5 deletions
diff --git a/src/com/cyanogenmod/setupwizard/setup/CyanogenServicesPage.java b/src/com/cyanogenmod/setupwizard/setup/CyanogenServicesPage.java
index 479f2be..e71dd79 100644
--- a/src/com/cyanogenmod/setupwizard/setup/CyanogenServicesPage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/CyanogenServicesPage.java
@@ -101,6 +101,9 @@ public class CyanogenServicesPage extends SetupPage {
resultCode == Activity.RESULT_OK ? "success" : "skipped");
if (SetupWizardUtils.accountExists(mContext,
mContext.getString(R.string.cm_account_type))) {
+ if (SetupWizardUtils.isDeviceLocked()) {
+ ((SetupWizardApp) mContext.getApplicationContext()).setIsAuthorized(true);
+ }
setHidden(true);
}
getCallbacks().onNextPage();
diff --git a/src/com/cyanogenmod/setupwizard/setup/CyanogenSettingsPage.java b/src/com/cyanogenmod/setupwizard/setup/CyanogenSettingsPage.java
index bdc3076..86906da 100644
--- a/src/com/cyanogenmod/setupwizard/setup/CyanogenSettingsPage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/CyanogenSettingsPage.java
@@ -42,6 +42,7 @@ import android.view.IWindowManager;
import android.view.View;
import android.view.WindowManagerGlobal;
import android.widget.CheckBox;
+import android.widget.ImageView;
import android.widget.TextView;
import com.cyanogenmod.setupwizard.R;
@@ -213,6 +214,9 @@ public class CyanogenSettingsPage extends SetupPage {
public static class CyanogenSettingsFragment extends SetupPageFragment {
+ private View mKillSwitchView;
+ private TextView mKillSwitchTitle;
+ private ImageView mKillSwitchStatus;
private View mMetricsRow;
private View mDefaultThemeRow;
private View mNavKeysRow;
@@ -287,6 +291,21 @@ public class CyanogenSettingsPage extends SetupPage {
privacyPolicy.setMovementMethod(LinkMovementMethod.getInstance());
privacyPolicy.setText(ss);
+ mKillSwitchView = mRootView.findViewById(R.id.killswitch);
+ mKillSwitchTitle = (TextView)mRootView.findViewById(R.id.killswitch_title);
+ mKillSwitchStatus = (ImageView)mRootView.findViewById(R.id.killswitch_check);
+ if (hideKillSwitch()) {
+ mKillSwitchView.setVisibility(View.GONE);
+ } else {
+ if (SetupWizardUtils.isDeviceLocked()) {
+ mKillSwitchTitle.setEnabled(true);
+ mKillSwitchStatus.setImageResource(R.drawable.tick);
+ } else {
+ mKillSwitchTitle.setEnabled(false);
+ mKillSwitchStatus.setImageResource(R.drawable.cross);
+ }
+ }
+
mMetricsRow = mRootView.findViewById(R.id.metrics);
mMetricsRow.setOnClickListener(mMetricsClickListener);
String metricsHelpImproveCM =
@@ -414,5 +433,9 @@ public class CyanogenSettingsPage extends SetupPage {
}
}
+ private static boolean hideKillSwitch() {
+ return !SetupWizardUtils.hasKillSwitch();
+ }
+
}
}
diff --git a/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java b/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java
index 1f63878..3f01e53 100644
--- a/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java
+++ b/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java
@@ -16,6 +16,10 @@
package com.cyanogenmod.setupwizard.setup;
+import android.accounts.AccountManager;
+import android.accounts.AccountManagerCallback;
+import android.accounts.AccountManagerFuture;
+import android.app.Activity;
import android.app.ActivityOptions;
import android.app.Fragment;
import android.app.FragmentManager;
@@ -25,14 +29,17 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
+import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.NumberPicker;
import com.cyanogenmod.setupwizard.R;
+import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.LocalePicker;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
+import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.util.Locale;
@@ -42,21 +49,23 @@ public class WelcomePage extends SetupPage {
private static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL";
+ private WelcomeFragment mWelcomeFragment;
+
public WelcomePage(Context context, SetupDataCallbacks callbacks) {
super(context, callbacks);
}
@Override
public Fragment getFragment(FragmentManager fragmentManager, int action) {
- Fragment fragment = fragmentManager.findFragmentByTag(getKey());
- if (fragment == null) {
+ mWelcomeFragment = (WelcomeFragment)fragmentManager.findFragmentByTag(getKey());
+ if (mWelcomeFragment == null) {
Bundle args = new Bundle();
args.putString(Page.KEY_PAGE_ARGUMENT, getKey());
args.putInt(Page.KEY_PAGE_ACTION, action);
- fragment = new WelcomeFragment();
- fragment.setArguments(args);
+ mWelcomeFragment = new WelcomeFragment();
+ mWelcomeFragment.setArguments(args);
}
- return fragment;
+ return mWelcomeFragment;
}
@Override
@@ -65,6 +74,16 @@ public class WelcomePage extends SetupPage {
}
@Override
+ public boolean doNextAction() {
+ if (isLocked()) {
+ confirmCyanogenCredentials(mWelcomeFragment);
+ return true;
+ } else {
+ return super.doNextAction();
+ }
+ }
+
+ @Override
public boolean doPreviousAction() {
Intent intent = new Intent(ACTION_EMERGENCY_DIAL);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
@@ -82,15 +101,65 @@ public class WelcomePage extends SetupPage {
}
@Override
+ public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == SetupWizardApp.REQUEST_CODE_UNLOCK) {
+ if (resultCode == Activity.RESULT_OK) {
+ ((SetupWizardApp) mContext.getApplicationContext()).setIsAuthorized(true);
+ getCallbacks().onNextPage();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
public String getKey() {
return TAG;
}
@Override
+ public int getNextButtonTitleResId() {
+ if (isLocked()) {
+ return R.string.setup_unlock;
+ } else {
+ return R.string.next;
+ }
+ }
+
+ @Override
public int getPrevButtonTitleResId() {
return R.string.emergency_call;
}
+ private void confirmCyanogenCredentials(final Fragment fragment) {
+ AccountManager accountManager = AccountManager.get(mContext);
+ accountManager.editProperties(SetupWizardApp.ACCOUNT_TYPE_CYANOGEN, null,
+ new AccountManagerCallback<Bundle>() {
+ public void run(AccountManagerFuture<Bundle> f) {
+ try {
+ Bundle b = f.getResult();
+ Intent i = b.getParcelable(AccountManager.KEY_INTENT);
+ i.putExtra(SetupWizardApp.EXTRA_FIRST_RUN, true);
+ i.putExtra(SetupWizardApp.EXTRA_SHOW_BUTTON_BAR, true);
+ i.putExtra(SetupWizardApp.EXTRA_USE_IMMERSIVE, true);
+ i.putExtra(SetupWizardApp.EXTRA_LOGIN_FOR_KILL_SWITCH, true);
+ fragment.startActivityForResult(i,
+ SetupWizardApp.REQUEST_CODE_UNLOCK);
+ } catch (Throwable t) {
+ Log.e(getKey(), "confirmCredentials failed", t);
+ }
+ }
+ }, null);
+ }
+
+ private boolean isLocked() {
+ boolean isAuthorized = ((SetupWizardApp) mContext.getApplicationContext()).isAuthorized();
+ if (SetupWizardUtils.isDeviceLocked()) {
+ return !isAuthorized;
+ }
+ return false;
+ }
+
public static class WelcomeFragment extends SetupPageFragment {
private ArrayAdapter<com.android.internal.app.LocalePicker.LocaleInfo> mLocaleAdapter;