From 267419ff8b6a0458c098a1787e11df2bc9ddb38a Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Thu, 9 Dec 2010 19:39:58 -0800 Subject: [PATCH 1/4] Update Settings for new NfcAdapter.getDefaultAdapter(Context) Change-Id: I3321d9ebd90313f98664d66b53bb36690808911a --- src/com/android/settings/WirelessSettings.java | 2 +- src/com/android/settings/nfc/NfcEnabler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java index 85cd54669ec..04faa0f7d68 100644 --- a/src/com/android/settings/WirelessSettings.java +++ b/src/com/android/settings/WirelessSettings.java @@ -123,7 +123,7 @@ public class WirelessSettings extends PreferenceActivity { } // Remove NFC if its not available - if (NfcAdapter.getDefaultAdapter() == null) { + if (NfcAdapter.getDefaultAdapter(this) == null) { getPreferenceScreen().removePreference(nfc); } diff --git a/src/com/android/settings/nfc/NfcEnabler.java b/src/com/android/settings/nfc/NfcEnabler.java index e3a44b71fdd..d1cec134880 100644 --- a/src/com/android/settings/nfc/NfcEnabler.java +++ b/src/com/android/settings/nfc/NfcEnabler.java @@ -60,7 +60,7 @@ public class NfcEnabler implements Preference.OnPreferenceChangeListener { public NfcEnabler(Context context, CheckBoxPreference checkBoxPreference) { mContext = context; mCheckbox = checkBoxPreference; - mNfcAdapter = NfcAdapter.getDefaultAdapter(); + mNfcAdapter = NfcAdapter.getDefaultAdapter(context); if (mNfcAdapter == null) { // NFC is not supported From 498d12bac0df509a4f74a4df8a8c69ec22583a1a Mon Sep 17 00:00:00 2001 From: Jaikumar Ganesh Date: Fri, 10 Dec 2010 17:51:52 -0800 Subject: [PATCH 2/4] Add ability to connect to only headset profile. Fix some SDP records issues. Change-Id: I42816527b1ae0749b4b59b7947f1acb9d2e6f001 --- .../settings/bluetooth/BluetoothSettings.java | 2 +- .../bluetooth/CachedBluetoothDevice.java | 6 ++- .../LocalBluetoothProfileManager.java | 38 ++++++++++++------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java index f89cc89c6aa..aae13115a4a 100644 --- a/src/com/android/settings/bluetooth/BluetoothSettings.java +++ b/src/com/android/settings/bluetooth/BluetoothSettings.java @@ -353,7 +353,7 @@ public class BluetoothSettings extends SettingsPreferenceFragment case BluetoothDevicePicker.FILTER_TYPE_AUDIO: if (uuids != null) { if (BluetoothUuid.containsAnyUuid(uuids, - LocalBluetoothProfileManager.A2DP_PROFILE_UUIDS)) return true; + LocalBluetoothProfileManager.A2DP_SINK_PROFILE_UUIDS)) return true; if (BluetoothUuid.containsAnyUuid(uuids, LocalBluetoothProfileManager.HEADSET_PROFILE_UUIDS)) return true; diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java index 76a5b992883..df455b3769c 100644 --- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java +++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java @@ -589,7 +589,11 @@ public class CachedBluetoothDevice implements Comparable ParcelUuid[] uuids = mDevice.getUuids(); if (uuids == null) return false; - LocalBluetoothProfileManager.updateProfiles(uuids, mProfiles); + BluetoothAdapter adapter = mLocalManager.getBluetoothAdapter(); + ParcelUuid[] localUuids = adapter.getUuids(); + if (localUuids == null) return false; + + LocalBluetoothProfileManager.updateProfiles(uuids, localUuids, mProfiles); if (DEBUG) { Log.e(TAG, "updating profiles for " + mDevice.getName()); diff --git a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java index 885706f39bf..f177ed073e5 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java @@ -48,11 +48,15 @@ public abstract class LocalBluetoothProfileManager { BluetoothUuid.Handsfree, }; - /* package */ static final ParcelUuid[] A2DP_PROFILE_UUIDS = new ParcelUuid[] { + /* package */ static final ParcelUuid[] A2DP_SINK_PROFILE_UUIDS = new ParcelUuid[] { BluetoothUuid.AudioSink, BluetoothUuid.AdvAudioDist, }; + /* package */ static final ParcelUuid[] A2DP_SRC_PROFILE_UUIDS = new ParcelUuid[] { + BluetoothUuid.AudioSource + }; + /* package */ static final ParcelUuid[] OPP_PROFILE_UUIDS = new ParcelUuid[] { BluetoothUuid.ObexObjectPush }; @@ -124,25 +128,24 @@ public abstract class LocalBluetoothProfileManager { // TODO(): Combine the init and updateLocalProfiles codes. // init can get called from various paths, it makes no sense to add and then delete. public static void updateLocalProfiles(LocalBluetoothManager localManager, ParcelUuid[] uuids) { - if (!BluetoothUuid.containsAnyUuid(uuids, HEADSET_PROFILE_UUIDS)) { + if (!BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Handsfree_AG) && + !BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.HSP_AG)) { sProfileMap.remove(Profile.HEADSET); } - if (BluetoothUuid.containsAnyUuid(uuids, A2DP_PROFILE_UUIDS)) { + if (!BluetoothUuid.containsAnyUuid(uuids, A2DP_SRC_PROFILE_UUIDS)) { sProfileMap.remove(Profile.A2DP); } - if (BluetoothUuid.containsAnyUuid(uuids, OPP_PROFILE_UUIDS)) { + if (!BluetoothUuid.containsAnyUuid(uuids, OPP_PROFILE_UUIDS)) { sProfileMap.remove(Profile.OPP); } - if (BluetoothUuid.containsAnyUuid(uuids, HID_PROFILE_UUIDS)) { - sProfileMap.remove(Profile.HID); - } - - if (BluetoothUuid.containsAnyUuid(uuids, PANU_PROFILE_UUIDS)) { + if (!BluetoothUuid.containsAnyUuid(uuids, PANU_PROFILE_UUIDS)) { sProfileMap.remove(Profile.PAN); } + + // There is no local SDP record for HID and Settings app doesn't control PBAP } private static LinkedList mServiceListeners = @@ -186,21 +189,28 @@ public abstract class LocalBluetoothProfileManager { * NOTE: This list happens to define the connection order. We should put this logic in a more * well known place when this method is no longer temporary. * @param uuids of the remote device + * @param localUuids UUIDs of the local device * @param profiles The list of profiles to fill */ - public static void updateProfiles(ParcelUuid[] uuids, List profiles) { + public static void updateProfiles(ParcelUuid[] uuids, ParcelUuid[] localUuids, + List profiles) { profiles.clear(); if (uuids == null) { return; } - if (BluetoothUuid.containsAnyUuid(uuids, HEADSET_PROFILE_UUIDS) && - sProfileMap.containsKey(Profile.HEADSET)) { - profiles.add(Profile.HEADSET); + if (sProfileMap.containsKey(Profile.HEADSET)) { + if ((BluetoothUuid.isUuidPresent(localUuids, BluetoothUuid.HSP_AG) && + BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.HSP)) || + (BluetoothUuid.isUuidPresent(localUuids, BluetoothUuid.Handsfree_AG) && + BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Handsfree))) { + profiles.add(Profile.HEADSET); + } } - if (BluetoothUuid.containsAnyUuid(uuids, A2DP_PROFILE_UUIDS) && + + if (BluetoothUuid.containsAnyUuid(uuids, A2DP_SINK_PROFILE_UUIDS) && sProfileMap.containsKey(Profile.A2DP)) { profiles.add(Profile.A2DP); } From b8be6da8874da8e5bb58eba13217a2e9f33c710a Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Mon, 13 Dec 2010 13:44:10 -0800 Subject: [PATCH 3/4] Fix master build. WirelessSettings is a fragment in master. Change-Id: I9ad1104605558859d90dd1ecc083e9ef35bf3fa0 --- src/com/android/settings/WirelessSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java index 5322555d62a..e46707d4ba1 100644 --- a/src/com/android/settings/WirelessSettings.java +++ b/src/com/android/settings/WirelessSettings.java @@ -127,7 +127,7 @@ public class WirelessSettings extends SettingsPreferenceFragment { } // Remove NFC if its not available - if (NfcAdapter.getDefaultAdapter(this) == null) { + if (NfcAdapter.getDefaultAdapter(activity) == null) { getPreferenceScreen().removePreference(nfc); } From cdbc80afb2dd191e1e2938a9939a1e11b5fd17ff Mon Sep 17 00:00:00 2001 From: Irfan Sheriff Date: Wed, 8 Dec 2010 11:28:25 -0800 Subject: [PATCH 4/4] Use WpsConfiguration for new API Change-Id: I4c1544178bcb29e751db56edb781faf9145cdf86 --- .../settings/wifi/WifiConfigController.java | 73 ++++++++++++++----- .../android/settings/wifi/WifiSettings.java | 7 +- 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java index d1c89dd4da2..1a882d40c29 100644 --- a/src/com/android/settings/wifi/WifiConfigController.java +++ b/src/com/android/settings/wifi/WifiConfigController.java @@ -30,6 +30,9 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.IpAssignment; import android.net.wifi.WifiConfiguration.AuthAlgorithm; import android.net.wifi.WifiConfiguration.KeyMgmt; +import android.net.wifi.WpsConfiguration; +import android.net.wifi.WpsConfiguration.Setup; + import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID; import android.net.wifi.WifiConfiguration.ProxySettings; import android.net.wifi.WifiInfo; @@ -114,6 +117,10 @@ public class WifiConfigController implements TextWatcher, private TextView mProxyPortView; private TextView mProxyExclusionListView; + private IpAssignment mIpAssignment; + private ProxySettings mProxySettings; + private LinkProperties mLinkProperties = new LinkProperties(); + static boolean requireKeyStore(WifiConfiguration config) { if (config == null) { return false; @@ -331,28 +338,37 @@ public class WifiConfigController implements TextWatcher, return null; } - config.ipAssignment = (mIpSettingsSpinner != null && + validateAndFetchIpAndProxyFields(); + + config.proxySettings = mProxySettings; + config.ipAssignment = mIpAssignment; + config.linkProperties = new LinkProperties(mLinkProperties); + + return config; + } + + private void validateAndFetchIpAndProxyFields() { + mLinkProperties.clear(); + mIpAssignment = (mIpSettingsSpinner != null && mIpSettingsSpinner.getSelectedItemPosition() == STATIC_IP) ? IpAssignment.STATIC : IpAssignment.DHCP; - if (config.ipAssignment == IpAssignment.STATIC) { + if (mIpAssignment == IpAssignment.STATIC) { //TODO: A better way to do this is to not dismiss the //dialog as long as one of the fields is invalid - LinkProperties linkProperties = new LinkProperties(); - int result = validateIpConfigFields(linkProperties); - if (result == 0) { - config.linkProperties = linkProperties; - } else { + int result = validateIpConfigFields(mLinkProperties); + if (result != 0) { + mLinkProperties.clear(); Toast.makeText(mConfigUi.getContext(), result, Toast.LENGTH_LONG).show(); - config.ipAssignment = IpAssignment.UNASSIGNED; + mIpAssignment = IpAssignment.UNASSIGNED; } } - config.proxySettings = (mProxySettingsSpinner != null && + mProxySettings = (mProxySettingsSpinner != null && mProxySettingsSpinner.getSelectedItemPosition() == PROXY_STATIC) ? ProxySettings.STATIC : ProxySettings.NONE; - if (config.proxySettings == ProxySettings.STATIC) { + if (mProxySettings == ProxySettings.STATIC) { String host = mProxyHostView.getText().toString(); String portStr = mProxyPortView.getText().toString(); String exclusionList = mProxyExclusionListView.getText().toString(); @@ -366,14 +382,12 @@ public class WifiConfigController implements TextWatcher, } if (result == 0) { ProxyProperties proxyProperties= new ProxyProperties(host, port, exclusionList); - config.linkProperties.setHttpProxy(proxyProperties); + mLinkProperties.setHttpProxy(proxyProperties); } else { Toast.makeText(mConfigUi.getContext(), result, Toast.LENGTH_LONG).show(); - config.proxySettings = ProxySettings.UNASSIGNED; + mProxySettings = ProxySettings.UNASSIGNED; } } - - return config; } private int validateIpConfigFields(LinkProperties linkProperties) { @@ -428,13 +442,32 @@ public class WifiConfigController implements TextWatcher, return MANUAL; } - int getWpsPin() { - try { - String wpsPin = ((TextView) mView.findViewById(R.id.wps_pin)).getText().toString(); - return Integer.parseInt(wpsPin); - } catch (NumberFormatException e) { - return -1; + WpsConfiguration getWpsConfig() { + WpsConfiguration config = new WpsConfiguration(); + switch (mNetworkSetupSpinner.getSelectedItemPosition()) { + case WPS_PBC: + config.setup = Setup.PBC; + break; + case WPS_PIN_FROM_ACCESS_POINT: + config.setup = Setup.PIN_FROM_ACCESS_POINT; + break; + case WPS_PIN_FROM_DEVICE: + config.setup = Setup.PIN_FROM_DEVICE; + break; + default: + config.setup = Setup.INVALID; + Log.e(TAG, "WPS not selected type"); + return config; } + config.pin = ((TextView) mView.findViewById(R.id.wps_pin)).getText().toString(); + config.BSSID = (mAccessPoint != null) ? mAccessPoint.bssid : null; + + validateAndFetchIpAndProxyFields(); + + config.proxySettings = mProxySettings; + config.ipAssignment = mIpAssignment; + config.linkProperties = new LinkProperties(mLinkProperties); + return config; } private void showSecurityFields() { diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java index 52d053f7513..3a1f7673c19 100644 --- a/src/com/android/settings/wifi/WifiSettings.java +++ b/src/com/android/settings/wifi/WifiSettings.java @@ -559,14 +559,11 @@ public class WifiSettings extends SettingsPreferenceFragment /* package */ void submit(WifiConfigController configController) { switch(configController.chosenNetworkSetupMethod()) { case WifiConfigController.WPS_PBC: - mWifiManager.startWpsPbc(mSelectedAccessPoint.bssid); - break; case WifiConfigController.WPS_PIN_FROM_ACCESS_POINT: - int apPin = configController.getWpsPin(); - mWifiManager.startWpsWithPinFromAccessPoint(mSelectedAccessPoint.bssid, apPin); + mWifiManager.startWps(configController.getWpsConfig()); break; case WifiConfigController.WPS_PIN_FROM_DEVICE: - int pin = mWifiManager.startWpsWithPinFromDevice(mSelectedAccessPoint.bssid); + String pin = mWifiManager.startWps(configController.getWpsConfig()); new AlertDialog.Builder(getActivity()) .setTitle(R.string.wifi_wps_pin_method_configuration) .setMessage(getResources().getString(R.string.wifi_wps_pin_output, pin))