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

Commit eadee841 authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Save call forwarding flag in SharedPreference.

Bug: 22822731
Change-Id: I801738685b65fc0ee0410c1ad4925d15694c81f4
parent 36767c5d
Loading
Loading
Loading
Loading
+55 −3
Original line number Diff line number Diff line
@@ -190,6 +190,11 @@ 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 for storing call forwarding status
    public static final String CF_STATUS = "cf_status_key";
    // Key used to read/write the ID for storing the call forwarding status
    public static final String CF_ID = "cf_id_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";

@@ -1447,10 +1452,58 @@ public abstract class PhoneBase extends Handler implements Phone {
        return mVmCount != 0;
    }

    private int getCallForwardingIndicatorFromSharedPref() {
        int status = IccRecords.CALL_FORWARDING_STATUS_DISABLED;
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
        String subscriberId = sp.getString(CF_ID, null);
        String currentSubscriberId = getSubscriberId();

        if (currentSubscriberId != null && currentSubscriberId.equals(subscriberId)) {
            // get call forwarding status from preferences
            status = sp.getInt(CF_STATUS, IccRecords.CALL_FORWARDING_STATUS_DISABLED);
            Rlog.d(LOG_TAG, "Call forwarding status from preference = " + status);
        } else {
            Rlog.d(LOG_TAG, "Call forwarding status retrieval returning DISABLED as status for " +
                    "matching subscriberId not found");

        }
        return status;
    }

    private void setCallForwardingIndicatorInSharedPref(boolean enable) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
        SharedPreferences.Editor editor = sp.edit();

        String imsi = getSubscriberId();

        editor.putInt(CF_STATUS, enable ? IccRecords.CALL_FORWARDING_STATUS_ENABLED :
                IccRecords.CALL_FORWARDING_STATUS_DISABLED);
        editor.putString(CF_ID, imsi);
        editor.apply();
    }

    public void setVoiceCallForwardingFlag(int line, boolean enable, String number) {
        setCallForwardingIndicatorInSharedPref(enable);
        mIccRecords.get().setVoiceCallForwardingFlag(line, enable, number);
    }

    protected void setVoiceCallForwardingFlag(IccRecords r, int line, boolean enable,
                                              String number) {
        setCallForwardingIndicatorInSharedPref(enable);
        r.setVoiceCallForwardingFlag(line, enable, number);
    }

    @Override
    public boolean getCallForwardingIndicator() {
        IccRecords r = mIccRecords.get();
        return (r != null) ? r.getVoiceCallForwardingFlag() : false;
        int callForwardingIndicator = IccRecords.CALL_FORWARDING_STATUS_UNKNOWN;
        if (r != null) {
            callForwardingIndicator = r.getVoiceCallForwardingFlag();
        }
        if (callForwardingIndicator == IccRecords.CALL_FORWARDING_STATUS_UNKNOWN) {
            callForwardingIndicator = getCallForwardingIndicatorFromSharedPref();
        }
        return (callForwardingIndicator == IccRecords.CALL_FORWARDING_STATUS_ENABLED);
    }

    /**
@@ -1722,8 +1775,7 @@ public abstract class PhoneBase extends Handler implements Phone {
        String subscriberId = sp.getString(VM_ID, null);
        String currentSubscriberId = getSubscriberId();

        if ((subscriberId != null) && (currentSubscriberId != null)
                && (currentSubscriberId.equals(subscriberId))) {
        if (currentSubscriberId != null && currentSubscriberId.equals(subscriberId)) {
            // get voice mail count from preferences
            countVoiceMessages = sp.getInt(VM_COUNT, 0);
            Rlog.d(LOG_TAG, "Voice Mail Count from preference = " + countVoiceMessages);
+3 −3
Original line number Diff line number Diff line
@@ -1582,7 +1582,7 @@ public class GSMPhone extends PhoneBase {
                IccRecords r = mIccRecords.get();
                Cfu cfu = (Cfu) ar.userObj;
                if (ar.exception == null && r != null) {
                    r.setVoiceCallForwardingFlag(1, msg.arg1 == 1, cfu.mSetCfNumber);
                    setVoiceCallForwardingFlag(1, msg.arg1 == 1, cfu.mSetCfNumber);
                }
                if (cfu.mOnComplete != null) {
                    AsyncResult.forMessage(cfu.mOnComplete, ar.result, ar.exception);
@@ -1744,11 +1744,11 @@ public class GSMPhone extends PhoneBase {
            if (infos == null || infos.length == 0) {
                // Assume the default is not active
                // Set unconditional CFF in SIM to false
                r.setVoiceCallForwardingFlag(1, false, null);
                setVoiceCallForwardingFlag(1, false, null);
            } else {
                for (int i = 0, s = infos.length; i < s; i++) {
                    if ((infos[i].serviceClass & SERVICE_CLASS_VOICE) != 0) {
                        r.setVoiceCallForwardingFlag(1, (infos[i].status == 1),
                        setVoiceCallForwardingFlag(1, (infos[i].status == 1),
                            infos[i].number);
                        // should only have the one
                        break;
+4 −4
Original line number Diff line number Diff line
@@ -307,7 +307,7 @@ public final class GsmMmiCode extends Handler implements MmiCode {

                    Rlog.d(LOG_TAG, "setVoiceCallForwardingFlag cffEnabled: " + cffEnabled);
                    if (mIccRecords != null) {
                        mIccRecords.setVoiceCallForwardingFlag(1, cffEnabled, null);
                        mPhone.setVoiceCallForwardingFlag(1, cffEnabled, null);
                        Rlog.d(LOG_TAG, "setVoiceCallForwardingFlag done from SS Info.");
                    } else {
                        Rlog.e(LOG_TAG, "setVoiceCallForwardingFlag aborted. sim records is null.");
@@ -1090,7 +1090,7 @@ public final class GsmMmiCode extends Handler implements MmiCode {
                if ((ar.exception == null) && (msg.arg1 == 1)) {
                    boolean cffEnabled = (msg.arg2 == 1);
                    if (mIccRecords != null) {
                        mIccRecords.setVoiceCallForwardingFlag(1, cffEnabled, mDialingNumber);
                        mPhone.setVoiceCallForwardingFlag(1, cffEnabled, mDialingNumber);
                    }
                }

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

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

                // Set unconditional CFF in SIM to false
                if (mIccRecords != null) {
                    mIccRecords.setVoiceCallForwardingFlag(1, false, null);
                    mPhone.setVoiceCallForwardingFlag(1, false, null);
                }
            } else {

+3 −3
Original line number Diff line number Diff line
@@ -1154,13 +1154,13 @@ public class ImsPhone extends ImsPhoneBase {
            if (r != null) {
                // Assume the default is not active
                // Set unconditional CFF in SIM to false
                r.setVoiceCallForwardingFlag(1, false, null);
                setVoiceCallForwardingFlag(r, 1, false, null);
            }
        } else {
            for (int i = 0, s = infos.length; i < s; i++) {
                if (infos[i].mCondition == ImsUtInterface.CDIV_CF_UNCONDITIONAL) {
                    if (r != null) {
                        r.setVoiceCallForwardingFlag(1, (infos[i].mStatus == 1),
                        setVoiceCallForwardingFlag(r, 1, (infos[i].mStatus == 1),
                            infos[i].mNumber);
                    }
                }
@@ -1230,7 +1230,7 @@ public class ImsPhone extends ImsPhoneBase {
                IccRecords r = getIccRecords();
                Cf cf = (Cf) ar.userObj;
                if (cf.mIsCfu && ar.exception == null && r != null) {
                    r.setVoiceCallForwardingFlag(1, msg.arg1 == 1, cf.mSetCfNumber);
                    setVoiceCallForwardingFlag(r, 1, msg.arg1 == 1, cf.mSetCfNumber);
                }
                sendResponse(cf.mOnComplete, null, ar.exception);
                break;
+3 −3
Original line number Diff line number Diff line
@@ -1049,7 +1049,7 @@ public final class ImsPhoneMmiCode extends Handler implements MmiCode {
                if ((ar.exception == null) && (msg.arg1 == 1)) {
                    boolean cffEnabled = (msg.arg2 == 1);
                    if (mIccRecords != null) {
                        mIccRecords.setVoiceCallForwardingFlag(1, cffEnabled, mDialingNumber);
                        mPhone.setVoiceCallForwardingFlag(1, cffEnabled, mDialingNumber);
                    }
                }

@@ -1300,7 +1300,7 @@ public final class ImsPhoneMmiCode extends Handler implements MmiCode {
                        == CommandsInterface.SERVICE_CLASS_VOICE) {
            boolean cffEnabled = (info.status == 1);
            if (mIccRecords != null) {
                mIccRecords.setVoiceCallForwardingFlag(1, cffEnabled, info.number);
                mPhone.setVoiceCallForwardingFlag(1, cffEnabled, info.number);
            }
        }

@@ -1338,7 +1338,7 @@ public final class ImsPhoneMmiCode extends Handler implements MmiCode {

                // Set unconditional CFF in SIM to false
                if (mIccRecords != null) {
                    mIccRecords.setVoiceCallForwardingFlag(1, false, null);
                    mPhone.setVoiceCallForwardingFlag(1, false, null);
                }
            } else {

Loading