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

Commit 5e8836a7 authored by Yorke Lee's avatar Yorke Lee
Browse files

Fix PhoneAccountPreferences not being saved

* Add a dummy PhoneAccountHandle, which is used to differentiate
between the user selecting a null PhoneAccountHandle, and no
preference being present at all.

* Refactor getDefaultOutgoingPhoneAccount slightly and add
getUserSelectedOutgoingPhoneAccount. getUserSelectedOutgoingPhoneAccount
is only used by PhoneAccountPreferencesActivity to determine the user's
true selection. getDefaultOutgoingPhoneAccount will continue to behave
the same, and is the method that will be continue to be used to determine
the correct default PhoneAccount to use.

Bug: 17140770

Change-Id: I5f5b4940d3babde05d563024ee9618d5d65204ea
parent 5a3bb67b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ public class PhoneAccountPreferencesActivity extends Activity {
            mDefaultOutgoingAccount.setModel(
                    registrar,
                    registrar.getOutgoingPhoneAccounts(),
                    registrar.getDefaultOutgoingPhoneAccount(),
                    registrar.getUserSelectedOutgoingPhoneAccount(),
                    getString(R.string.account_ask_every_time));

            mSimCallManagerAccount.setModel(
+27 −10
Original line number Diff line number Diff line
@@ -64,6 +64,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
 */
public final class PhoneAccountRegistrar {

    public static final PhoneAccountHandle NO_ACCOUNT_SELECTED =
            new PhoneAccountHandle(new ComponentName("null", "null"), "NO_ACCOUNT_SELECTED");

    public abstract static class Listener {
        public void onAccountsChanged(PhoneAccountRegistrar registrar) {}
        public void onDefaultOutgoingChanged(PhoneAccountRegistrar registrar) {}
@@ -89,16 +92,9 @@ public final class PhoneAccountRegistrar {
    }

    public PhoneAccountHandle getDefaultOutgoingPhoneAccount() {
        if (mState.defaultOutgoing != null) {
            // Return the registered outgoing default iff it still exists (we keep a sticky
            // default to survive account deletion and re-addition)
            for (int i = 0; i < mState.accounts.size(); i++) {
                if (mState.accounts.get(i).getAccountHandle().equals(mState.defaultOutgoing)) {
                    return mState.defaultOutgoing;
                }
            }
            // At this point, there was a registered default but it has been deleted; proceed
            // as though there were no default
        final PhoneAccountHandle userSelected = getUserSelectedOutgoingPhoneAccount();
        if (userSelected != null) {
            return userSelected;
        }

        List<PhoneAccountHandle> outgoing = getOutgoingPhoneAccounts();
@@ -115,6 +111,21 @@ public final class PhoneAccountRegistrar {
        }
    }

    PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
        if (mState.defaultOutgoing != null) {
            // Return the registered outgoing default iff it still exists (we keep a sticky
            // default to survive account deletion and re-addition)
            for (int i = 0; i < mState.accounts.size(); i++) {
                if (mState.accounts.get(i).getAccountHandle().equals(mState.defaultOutgoing)) {
                    return mState.defaultOutgoing;
                }
            }
            // At this point, there was a registered default but it has been deleted; proceed
            // as though there were no default
        }
        return null;
    }

    public void setDefaultOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
        if (accountHandle == null) {
            // Asking to clear the default outgoing is a valid request
@@ -157,14 +168,20 @@ public final class PhoneAccountRegistrar {
                Log.d(this, "setSimCallManager: Not a call manager: %s", callManagerAccount);
                return;
            }
        } else {
            callManager = NO_ACCOUNT_SELECTED;
        }
        mState.simCallManager = callManager;

        write();
        fireSimCallManagerChanged();
    }

    public PhoneAccountHandle getSimCallManager() {
        if (mState.simCallManager != null) {
            if (NO_ACCOUNT_SELECTED.equals(mState.simCallManager)) {
                return null;
            }
            // Return the registered sim call manager iff it still exists (we keep a sticky
            // setting to survive account deletion and re-addition)
            for (int i = 0; i < mState.accounts.size(); i++) {