wifi: Fix StringIndexOutOfBoundsException for incorrectly encoded SSIDs

If the last character of a SSID is a unescaped backslash then WifiSsid
convertToBytes() will throw a StringIndexOutOfBoundsException and takes the
whole ROM down.

The issue was reported by andreip in the HTC One X XDA thread. His SSID was
set to "/ Andrew \".

04-10 21:33:54.265 E/AndroidRuntime(10479): *** FATAL EXCEPTION IN SYSTEM PROCESS: WifiStateMachine
04-10 21:33:54.265 E/AndroidRuntime(10479): java.lang.StringIndexOutOfBoundsException: length=10; index=10
04-10 21:33:54.265 E/AndroidRuntime(10479):     at android.net.wifi.WifiSsid.convertToBytes(WifiSsid.java:89)
04-10 21:33:54.265 E/AndroidRuntime(10479):     at android.net.wifi.WifiSsid.createFromAsciiEncoded(WifiSsid.java:54)
04-10 21:33:54.265 E/AndroidRuntime(10479):     at android.net.wifi.WifiStateMachine.setScanResults(WifiStateMachine.java:1522)
04-10 21:33:54.265 E/AndroidRuntime(10479):     at android.net.wifi.WifiStateMachine.access$7100(WifiStateMachine.java:103)
04-10 21:33:54.265 E/AndroidRuntime(10479):     at android.net.wifi.WifiStateMachine$SupplicantStartedState.processMessage(WifiStateMachine.java:2511)
04-10 21:33:54.265 E/AndroidRuntime(10479):     at com.android.internal.util.StateMachine$SmHandler.processMsg(StateMachine.java:905)
04-10 21:33:54.265 E/AndroidRuntime(10479):     at com.android.internal.util.StateMachine$SmHandler.handleMessage(StateMachine.java:760)
04-10 21:33:54.265 E/AndroidRuntime(10479):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-10 21:33:54.265 E/AndroidRuntime(10479):     at android.os.Looper.loop(Looper.java:137)
04-10 21:33:54.265 E/AndroidRuntime(10479):     at android.os.HandlerThread.run(HandlerThread.java:60)

Change-Id: I8273decacfffea4e4cae3bb957c925833dab09e2
Wi-Fi: Ping the driver for wifi-only devices

Wifi-only devices are not capable to find APs with hidden SSID unless a DRIVER COUNTRY command
will send to wifi driver. This change has:

- Send DRIVER COUNTRY command to ping the driver (to correct the seek of hiddens SSIDs)
- Save mCountryCode as uppercase because the wifi_countrycode_values array is in uppercase.
  Otherwise the preference will not be found.

Patchset 7: Rebase
            Do not set mCountryCode if country is null

Change-Id: I85ab47c6768af3dddd0d33a7c42c6c1e2826be5f
Clear the scan list when an empty list is received

When the framework receives an empty scan list from supplicant, it does
not clear the local list. So the UI will continue to show the previous
scan list even when there are no APs around. So clear the local list,
when an empty list is received.

CRs-Fixed: 552212
Change-Id: I8715bc31ce0df7bd54c96fcf7d7b73592429f12a
Avoid possible memory leaks by ensuring stream closures

Stream close() methods should always be called in finally block
to ensure we don't accidentally leak a stream.

Time to fix some old sloppy code.

Patch Set 2:
 + ensure closure of some other streams
Patch Set 3:
 + missing import java.io.IOException
Patch Set 4:
 + missing import
Patch Set 5:
 + missing ';'
 + whitespace cleanup
Patch Set 6:
 - Reverted changes to MemoryUsage (final requirement
     prevents my implentation)
 + fixed Object allocation in Root.java
Patch Set 7:
 + fixed curly bracket style violations
Patch Set 8:
 x fixed my own sloppy code :/

Change-Id: I3460b558ed5b4489296388c9a52fbb773cefd31f
Signed-off-by: pcarenza <pcarenza@gmail.com>

Conflicts:
	packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java

Conflicts:
	packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
Close sockets on wpa_supplicant termination.

Framework does not close the sockets on supplicant
termination, leading to leakage of file descriptors.

Thus close the socket on supplicant termination.

Change-Id: I50aefc6d60b3794288564f403a42258442e224df
CRs-Fixed: 576276
Signed-off-by: pcarenza <pcarenza@gmail.com>
frameworks: Fix interface monitoring failure

On supplicant restart condition monitoring ifname
is getting removed from hash map. Due to which
the monitoring is getting failed after restarting
of the supplicant.

