diff options
Diffstat (limited to 'wifi/java/android')
8 files changed, 67 insertions, 56 deletions
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java index dfc1b18..0a846fd 100644 --- a/wifi/java/android/net/wifi/WifiConfiguration.java +++ b/wifi/java/android/net/wifi/WifiConfiguration.java @@ -56,6 +56,12 @@ public class WifiConfiguration implements Parcelable { */ public static final String ENGINE_ENABLE = "1"; + /** + * String to set the engine value to when it should be disabled. + * @hide + */ + public static final String ENGINE_DISABLE = "0"; + /** {@hide} */ public static final String ssidVarName = "ssid"; /** {@hide} */ diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index 73618f6..0a87a53 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -442,8 +442,8 @@ public class WifiNative { return doBooleanCommand("SET p2p_ssid_postfix " + postfix); } - public boolean setP2pGroupIdle(int time) { - return doBooleanCommand("SET p2p_group_idle " + time); + public boolean setP2pGroupIdle(String iface, int time) { + return doBooleanCommand("SET interface=" + iface + " p2p_group_idle " + time); } public void setPowerSave(boolean enabled) { @@ -624,13 +624,6 @@ public class WifiNative { return ""; } - public boolean isGroupOwner(String deviceAddress) { - /* BSS returns details only for a GO */ - String bssInfo = doStringCommand("BSS p2p_dev_addr=" + deviceAddress); - if (TextUtils.isEmpty(bssInfo)) return false; - return true; - } - public String p2pPeer(String deviceAddress) { return doStringCommand("P2P_PEER " + deviceAddress); } diff --git a/wifi/java/android/net/wifi/WifiWatchdogStateMachine.java b/wifi/java/android/net/wifi/WifiWatchdogStateMachine.java index f31ee68..5220d04 100644 --- a/wifi/java/android/net/wifi/WifiWatchdogStateMachine.java +++ b/wifi/java/android/net/wifi/WifiWatchdogStateMachine.java @@ -100,15 +100,11 @@ public class WifiWatchdogStateMachine extends StateMachine { Level 1 -88 <= RSSI < -78 Level 0 RSSI < -88 */ - /* Wi-fi connection is considered poor below this - RSSI level threshold and the watchdog report it - to the WifiStateMachine */ - private static final int RSSI_LEVEL_CUTOFF = 0; /* Wi-fi connection is monitored actively below this threshold */ - private static final int RSSI_LEVEL_MONITOR = 1; - /* RSSI threshold during monitoring below which network is avoided */ - private static final int RSSI_MONITOR_THRESHOLD = -84; + private static final int RSSI_LEVEL_MONITOR = 0; + /* Rssi threshold is at level 0 (-88dBm) */ + private static final int RSSI_MONITOR_THRESHOLD = -88; /* Number of times RSSI is measured to be low before being avoided */ private static final int RSSI_MONITOR_COUNT = 5; private int mRssiMonitorCount = 0; @@ -193,7 +189,7 @@ public class WifiWatchdogStateMachine extends StateMachine { private WalledGardenCheckState mWalledGardenCheckState = new WalledGardenCheckState(); /* Online and watching link connectivity */ private OnlineWatchState mOnlineWatchState = new OnlineWatchState(); - /* RSSI level is at RSSI_LEVEL_MONITOR and needs close monitoring */ + /* RSSI level is below RSSI_LEVEL_MONITOR and needs close monitoring */ private RssiMonitoringState mRssiMonitoringState = new RssiMonitoringState(); /* Online and doing nothing */ private OnlineState mOnlineState = new OnlineState(); @@ -731,9 +727,7 @@ public class WifiWatchdogStateMachine extends StateMachine { } private void handleRssiChange() { - if (mCurrentSignalLevel <= RSSI_LEVEL_CUTOFF) { - sendPoorLinkDetected(); - } else if (mCurrentSignalLevel <= RSSI_LEVEL_MONITOR) { + if (mCurrentSignalLevel <= RSSI_LEVEL_MONITOR) { transitionTo(mRssiMonitoringState); } else { //stay here @@ -773,9 +767,7 @@ public class WifiWatchdogStateMachine extends StateMachine { switch (msg.what) { case EVENT_RSSI_CHANGE: mCurrentSignalLevel = calculateSignalLevel(msg.arg1); - if (mCurrentSignalLevel <= RSSI_LEVEL_CUTOFF) { - sendPoorLinkDetected(); - } else if (mCurrentSignalLevel <= RSSI_LEVEL_MONITOR) { + if (mCurrentSignalLevel <= RSSI_LEVEL_MONITOR) { //stay here; } else { //We dont need frequent RSSI monitoring any more diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java index 8942ff1..b2347c8 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java @@ -108,6 +108,15 @@ public class WifiP2pDeviceList implements Parcelable { return Collections.unmodifiableCollection(mDevices.values()); } + /** @hide */ + public boolean isGroupOwner(String deviceAddress) { + if (deviceAddress != null) { + WifiP2pDevice device = mDevices.get(deviceAddress); + if (device != null) return device.isGroupOwner(); + } + return false; + } + public String toString() { StringBuffer sbuf = new StringBuffer(); for (WifiP2pDevice device : mDevices.values()) { diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java index ef77d45..2c25e9d 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java @@ -21,7 +21,6 @@ import android.annotation.SdkConstant.SdkConstantType; import android.content.Context; import android.net.ConnectivityManager; import android.net.IConnectivityManager; -import android.net.nsd.DnsSdTxtRecord; import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceInfo; import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceResponse; import android.net.wifi.p2p.nsd.WifiP2pServiceInfo; @@ -46,6 +45,7 @@ import com.android.internal.util.Protocol; import java.util.HashMap; import java.util.List; +import java.util.Map; /** * This class provides the API for managing Wi-Fi peer-to-peer connectivity. This lets an @@ -585,11 +585,11 @@ public class WifiP2pManager { * * @param fullDomainName full domain name. <br> * e.g) "MyPrinter._ipp._tcp.local.". - * @param record txt record. + * @param txtRecordMap TXT record data as a map of key/value pairs * @param srcDevice source device. */ public void onDnsSdTxtRecordAvailable(String fullDomainName, - DnsSdTxtRecord record, + Map<String, String> txtRecordMap, WifiP2pDevice srcDevice); } diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java index b4a879a..cc49cae 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java @@ -159,6 +159,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub { * is invoked */ private boolean mAutonomousGroup; + /* Invitation to join an existing p2p group */ + private boolean mJoinExistingGroup; + /* Track whether we are in p2p discovery. This is used to avoid sending duplicate * broadcasts */ @@ -761,7 +764,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { //Stop discovery before issuing connect mWifiNative.p2pStopFind(); - if (mWifiNative.isGroupOwner(mSavedPeerConfig.deviceAddress)) { + if (mPeers.isGroupOwner(mSavedPeerConfig.deviceAddress)) { p2pConnectWithPinDisplay(mSavedPeerConfig, JOIN_GROUP); } else { p2pConnectWithPinDisplay(mSavedPeerConfig, FORM_GROUP); @@ -778,7 +781,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { mWifiNative.p2pStopFind(); //If peer is a GO, we do not need to send provisional discovery, //the supplicant takes care of it. - if (mWifiNative.isGroupOwner(mSavedPeerConfig.deviceAddress)) { + if (mPeers.isGroupOwner(mSavedPeerConfig.deviceAddress)) { if (DBG) logd("Sending join to GO"); p2pConnectWithPinDisplay(mSavedPeerConfig, JOIN_GROUP); transitionTo(mGroupNegotiationState); @@ -795,6 +798,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub { case WifiMonitor.P2P_GO_NEGOTIATION_REQUEST_EVENT: mSavedPeerConfig = (WifiP2pConfig) message.obj; + mAutonomousGroup = false; + mJoinExistingGroup = false; if (!sendConnectNoticeToApp(mPeers.get(mSavedPeerConfig.deviceAddress), mSavedPeerConfig)) { transitionTo(mUserAuthorizingInvitationState); @@ -824,6 +829,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub { } } + mAutonomousGroup = false; + mJoinExistingGroup = true; //TODO In the p2p client case, we should set source address correctly. if (!sendConnectNoticeToApp(mPeers.get(mSavedPeerConfig.deviceAddress), mSavedPeerConfig)) { @@ -840,8 +847,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub { break; case WifiP2pManager.CREATE_GROUP: mAutonomousGroup = true; - // An autonomous GO requires group idle settings to be reset - mWifiNative.setP2pGroupIdle(0); if (mWifiNative.p2pGroupAdd()) { replyToMessage(message, WifiP2pManager.CREATE_GROUP_SUCCEEDED); } else { @@ -863,11 +868,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub { if (DBG) logd(getName()); sendMessageDelayed(obtainMessage(GROUP_CREATING_TIMED_OUT, ++mGroupCreatingTimeoutIndex, 0), GROUP_CREATING_WAIT_TIME_MS); - - // Set default group idle settings - if (!mAutonomousGroup) { - mWifiNative.setP2pGroupIdle(GROUP_IDLE_TIME_S); - } } @Override @@ -921,7 +921,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { switch (message.what) { case PEER_CONNECTION_USER_ACCEPT: //TODO: handle persistence - if (mWifiNative.isGroupOwner(mSavedPeerConfig.deviceAddress)) { + if (mJoinExistingGroup) { p2pConnectWithPinDisplay(mSavedPeerConfig, JOIN_GROUP); } else { p2pConnectWithPinDisplay(mSavedPeerConfig, FORM_GROUP); @@ -983,6 +983,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { mWifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP); transitionTo(mGroupNegotiationState); } else { + mJoinExistingGroup = false; transitionTo(mUserAuthorizingInvitationState); } } @@ -1031,6 +1032,10 @@ public class WifiP2pService extends IWifiP2pManager.Stub { if (mGroup.isGroupOwner()) { startDhcpServer(mGroup.getInterface()); } else { + // Set group idle only for a client on the group interface to speed up + // disconnect when GO is gone. Setting group idle time for a group owner + // causes connectivity issues for new clients + mWifiNative.setP2pGroupIdle(mGroup.getInterface(), GROUP_IDLE_TIME_S); mDhcpStateMachine = DhcpStateMachine.makeDhcpStateMachine(mContext, P2pStateMachine.this, mGroup.getInterface()); mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP); @@ -1455,6 +1460,13 @@ public class WifiP2pService extends IWifiP2pManager.Stub { sendMessage(PEER_CONNECTION_USER_REJECT); } }) + .setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface arg0) { + if (DBG) logd(getName() + " ignore connect"); + sendMessage(PEER_CONNECTION_USER_REJECT); + } + }) .create(); //make the enter pin area or the display pin area visible diff --git a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceInfo.java b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceInfo.java index 54b7ac4..bc1d3c6 100644 --- a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceInfo.java +++ b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceInfo.java @@ -83,19 +83,22 @@ public class WifiP2pDnsSdServiceInfo extends WifiP2pServiceInfo { * e.g) "MyPrinter" * @param serviceType service type.<br> * e.g) "_ipp._tcp" - * @param txtRecord TXT record as defined at + * @param txtMap TXT record with key/value pair in a map confirming to format defined at * http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt * @return Bonjour service information object */ public static WifiP2pDnsSdServiceInfo newInstance(String instanceName, - String serviceType, DnsSdTxtRecord txtRecord) { + String serviceType, Map<String, String> txtMap) { if (TextUtils.isEmpty(instanceName) || TextUtils.isEmpty(serviceType)) { throw new IllegalArgumentException( "instance name or service type cannot be empty"); } - if (txtRecord == null) { - txtRecord = new DnsSdTxtRecord(); + DnsSdTxtRecord txtRecord = new DnsSdTxtRecord(); + if (txtMap != null) { + for (String key : txtMap.keySet()) { + txtRecord.set(key, txtMap.get(key)); + } } ArrayList<String> queries = new ArrayList<String>(); diff --git a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceResponse.java b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceResponse.java index c053c8a..ed84a1a 100644 --- a/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceResponse.java +++ b/wifi/java/android/net/wifi/p2p/nsd/WifiP2pDnsSdServiceResponse.java @@ -16,7 +16,6 @@ package android.net.wifi.p2p.nsd; -import android.net.nsd.DnsSdTxtRecord; import android.net.wifi.p2p.WifiP2pDevice; import java.io.ByteArrayInputStream; @@ -68,7 +67,7 @@ public class WifiP2pDnsSdServiceResponse extends WifiP2pServiceResponse { * This field is only used when the dns type equals to * {@link WifiP2pDnsSdServiceInfo#DNS_TYPE_TXT}. */ - private DnsSdTxtRecord mTxtRecord; + private final HashMap<String, String> mTxtRecord = new HashMap<String, String>(); /** * Virtual memory packet. @@ -121,7 +120,7 @@ public class WifiP2pDnsSdServiceResponse extends WifiP2pServiceResponse { * Return TXT record data. * @return TXT record data. */ - public DnsSdTxtRecord getTxtRecord() { + public Map<String, String> getTxtRecord() { return mTxtRecord; } @@ -133,8 +132,9 @@ public class WifiP2pDnsSdServiceResponse extends WifiP2pServiceResponse { sbuf.append(" srcAddr:").append(mDevice.deviceAddress); sbuf.append(" version:").append(String.format("%02x", mVersion)); sbuf.append(" dnsName:").append(mDnsQueryName); - if (mTxtRecord != null) { - sbuf.append(" TxtRecord:").append(mTxtRecord); + sbuf.append(" TxtRecord:"); + for (String key : mTxtRecord.keySet()) { + sbuf.append(" key:").append(key).append(" value:").append(mTxtRecord.get(key)); } if (mInstanceName != null) { sbuf.append(" InsName:").append(mInstanceName); @@ -205,10 +205,7 @@ public class WifiP2pDnsSdServiceResponse extends WifiP2pServiceResponse { mInstanceName = rData.substring(0, rData.length() - mDnsQueryName.length() -1); } else if (mDnsType == WifiP2pDnsSdServiceInfo.DNS_TYPE_TXT) { - mTxtRecord = readTxtData(dis); - if (mTxtRecord == null) { - return false; - } + return readTxtData(dis); } else { return false; } @@ -261,10 +258,9 @@ public class WifiP2pDnsSdServiceResponse extends WifiP2pServiceResponse { * Read TXT record data. * * @param dis - * @return TXT record data + * @return true if TXT data is valid */ - private DnsSdTxtRecord readTxtData(DataInputStream dis) { - DnsSdTxtRecord txtRecord = new DnsSdTxtRecord(); + private boolean readTxtData(DataInputStream dis) { try { while (dis.available() > 0) { int len = dis.readUnsignedByte(); @@ -275,15 +271,15 @@ public class WifiP2pDnsSdServiceResponse extends WifiP2pServiceResponse { dis.readFully(data); String[] keyVal = new String(data).split("="); if (keyVal.length != 2) { - return null; + return false; } - txtRecord.set(keyVal[0], keyVal[1]); + mTxtRecord.put(keyVal[0], keyVal[1]); } - return txtRecord; + return true; } catch (IOException e) { e.printStackTrace(); } - return null; + return false; } /** |
