Read IMSI using SIM I/O for CSIM/RUIM

Use Sim I/O command to read the EF_IMSIM to retrieve the IMSI
from the card, rather than using CommandsInterface.getIMSIForApp.
When both SIM and RUIM app exists, we cannot specify the
application for which we should retrieve the IMSI using the getIMSI
API, since SIM and RUIM have no AID.

Change-Id: I905d4a271dfba168f2bc3830b8a50733cbe17f8c
CRs-fixed: 514270
(cherry picked from commit 8cf68fb9ac8f1fe972dbff96121fb5407ad179d7)
(cherry picked from commit 77126e1f020ba45f5494683781cb81d35d80a256)
(cherry picked from commit 08f864df8d3e04e4325eba99e63e402b6f2a1757)

Conflicts:
	src/java/com/android/internal/telephony/uicc/RuimRecords.java
Telephony: Don't read records from card if not needed.

Specifically handle the scenario where there is an RUIM card
 inserted but we are in NV mode. In this case, don't read
records from the card.
IccCardProxy tells the IccRecord that it will be requiring records
from the card. RuimRecord waits for this indication before fetching
records from the card

Change-Id: Ifa95dda2958922901e887b386c55556f947a881d
(cherry picked from commit 174cb8b06d0367b301f6dc76aa5b7b546ac630a7)
(cherry picked from commit 61046da5e4c4ca12290b10a3d3c1c07592accd25)
(cherry picked from commit 3d0c3e0280096081402502978f0e25ef0fdfd20a)
Create ApnSetting if none are found in database.

Bug: 9315957
Change-Id: I0cf0debb703f6a4cad35300315922a5566871f85

Conflicts:
	src/java/com/android/internal/telephony/dataconnection/DcTracker.java
Use proper coded for when a contact is written into EF_ADN of USIM

Based on the description in "3GPP TS 31.102 clause 4.4.2.3" shown below,
Alpha Identifier of EF_ADN of USIM is defined in default 7-bit coded
alphabet if bit8 is set to 0 otherwise, it is defined in UCS2 coded.

Change-Id: I02a68d9db7ede30661f2526d3b354bbc1f556110
CRs-fixed: 553329
Frameworks: Add ADN capabilities for CDMA phone

CDMA can support Abbreviated Dialing Numbers so add
CDMA in TelephonyCapabilities.

Change-Id: Ia33618d42664560f33bfa5b995b89cd030ee20de
(cherry picked from commit b52f52d1c2b3e5cb53a280bfdf4dc8ab807e6642)
(cherry picked from commit b0cb815ba965748b3e9a9057d870f19d4d786948)
(cherry picked from commit fa9d968223657f5a0830a3f1399cd317761d9e2a)
Move ConnectTimeReal to base class Connection.java

Move ConnectTime Real from derived classes GsmConnection
and CdmaConnection to Connection base class.
This gives the flexibility
to access ConnectTimeReal from different derived classes
using base class object.
This is needed to transfer time from ImsConnection
to CS connection for SRVCC.

Change-Id: I4f2a834f9df27514373de22a1c71d3923b66dc14
CRs-Fixed: 412754
(cherry picked from commit a8a1eb130bd51bcedad53f77fc31174f4b2cd3eb)
(cherry picked from commit a568c5244e70dd5f06bd073f48fe881f4c217edc)
(cherry picked from commit 737dda096eeee1fa5bbd30c9e324d1f73fdc68bf)
telephony : Support for voicemail in TP-UDH of SMS

Added support for processing special message indication
for voice mail in TP user data header for SMS
Spec reference: 3GPP TS 23.040 V6.8.1

CPHS method does not use message count.
0xff is used to indicate unknown message count for CPHS
Ref[Adapt requirement CDR-MWI-120, TC: GSM-BTR-1-4700]

