diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/CryptKeeper.java | 117 | ||||
-rw-r--r-- | src/com/android/settings/DevelopmentSettings.java | 6 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiPickerActivity.java | 5 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiSettingsForSetupWizard.java | 178 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiSetupActivity.java | 199 |
5 files changed, 292 insertions, 213 deletions
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java index 4e20823..e9fed4f 100644 --- a/src/com/android/settings/CryptKeeper.java +++ b/src/com/android/settings/CryptKeeper.java @@ -65,6 +65,8 @@ import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternView; import com.android.internal.widget.LockPatternView.Cell; +import static com.android.internal.widget.LockPatternView.DisplayMode; + import java.util.List; /** @@ -122,6 +124,16 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList private int mNotificationCountdown = 0; /** Number of calls to {@link #notifyUser()} before we release the wakelock */ private int mReleaseWakeLockCountdown = 0; + private int mStatusString = R.string.enter_password; + + // how long we wait to clear a wrong pattern + private static final int WRONG_PATTERN_CLEAR_TIMEOUT_MS = 1500; + + private Runnable mClearPatternRunnable = new Runnable() { + public void run() { + mLockPatternView.clearPattern(); + } + }; /** * Used to propagate state through configuration changes (e.g. screen rotation) @@ -175,21 +187,32 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } else if (failedAttempts == MAX_FAILED_ATTEMPTS) { // Factory reset the device. sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); - } else if ((failedAttempts % COOL_DOWN_ATTEMPTS) == 0) { - if (mLockPatternView != null) { - mLockPatternView.clearPattern(); - } - mCooldown = COOL_DOWN_INTERVAL; - cooldown(); } else { - final TextView status = (TextView) findViewById(R.id.status); - status.setText(R.string.try_again); - // Reenable the password entry - if (mPasswordEntry != null) { - mPasswordEntry.setEnabled(true); - } + // Wrong entry. Handle pattern case. if (mLockPatternView != null) { - mLockPatternView.setEnabled(true); + mLockPatternView.setDisplayMode(DisplayMode.Wrong); + mLockPatternView.removeCallbacks(mClearPatternRunnable); + mLockPatternView.postDelayed(mClearPatternRunnable, WRONG_PATTERN_CLEAR_TIMEOUT_MS); + } + if ((failedAttempts % COOL_DOWN_ATTEMPTS) == 0) { + mCooldown = COOL_DOWN_INTERVAL; + cooldown(); + } else { + final TextView status = (TextView) findViewById(R.id.status); + status.setText(R.string.try_again); + if (mLockPatternView != null) { + mLockPatternView.setDisplayMode(DisplayMode.Wrong); + } + // Reenable the password entry + if (mPasswordEntry != null) { + mPasswordEntry.setEnabled(true); + final InputMethodManager imm = (InputMethodManager) getSystemService( + Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mPasswordEntry, 0); + } + if (mLockPatternView != null) { + mLockPatternView.setEnabled(true); + } } } } @@ -398,19 +421,28 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList public void onPostExecute(java.lang.Void v) { if(type == StorageManager.CRYPT_TYPE_PIN) { setContentView(R.layout.crypt_keeper_pin_entry); - ((TextView)findViewById(R.id.status)).setText(R.string.enter_pin); + mStatusString = R.string.enter_pin; } else if (type == StorageManager.CRYPT_TYPE_PATTERN) { setContentView(R.layout.crypt_keeper_pattern_entry); setBackFunctionality(false); - ((TextView)findViewById(R.id.status)).setText(R.string.enter_pattern); + mStatusString = R.string.enter_pattern; } else { setContentView(R.layout.crypt_keeper_password_entry); + mStatusString = R.string.enter_password; } + final TextView status = (TextView) findViewById(R.id.status); + status.setText(mStatusString); + + final TextView ownerInfo = (TextView) findViewById(R.id.owner_info); + ownerInfo.setText(owner_info); + ownerInfo.setSelected(true); // Required for marquee'ing to work - final TextView status = (TextView) findViewById(R.id.owner_info); - status.setText(owner_info); - status.setSelected(true); // Required for marquee'ing to work passwordEntryInit(); + + if (mCooldown > 0) { + setBackFunctionality(false); + cooldown(); // in case we are cooling down and coming back from emergency dialler + } } }.execute(); } else if (!mValidationRequested) { @@ -553,13 +585,24 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList // Re-enable the password entry and back presses. if (mPasswordEntry != null) { mPasswordEntry.setEnabled(true); + final InputMethodManager imm = (InputMethodManager) getSystemService( + Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mPasswordEntry, 0); setBackFunctionality(true); } if (mLockPatternView != null) { mLockPatternView.setEnabled(true); } - status.setText(R.string.enter_password); + status.setText(mStatusString); } else { + // Disable the password entry and back presses. + if (mPasswordEntry != null) { + mPasswordEntry.setEnabled(false); + } + if (mLockPatternView != null) { + mLockPatternView.setEnabled(false); + } + CharSequence template = getText(R.string.crypt_keeper_cooldown); status.setText(TextUtils.expandTemplate(template, Integer.toString(mCooldown))); @@ -583,25 +626,26 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } protected LockPatternView.OnPatternListener mChooseNewLockPatternListener = - new LockPatternView.OnPatternListener() { + new LockPatternView.OnPatternListener() { - @Override - public void onPatternStart() { - } + @Override + public void onPatternStart() { + mLockPatternView.removeCallbacks(mClearPatternRunnable); + } - @Override - public void onPatternCleared() { - } + @Override + public void onPatternCleared() { + } - @Override - public void onPatternDetected(List<LockPatternView.Cell> pattern) { - mLockPatternView.setEnabled(false); - new DecryptTask().execute(LockPatternUtils.patternToString(pattern)); - } + @Override + public void onPatternDetected(List<LockPatternView.Cell> pattern) { + mLockPatternView.setEnabled(false); + new DecryptTask().execute(LockPatternUtils.patternToString(pattern)); + } - @Override - public void onPatternCellAdded(List<Cell> pattern) { - } + @Override + public void onPatternCellAdded(List<Cell> pattern) { + } }; private void passwordEntryInit() { @@ -655,13 +699,13 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList mWakeLock.acquire(); // Keep awake for 10 minutes - if the user hasn't been alerted by then // best not to just drain their battery - mReleaseWakeLockCountdown = 96; // 96 * 5 + 120 = 600 + mReleaseWakeLockCountdown = 96; // 96 * 5 secs per click + 120 secs before we show this = 600 } } // Asynchronously throw up the IME, since there are issues with requesting it to be shown // immediately. - if (mLockPatternView == null) { + if (mLockPatternView == null && mCooldown <= 0) { mHandler.postDelayed(new Runnable() { @Override public void run() { imm.showSoftInputUnchecked(0, null); @@ -846,6 +890,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList final Intent intent = new Intent(ACTION_EMERGENCY_DIAL); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + setBackFunctionality(true); startActivity(intent); } diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java index 6d9206c..3708999 100644 --- a/src/com/android/settings/DevelopmentSettings.java +++ b/src/com/android/settings/DevelopmentSettings.java @@ -359,8 +359,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment mWebViewDataReductionProxy = findAndInitCheckboxPref(WEBVIEW_DATA_REDUCTION_PROXY_KEY); String key = Settings.Global.getString(getActivity().getContentResolver(), Settings.Global.WEBVIEW_DATA_REDUCTION_PROXY_KEY); - // Make it not selectable if the key is not available for some reason. - mWebViewDataReductionProxy.setSelectable(key != null && !key.isEmpty()); + // Disable the selection if the key is not available for some reason. + if (key == null || key.isEmpty()) { + disableForUser(mWebViewDataReductionProxy); + } } private ListPreference addListPreference(String prefKey) { diff --git a/src/com/android/settings/wifi/WifiPickerActivity.java b/src/com/android/settings/wifi/WifiPickerActivity.java index 4cb78bd..eec9963 100644 --- a/src/com/android/settings/wifi/WifiPickerActivity.java +++ b/src/com/android/settings/wifi/WifiPickerActivity.java @@ -20,6 +20,7 @@ import com.android.settings.SettingsActivity; import com.android.settings.wifi.p2p.WifiP2pSettings; import android.content.Intent; +import android.preference.PreferenceFragment; import java.lang.Class; @@ -36,13 +37,13 @@ public class WifiPickerActivity extends SettingsActivity implements ButtonBarHan @Override protected boolean isValidFragment(String fragmentName) { - if (getWifiSettingsClass().getName().equals(fragmentName) + if (WifiSettings.class.getName().equals(fragmentName) || WifiP2pSettings.class.getName().equals(fragmentName) || AdvancedWifiSettings.class.getName().equals(fragmentName)) return true; return false; } - /* package */ Class getWifiSettingsClass() { + /* package */ Class<? extends PreferenceFragment> getWifiSettingsClass() { return WifiSettings.class; } }
\ No newline at end of file diff --git a/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java index 17fca9f..325e1eb 100644 --- a/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java +++ b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java @@ -17,11 +17,8 @@ package com.android.settings.wifi; import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; import android.content.BroadcastReceiver; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.res.TypedArray; @@ -63,25 +60,9 @@ public class WifiSettingsForSetupWizard extends WifiSettings { // this boolean extra specifies whether to auto finish when connection is established private static final String EXTRA_AUTO_FINISH_ON_CONNECT = "wifi_auto_finish_on_connect"; - // this boolean extra shows a custom button that we can control - protected static final String EXTRA_SHOW_CUSTOM_BUTTON = "wifi_show_custom_button"; - // show a text regarding data charges when wifi connection is required during setup wizard protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info"; - // this boolean extra is set if we are being invoked by the Setup Wizard - private static final String EXTRA_IS_FIRST_RUN = "firstRun"; - - // Activity result when pressing the Skip button - private static final int RESULT_SKIP = Activity.RESULT_FIRST_USER; - - // From WizardManager (must match constants maintained there) - private static final String ACTION_NEXT = "com.android.wizard.NEXT"; - private static final String EXTRA_SCRIPT_URI = "scriptUri"; - private static final String EXTRA_ACTION_ID = "actionId"; - private static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode"; - private static final int NEXT_REQUEST = 10000; - // should Next button only be enabled when we have a connection? private boolean mEnableNextOnConnection; @@ -105,7 +86,8 @@ public class WifiSettingsForSetupWizard extends WifiSettings { changeNextButtonState(info.isConnected()); if (mAutoFinishOnConnection && info.isConnected()) { Log.d(TAG, "mReceiver.onReceive context=" + context + " intent=" + intent); - finishOrNext(Activity.RESULT_OK); + WifiSetupActivity activity = (WifiSetupActivity) getActivity(); + activity.finishOrNext(Activity.RESULT_OK); } } }; @@ -150,36 +132,6 @@ public class WifiSettingsForSetupWizard extends WifiSettings { } final Intent intent = getActivity().getIntent(); - if (intent.getBooleanExtra(EXTRA_SHOW_CUSTOM_BUTTON, false)) { - view.findViewById(R.id.button_bar).setVisibility(View.VISIBLE); - view.findViewById(R.id.back_button).setVisibility(View.INVISIBLE); - view.findViewById(R.id.skip_button).setVisibility(View.INVISIBLE); - view.findViewById(R.id.next_button).setVisibility(View.INVISIBLE); - - Button customButton = (Button) view.findViewById(R.id.custom_button); - customButton.setVisibility(View.VISIBLE); - customButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - boolean isConnected = false; - Activity activity = getActivity(); - final ConnectivityManager connectivity = (ConnectivityManager) - activity.getSystemService(Context.CONNECTIVITY_SERVICE); - if (connectivity != null) { - final NetworkInfo info = connectivity.getActiveNetworkInfo(); - isConnected = (info != null) && info.isConnected(); - } - if (isConnected) { - // Warn of possible data charges - showDialog(WIFI_SKIPPED_DIALOG_ID); - } else { - // Warn of lack of updates - showDialog(WIFI_AND_MOBILE_SKIPPED_DIALOG_ID); - } - } - }); - } - if (intent.getBooleanExtra(EXTRA_SHOW_WIFI_REQUIRED_INFO, false)) { view.findViewById(R.id.wifi_required_info).setVisibility(View.VISIBLE); } @@ -197,30 +149,32 @@ public class WifiSettingsForSetupWizard extends WifiSettings { View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS | View.STATUS_BAR_DISABLE_CLOCK); - final Activity activity = getActivity(); + final WifiSetupActivity activity = (WifiSetupActivity) getActivity(); final Intent intent = activity.getIntent(); // first if we're supposed to finish once we have a connection mAutoFinishOnConnection = intent.getBooleanExtra(EXTRA_AUTO_FINISH_ON_CONNECT, false); - /* - * When entering with a savedInstanceState, we may be returning from a later activity in the - * setup flow. It's not clear yet if there are other possible circumstances. It's not - * appropriate to refire our activity results, so we skip that here. - */ - if (mAutoFinishOnConnection && null == savedInstanceState) { + if (mAutoFinishOnConnection) { // Hide the next button if (hasNextButton()) { getNextButton().setVisibility(View.GONE); } - final ConnectivityManager connectivity = (ConnectivityManager) - activity.getSystemService(Context.CONNECTIVITY_SERVICE); - if (connectivity != null - && connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) { - Log.d(TAG, "onActivityCreated Auto-finishing"); - finishOrNext(Activity.RESULT_OK); - return; + /* + * When entering with a savedInstanceState, we may be returning from a later activity in + * the setup flow. It's not clear yet if there are other possible circumstances. It's + * not appropriate to refire our activity results, so we skip that here. + */ + if (savedInstanceState == null) { + final ConnectivityManager connectivity = (ConnectivityManager) + activity.getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivity != null && + connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) { + Log.d(TAG, "onActivityCreated Auto-finishing"); + activity.finishOrNext(Activity.RESULT_OK); + return; + } } } @@ -242,49 +196,6 @@ public class WifiSettingsForSetupWizard extends WifiSettings { } @Override - public Dialog onCreateDialog(int dialogId) { - switch (dialogId) { - case WIFI_SKIPPED_DIALOG_ID: - return new AlertDialog.Builder(getActivity()) - .setMessage(R.string.wifi_skipped_message) - .setCancelable(false) - .setNegativeButton(R.string.wifi_skip_anyway, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - finishOrNext(RESULT_SKIP); - } - }) - .setPositiveButton(R.string.wifi_dont_skip, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - } - }) - .create(); - case WIFI_AND_MOBILE_SKIPPED_DIALOG_ID: - return new AlertDialog.Builder(getActivity()) - .setMessage(R.string.wifi_and_mobile_skipped_message) - .setCancelable(false) - .setNegativeButton(R.string.wifi_skip_anyway, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - finishOrNext(RESULT_SKIP); - } - }) - .setPositiveButton(R.string.wifi_dont_skip, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - } - }) - .create(); - } - return super.onCreateDialog(dialogId); - } - - @Override public void onResume() { super.onResume(); getActivity().registerReceiver(mReceiver, mFilter); @@ -297,24 +208,6 @@ public class WifiSettingsForSetupWizard extends WifiSettings { } @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - if (resultCode == Activity.RESULT_CANCELED) { - // Before returning to the settings panel, forget any current access point so it will - // not attempt to automatically reconnect and advance - // FIXME: when coming back, it would be better to keep the current connection and - // override the auto-advance feature - final WifiInfo info = mWifiManager.getConnectionInfo(); - if (null != info) { - int netId = info.getNetworkId(); - if (netId != WifiConfiguration.INVALID_NETWORK_ID) { - mWifiManager.forget(netId, null); - } - } - } - super.onActivityResult(requestCode, resultCode, data); - } - - @Override public void registerForContextMenu(View view) { // Suppressed during setup wizard } @@ -359,39 +252,4 @@ public class WifiSettingsForSetupWizard extends WifiSettings { getNextButton().setEnabled(enabled); } } - - /** - * Complete this activity and return the results to the caller. If using WizardManager, this - * will invoke the next scripted action; otherwise, we simply finish. - */ - private void finishOrNext(int resultCode) { - Log.d(TAG, "finishOrNext resultCode=" + resultCode - + " isUsingWizardManager=" + isUsingWizardManager()); - if (isUsingWizardManager()) { - sendResultsToSetupWizard(resultCode); - } else { - Activity activity = getActivity(); - activity.setResult(resultCode); - activity.finish(); - } - } - - private boolean isUsingWizardManager() { - return getActivity().getIntent().hasExtra(EXTRA_SCRIPT_URI); - } - - /** - * Send the results of this activity to WizardManager, which will then send out the next - * scripted activity. WizardManager does not actually return an activity result, but if we - * invoke WizardManager without requesting a result, the framework will choose not to issue a - * call to onActivityResult with RESULT_CANCELED when navigating backward. - */ - private void sendResultsToSetupWizard(int resultCode) { - final Intent intent = getActivity().getIntent(); - final Intent nextIntent = new Intent(ACTION_NEXT); - nextIntent.putExtra(EXTRA_SCRIPT_URI, intent.getStringExtra(EXTRA_SCRIPT_URI)); - nextIntent.putExtra(EXTRA_ACTION_ID, intent.getStringExtra(EXTRA_ACTION_ID)); - nextIntent.putExtra(EXTRA_RESULT_CODE, resultCode); - startActivityForResult(nextIntent, NEXT_REQUEST); - } } diff --git a/src/com/android/settings/wifi/WifiSetupActivity.java b/src/com/android/settings/wifi/WifiSetupActivity.java index d4811ed..8e4ff48 100644 --- a/src/com/android/settings/wifi/WifiSetupActivity.java +++ b/src/com/android/settings/wifi/WifiSetupActivity.java @@ -15,37 +15,210 @@ */ package com.android.settings.wifi; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.res.Resources; +import android.graphics.Color; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.Bundle; +import android.preference.PreferenceFragment; +import android.util.Log; + import com.android.settings.ButtonBarHandler; +import com.android.settings.R; +import com.android.setupwizard.navigationbar.SetupWizardNavBar; +import com.android.setupwizard.navigationbar.SetupWizardNavBar.NavigationBarListener; -import android.content.res.Resources; +public class WifiSetupActivity extends WifiPickerActivity + implements ButtonBarHandler, NavigationBarListener { + private static final String TAG = "WifiSetupActivity"; -import java.lang.Class; + private static final String EXTRA_ALLOW_SKIP = "allowSkip"; + private static final String EXTRA_USE_IMMERSIVE_MODE = "useImmersiveMode"; + + // this boolean extra shows a custom button that we can control + protected static final String EXTRA_SHOW_CUSTOM_BUTTON = "wifi_show_custom_button"; -public class WifiSetupActivity extends WifiPickerActivity implements ButtonBarHandler { // Extra containing the resource name of the theme to be used private static final String EXTRA_THEME = "theme"; private static final String THEME_HOLO = "holo"; private static final String THEME_HOLO_LIGHT = "holo_light"; + private static final String THEME_MATERIAL = "material"; + private static final String THEME_MATERIAL_LIGHT = "material_light"; + + // Activity result when pressing the Skip button + private static final int RESULT_SKIP = Activity.RESULT_FIRST_USER; - // Style resources containing theme settings - private static final String RESOURCE_THEME_DARK = "SetupWizardWifiTheme"; - private static final String RESOURCE_THEME_LIGHT = "SetupWizardWifiTheme.Light"; + // From WizardManager (must match constants maintained there) + private static final String ACTION_NEXT = "com.android.wizard.NEXT"; + private static final String EXTRA_SCRIPT_URI = "scriptUri"; + private static final String EXTRA_ACTION_ID = "actionId"; + private static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode"; + private static final int NEXT_REQUEST = 10000; @Override protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { String themeName = getIntent().getStringExtra(EXTRA_THEME); - if (THEME_HOLO_LIGHT.equalsIgnoreCase(themeName)) { - resid = getResources().getIdentifier(RESOURCE_THEME_LIGHT, "style", - getPackageName()); - } else if (THEME_HOLO.equalsIgnoreCase(themeName)) { - resid = getResources().getIdentifier(RESOURCE_THEME_DARK, "style", - getPackageName()); + if (THEME_HOLO_LIGHT.equalsIgnoreCase(themeName) || + THEME_MATERIAL_LIGHT.equalsIgnoreCase(themeName)) { + resid = R.style.SetupWizardWifiTheme_Light; + } else if (THEME_HOLO.equalsIgnoreCase(themeName) || + THEME_MATERIAL.equalsIgnoreCase(themeName)) { + resid = R.style.SetupWizardWifiTheme; } super.onApplyThemeResource(theme, resid, first); } @Override - /* package */ Class getWifiSettingsClass() { + protected boolean isValidFragment(String fragmentName) { + return WifiSettingsForSetupWizard.class.getName().equals(fragmentName); + } + + @Override + /* package */ Class<? extends PreferenceFragment> getWifiSettingsClass() { return WifiSettingsForSetupWizard.class; } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (resultCode == Activity.RESULT_CANCELED) { + // Before returning to the settings panel, forget any current access point so it will + // not attempt to automatically reconnect and advance + // FIXME: when coming back, it would be better to keep the current connection and + // override the auto-advance feature + final WifiManager wifiManager = (WifiManager)(getSystemService(Context.WIFI_SERVICE)); + if (wifiManager != null) { + final WifiInfo info = wifiManager.getConnectionInfo(); + if (info != null) { + int netId = info.getNetworkId(); + if (netId != WifiConfiguration.INVALID_NETWORK_ID) { + wifiManager.forget(netId, null); + } + } + } + } + super.onActivityResult(requestCode, resultCode, data); + } + + /** + * Complete this activity and return the results to the caller. If using WizardManager, this + * will invoke the next scripted action; otherwise, we simply finish. + */ + public void finishOrNext(int resultCode) { + Log.d(TAG, "finishOrNext resultCode=" + resultCode + + " isUsingWizardManager=" + isUsingWizardManager()); + if (isUsingWizardManager()) { + sendResultsToSetupWizard(resultCode); + } else { + setResult(resultCode); + finish(); + } + } + + private boolean isUsingWizardManager() { + return getIntent().hasExtra(EXTRA_SCRIPT_URI); + } + + /** + * Send the results of this activity to WizardManager, which will then send out the next + * scripted activity. WizardManager does not actually return an activity result, but if we + * invoke WizardManager without requesting a result, the framework will choose not to issue a + * call to onActivityResult with RESULT_CANCELED when navigating backward. + */ + private void sendResultsToSetupWizard(int resultCode) { + final Intent intent = getIntent(); + final Intent nextIntent = new Intent(ACTION_NEXT); + nextIntent.putExtra(EXTRA_SCRIPT_URI, intent.getStringExtra(EXTRA_SCRIPT_URI)); + nextIntent.putExtra(EXTRA_ACTION_ID, intent.getStringExtra(EXTRA_ACTION_ID)); + nextIntent.putExtra(EXTRA_RESULT_CODE, resultCode); + startActivityForResult(nextIntent, NEXT_REQUEST); + } + + @Override + public void onNavigationBarCreated(final SetupWizardNavBar bar) { + final boolean useImmersiveMode = + getIntent().getBooleanExtra(EXTRA_USE_IMMERSIVE_MODE, false); + bar.setUseImmersiveMode(useImmersiveMode); + if (useImmersiveMode) { + getWindow().setNavigationBarColor(Color.TRANSPARENT); + getWindow().setStatusBarColor(Color.TRANSPARENT); + } + getIntent().putExtra(EXTRA_SHOW_CUSTOM_BUTTON, false); + bar.getNextButton().setText(R.string.skip_label); + + if (!getIntent().getBooleanExtra(EXTRA_ALLOW_SKIP, true)) { + bar.getNextButton().setEnabled(false); + } + } + + @Override + public void onNavigateBack() { + onBackPressed(); + } + + @Override + public void onNavigateNext() { + boolean isConnected = false; + final ConnectivityManager connectivity = (ConnectivityManager) + getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivity != null) { + final NetworkInfo info = connectivity.getActiveNetworkInfo(); + isConnected = (info != null) && info.isConnected(); + } + if (isConnected) { + // Warn of possible data charges + WifiSkipDialog.newInstance(R.string.wifi_skipped_message) + .show(getFragmentManager(), "dialog"); + } else { + // Warn of lack of updates + WifiSkipDialog.newInstance(R.string.wifi_and_mobile_skipped_message) + .show(getFragmentManager(), "dialog"); + } + } + + private static class WifiSkipDialog extends DialogFragment { + public static WifiSkipDialog newInstance(int messageRes) { + final Bundle args = new Bundle(); + args.putInt("messageRes", messageRes); + final WifiSkipDialog dialog = new WifiSkipDialog(); + dialog.setArguments(args); + return dialog; + } + + public WifiSkipDialog() { + // no-arg constructor for fragment + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + int messageRes = getArguments().getInt("messageRes"); + return new AlertDialog.Builder(getActivity()) + .setMessage(messageRes) + .setCancelable(false) + .setNegativeButton(R.string.wifi_skip_anyway, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + WifiSetupActivity activity = (WifiSetupActivity) getActivity(); + activity.finishOrNext(RESULT_SKIP); + } + }) + .setPositiveButton(R.string.wifi_dont_skip, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + } + }) + .create(); + } + } } |