Telephony: Samsung STK Support

Squashed Commits of the following:

    Add Samsung STK support (telephony part)

    Support for SMS-based SIM applications.
    Partially rewritten the original patch by Jüri Schultz to be less intrusive.

    Change-Id: I15d2de1781a2823e24941dd792db3d372578aa9f

    Samsung STK: Add USSD support

    Allow USSD-based STK applications to work

    Change-Id: I483f37a44a6c3ed43eefcf979e17b84877d03f93

    Samsung STK: Fix SMS-based STK

    SEND_SMS was falling through to SEND_USSD (which used to do nothing
    until USSD support was added) causing an Exception because cmdParams
    is not an instance of SendUSSDParams.

    Fix by using type-checking instead of checking if Samsung STK is
    enabled (because SendSMSParams and SendUSSDParams will only be
    created if Samsung STK is enabled.)

    Change-Id: I671014e295e9e529aad25a8b6fbd5a2e5788fc44

Change-Id: I67866c9db4d5e5b42d8aa8d465d931f74c67e308
PhoneFactory: fall back to default RIL if custom RIL Class fails

If the ro.telephony.ril_class property is set to an invalid class it will cause
Phone to repeatedly FC and make the device unuseable. This allows it to handle the
exceptions gracefully and fall back on the default RIL.

Change-Id: Ic9c309aff173de5267aa7ef633bfff87243f24fd
Merge "Telephony: Samsung STK Support" into android-4.4
Fix enabling data connection

Could not enable the default type APN in below case:
1. Default apn exists, connect wifi
2. Delete default apn
3. Disconnect wifi

enableApnType won't reactivate default apn type when no
default apn exists. Add default apn criterium to avoid this.

Change-Id: Ic8699669e576e5d2140852f359e34ed6c3275633
Don't assume 3GPP as active app on CDMA with LTE device

IccCardProxy assumes, that on a CDMA+LTE device, the active app
is the SIM/USIM and not the RUIM/CSIM. However, for voice RUIM/CSIM
is the active app on such a device. All services, like FDN,etc. should
be tied to the active voice app.
CRs-Fixed: 428304, 506938

Change-Id: I70894a1aab0a812a50f1cbab986161bb3b708b85
(cherry picked from commit 4d19143c3cf2ea1ee37fa1c05cac984ab14ce603)
(cherry picked from commit c623954a27891a0693bf2208bb095183f1d1b9d9)
(cherry picked from commit e48c977e219b4afba93eb71ac0c4e937f3376710)
Telephony: Decode SPN from RuimRecords properly

To address issues with incorrect encoding scheme programmed
in some commercial CSIM cards, the decoded SPN is checked to
have characters in printable ASCII range. If not, they are
decoded with ENCODING_GSM_7BIT_ALPHABET scheme.

Change-Id: I938f4ac7d2c4cee6732c3abad1be7db7395276ad
CRs-Fixed: 483975
(cherry picked from commit cf50334109bd6259445beb3345b6da038a5b7927)
(cherry picked from commit 1f37671a2c611971102a1c99da3da9893adc4247)
(cherry picked from commit 084a2d80cb4f6c4130900a3e9017f1927bb0b52e)
Clean up Icc Refresh handling.

1. When a SIM refresh is received of type INIT or RESET,
don't immediately start re-fetching the records, because
the app might not be ready. In this case, we could end up
broadcasting that all records are loaded pre-maturely.

On a refresh of the above type, the app will move out of the
ready state and back into the PIN state, if PIN is enabled.
Start reading the records only after the PIN has been verified
and the app has moved to the READY state.

2. UiccController will listen for refresh and propagate it to
the Card and the Apps. The App will set its state to UNKNOWN
on receiving a refresh.
UiccController will also request card status on receiving
refresh to get the latest state.

This avoids having to make assumptions on the ordering of the
Unsols for Sim Refresh and card state changes. This also
ensures that after an app state is marked UNKNOWN,
it will move to READY, if it is truly ready.

3. Moved common implementation for refresh into IccRecords
for better code reuse.

4. Side effect of #3 is RuimRecords will now reset AdnCache when
refresh of type INIT is received.

Change-Id: I58b1237a49d4f943a699d751a8680c25ce4394ad
CRs-Fixed: 503646
(cherry picked from commit 6000bfc07122c07f7b8f075f272fdf1e384032e6)
(cherry picked from commit 5a1abe073cb648a8772bcfa2d5fdee88070e4b8b)
(cherry picked from commit 12a9a344eb49498b44ddb0e4f1c8126c6507b56e)
Telephony:Prevent duplicate auto mode request on EF_CSP read