Change-Id: I893252d5cacd5c1c8680a8ca6c3a6dba95ef3e1f
(cherry picked from commit ce64a3c4a4cd98931ae888dc3f6c45570bbc78f5)
(cherry picked from commit 3cc432cc2d3f8c44884ddc27b781d1a4e4d68c27)
(cherry picked from commit 9e80253570db3c519a26154a49461ba4a7f27f02)
Telephony: Set digit_mode to 8 bit in case when ton set to 1

C.S0005 requires that digit_mode parameter in mobile originated
cdma sms address needs to be set to 8 bit when type_of_number
parameter is present.
CRs-Fixed: 295542

Change-Id: I3077d9a7b09933732bbff8119308ae3de6259821
(cherry picked from commit 250a99f43642f5f117f860b56ba07deb4c29c250)
(cherry picked from commit b8d7c02eab970caab5f118a8b9e19f2dce5acf78)
(cherry picked from commit 0b1f39924d74a28dc005ae82709e645bf8317568)
Telephony: Ignore data registration when bringing down call

Bring down data call even if we have it while data registration indicates
phone is in unregistered state.
getAnyDataEnabled will return false if phone is not registered hence
user disabling data while phone is unregistered will have no effect
(and data call will remain there indefinitely).

Change-Id: I72cf1fb8b89cad5bb8595233721d1ac315750dbf
CRs-Fixed: 372219
(cherry picked from commit 0bf3869ffd41af11d2f144ac0fec174a582fd023)
(cherry picked from commit 422e033ca7fb169362ddae65448f96ae681787d5)
(cherry picked from commit 8b009c7dadc1cfc213d86f7d6641da36c06ec23a)
Telephony: Multiparty Call related fix

Block multiple Call switch request to RIL

Sending a call switch request to RIL before receiving
a response for the previous request causes the lower
layers to not respond. Pending responses from RIL
block the call polling in telephony.
CRs-Fixed: 269330, 278014, 282061, 293727, 441309

Change-Id: I078945f7427fdc7b2b26d6563bc117a3dd4fc9c4
(cherry picked from commit 37ec45c237446a92d0aa008788f4da76ffda8708)
(cherry picked from commit c9ad7936c732e65cdd92029709c3afa7d68017fe)
(cherry picked from commit 3f1bbf5b7ba2fcebd3b2f7442545cbd92446d454)
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)
Telephony: Consider dataRegState to determine SPN display

There may be situations where voice service state is OOS and data
service state is IN_SERVICE. In such cases, both regStates need to be
considered to determine what to show in UI for SPN.

Change-Id: Iab17ed07611b6fd95d6bc6ee3e2e095f6700e3ba
CRs-Fixed: 532471
(cherry picked from commit 2e82847bccabaea72796c1b147ca1ace92567b41)
(cherry picked from commit a8a96a1c846ad2a36b861c6d3c526a3f7edf130d)
(cherry picked from commit c13654c1db55d5963e8a42d6ba23134661258605)
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)
Use EF_EXT5 as extension for EF_MSISDN on USIM

For USIM applications, use EF_EXT5 as the extension for EF_MSISDN
as per TS 31.102 Section 4.2.37

Change-Id: Ib3bd3d8160d73fcc02b80ef420d8c8f2ffb4992f
CRs-Fixed: 433379
(cherry picked from commit d380a0adcb8ef31153517ab5690361bb757fd5ef)
(cherry picked from commit 4c1d3ad173d66c6416a9f0f74f0e81dee9f24c1f)
(cherry picked from commit 4a4ed85ea15f20520652215476f432b4bb216bd7)
Stk: Ensure that APDU input length does NOT exceed 255 Bytes.

- Depending on the encoding , the number of characters that
can be stored in 255 bytes varies. See details below.
- detect the current encoding used and enforce max length

Details:
As per TS 102.223 Annex C, Structure of CAT communications,
the APDU length can be max 255 bytes. This leaves only 239 bytes for
user input string. CMD details TLV + Device IDs TLV + Result TLV + Other
details of TextString TLV not including user input take 16 bytes.

