diff options
Diffstat (limited to 'wifi')
| -rw-r--r-- | wifi/java/android/net/wifi/IWifiManager.aidl | 6 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 61 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiStateTracker.java | 64 |
3 files changed, 105 insertions, 26 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index f9a0845..7c3af69 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -69,5 +69,11 @@ interface IWifiManager boolean acquireWifiLock(IBinder lock, int lockType, String tag); boolean releaseWifiLock(IBinder lock); + + boolean isMulticastEnabled(); + + void enableMulticast(IBinder binder, String tag); + + void disableMulticast(); } diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index a51e88f..1a7caef 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -823,4 +823,65 @@ public class WifiManager { public WifiLock createWifiLock(String tag) { return new WifiLock(WIFI_MODE_FULL, tag); } + + /** + * Check multicast filter status. + * + * @return true if multicast packets are allowed. + * + * @hide pending API council approval + */ + public boolean isMulticastEnabled() { + try { + return mService.isMulticastEnabled(); + } catch (RemoteException e) { + return false; + } + } + + /** + * Turn on the reception of multicast packets. + * The default behavior is to disable multicast packets as they + * have a noticable negative effect on battery life. An + * application can turn them on, but should not leave it on for longer + * than needed. When the app quits (or crashes) its request will + * be reverted. + * + * @param tag a string associated with this request for debugging. + * + * @return true on success + * + * @see #disableMulticast + * + * @hide pending API council approval + */ + public boolean enableMulticast(String tag) { + try { + mService.enableMulticast(new Binder(), tag); + return true; + } catch (RemoteException e) { + return false; + } + } + + /** + * Return to the default multicast-off setting. + * Note that if others had turned on Multicast reception, your + * call will not turn it back off - they must also turn off their + * request for multicast reception. + * + * @return true on success + * + * @see #enableMulticast + * + * @hide pending API council approval + */ + public boolean disableMulticast() { + try { + mService.disableMulticast(); + return true; + } catch (RemoteException e) { + return false; + } + } } diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java index 6ea35f5..6771136 100644 --- a/wifi/java/android/net/wifi/WifiStateTracker.java +++ b/wifi/java/android/net/wifi/WifiStateTracker.java @@ -161,8 +161,8 @@ public class WifiStateTracker extends NetworkStateTracker { private WifiInfo mWifiInfo; private List<ScanResult> mScanResults; private WifiManager mWM; - private boolean mHaveIPAddress; - private boolean mObtainingIPAddress; + private boolean mHaveIpAddress; + private boolean mObtainingIpAddress; private boolean mTornDownByConnMgr; /** * A DISCONNECT event has been received, but processing it @@ -303,8 +303,8 @@ public class WifiStateTracker extends NetworkStateTracker { mWifiInfo = new WifiInfo(); mWifiMonitor = new WifiMonitor(this); - mHaveIPAddress = false; - mObtainingIPAddress = false; + mHaveIpAddress = false; + mObtainingIpAddress = false; setTornDownByConnMgr(false); mDisconnectPending = false; mScanResults = new ArrayList<ScanResult>(); @@ -444,6 +444,14 @@ public class WifiStateTracker extends NetworkStateTracker { } /** + * Report whether the Wi-Fi connection has successfully acquired an IP address. + * @return {@code true} if the Wi-Fi connection has been assigned an IP address. + */ + public boolean hasIpAddress() { + return mHaveIpAddress; + } + + /** * Send the tracker a notification that a user-entered password key * may be incorrect (i.e., caused authentication to fail). */ @@ -724,7 +732,7 @@ public class WifiStateTracker extends NetworkStateTracker { intent.putExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, true); mContext.sendBroadcast(intent); } - if (supplState == SupplicantState.COMPLETED && mHaveIPAddress) { + if (supplState == SupplicantState.COMPLETED && mHaveIpAddress) { setDetailedState(DetailedState.CONNECTED); } else { setDetailedState(WifiInfo.getDetailedStateOf(supplState)); @@ -732,15 +740,19 @@ public class WifiStateTracker extends NetworkStateTracker { /* * Filter out multicast packets. This saves battery power, since * the CPU doesn't have to spend time processing packets that - * are going to end up being thrown away. Obviously, if we - * ever want to support multicast, this will have to change. + * are going to end up being thrown away. + * + * Note that rather than turn this off directly, we use the + * public api - this keeps us all in sync - turn multicast on + * first and then off.. if nobody else wants it on it'll be + * off then and it's all synchronized within the API. */ + mWM.enableMulticast("WifiStateTracker"); + mWM.disableMulticast(); + if (mBluetoothA2dp == null) { mBluetoothA2dp = new BluetoothA2dp(mContext); } - synchronized (this) { - WifiNative.startPacketFiltering(); - } checkIsBluetoothPlaying(); break; @@ -779,8 +791,8 @@ public class WifiStateTracker extends NetworkStateTracker { } setDetailedState(DetailedState.DISCONNECTED); setSupplicantState(SupplicantState.UNINITIALIZED); - mHaveIPAddress = false; - mObtainingIPAddress = false; + mHaveIpAddress = false; + mObtainingIpAddress = false; if (died) { mWM.setWifiEnabled(false); } @@ -950,7 +962,7 @@ public class WifiStateTracker extends NetworkStateTracker { } requestConnectionStatus(mWifiInfo); if (!(result.state == DetailedState.CONNECTED && - (!mHaveIPAddress || mDisconnectPending))) { + (!mHaveIpAddress || mDisconnectPending))) { setDetailedState(result.state); } @@ -979,7 +991,7 @@ public class WifiStateTracker extends NetworkStateTracker { mLastBssid = result.BSSID; mLastSsid = mWifiInfo.getSSID(); mLastNetworkId = result.networkId; - if (mHaveIPAddress) { + if (mHaveIpAddress) { setDetailedState(DetailedState.CONNECTED); } else { setDetailedState(DetailedState.OBTAINING_IPADDR); @@ -1047,8 +1059,8 @@ public class WifiStateTracker extends NetworkStateTracker { break; } mReconnectCount = 0; - mHaveIPAddress = true; - mObtainingIPAddress = false; + mHaveIpAddress = true; + mObtainingIpAddress = false; mWifiInfo.setIpAddress(mDhcpInfo.ipAddress); mLastSignalLevel = -1; // force update of signal strength if (mNetworkInfo.getDetailedState() != DetailedState.CONNECTED) { @@ -1074,9 +1086,9 @@ public class WifiStateTracker extends NetworkStateTracker { // [ 0- 0] Interface configuration succeeded (1) or failed (0) EventLog.writeEvent(EVENTLOG_INTERFACE_CONFIGURATION_STATE_CHANGED, 0); - mHaveIPAddress = false; + mHaveIpAddress = false; mWifiInfo.setIpAddress(0); - mObtainingIPAddress = false; + mObtainingIpAddress = false; synchronized(this) { WifiNative.disconnectCommand(); } @@ -1152,18 +1164,18 @@ public class WifiStateTracker extends NetworkStateTracker { setPollTimer(); mLastSignalLevel = -1; if (!mUseStaticIp) { - if (!mHaveIPAddress && !mObtainingIPAddress) { - mObtainingIPAddress = true; + if (!mHaveIpAddress && !mObtainingIpAddress) { + mObtainingIpAddress = true; mDhcpTarget.sendEmptyMessage(EVENT_DHCP_START); } } else { int event; if (NetworkUtils.configureInterface(mInterfaceName, mDhcpInfo)) { - mHaveIPAddress = true; + mHaveIpAddress = true; event = EVENT_INTERFACE_CONFIGURATION_SUCCEEDED; if (LOCAL_LOGD) Log.v(TAG, "Static IP configuration succeeded"); } else { - mHaveIPAddress = false; + mHaveIpAddress = false; event = EVENT_INTERFACE_CONFIGURATION_FAILED; if (LOCAL_LOGD) Log.v(TAG, "Static IP configuration failed"); } @@ -1196,8 +1208,8 @@ public class WifiStateTracker extends NetworkStateTracker { * using the interface, stopping DHCP, and disabling the interface. */ public void resetInterface() { - mHaveIPAddress = false; - mObtainingIPAddress = false; + mHaveIpAddress = false; + mObtainingIpAddress = false; mWifiInfo.setIpAddress(0); /* @@ -1608,8 +1620,8 @@ public class WifiStateTracker extends NetworkStateTracker { } sb.append(LS).append(mWifiInfo).append(LS); sb.append(mDhcpInfo).append(LS); - sb.append("haveIpAddress=").append(mHaveIPAddress). - append(", obtainingIpAddress=").append(mObtainingIPAddress). + sb.append("haveIpAddress=").append(mHaveIpAddress). + append(", obtainingIpAddress=").append(mObtainingIpAddress). append(", scanModeActive=").append(mIsScanModeActive).append(LS). append("lastSignalLevel=").append(mLastSignalLevel). append(", explicitlyDisabled=").append(mTornDownByConnMgr); |