So dont remove the ifname from Hash map in
WifiMonitor on supplicant connection fail case.

Bug 67606

Change-Id: If972151ebc9b7f312be583dc8562ca24677e8dc0
WifiStateMachine: fix socket fd missed closing issue

Socket fd closing operation is missed in SupplicantStartingState
which will lead to fd leakage in system_server process

Change-Id: I9947d13fc73f16ca71a7b234727f39a39c6a60c8
Signed-off-by: jiaguo <jiaguo@marvell.com>
core and telephony: Additional HSPAP support

Change-Id: I5e921d2308d873678d6ef67a91cff50d383a176b
telephony: SignalStrengh: Don't calculate a LTE snr if the srq is invalid

If the previous values are invalid and signal quality is -1, chances are there's
no LTE signal at all, so don't calculate the SNR and mark it invalid as well.

This fixes the strength indicator in GSM devices where it was being skewed
by the ghost LTE value

Change-Id: I070573401c141aa99941a332ee256246697abb90
Framework: Fix GSM signal strength

Certain OEM gsm ril libs send back a bogus value for LTE signal
that causes SignalStrength.java to default to LTE and report
incorrect signal values.
Use prop value ro.telephony.ril.v3=signalstrength to get proper
GSM signal reading on certain devices.

Signed-off-by: dhacker29 <davidhackerdvm@gmail.com>

Change-Id: I86279dcbc350fe718d89070acc12178de3c600c2
Signal strength: add more checks to signal strength,
so it doesn't fall under the range of poor signal and automatically
assumes a gsm signal, actually checks if all values are true and not
valid then pass it on to lte or gsm. This fixes cases when gsm signal
is not valid and lte is active. When lte is active and shows a really
weak and gsm signal is not avalible due some broken vendor ril or
just running cdma lte and a few others senario creates this issue.

Change-Id: Ib0d04adbf615502081470bd03d995228f1d40d81
ServiceState: add support for DCHSPAP

Change-Id: Ib0a328652c14580718400b00146b770481be5458
Telephony: Initialize GsmCellLocation class members properly

Default values for class members mLac, mCid, mPsc would be 0.
Initialize these variables with -1 as 0 is considered as valid value.

Change-Id: Idb3d1737c7101b97a90eab3dc7436ee1806d0bc4
CRs-Fixed: 406479
Fix issue in PhoneNumberUtils.compareLoosely

There is an issue with MMS delivery report where
even if the report was received the status is shown
as pending.

If the number of matched digits is greater than or
equal to MIN_MATCH and if one of the input strings
index has reached the lower limit,
PhoneNumberUtils.compareLoosely should return true.
Currently, it doesn't return true as it is expecting
the index to be < 0 which will not happen for the
following case where country code + number is without
"+" prefix or the number is without country code-

This patch fixes the issue by checking the index <= 0.

Change-Id: I22209e4912388411d863fbd28fe3edb27edbb3b0
Signed-off-by: Jeevaka Badrappan <jeevaka.badrappan@intel.com>
Signed-off-by: Arun Ravindran <arun.ravindran@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Signed-off-by: Jian Luo <luo.jian@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Author-tracking-BZ: 64234
Add support for NETWORK_TYPE_GSM

Add support for NETWORK_TYPE_GSM in TelephonyManager and
corresponding mapping in ServicState.java so that when
application queries for getVoiceNetworkType() and currently
camped rat is GSM, they get network mode as GSM instead
of network mode unknown.

Change-Id: Ibe4672b04a5044710d63499c4cf2b6ebe91444bf
Wifi: Adjustments for sleep policy

   The wifi sleep policy "When screen turns off" will switch
off wifi although the USB tethering is active.With this
patch, the sleep policy is removed when the usb tethering is
active.The WifiService maintains a local status variable in
according with the wifi tethering (on,off).If the usb tethering
is on, the alarm, to switch off the wifi, is cancelled.If the
device in unplugged after turning off the display while still
not connected, it's better to directly turn off wifi in order to
reduce power consumption.So when unplugged while screen is
already off, request to go in idle (and so turns off wifi) if
wifi is not connected.
   When USB tethering is enabled, don't care about sleep policy:
- first because DUT is powered by USB
- secondly because DUT is used as wifi card and so used by PC

Signed-off-by: Paul Naoumenko <paulx.naoumenko@intel.com>
Signed-off-by: Cedric IZOARD<cedricx.izoard@intel.com>
Signed-off-by: chenxi2x <xiaolongx.chen@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Change-Id: Ic1af2367a2f73965c32d300450ee76cf5593af78