Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fde20da1 authored by Fang Yunong's avatar Fang Yunong Committed by Gerrit - the friendly Code Review server
Browse files

InCallUI: Add international prefix support

When international prefix is enabled in CDMA mode, check and
convert international prefix.

When MO/MT call, check phone number with international prefix.
add flag of whether with international prefix,if has prefix,
will add the prefix before the number,eg:+33.
API name change:
in M Android:SubscriptionManager.getDefaultVoiceSubId();
in N :SubscriptionManager.getDefaultVoiceSubscriptionId().

Change-Id: I62071721b4e5217063872f604fa5cc3f0a2676dd
CRs-fixed: 1037633
parent 017d2e5d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -24,4 +24,6 @@
    <!-- The number of milliseconds after which a video call will automatically enter fullscreen
         mode (requires video_call_auto_fullscreen to be true). -->
    <integer name="video_call_auto_fullscreen_timeout">5000</integer>
    <!-- When international prefix is enabled in CDMA mode, whether with international prefix -->
    <bool name="phone_number_with_intl_prefix">false</bool>
</resources>
+44 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2015, The Linux Foundation. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.
    * Neither the name of The Linux Foundation nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<resources>

    <!--
        customize the default value to check idp, default value is none,
        0-none, 1-CDMA, 2-GSM, 3-CDMA/GSM
    -->
    <integer name="check_idp" translatable="false">0</integer>
    <!-- the international_idp array index that check phone roaming
        state, -1:none-->
    <integer name="check_idp_roaming_idx" translatable="false">-1</integer>
    <!-- the international_idp array index that to be reconverted,
       -1:none-->
    <integer name="check_idp_reconvert_idx" translatable="false">-1</integer>

</resources>
+9 −0
Original line number Diff line number Diff line
@@ -168,4 +168,13 @@
    <string name="low_battery_msg">Your battery level is below 15%. Do you want to continue with the video call or convert it to Voice call</string>
    <!-- No option of the low battery alert dialog for MO/MT Video calls -->
    <string name="low_battery_convert">Convert</string>
    <!-- International prefix source-->
    <string-array name="international_idp" translatable="false">
        <item>+33</item>
    </string-array>

    <!-- International prefix converted value-->
    <string-array name="international_idp_values" translatable="false">
        <item>"0033"</item>
    </string-array>
</resources>
+88 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
import android.telephony.PhoneNumberUtils;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
@@ -76,6 +77,11 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi>
    private static final String TAG = CallCardPresenter.class.getSimpleName();
    private static final long CALL_TIME_UPDATE_INTERVAL_MS = 1000;

    private static final int IDP_NONE = 0;
    private static final int IDP_CDMA = 1;
    private static final int IDP_GSM = 2;
    private static final int IDP_BOTH = 3;

    private final EmergencyCallListener mEmergencyCallListener =
            ObjectFactory.newEmergencyCallListener();
    private DistanceHelper mDistanceHelper;
@@ -753,6 +759,82 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi>
        return retval;
    }

    private boolean checkIdpEnable(int subId) {
        boolean ret = false;
        final int checkIdp = mContext.getResources().getInteger(R.integer.check_idp);
        final int phoneType = TelephonyManager.getDefault().getCurrentPhoneType(subId);

        if (checkIdp == IDP_BOTH ||
                (checkIdp == IDP_CDMA && phoneType == TelephonyManager.PHONE_TYPE_CDMA) ||
                (checkIdp == IDP_GSM && phoneType == TelephonyManager.PHONE_TYPE_GSM)) {
            ret = true;
        }

        Log.i(this, "checkIdp phone type:" + phoneType + " enabled:" + ret);
        return ret;
    }

    private int getSubId() {
        int subId = SubscriptionManager.getDefaultVoiceSubscriptionId();

        PhoneAccountHandle accountHandle = mPrimary.getAccountHandle();
        if (accountHandle != null) {
            TelecomManager mgr = InCallPresenter.getInstance().getTelecomManager();
            PhoneAccount account = mgr.getPhoneAccount(accountHandle);
            if (account != null) {
                subId = TelephonyManager.getDefault().getSubIdForPhoneAccount(account);
                Log.d(this, "get sub id from phone account = " + subId);
            }
        }

        return subId;
    }

    private String checkIdp(String number, boolean nameIsNumber, boolean isIncoming) {
        int subId = getSubId();
        String checkedNumber = number;
        String[] idp = mContext.getResources().getStringArray(R.array.international_idp);
        String[] idpValues = mContext.getResources().
                getStringArray(R.array.international_idp_values);
        boolean isDataInValid = (idp.length == 0 || idpValues.length == 0 ||
                idp.length != idpValues.length);

        if (checkIdpEnable(subId) && nameIsNumber && !isDataInValid) {
            if (!isIncoming) {
                final int checkRoamingIdx = mContext.getResources().
                        getInteger(R.integer.check_idp_roaming_idx);
                final boolean isNetworkRoaming =
                        TelephonyManager.getDefault().isNetworkRoaming(subId);
                for (int i = 0; i < idp.length; i++) {
                    Log.i(this, "checkIdp idp:" + idp[i] + " idp value:" + idpValues[i] +
                            " roaming idx:" + checkRoamingIdx);
                    int indexIdp = checkedNumber.indexOf(idp[i]);

                    if (indexIdp != -1) {
                        if ((checkRoamingIdx == i && !isNetworkRoaming) ||
                                checkRoamingIdx != i) {
                            checkedNumber = checkedNumber.substring(0, indexIdp) + idpValues[i] +
                                    checkedNumber.substring(indexIdp + idp[i].length());
                        }
                    }
                }
            } else {
                final int checkReconvertIdx = mContext.getResources().
                        getInteger(R.integer.check_idp_reconvert_idx);
                if (checkReconvertIdx >= 0 && checkReconvertIdx < idp.length &&
                        number.indexOf(idpValues[checkReconvertIdx]) == 0) {
                    checkedNumber = idp[checkReconvertIdx] +
                            number.substring(idpValues[checkReconvertIdx].length());
                }
            }
        }

        Log.i(this, "checkIdp number: " + number + " subid:" + subId + " isIncoming:" +
                isIncoming + " checked number:" + checkedNumber + " inValid:" +
                isDataInValid + " nameIsNumber" + nameIsNumber);
        return checkedNumber;
    }

    private void updatePrimaryDisplayInfo() {
        final CallCardUi ui = getUi();
        if (ui == null) {
@@ -821,6 +903,12 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi>
            boolean nameIsNumber = name != null && name.equals(mPrimaryContactInfo.number);
            // Call with caller that is a work contact.
            boolean isWorkContact = (mPrimaryContactInfo.userType == ContactsUtils.USER_TYPE_WORK);
            boolean isIncoming = mPrimary.getState() == Call.State.INCOMING;
            boolean isWithPrefix = mContext.getResources().
                getBoolean(R.bool.phone_number_with_intl_prefix);
            if(isWithPrefix == true){
                name = checkIdp(name, nameIsNumber, isIncoming);
            }
            ui.setPrimary(
                    number,
                    name,