diff options
Diffstat (limited to 'src')
5 files changed, 215 insertions, 147 deletions
diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java index 7f159ab..0ddeb50 100644 --- a/src/com/android/settings/CryptKeeper.java +++ b/src/com/android/settings/CryptKeeper.java @@ -148,22 +148,6 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } } - /** - * Activity used to fade the screen to black after the password is entered. - */ - public static class FadeToBlack extends Activity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.crypt_keeper_blank); - } - /** Ignore all back events. */ - @Override - public void onBackPressed() { - return; - } - } - private class DecryptTask extends AsyncTask<String, Void, Integer> { @Override protected Integer doInBackground(String... params) { @@ -179,13 +163,8 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList @Override protected void onPostExecute(Integer failedAttempts) { if (failedAttempts == 0) { - // The password was entered successfully. Start the Blank activity - // so this activity animates to black before the devices starts. Note - // It has 1 second to complete the animation or it will be frozen - // until the boot animation comes back up. - Intent intent = new Intent(CryptKeeper.this, FadeToBlack.class); - finish(); - startActivity(intent); + // The password was entered successfully. Simply do nothing + // and wait for the service restart to switch to surfacefligner } else if (failedAttempts == MAX_FAILED_ATTEMPTS) { // Factory reset the device. sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); @@ -862,14 +841,10 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList int textId; if (getPhoneManager().isInAPhoneCall()) { - // Show "return to call" text and show phone icon + // Show "return to call" textId = R.string.cryptkeeper_return_to_call; - final int phoneCallIcon = R.drawable.stat_sys_phone_call; - emergencyCall.setCompoundDrawablesWithIntrinsicBounds(phoneCallIcon, 0, 0, 0); } else { textId = R.string.cryptkeeper_emergency_call; - final int emergencyIcon = R.drawable.ic_emergency; - emergencyCall.setCompoundDrawablesWithIntrinsicBounds(emergencyIcon, 0, 0, 0); } emergencyCall.setText(textId); } diff --git a/src/com/android/settings/accounts/AccountSyncSettings.java b/src/com/android/settings/accounts/AccountSyncSettings.java index 77b1124..458adca 100644 --- a/src/com/android/settings/accounts/AccountSyncSettings.java +++ b/src/com/android/settings/accounts/AccountSyncSettings.java @@ -17,7 +17,6 @@ package com.android.settings.accounts; import com.google.android.collect.Lists; -import com.google.android.collect.Maps; import android.accounts.Account; import android.accounts.AccountManager; @@ -59,7 +58,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Date; -import java.util.HashMap; import java.util.List; public class AccountSyncSettings extends AccountPreferenceBase { @@ -76,9 +74,6 @@ public class AccountSyncSettings extends AccountPreferenceBase { private ImageView mProviderIcon; private TextView mErrorInfoView; private Account mAccount; - // List of all accounts, updated when accounts are added/removed - // We need to re-scan the accounts on sync events, in case sync state changes. - private Account[] mAccounts; private ArrayList<SyncStateCheckBoxPreference> mCheckBoxes = new ArrayList<SyncStateCheckBoxPreference>(); private ArrayList<SyncAdapterType> mInvisibleAdapters = Lists.newArrayList(); @@ -185,11 +180,16 @@ public class AccountSyncSettings extends AccountPreferenceBase { return; } mAccount = (Account) arguments.getParcelable(ACCOUNT_KEY); - if (mAccount != null) { - if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "Got account: " + mAccount); - mUserId.setText(mAccount.name); - mProviderId.setText(mAccount.type); + if (!accountExists(mAccount)) { + Log.e(TAG, "Account provided does not exist: " + mAccount); + finish(); + return; } + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "Got account: " + mAccount); + } + mUserId.setText(mAccount.name); + mProviderId.setText(mAccount.type); } @Override @@ -336,10 +336,7 @@ public class AccountSyncSettings extends AccountPreferenceBase { // plus whatever the system needs to sync, e.g., invisible sync adapters if (mAccount != null) { for (SyncAdapterType syncAdapter : mInvisibleAdapters) { - // invisible sync adapters' account type should be same as current account type - if (syncAdapter.accountType.equals(mAccount.type)) { - requestOrCancelSync(mAccount, syncAdapter.authority, startSync); - } + requestOrCancelSync(mAccount, syncAdapter.authority, startSync); } } } @@ -378,7 +375,7 @@ public class AccountSyncSettings extends AccountPreferenceBase { boolean syncIsFailing = false; // Refresh the sync status checkboxes - some syncs may have become active. - updateAccountCheckboxes(mAccounts); + updateAccountCheckboxes(); for (int i = 0, count = getPreferenceScreen().getPreferenceCount(); i < count; i++) { Preference pref = getPreferenceScreen().getPreference(i); @@ -446,29 +443,42 @@ public class AccountSyncSettings extends AccountPreferenceBase { @Override public void onAccountsUpdate(final UserHandle userHandle) { super.onAccountsUpdate(userHandle); - mAccounts = AccountManager.get(getActivity()).getAccountsAsUser( - mUserHandle.getIdentifier()); - updateAccountCheckboxes(mAccounts); + if (!accountExists(mAccount)) { + // The account was deleted + finish(); + return; + } + updateAccountCheckboxes(); onSyncStateUpdated(); } - private void updateAccountCheckboxes(Account[] accounts) { + private boolean accountExists(Account account) { + if (account == null) return false; + + Account[] accounts = AccountManager.get(getActivity()).getAccountsByTypeAsUser( + account.type, mUserHandle); + final int count = accounts.length; + for (int i = 0; i < count; i++) { + if (accounts[i].equals(account)) { + return true; + } + } + return false; + } + + private void updateAccountCheckboxes() { mInvisibleAdapters.clear(); - SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser( + SyncAdapterType[] syncAdapters = ContentResolver.getSyncAdapterTypesAsUser( mUserHandle.getIdentifier()); - HashMap<String, ArrayList<String>> accountTypeToAuthorities = - Maps.newHashMap(); + ArrayList<String> authorities = new ArrayList<String>(); for (int i = 0, n = syncAdapters.length; i < n; i++) { final SyncAdapterType sa = syncAdapters[i]; + // Only keep track of sync adapters for this account + if (!sa.accountType.equals(mAccount.type)) continue; if (sa.isUserVisible()) { - ArrayList<String> authorities = accountTypeToAuthorities.get(sa.accountType); - if (authorities == null) { - authorities = new ArrayList<String>(); - accountTypeToAuthorities.put(sa.accountType, authorities); - } if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.d(TAG, "onAccountUpdated: added authority " + sa.authority + Log.d(TAG, "updateAccountCheckboxes: added authority " + sa.authority + " to accountType " + sa.accountType); } authorities.add(sa.authority); @@ -484,25 +494,19 @@ public class AccountSyncSettings extends AccountPreferenceBase { } mCheckBoxes.clear(); - for (int i = 0, n = accounts.length; i < n; i++) { - final Account account = accounts[i]; + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.d(TAG, "looking for sync adapters that match account " + mAccount); + } + for (int j = 0, m = authorities.size(); j < m; j++) { + final String authority = authorities.get(j); + // We could check services here.... + int syncState = ContentResolver.getIsSyncableAsUser(mAccount, authority, + mUserHandle.getIdentifier()); if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.d(TAG, "looking for sync adapters that match account " + account); + Log.d(TAG, " found authority " + authority + " " + syncState); } - final ArrayList<String> authorities = accountTypeToAuthorities.get(account.type); - if (authorities != null && (mAccount == null || mAccount.equals(account))) { - for (int j = 0, m = authorities.size(); j < m; j++) { - final String authority = authorities.get(j); - // We could check services here.... - int syncState = ContentResolver.getIsSyncableAsUser(account, authority, - mUserHandle.getIdentifier()); - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.d(TAG, " found authority " + authority + " " + syncState); - } - if (syncState > 0) { - addSyncStateCheckBox(account, authority); - } - } + if (syncState > 0) { + addSyncStateCheckBox(mAccount, authority); } } diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java index 474a857..c0a13c1 100644 --- a/src/com/android/settings/location/LocationSettings.java +++ b/src/com/android/settings/location/LocationSettings.java @@ -54,17 +54,13 @@ public class LocationSettings extends LocationSettingsBase private SwitchBar mSwitchBar; private Switch mSwitch; - private boolean mValidListener; + private boolean mValidListener = false; private Preference mLocationMode; private PreferenceCategory mCategoryRecentLocationRequests; /** Receives UPDATE_INTENT */ private BroadcastReceiver mReceiver; private SettingsInjector injector; - public LocationSettings() { - mValidListener = false; - } - @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -79,21 +75,17 @@ public class LocationSettings extends LocationSettingsBase @Override public void onDestroyView() { super.onDestroyView(); - mSwitchBar.hide(); } @Override - public void onStop() { - super.onStop(); - } - - @Override public void onResume() { super.onResume(); createPreferenceHierarchy(); - mSwitchBar.addOnSwitchChangeListener(this); - mValidListener = true; + if (!mValidListener) { + mSwitchBar.addOnSwitchChangeListener(this); + mValidListener = true; + } } @Override @@ -102,10 +94,15 @@ public class LocationSettings extends LocationSettingsBase getActivity().unregisterReceiver(mReceiver); } catch (RuntimeException e) { // Ignore exceptions caused by race condition + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "Swallowing " + e); + } + } + if (mValidListener) { + mSwitchBar.removeOnSwitchChangeListener(this); + mValidListener = false; } super.onPause(); - mSwitchBar.removeOnSwitchChangeListener(this); - mValidListener = false; } private void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) { diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java index 1237715..0721248 100644 --- a/src/com/android/settings/wifi/WifiSettings.java +++ b/src/com/android/settings/wifi/WifiSettings.java @@ -25,7 +25,6 @@ import com.android.settings.SettingsActivity; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settings.search.SearchIndexableRaw; -import com.android.settings.wifi.p2p.WifiP2pSettings; import android.app.Activity; import android.app.Dialog; @@ -37,10 +36,12 @@ import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.res.Resources; import android.content.res.TypedArray; +import android.content.SharedPreferences; import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.NetworkInfo.DetailedState; +import android.net.NetworkScoreManager; import android.net.wifi.ScanResult; import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; @@ -59,7 +60,9 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.View.OnClickListener; import android.widget.AdapterView.AdapterContextMenuInfo; +import android.widget.Button; import android.widget.TextView; import android.widget.Toast; @@ -82,6 +85,7 @@ public class WifiSettings extends RestrictedSettingsFragment implements DialogInterface.OnClickListener, Indexable { private static final String TAG = "WifiSettings"; + /* package */ static final int MENU_ID_WPS_PBC = Menu.FIRST; private static final int MENU_ID_WPS_PIN = Menu.FIRST + 1; private static final int MENU_ID_SAVED_NETWORK = Menu.FIRST + 2; @@ -93,6 +97,13 @@ public class WifiSettings extends RestrictedSettingsFragment private static final int MENU_ID_MODIFY = Menu.FIRST + 8; private static final int MENU_ID_WRITE_NFC = Menu.FIRST + 9; + private static final String KEY_ASSISTANT_DISMISS_TIME = "wifi_assistant_dismiss_time"; + private static final String KEY_ASSISTANT_START_TIME = "wifi_assistant_start_time"; + + private static final long MILI_SECONDS_30_DAYS = 30L * 24L * 60L * 60L * 1000L; + private static final long MILI_SECONDS_90_DAYS = MILI_SECONDS_30_DAYS * 3L; + private static final long MILI_SECONDS_180_DAYS = MILI_SECONDS_90_DAYS * 2L; + public static final int WIFI_DIALOG_ID = 1; /* package */ static final int WPS_PBC_DIALOG_ID = 2; private static final int WPS_PIN_DIALOG_ID = 3; @@ -142,6 +153,7 @@ public class WifiSettings extends RestrictedSettingsFragment private boolean mDlgEdit; private AccessPoint mDlgAccessPoint; private Bundle mAccessPointSavedState; + private Preference mWifiAssistant; /** verbose logging flag. this flag is set thru developer debugging options * and used so as to assist with in-the-field WiFi connectivity debugging */ @@ -149,6 +161,105 @@ public class WifiSettings extends RestrictedSettingsFragment /* End of "used in Wifi Setup context" */ + /** Holds the Wifi Assistant Card. */ + private static class WifiAssistantPreference extends Preference { + final WifiSettings mWifiSettings; + + public WifiAssistantPreference(WifiSettings wifiSettings) { + super(wifiSettings.getActivity()); + mWifiSettings = wifiSettings; + setLayoutResource(R.layout.wifi_assistant_card); + } + + @Override + public void onBindView(View view) { + super.onBindView(view); + final Preference pref = this; + Button setup = (Button)view.findViewById(R.id.setup); + Button noThanks = (Button)view.findViewById(R.id.no_thanks_button); + + if (setup != null && noThanks != null) { + setup.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(NetworkScoreManager.ACTION_CHANGE_ACTIVE); + intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME, "wifi-assistant"); + mWifiSettings.startActivity(intent); + mWifiSettings.setWifiAssistantTimeout(); + mWifiSettings.getPreferenceScreen().removePreference(pref); + } + }); + + noThanks.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + mWifiSettings.setWifiAssistantTimeout(); + mWifiSettings.getPreferenceScreen().removePreference(pref); + } + }); + } + } + } + + /** A restricted multimap for use in constructAccessPoints */ + private static class Multimap<K,V> { + private final HashMap<K,List<V>> store = new HashMap<K,List<V>>(); + /** retrieve a non-null list of values with key K */ + List<V> getAll(K key) { + List<V> values = store.get(key); + return values != null ? values : Collections.<V>emptyList(); + } + + void put(K key, V val) { + List<V> curVals = store.get(key); + if (curVals == null) { + curVals = new ArrayList<V>(3); + store.put(key, curVals); + } + curVals.add(val); + } + } + + private static class Scanner extends Handler { + private int mRetry = 0; + private WifiSettings mWifiSettings = null; + + Scanner(WifiSettings wifiSettings) { + mWifiSettings = wifiSettings; + } + + void resume() { + if (!hasMessages(0)) { + sendEmptyMessage(0); + } + } + + void forceScan() { + removeMessages(0); + sendEmptyMessage(0); + } + + void pause() { + mRetry = 0; + removeMessages(0); + } + + @Override + public void handleMessage(Message message) { + if (mWifiSettings.mWifiManager.startScan()) { + mRetry = 0; + } else if (++mRetry >= 3) { + mRetry = 0; + Activity activity = mWifiSettings.getActivity(); + if (activity != null) { + Toast.makeText(activity, R.string.wifi_fail_to_scan, Toast.LENGTH_LONG).show(); + } + return; + } + sendEmptyMessageDelayed(0, WIFI_RESCAN_INTERVAL_MS); + } + } + public WifiSettings() { super(DISALLOW_CONFIG_WIFI); mFilter = new IntentFilter(); @@ -168,7 +279,7 @@ public class WifiSettings extends RestrictedSettingsFragment } }; - mScanner = new Scanner(); + mScanner = new Scanner(this); } @Override @@ -248,6 +359,8 @@ public class WifiSettings extends RestrictedSettingsFragment addPreferencesFromResource(R.xml.wifi_settings); + mWifiAssistant = new WifiAssistantPreference(this); + mEmptyView = (TextView) getView().findViewById(android.R.id.empty); getListView().setEmptyView(mEmptyView); registerForContextMenu(getListView()); @@ -322,7 +435,7 @@ public class WifiSettings extends RestrictedSettingsFragment .setIcon(ta.getDrawable(0)) .setEnabled(wifiIsEnabled) .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); - if (savedNetworksExist){ + if (savedNetworksExist) { menu.add(Menu.NONE, MENU_ID_SAVED_NETWORK, 0, R.string.wifi_saved_access_points_label) .setIcon(ta.getDrawable(0)) .setEnabled(wifiIsEnabled) @@ -483,7 +596,7 @@ public class WifiSettings extends RestrictedSettingsFragment if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE && mSelectedAccessPoint.networkId == INVALID_NETWORK_ID) { mSelectedAccessPoint.generateOpenNetworkConfig(); - if (!savedNetworksExist){ + if (!savedNetworksExist) { savedNetworksExist = true; getActivity().invalidateOptionsMenu(); } @@ -566,9 +679,14 @@ public class WifiSettings extends RestrictedSettingsFragment final Collection<AccessPoint> accessPoints = constructAccessPoints(getActivity(), mWifiManager, mLastInfo, mLastState); getPreferenceScreen().removeAll(); - if(accessPoints.size() == 0) { + if (accessPoints.size() == 0) { addMessagePreference(R.string.wifi_empty_list_wifi_on); } + + if (showWifiAssistantCard()) { + getPreferenceScreen().addPreference(mWifiAssistant); + } + for (AccessPoint accessPoint : accessPoints) { getPreferenceScreen().addPreference(accessPoint); } @@ -588,6 +706,34 @@ public class WifiSettings extends RestrictedSettingsFragment } } + private boolean showWifiAssistantCard() { + SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences(); + long lastTimeoutEndTime = sharedPreferences.getLong(KEY_ASSISTANT_START_TIME, 0); + long dismissTime = sharedPreferences.getLong(KEY_ASSISTANT_DISMISS_TIME, 0); + + return ((System.currentTimeMillis() - lastTimeoutEndTime) > dismissTime); + } + + private void setWifiAssistantTimeout() { + SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences(); + SharedPreferences.Editor editor = sharedPreferences.edit(); + long dismissTime = sharedPreferences.getLong(KEY_ASSISTANT_DISMISS_TIME, 0); + + if (dismissTime == 0) { + dismissTime = MILI_SECONDS_30_DAYS; + } else if (dismissTime == MILI_SECONDS_30_DAYS) { + dismissTime = MILI_SECONDS_90_DAYS; + } else if (dismissTime == MILI_SECONDS_90_DAYS) { + dismissTime = MILI_SECONDS_180_DAYS; + } else if (dismissTime == MILI_SECONDS_180_DAYS) { + dismissTime = java.lang.Long.MAX_VALUE; + } + + editor.putLong(KEY_ASSISTANT_DISMISS_TIME, dismissTime); + editor.putLong(KEY_ASSISTANT_START_TIME, System.currentTimeMillis()); + editor.apply(); + } + private void setOffMessage() { if (mEmptyView != null) { mEmptyView.setCompoundDrawablesWithIntrinsicBounds(0, @@ -663,25 +809,6 @@ public class WifiSettings extends RestrictedSettingsFragment return accessPoints; } - /** A restricted multimap for use in constructAccessPoints */ - private static class Multimap<K,V> { - private final HashMap<K,List<V>> store = new HashMap<K,List<V>>(); - /** retrieve a non-null list of values with key K */ - List<V> getAll(K key) { - List<V> values = store.get(key); - return values != null ? values : Collections.<V>emptyList(); - } - - void put(K key, V val) { - List<V> curVals = store.get(key); - if (curVals == null) { - curVals = new ArrayList<V>(3); - store.put(key, curVals); - } - curVals.add(val); - } - } - private void handleEvent(Context context, Intent intent) { String action = intent.getAction(); if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { @@ -773,41 +900,6 @@ public class WifiSettings extends RestrictedSettingsFragment mScanner.pause(); } - private class Scanner extends Handler { - private int mRetry = 0; - - void resume() { - if (!hasMessages(0)) { - sendEmptyMessage(0); - } - } - - void forceScan() { - removeMessages(0); - sendEmptyMessage(0); - } - - void pause() { - mRetry = 0; - removeMessages(0); - } - - @Override - public void handleMessage(Message message) { - if (mWifiManager.startScan()) { - mRetry = 0; - } else if (++mRetry >= 3) { - mRetry = 0; - Activity activity = getActivity(); - if (activity != null) { - Toast.makeText(activity, R.string.wifi_fail_to_scan, Toast.LENGTH_LONG).show(); - } - return; - } - sendEmptyMessageDelayed(0, WIFI_RESCAN_INTERVAL_MS); - } - } - /** * Renames/replaces "Next" button when appropriate. "Next" button usually exists in * Wifi setup screens, not in usual wifi settings screen. diff --git a/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java index 888396d..ea884e1 100644 --- a/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java +++ b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java @@ -95,7 +95,7 @@ public class WifiSettingsForSetupWizard extends WifiSettings { final View title = view.findViewById(R.id.title); if (title == null) { final View header = inflater.inflate(R.layout.setup_wizard_header, list, false); - list.addHeaderView(header); + list.addHeaderView(header, null, false); } final View other = inflater.inflate(R.layout.setup_wifi_add_network, list, false); |