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

Commit 988c998e authored by Suchand Ghosh's avatar Suchand Ghosh Committed by Linux Build Service Account
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. Added a preference parameter to store the icon
status, in case it is not updated correctly by the network
operator.

Change-Id: I06ae47c8decae64807de78461382ca746900a8dd
CRs-Fixed: 275722
(cherry picked from commit e59de9c0944ccd8cc46dab1b03c95e965c670040)
(cherry picked from commit 8989aaf096fb9141277ae5ab483abbb887f7f452)
parent b0c1d7d5
Loading
Loading
Loading
Loading
+69 −1
Original line number Diff line number Diff line
@@ -106,6 +106,11 @@ public class GSMPhone extends PhoneBase {
    public static final String VM_NUMBER = "vm_number_key";
    // Key used to read/write the SIM IMSI used for storing the voice mail
    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";

    // Event constant for checking if Call Forwarding is enabled
    private static final int CHECK_CALLFORWARDING_STATUS = 75;

    // Instance Variables
    GsmCallTracker mCT;
@@ -287,6 +292,18 @@ public class GSMPhone extends PhoneBase {
        return mCT;
    }


    public boolean getCallForwardingIndicator() {
        boolean cf = false;
        IccRecords r = mIccRecords.get();
        if (r != null) {
            cf = r.getVoiceCallForwardingFlag();
        }
        if (!cf) {
            cf = getCallForwardingPreference();
        }
        return cf;
    }
    @Override
    public List<? extends MmiCode>
    getPendingMmiCodes() {
@@ -1159,6 +1176,45 @@ public class GSMPhone extends PhoneBase {
        }
    }

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

        // Using the same method as VoiceMail to be able to track when the sim card is changed.
        setVmSimImsi(getSubscriberId());
    }

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

        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
        boolean cf = sp.getBoolean(CF_ENABLED, false);
        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.
     */
    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(CHECK_CALLFORWARDING_STATUS);
            sendMessage(msg);
        }
    }

    private void
    onNetworkInitiatedUssd(GsmMmiCode mmi) {
@@ -1257,14 +1313,16 @@ public class GSMPhone extends PhoneBase {
                updateCurrentCarrierInProvider();

                // Check if this is a different SIM than the previous one. If so unset the
                // voice mail number.
                // voice mail number and the call forwarding flag.
                String imsi = getVmSimImsi();
                String imsiFromSIM = getSubscriberId();
                if (imsi != null && imsiFromSIM != null && !imsiFromSIM.equals(imsi)) {
                    storeVoiceMailNumber(null);
                    setCallForwardingPreference(false);
                    setVmSimImsi(null);
                }

                updateCallForwardStatus();
            break;

            case EVENT_GET_BASEBAND_VERSION_DONE:
@@ -1337,6 +1395,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);
@@ -1415,6 +1474,14 @@ public class GSMPhone extends PhoneBase {
                mmi.processSsData(ar);
                break;

            case CHECK_CALLFORWARDING_STATUS:
                boolean cfEnabled = getCallForwardingPreference();
                if (LOCAL_DEBUG) Rlog.d(LOG_TAG, "Callforwarding is " + cfEnabled);
                if (cfEnabled) {
                    notifyCallForwardingIndicator();
                }
                break;

             default:
                 super.handleMessage(msg);
        }
@@ -1543,6 +1610,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
@@ -1058,6 +1058,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);
                    }
                }

@@ -1415,6 +1416,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);
            }
        }

@@ -1441,6 +1443,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 {
+8 −0
Original line number Diff line number Diff line
@@ -529,6 +529,14 @@ public abstract class IccRecords extends Handler implements IccConstants {
        return null;
    }

    /**
     * Check if call forward info is stored on SIM
     * @return true if call forward info is stored on SIM.
     */
    public boolean isCallForwardStatusStored() {
        return false;
    }

    /**
     * Get the current Voice call forwarding flag for GSM/UMTS and the like SIMs
     *
+8 −0
Original line number Diff line number Diff line
@@ -466,6 +466,14 @@ public class SIMRecords extends IccRecords {
        return ((data != null) && (data[0] >= 1) && (data[0] <= 4));
    }

    /**
     * {@inheritDoc}
     */
     @Override
     public boolean isCallForwardStatusStored() {
         return (mEfCfis != null) || (mEfCff != null);
     }

    /**
     * {@inheritDoc}
     */