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

Commit 38ba1232 authored by Suchand Ghosh's avatar Suchand Ghosh Committed by Muhammed Siju
Browse files

Telephony: Call forwarding icon is shown after powerup.

If call forwarding was enabled, then the call forwarding
icon should be shown after the phone has powered down and
powered-up irrespective of SIM having EfCfis and EfCff.
Added a preference parameter to store the call forwarding
status, in case it's not updated correctly by the network
operator.

CRs-Fixed: 275722 795137 806156
Change-Id: I616d2e73fd75a58fc1628bedb34126b00d31cba1
parent 27d8ca44
Loading
Loading
Loading
Loading
+93 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.VoLteServiceState;
import android.telephony.ModemActivityInfo;
import android.text.TextUtils;
@@ -178,8 +179,9 @@ public abstract class PhoneBase extends Handler implements Phone {
    protected static final int EVENT_SS                             = 36;
    protected static final int EVENT_CONFIG_LCE                     = 37;
    private static final int EVENT_CHECK_FOR_NETWORK_AUTOMATIC      = 38;
    protected static final int EVENT_GET_CALLFORWARDING_STATUS      = 39;
    protected static final int EVENT_LAST                           =
            EVENT_CHECK_FOR_NETWORK_AUTOMATIC;
            EVENT_GET_CALLFORWARDING_STATUS;

    // For shared prefs.
    private static final String GSM_ROAMING_LIST_OVERRIDE_PREFIX = "gsm_roaming_list_";
@@ -195,6 +197,13 @@ public abstract class PhoneBase extends Handler implements Phone {
    // Key used to read/write the ID for storing the voice mail
    public static final String VM_ID = "vm_id_key";

    // Key used to read/write the SIM IMSI used for storing the imsi
    public static final String SIM_IMSI = "sim_imsi_key";
    // Key used to read/write SIM IMSI used for storing the imsi
    public static final String VM_SIM_IMSI = "vm_sim_imsi_key";
    // Key used to read/write if Call Forwarding is enabled
    public static final String CF_ENABLED = "cf_enabled_key";

    // Key used to read/write "disable DNS server check" pref (used for testing)
    public static final String DNS_SERVER_CHECK_DISABLED_KEY = "dns_server_check_disabled_key";

@@ -1441,6 +1450,89 @@ public abstract class PhoneBase extends Handler implements Phone {
        return (r != null) ? r.getVoiceCallForwardingFlag() : false;
    }

    /**
     * This method stores the CF_ENABLED flag in preferences
     * @param enabled
     */
    public void setCallForwardingPreference(boolean enabled) {
        Rlog.d(LOG_TAG, "Set callforwarding info to perferences");
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
        SharedPreferences.Editor edit = sp.edit();
        edit.putBoolean(CF_ENABLED + getSubId(), enabled);
        edit.commit();

        // set the sim imsi to be able to track when the sim card is changed.
        setSimImsi(getSubscriberId());
    }

    public boolean getCallForwardingPreference() {
        Rlog.d(LOG_TAG, "Get callforwarding info from perferences");

        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
        boolean cf = false;
        // Migrate CF enabled flag from phoneid based preference to subId based.
        boolean needMigration = false;
        String oldCfKey = null;
        if (TelephonyManager.getDefault().isMultiSimEnabled()) {
            if (!sp.contains(CF_ENABLED + getSubId()) && sp.contains(CF_ENABLED + mPhoneId)) {
                oldCfKey = CF_ENABLED + mPhoneId;
                needMigration = true;
            }
        } else {
            if (!sp.contains(CF_ENABLED + getSubId()) && sp.contains(CF_ENABLED)) {
                oldCfKey = CF_ENABLED;
                needMigration = true;
            }
        }
        if (needMigration) {
            // Save cf flag based on subId and remove old preference
            cf = sp.getBoolean(oldCfKey, false);
            setCallForwardingPreference(cf);
            SharedPreferences.Editor edit = sp.edit();
            edit.remove(oldCfKey);
            edit.commit();
            return cf;
        }
        cf = sp.getBoolean(CF_ENABLED + getSubId(), false);
        return cf;
    }

    public String getSimImsi() {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
        boolean needMigration = false;
        String oldImsiKey = null;
        if (TelephonyManager.getDefault().isMultiSimEnabled()) {
            //Migrate sim_imsi value for msim
            if (!sp.contains(SIM_IMSI + getSubId()) && sp.contains(VM_SIM_IMSI + mPhoneId)) {
                oldImsiKey = VM_SIM_IMSI + mPhoneId;
                needMigration = true;
            }
        } else {
            //Migrate sim_imsi value for single sim
            if (!sp.contains(SIM_IMSI + getSubId()) && sp.contains(VM_SIM_IMSI)) {
                oldImsiKey = VM_SIM_IMSI;
                needMigration = true;
            }
        }
        if (needMigration) {
            // Save imsi based on subId and remove old preference
            String imsi = sp.getString(oldImsiKey, null);
            setSimImsi(imsi);
            SharedPreferences.Editor editor = sp.edit();
            editor.remove(oldImsiKey);
            editor.commit();
            return imsi;
        }
        return sp.getString(SIM_IMSI + getSubId(), null);
    }

    public void setSimImsi(String imsi) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(SIM_IMSI + getSubId(), imsi);
        editor.apply();
    }

    /**
     *  Query the status of the CDMA roaming preference
     */
+12 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -31,6 +32,7 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.telephony.RadioAccessFamily;
import android.telephony.Rlog;
@@ -1665,6 +1667,16 @@ public class SubscriptionController extends ISub.Stub {
        return retVal;
    }

    public void removeStaleSubPreferences(String prefKey) {
        List<SubscriptionInfo> subInfoList = getAllSubInfoList(mContext.getOpPackageName());
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
        for (SubscriptionInfo subInfo : subInfoList) {
            if (subInfo.getSimSlotIndex() == -1) {
                sp.edit().remove(prefKey + subInfo.getSubscriptionId()).commit();
            }
        }
    }

    /**
     * Get the SIM state for the slot idx
     * @return SIM state as the ordinal of {@See IccCardConstants.State}
+40 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneNotifier;
import com.android.internal.telephony.PhoneProxy;
import com.android.internal.telephony.PhoneSubInfo;
import com.android.internal.telephony.SubscriptionController;
import com.android.internal.telephony.UUSInfo;
import com.android.internal.telephony.imsphone.ImsPhone;
import com.android.internal.telephony.test.SimulatedRadioControl;
@@ -325,6 +326,17 @@ public class GSMPhone extends PhoneBase {
        setVoiceMessageCount(countVoiceMessages);
    }

    public boolean getCallForwardingIndicator() {
        boolean cf = false;
        IccRecords r = mIccRecords.get();
        if (r != null && r.isCallForwardStatusStored()) {
            cf = r.getVoiceCallForwardingFlag();
        } else {
            cf = getCallForwardingPreference();
        }
        return cf;
    }

    @Override
    public List<? extends MmiCode>
    getPendingMmiCodes() {
@@ -1400,6 +1412,22 @@ public class GSMPhone extends PhoneBase {
        }
    }

    /**
     * Used to check if Call Forwarding status is present on sim card. If not, a message is
     * sent so we can check if the CF status is stored as a Shared Preference.
     */
    private void updateCallForwardStatus() {
        if (LOCAL_DEBUG) Rlog.d(LOG_TAG, "updateCallForwardStatus got sim records");
        IccRecords r = mIccRecords.get();
        if (r != null && r.isCallForwardStatusStored()) {
            // The Sim card has the CF info
            if (LOCAL_DEBUG) Rlog.d(LOG_TAG, "Callforwarding info is present on sim");
            notifyCallForwardingIndicator();
        } else {
            Message msg = obtainMessage(EVENT_GET_CALLFORWARDING_STATUS);
            sendMessage(msg);
        }
    }

    private void
    onNetworkInitiatedUssd(GsmMmiCode mmi) {
@@ -1524,11 +1552,16 @@ public class GSMPhone extends PhoneBase {
                String imsiFromSIM = getSubscriberId();
                if (imsi != null && imsiFromSIM != null && !imsiFromSIM.equals(imsi)) {
                    storeVoiceMailNumber(null);
                    setCallForwardingPreference(false);
                    setVmSimImsi(null);
                    SubscriptionController controller =
                            SubscriptionController.getInstance();
                    controller.removeStaleSubPreferences(CF_ENABLED);
                }

                mSimRecordsLoadedRegistrants.notifyRegistrants();
                updateVoiceMail();
                updateCallForwardStatus();
            break;

            case EVENT_GET_BASEBAND_VERSION_DONE:
@@ -1608,6 +1641,7 @@ public class GSMPhone extends PhoneBase {
                Cfu cfu = (Cfu) ar.userObj;
                if (ar.exception == null && r != null) {
                    r.setVoiceCallForwardingFlag(1, msg.arg1 == 1, cfu.mSetCfNumber);
                    setCallForwardingPreference(msg.arg1 == 1);
                }
                if (cfu.mOnComplete != null) {
                    AsyncResult.forMessage(cfu.mOnComplete, ar.result, ar.exception);
@@ -1680,6 +1714,11 @@ public class GSMPhone extends PhoneBase {
                mmi.processSsData(ar);
                break;

            case EVENT_GET_CALLFORWARDING_STATUS:
                if (LOCAL_DEBUG) Rlog.d(LOG_TAG, "EVENT_GET_CALLFORWARDING_STATUS");
                notifyCallForwardingIndicator();
                break;

             default:
                 super.handleMessage(msg);
        }
@@ -1789,6 +1828,7 @@ public class GSMPhone extends PhoneBase {
            } else {
                for (int i = 0, s = infos.length; i < s; i++) {
                    if ((infos[i].serviceClass & SERVICE_CLASS_VOICE) != 0) {
                        setCallForwardingPreference(infos[i].status == 1);
                        r.setVoiceCallForwardingFlag(1, (infos[i].status == 1),
                            infos[i].number);
                        // should only have the one
+3 −0
Original line number Diff line number Diff line
@@ -1091,6 +1091,7 @@ public final class GsmMmiCode extends Handler implements MmiCode {
                    boolean cffEnabled = (msg.arg2 == 1);
                    if (mIccRecords != null) {
                        mIccRecords.setVoiceCallForwardingFlag(1, cffEnabled, mDialingNumber);
                        mPhone.setCallForwardingPreference(cffEnabled);
                    }
                }

@@ -1450,6 +1451,7 @@ public final class GsmMmiCode extends Handler implements MmiCode {
            boolean cffEnabled = (info.status == 1);
            if (mIccRecords != null) {
                mIccRecords.setVoiceCallForwardingFlag(1, cffEnabled, info.number);
                mPhone.setCallForwardingPreference(cffEnabled);
            }
        }

@@ -1483,6 +1485,7 @@ public final class GsmMmiCode extends Handler implements MmiCode {

                // Set unconditional CFF in SIM to false
                if (mIccRecords != null) {
                    mPhone.setCallForwardingPreference(false);
                    mIccRecords.setVoiceCallForwardingFlag(1, false, null);
                }
            } else {
+43 −0
Original line number Diff line number Diff line
@@ -264,6 +264,34 @@ public class ImsPhone extends ImsPhoneBase {
        return mCT;
    }

    public boolean getCallForwardingIndicator() {
        boolean cf = false;
        IccRecords r = getIccRecords();
        if (r != null && r.isCallForwardStatusStored()) {
            cf = r.getVoiceCallForwardingFlag();
        } else {
            cf = getCallForwardingPreference();
        }
        return cf;
    }

    /**
     * Used to check if Call Forwarding status is present on sim card. If not, a message is
     * sent so we can check if the CF status is stored as a Shared Preference.
     */
    public void updateCallForwardStatus() {
        Rlog.d(LOG_TAG, "updateCallForwardStatus");
        IccRecords r = getIccRecords();
        if (r != null && r.isCallForwardStatusStored()) {
            // The Sim card has the CF info
            Rlog.d(LOG_TAG, "Callforwarding info is present on sim");
            notifyCallForwardingIndicator();
        } else {
            Message msg = obtainMessage(EVENT_GET_CALLFORWARDING_STATUS);
            sendMessage(msg);
        }
    }

    @Override
    public List<? extends ImsPhoneMmiCode>
    getPendingMmiCodes() {
@@ -1136,6 +1164,12 @@ public class ImsPhone extends ImsPhoneBase {
        return mDefaultPhone.getSubId();
    }

    @Override
    public String getSubscriberId() {
        IccRecords r = getIccRecords();
        return (r != null) ? r.getIMSI() : null;
    }

    @Override
    public int getPhoneId() {
        return mDefaultPhone.getPhoneId();
@@ -1174,6 +1208,7 @@ public class ImsPhone extends ImsPhoneBase {
            for (int i = 0, s = infos.length; i < s; i++) {
                if (infos[i].mCondition == ImsUtInterface.CDIV_CF_UNCONDITIONAL) {
                    if (r != null) {
                        setCallForwardingPreference(infos[i].mStatus == 1);
                        r.setVoiceCallForwardingFlag(1, (infos[i].mStatus == 1),
                            infos[i].mNumber);
                    }
@@ -1241,9 +1276,11 @@ public class ImsPhone extends ImsPhoneBase {
                IccRecords r = getIccRecords();
                Cf cf = (Cf) ar.userObj;
                if (cf.mIsCfu && ar.exception == null && r != null) {
                    setCallForwardingPreference(msg.arg1 == 1);
                    r.setVoiceCallForwardingFlag(1, msg.arg1 == 1, cf.mSetCfNumber);
                }
                sendResponse(cf.mOnComplete, null, ar.exception);
                updateCallForwardStatus();
                break;

            case EVENT_GET_CALL_FORWARD_DONE:
@@ -1252,6 +1289,7 @@ public class ImsPhone extends ImsPhoneBase {
                    cfInfos = handleCfQueryResult((ImsCallForwardInfo[])ar.result);
                }
                sendResponse((Message) ar.userObj, cfInfos, ar.exception);
                updateCallForwardStatus();
                break;

             case EVENT_GET_CALL_BARRING_DONE:
@@ -1287,6 +1325,11 @@ public class ImsPhone extends ImsPhoneBase {
                 updateDataServiceState();
                 break;

             case EVENT_GET_CALLFORWARDING_STATUS:
                 if (DBG) Rlog.d(LOG_TAG, "EVENT_GET_CALLFORWARDING_STATUS");
                 notifyCallForwardingIndicator();
                 break;

             default:
                 super.handleMessage(msg);
                 break;
Loading