Prevent duplicate auto network selection mode request
if triggered internally by Android due to
PLMN disabled in EF_CSP SIM record.
Allow mode change request if triggered by user.
CRs-Fixed: 301052

Change-Id: I9f6828e59abada64fab66d6ff747bf83a3ec4d6c
(cherry picked from commit d13254b8d1b238f5e2f417da8839d5120952898d)
(cherry picked from commit db52d32cc814ee8081de8838bf57936bbcf03a44)
(cherry picked from commit eee13b4a953a8b2587f7181160a6db8ad36ffad4)
STK: Handle ICC refresh and card removal, and re-work clean up

Register for ICC refresh and let CatService's clients know when
an ICC refresh occurs.

Monitor card status. When card status moves to absent/present let
clients know.

Don't dispose CatService based on the number of applications.
Instead dispose it when UiccCard goes away

This helps avoid the race condition in the following scenario:
1. Radio is on and card is present
2. Turn Radio Off
3. Turn Radio On
4. Proactive command received

If CatService was disposed when card goes away on radio off
then it is possible for the unsol proactive command to be received
before Catservice is up and running on radio on.

Change-Id: Iee4ab009a0f9708a1ee2d87460e60765e46b4229
CRs-Fixed:270755, 283523, 450167, 442985
(cherry picked from commit f1f780eb194b66ccb4b37e64dd7ff67913a68915)
(cherry picked from commit ccd36c4495fb7e8c324a39ac07ec1d1bbb288908)
(cherry picked from commit e2998b862d8adf5e0134e879ed01b751deb73823)
Stk: dispose objects properly for hotswap

During hotswap, CatService object is disposed and new
object is created. However RilMessageDecoder still
holds reference to old object of CatService, and hence sends
decoded command to old object of CatService leading to stk failure.
In this fix below objects are disposed properly when CatService
is disposed.

1) RilMessageDecoder
2) CommandParamsFactory
3) IconLoader

Change-Id: Idf6b1ad3fad4b633e7dcf8082151de12abc83899
CRs-Fixed: 489025
(cherry picked from commit 2007816daf4c2a2d0f03193b944a5bb75d54b174)
(cherry picked from commit ada77eeaf2a385e024f86e44ae7f9edef6db4137)
(cherry picked from commit 42707f94dfac241e7df9c2f71742e9e0171c6a51)

Conflicts:
	src/java/com/android/internal/telephony/cat/CatService.java

Conflicts:
	src/java/com/android/internal/telephony/cat/CatService.java
Build Fixes

Change-Id: I9e9ed9e67f66a5cbf9a25d7f6d9dceb8583ef53a
Revert "Remove special code for fake CDMA APN"

This reverts commit 150b65fc3b52beab23f0d714e4c3166f90d3985e.
DcTracker: generate APNs for Sprint EVDO/1xRTT

*Squashed: Reverts a revert that removed this ability
*Add null check prior to defining 'operator', removing the need for it after
*Use ro.cdma.home.operator.numeric instead of mPhone.getPhoneType()
*Add IPv6 support to generated APN to match normal APNs
*Fixed a typo with DEFALUT_DATA_ON_BOOT_PROP
*Fixed incorrect logging typos

Change-Id: I35b3784cbec81eaed0c0bcdd0f88abc583978ef4
Fix cdma data calls based on NV

For NV data calls we need to create dummy profiles
When DcTracker switches from lte to cdma we need to bring
down existing data call and establish new one (same goes
for switching cdma->lte)

Bug: 10804691
Change-Id: I7ad8d0632854ea9875afb76709c1ba894bf048fd
(cherry picked from commit 4ead798ed4964952c3086b3224d775479d66d240)
(cherry picked from commit f333f0ca7b1c992ab36af83ca74a1131d3ae17b8)
(cherry picked from commit 14e5657432de2eb9ba52ebf28a8967ed62ee4a0b)

Conflicts:
	src/java/com/android/internal/telephony/cdma/CDMAPhone.java
	src/java/com/android/internal/telephony/dataconnection/DcTracker.java
Enable verbose logging in CDMAPhone

Change-Id: Iae2e12c8e998249a84289d454d50233cac6196bc
cdma: Restore SVDO after merge.

Allow evdo/ehrpd + voice simutaneously.
Use ro.ril.svdo=true

Change-Id: If7be25edc10f21680adbe3a059370d77a82ef076
Telephony: DcTracker: Fix CDMA APN Data issues.

Fixes Data on CDMA when APN Match cannot be found
Original commit: cd2585eb3f4e2db5c8a36382ffa644fa0d1515b4

PS2: Fixed small derp that was breaking build
PS3: Change author name to original author

Change-Id: Iad7737635686fdb9d7d35099d3cf615eb47a3dfd