Telephony: Consider EF-SMS for both gsm and cdma

EF-SMS each record length is 176 for GSM and 255 for CDMA.
Consider proper length depending on phone type to avoid crash.
Spec Ref: TS 51.011 10.5.3 for GSM and C.S0023 3.4.27 for CDMA.
CRs-Fixed: 385474

Change-Id: Ia43d0ad0984da9855493e968ad9d046ae0fa7d02
(cherry picked from commit 9056e0750498ac8a8c42290d2dbdebbbb35f2d75)
(cherry picked from commit 13fe891e8e27c03793484b4bbb8d33b5c63739b8)
(cherry picked from commit b425bd894a3d4e1090587302c500755c72dcb547)
Telephony: Set RESULT tag properly when sending TR

While encoding terminal response, result tag is
always encoded with CR flag, although spec is not
clear on when to set CR flag, setting it always leads to
issues with some cards, hence set CR flag based on
CR flag in command details tag received from card.

Change-Id: Ia9a1334c9e1350e2e6cdaa66eb1e0673e5de9d46
CRs-fixed: 481803 356891
(cherry picked from commit 6aac3b2827d62c8a5297247c2af957a99ffd9a97)
(cherry picked from commit 917312567ac958d1740cdbb4454972f5aaab6dc7)
(cherry picked from commit 38c88f94f1a8890809813d6fbf933f1626fcd5c6)
Telephony: Managed Roaming feature re-design.

Add support to broadcast Managed Roaming intent.
When device is in manual network mode, if network rejects the
manual registration request with cause code "Persistent
location update reject", telephony broadcast this intent.

Change-Id: Ideadfb9320b057b332601dde0dc0305a2cb2905d
(cherry picked from commit 747624f61cc3cd5f3d259b6c68020388f2a63a27)
(cherry picked from commit e5454d0f03e8bc02aefb2cbe754b8a3533bcf4f0)
(cherry picked from commit 58efcb9e7241c0092a979d0250cb6676c13d9acd)
Add support CallBarring

Add support for CallBarring in the Phone App
CallBarring now supports the following
-Barr All Outgoing Calls
-Barr Outgoing International Calls
-Barr Outgoing International Calls except to Home Country
-Barr All Incoming Calls
-Barr Incoming Calls when Roaming outside the home country
-All Barring services

Change-Id: I6b69aaa422a06a8a839537ef658f24af32ace52c
CRs-Fixed: 520315
(cherry picked from commit 6180fa0ed7c598b43fe74c3ab85da35c771b9509)
(cherry picked from commit 8241883972952f120cba5cc1afcc13a5c497a61b)
(cherry picked from commit 61bd791952a6e4043dfae5414fee670640f1859c)
Use Data Radio Tech for concurrent voice and data support.

To determine concurrent voice and data support
we need to query Data Radio Tech.

Change-Id: I1fb43442e08915a7fff1cf2a5bcfb01d2a66a63b
CRs-Fixed: 505524
(cherry picked from commit dc86a90c2cde2e80fdec5fe26d7a13f6b475f322)
(cherry picked from commit f86deb32c3aa5cd73349f7142345c961258dedc0)
(cherry picked from commit 4afe1ddff73acad54e0bb068e85a6d099e356fbd)
Handle ICC IO error

Following changes have been made as part of this:
-> At present in Android all ICC Card states other than ICC
   PRESENT are treated as ICC ABSENT. Adding functionality
   to handle ICC IO error card state.
->IccCardProxy broadcasts card error intent when application index
  received from UIM is invalid(i.e.mUiccAplication is null) during
  initialization of card for fraction of time. As a result of which
  "Invalid Card" is displayed on UI momentarily.

  To fix this, When app index received from UIM is invalid broadcast
  "NOT_READY" intent.

Change-Id: I6489e5be0b64073c70bd12db645a4ac25b34af39
CRs-Fixed: 184479 399597
(cherry picked from commit dbc51a555f68d097a5dad9c54af88af8ba669721)
(cherry picked from commit fd68002b7b88e3132c7383b9eb2275b65d49e6d5)
(cherry picked from commit 6f29acdd155d1d99805d60aa3202b4d50d90d9fe)
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)
Update copyright to The Linux Foundation

Change-Id: I2954254ec766b882179edebdf7d98159495926a8
(cherry picked from commit 8942865fde6508368e93359a99c81eb0b91bb5f0)
(cherry picked from commit 1c77cf5378becfaeb9a8546ffe82d7daddcee509)
(cherry picked from commit 563e27b1eacd02e3d12540153ecae8978f5407a6)
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)