diff options
Diffstat (limited to 'wifi/java')
| -rw-r--r-- | wifi/java/android/net/wifi/IWifiManager.aidl | 6 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiConfiguration.java | 119 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 177 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiStateTracker.java | 56 |
4 files changed, 287 insertions, 71 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index 00829d6..3d65d3c 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -70,10 +70,10 @@ interface IWifiManager boolean releaseWifiLock(IBinder lock); - boolean isWifiMulticastEnabled(); + boolean isMulticastEnabled(); - void enableWifiMulticast(IBinder binder, String tag); + void acquireMulticastLock(IBinder binder, String tag); - void disableWifiMulticast(); + void releaseMulticastLock(); } diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java index 3bee3b6..eda2f2d 100644 --- a/wifi/java/android/net/wifi/WifiConfiguration.java +++ b/wifi/java/android/net/wifi/WifiConfiguration.java @@ -42,13 +42,29 @@ public class WifiConfiguration implements Parcelable { public static final String priorityVarName = "priority"; /** {@hide} */ public static final String hiddenSSIDVarName = "scan_ssid"; + /** {@hide} */ + public static final String eapVarName = "eap"; + /** {@hide} */ + public static final String identityVarName = "identity"; + /** {@hide} */ + public static final String anonymousIdentityVarName = "anonymous_identity"; + /** {@hide} */ + public static final String passwordVarName = "password"; + /** {@hide} */ + public static final String clientCertVarName = "client_cert"; + /** {@hide} */ + public static final String caCertVarName = "ca_cert"; + /** {@hide} */ + public static final String privateKeyVarName = "private_key"; + /** {@hide} */ + public static final String privateKeyPasswdVarName = "private_key_passwd"; /** * Recognized key management schemes. */ public static class KeyMgmt { private KeyMgmt() { } - + /** WPA is not used; plaintext or static WEP could be used. */ public static final int NONE = 0; /** WPA pre-shared key (requires {@code preSharedKey} to be specified). */ @@ -63,7 +79,7 @@ public class WifiConfiguration implements Parcelable { public static final String[] strings = { "NONE", "WPA_PSK", "WPA_EAP", "IEEE8021X" }; } - + /** * Recognized security protocols. */ @@ -112,7 +128,7 @@ public class WifiConfiguration implements Parcelable { public static final int CCMP = 2; public static final String varName = "pairwise"; - + public static final String[] strings = { "NONE", "TKIP", "CCMP" }; } @@ -202,7 +218,7 @@ public class WifiConfiguration implements Parcelable { * string otherwise. */ public String[] wepKeys; - + /** Default WEP key index, ranging from 0 to 3. */ public int wepTxKeyIndex; @@ -249,6 +265,40 @@ public class WifiConfiguration implements Parcelable { */ public BitSet allowedGroupCiphers; + /* The following fields are used for EAP/IEEE8021X authentication */ + + /** + * The eap mode should be PEAP, TLS or TTLS. + * {@hide} + */ + public String eap; + /** + * The identity of the user in string, + * which is used for the authentication. + * {@hide} + */ + public String identity; + /** {@hide} */ + public String anonymousIdentity; + /** {@hide} */ + public String password; + /** The path of the client certificate file. + * {@hide} + */ + public String clientCert; + /** The path of the CA certificate file. + * {@hide} + */ + public String caCert; + /** The path of the private key file. + * {@hide} + */ + public String privateKey; + /** The password of the private key file if encrypted. + * {@hide} + */ + public String privateKeyPasswd; + public WifiConfiguration() { networkId = -1; SSID = null; @@ -263,6 +313,14 @@ public class WifiConfiguration implements Parcelable { wepKeys = new String[4]; for (int i = 0; i < wepKeys.length; i++) wepKeys[i] = null; + eap = null; + identity = null; + anonymousIdentity = null; + password = null; + clientCert = null; + caCert = null; + privateKey = null; + privateKeyPasswd = null; } public String toString() { @@ -333,10 +391,43 @@ public class WifiConfiguration implements Parcelable { } } } - sbuf.append('\n'); + sbuf.append('\n').append(" PSK: "); if (this.preSharedKey != null) { - sbuf.append(" PSK: ").append('*'); + sbuf.append('*'); + } + sbuf.append('\n').append(" eap: "); + if (this.eap != null) { + sbuf.append(eap); } + sbuf.append('\n').append(" Identity: "); + if (this.identity != null) { + sbuf.append(identity); + } + sbuf.append('\n').append(" AnonymousIdentity: "); + if (this.anonymousIdentity != null) { + sbuf.append(anonymousIdentity); + } + sbuf.append('\n').append(" Password: "); + if (this.password != null) { + sbuf.append(password); + } + sbuf.append('\n').append(" ClientCert: "); + if (this.clientCert != null) { + sbuf.append(clientCert); + } + sbuf.append('\n').append(" CaCert: "); + if (this.caCert != null) { + sbuf.append(caCert); + } + sbuf.append('\n').append(" PrivateKey: "); + if (this.privateKey != null) { + sbuf.append(privateKey); + } + sbuf.append('\n').append(" PrivateKeyPasswd: "); + if (this.privateKeyPasswd != null) { + sbuf.append(privateKeyPasswd); + } + sbuf.append('\n'); return sbuf.toString(); } @@ -394,6 +485,14 @@ public class WifiConfiguration implements Parcelable { writeBitSet(dest, allowedAuthAlgorithms); writeBitSet(dest, allowedPairwiseCiphers); writeBitSet(dest, allowedGroupCiphers); + dest.writeString(eap); + dest.writeString(identity); + dest.writeString(anonymousIdentity); + dest.writeString(password); + dest.writeString(clientCert); + dest.writeString(caCert); + dest.writeString(privateKey); + dest.writeString(privateKeyPasswd); } /** Implement the Parcelable interface {@hide} */ @@ -416,6 +515,14 @@ public class WifiConfiguration implements Parcelable { config.allowedAuthAlgorithms = readBitSet(in); config.allowedPairwiseCiphers = readBitSet(in); config.allowedGroupCiphers = readBitSet(in); + config.eap = in.readString(); + config.identity = in.readString(); + config.anonymousIdentity = in.readString(); + config.password = in.readString(); + config.clientCert = in.readString(); + config.caCert = in.readString(); + config.privateKey = in.readString(); + config.privateKeyPasswd = in.readString(); return config; } diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index 658a7b2..7a15f27 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -253,6 +253,15 @@ public class WifiManager { IWifiManager mService; Handler mHandler; + /* Maximum number of active locks we allow. + * This limit was added to prevent apps from creating a ridiculous number + * of locks and crashing the system by overflowing the global ref table. + */ + private static final int MAX_ACTIVE_LOCKS = 50; + + /* Number of currently active WifiLocks and MulticastLocks */ + private int mActiveLockCount; + /** * Create a new WifiManager instance. * Applications will almost always want to use @@ -702,6 +711,14 @@ public class WifiManager { if (mRefCounted ? (++mRefCount > 0) : (!mHeld)) { try { mService.acquireWifiLock(mBinder, mLockType, mTag); + synchronized (WifiManager.this) { + if (mActiveLockCount >= MAX_ACTIVE_LOCKS) { + mService.releaseWifiLock(mBinder); + throw new UnsupportedOperationException( + "Exceeded maximum number of wifi locks"); + } + mActiveLockCount++; + } } catch (RemoteException ignore) { } mHeld = true; @@ -726,6 +743,9 @@ public class WifiManager { if (mRefCounted ? (--mRefCount == 0) : (mHeld)) { try { mService.releaseWifiLock(mBinder); + synchronized (WifiManager.this) { + mActiveLockCount--; + } } catch (RemoteException ignore) { } mHeld = false; @@ -783,6 +803,9 @@ public class WifiManager { if (mHeld) { try { mService.releaseWifiLock(mBinder); + synchronized (WifiManager.this) { + mActiveLockCount--; + } } catch (RemoteException ignore) { } } @@ -824,62 +847,138 @@ public class WifiManager { return new WifiLock(WIFI_MODE_FULL, tag); } + /** - * Check multicast filter status. + * Create a new MulticastLock * - * @return true if multicast packets are allowed. + * @param tag a tag for the MulticastLock to identify it in debugging + * messages. * - * @hide pending API council approval + * @return a new, unacquired MulticastLock with the given tag. + * + * @see MulticastLock */ - public boolean isWifiMulticastEnabled() { - try { - return mService.isWifiMulticastEnabled(); - } catch (RemoteException e) { - return false; - } + public MulticastLock createMulticastLock(String tag) { + return new MulticastLock(tag); } /** - * 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 #disableWifiMulticast - * - * @hide pending API council approval + * Allows an application to receive Wifi Multicast packets. + * Normally the Wifi stack filters out packets not explicitly + * addressed to this device. Acquring a MulticastLock will + * cause the stack to receive packets addressed to multicast + * addresses. Processing these extra packets can cause a noticable + * battery drain and should be disabled when not needed */ - public boolean enableWifiMulticast(String tag) { - try { - mService.enableWifiMulticast(new Binder(), tag); - return true; - } catch (RemoteException e) { - return false; + public class MulticastLock { + private String mTag; + private final IBinder mBinder; + private boolean mHeld; + + private MulticastLock(String tag) { + mTag = tag; + mBinder = new Binder(); + mHeld = false; + } + + /** + * Locks Wifi Multicast on until {@link #release} is called. + * + * The first call to {@code acquire} will lock the Multicast on + * but subsequent calls will be ignored. Only one call to + * {@link #release} will be required, regardless of the number of + * times that {@code acquire} is called. + * + * Note that other applications may also lock Wifi Multicast on. + * Only they can relinquish their lock. + * + * Also note that applications cannot leave Multicast locked on. + * When an app exits or crashes, any Multicast locks will be released. + */ + public void acquire() { + synchronized (mBinder) { + if (!mHeld) { + try { + mService.acquireMulticastLock(mBinder, mTag); + synchronized (WifiManager.this) { + if (mActiveLockCount >= MAX_ACTIVE_LOCKS) { + mService.releaseMulticastLock(); + throw new UnsupportedOperationException( + "Exceeded maximum number of wifi locks"); + } + mActiveLockCount++; + } + mHeld = true; + } catch (RemoteException ignore) { + } + } + } + } + + /** + * Unlocks Wifi Multicast, restoring the filter of packets + * not addressed specifically to this device and saving power. + * + * Note that if any other Wifi Multicast Locks are still outstanding + * this {@code release} call will not have an immediate effect. Only + * when all applications have released all their Multicast Locks will + * the Multicast filter be turned back on. + * + * Also note that when an app exits or crashes all of its Multicast + * Locks will be automatically released. + */ + public void release() { + synchronized (mBinder) { + if (mHeld) { + try { + mService.releaseMulticastLock(); + synchronized (WifiManager.this) { + mActiveLockCount--; + } + mHeld = false; + } catch (RemoteException ignore) { + } + } + } + } + + /** + * Checks whether this MulticastLock is currently held. + * + * @return true if this MulticastLock is held, false otherwise + */ + public boolean isHeld() { + synchronized (mBinder) { + return mHeld; + } + } + + public String toString() { + String s1, s2; + synchronized (mBinder) { + s1 = Integer.toHexString(System.identityHashCode(this)); + s2 = mHeld ? "held; " : ""; + return "MulticastLock{ " + s1 + "; " + s2 + " }"; + } + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + release(); } } /** - * 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 + * Check multicast filter status. * - * @see #enableWifiMulticast + * @return true if multicast packets are allowed. * * @hide pending API council approval */ - public boolean disableWifiMulticast() { + public boolean isMulticastEnabled() { try { - mService.disableWifiMulticast(); - return true; + return mService.isMulticastEnabled(); } catch (RemoteException e) { return false; } diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java index 64084cf..2fbc779 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)); @@ -739,8 +747,10 @@ public class WifiStateTracker extends NetworkStateTracker { * first and then off.. if nobody else wants it on it'll be * off then and it's all synchronized within the API. */ - mWM.enableWifiMulticast("WifiStateTracker"); - mWM.disableWifiMulticast(); + WifiManager.MulticastLock l = + mWM.createMulticastLock("WifiStateTracker"); + l.acquire(); + l.release(); if (mBluetoothA2dp == null) { mBluetoothA2dp = new BluetoothA2dp(mContext); @@ -783,8 +793,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); } @@ -954,7 +964,7 @@ public class WifiStateTracker extends NetworkStateTracker { } requestConnectionStatus(mWifiInfo); if (!(result.state == DetailedState.CONNECTED && - (!mHaveIPAddress || mDisconnectPending))) { + (!mHaveIpAddress || mDisconnectPending))) { setDetailedState(result.state); } @@ -983,7 +993,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); @@ -1051,8 +1061,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) { @@ -1078,9 +1088,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(); } @@ -1156,18 +1166,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"); } @@ -1200,8 +1210,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); /* @@ -1612,8 +1622,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); |