If UCS2 encoding is used, maximum 118 UCS2 chars can be encoded in 238
bytes.Each UCS2 char takes 2 bytes. Byte Order Mask(BOM), 0xFEFF takes
2 bytes.

If GSM 7 bit default(use 8 bits to represent a 7 bit char) format is
used,maximum 239 chars can be encoded in 239 bytes since each char takes
1 byte.

No issues for GSM 7 bit packed format encoding.

Change-Id: I6a12b9a9c8f8b6b44c0164fc4e038c92c05284ce
(cherry picked from commit fe8b1820ef9fdddb29754677549b38ae1e84dc0d)
(cherry picked from commit dccb5d460f71d44b2fab524e829224867a263b1d)
(cherry picked from commit 2a80a4e485739b764ce3908538353344588f88ec)
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)
Fix for data and roaming icons

- Enable data connected flag based on the data state.

- Do not display data icon in data connected state
if radio type is unknown

- Display data icon independent of voice service state
i.e even if voice network is unavailable

- Show cdma roaming indicators if either voice
or data is roaming.

- Cleanup roaming indicator default values.
Set default CDMA Eri index to roaming off

- Show service if either voice/data is in
service if ro.config.combined_signal is true

- Consider eri only when in service

- Add in service check to isCdmaEri.
roaming related information
in registration state will not be valid
during out of service.

Change-Id: I915421a6f5906d80ed5b8dd9c433115ad5df1f14
CRs-Fixed: 285986, 303275, 326204, 326634, 333008, 339297
(cherry picked from commit 5e973bedadf36b08a1e2a82745d912fcfdebb020)
(cherry picked from commit fd4dcb2c518eef3e655136cbd69c94b5a3fffb1b)
(cherry picked from commit c5b8a284415d65bad41915b3e50fed853d5f5110)
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)
Telephony: Add isRadioOn() method

The implementation of ITelephony.isRadioOn() method checks for
service state instead of radio state. In cases of basebandless
targets, service state is not changed and would remain in the
initialized OUT_OF_SERVICE state. This causes delay in shutdown
procedure for such targets.

Hence a method isRadioOn() is added in phone interface to get
the radio state.

Change-Id: I33760b710a1ef5ba50b92a014c72f33d8dc5e782
CRs-Fixed: 502317
(cherry picked from commit 21554a64826befd6fbaa6e5d341d60b4722b2a6a)
(cherry picked from commit 512862bcca51fb58e0f2b6b32a6d335db6cf257c)
(cherry picked from commit 7042c2deb7dc0e235e453c887aa7596e6db1110e)

Conflicts:
	src/java/com/android/internal/telephony/PhoneBase.java
	src/java/com/android/internal/telephony/PhoneProxy.java
Usat Phase 2 feature and Screen status

This change combines below 3 fixes.
1) Usat Phase 2 fixes
Added changes to support Idle screen, Language Selection.

This also includes change to support Idle screen status information.

Fix to address alpha display for proactive commands
CRs-Fixed: 432647
2) Telephony: Correct terminal response sent for Idle mode text cmd

When a proactive command : SET_UP_IDLE_MODE_TEXT arrives with
empty text and non-self explanatory icon, terminal response
:CMD_DATA_NOT_UNDERSTOOD should be sent back to the UICC as
per the SAT spec
CRs-Fixed: 280223

3) The GCF Testcase GCF-PTCRB SAT/USAT 27.22.4.1.1seq1.2 expects a
screen busy response if the ME is not in idle screen and if the
display text message is a low priority message. Hence sending screen busy
response instead of RESPONSE_TIMEOUT. In present implementation a
USER_RESPONSE_TIMEOUT response is sent for all timeout cases.

Change-Id: I8370dfab498ce632a04d1b24ad576c30dbd8ccfd
(cherry picked from commit 3e818d3bcaec969a1ebf11221fbb8c34c942baaa)
(cherry picked from commit fb24c77ab64d1792caefdc8fa56bf24a824c17d2)
(cherry picked from commit d3feb56b34a6f84dddcae59058bd286e37723f00)