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

Commit be207a16 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "Merge commit Fix for SimSettings.java"

parents 4cbcc2f8 d99988fa
Loading
Loading
Loading
Loading
+49 −106
Original line number Diff line number Diff line
@@ -17,12 +17,15 @@
package com.android.settings.sim;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.ContentUris;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemProperties;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
@@ -34,6 +37,7 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.PhoneStateListener;
import android.text.Editable;
import android.text.TextUtils;
@@ -56,8 +60,6 @@ import com.android.settings.search.Indexable.SearchIndexProvider;
import com.android.settings.R;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

@@ -355,30 +357,36 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
    }

    private void updateCellularDataValues() {
        final Preference simPref = findPreference(KEY_CELLULAR_DATA);
        final SubscriptionInfo sir = Utils.findRecordBySubId(getActivity(),
                SubscriptionManager.getDefaultDataSubId());
        simPref.setTitle(R.string.cellular_data_title);
        if (DBG) log("[updateCellularDataValues] mSubInfoList=" + mSubInfoList);

        final DropDownPreference simPref = findPreference(KEY_CELLULAR_DATA);
        final SubscriptionInfo sir = findRecordBySubId(SubscriptionManager.getDefaultDataSubId());
        boolean isCellularDataEnabled = false;
        if (sir != null) {
            simPref.setSummary(sir.getDisplayName());
        } else if (sir == null) {
            simPref.setSummary(R.string.sim_selection_required_pref);
            simPref.setSelectedValue(sir, false);
        }
        simPref.setEnabled(mSelectableSubInfos.size() >= 1);
        if (mNumSims > 1 && !needDisableDataSub2()) {
            isCellularDataEnabled = true;
        }
        simPref.setEnabled(isCellularDataEnabled);
        updateCellularDataPreference();
    }

    private void updateCallValues() {
        final Preference simPref = findPreference(KEY_CALLS);
        final TelecomManager telecomManager = TelecomManager.from(getActivity());
        final PhoneAccountHandle phoneAccount =
            telecomManager.getUserSelectedOutgoingPhoneAccount();

        simPref.setTitle(R.string.calls_title);
        simPref.setSummary(phoneAccount == null
                ? getResources().getString(R.string.sim_selection_required_pref)
                : (String)telecomManager.getPhoneAccount(phoneAccount).getLabel());
    private void updateCellularDataPreference() {
        final DropDownPreference simPref = (DropDownPreference) findPreference(KEY_CELLULAR_DATA);
        boolean callStateIdle = isCallStateIdle();
        // Enable data preference in msim mode and call state idle
        boolean disableCellulardata = getResources().getBoolean(R.bool.disbale_cellular_data);
        simPref.setEnabled((mNumSims > 1) && callStateIdle && (!disableCellulardata));
        // Display toast only once when the user enters the activity even though the call moves
        // through multiple call states (eg - ringing to offhook for incoming calls)
        if (callStateIdle == false && inActivity && dataDisableToastDisplayed == false) {
            Toast.makeText(getActivity(), R.string.data_disabled_in_active_call,
                    Toast.LENGTH_SHORT).show();
            dataDisableToastDisplayed = true;
        }
        // Reset dataDisableToastDisplayed
        if (callStateIdle == true) {
            dataDisableToastDisplayed = false;
        }
    }

    private boolean isCallStateIdle() {
@@ -392,6 +400,18 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
        return callStateIdle;
    }

    private void updateCallValues() {
        final Preference simPref = findPreference(KEY_CALLS);
        final TelecomManager telecomManager = TelecomManager.from(getActivity());
        final PhoneAccountHandle phoneAccount =
            telecomManager.getUserSelectedOutgoingPhoneAccount();

        simPref.setTitle(R.string.calls_title);
        simPref.setSummary(phoneAccount == null
                ? getResources().getString(R.string.sim_calls_ask_first_prefs_title)
                : (String)telecomManager.getPhoneAccount(phoneAccount).getLabel());
    }

    @Override
    public void onPause() {
        super.onPause();
@@ -413,80 +433,6 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
        updateAllOptions();
    }

    @Override
    public Dialog onCreateDialog(final int id) {
        final ArrayList<String> list = new ArrayList<String>();
        final int selectableSubInfoLength = mSelectableSubInfos.size();

        final DialogInterface.OnClickListener selectionListener =
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int value) {

                        final SubscriptionInfo sir;

                        if (id == DATA_PICK) {
                            sir = mSelectableSubInfos.get(value);
                            mSubscriptionManager.setDefaultDataSubId(sir.getSubscriptionId());
                        } else if (id == CALLS_PICK) {
                            final TelecomManager telecomManager =
                                    TelecomManager.from(getActivity());
                            final List<PhoneAccountHandle> phoneAccountsList =
                                    telecomManager.getCallCapablePhoneAccounts();
                            telecomManager.setUserSelectedOutgoingPhoneAccount(
                                    value < 1 ? null : phoneAccountsList.get(value - 1));
                        } else if (id == SMS_PICK) {
                            sir = mSelectableSubInfos.get(value);
                            mSubscriptionManager.setDefaultSmsSubId(sir.getSubscriptionId());
                        }

                        updateActivitesCategory();
                    }
                };

        if (id == CALLS_PICK) {
            final TelecomManager telecomManager = TelecomManager.from(getActivity());
            final Iterator<PhoneAccountHandle> phoneAccounts =
                    telecomManager.getCallCapablePhoneAccounts().listIterator();

            list.add(getResources().getString(R.string.sim_calls_ask_first_prefs_title));
            while (phoneAccounts.hasNext()) {
                final PhoneAccount phoneAccount =
                        telecomManager.getPhoneAccount(phoneAccounts.next());
                list.add((String)phoneAccount.getLabel());
            }
        } else {
            for (int i = 0; i < selectableSubInfoLength; ++i) {
                final SubscriptionInfo sir = mSelectableSubInfos.get(i);
                CharSequence displayName = sir.getDisplayName();
                if (displayName == null) {
                    displayName = "";
                }
                list.add(displayName.toString());
            }
        }

        String[] arr = list.toArray(new String[0]);

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        ListAdapter adapter = new SelectAccountListAdapter(
                builder.getContext(),
                R.layout.select_account_list_item,
                arr, id);

        if (id == DATA_PICK) {
            builder.setTitle(R.string.select_sim_for_data);
        } else if (id == CALLS_PICK) {
            builder.setTitle(R.string.select_sim_for_calls);
        } else if (id == SMS_PICK) {
            builder.setTitle(R.string.sim_card_select_title);
        }

        return builder.setAdapter(adapter, selectionListener)
            .create();
    }

    private void initLTEPreference() {
        boolean isPrimarySubFeatureEnable = SystemProperties
                .getBoolean("persist.radio.primarycard", false);
@@ -596,15 +542,12 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
                        SubscriptionManager.from(getActivity()).setDefaultDataSubId(subId);
                    }
                } else if (simPref.getKey().equals(KEY_CALLS)) {
                    //subId 0 is meant for "Ask First"/"Prompt" option as per AOSP
                    if (subId == 0) {
                        SubscriptionManager.setVoicePromptEnabled(true);
                    } else {
                        SubscriptionManager.setVoicePromptEnabled(false);
                        if (SubscriptionManager.getDefaultVoiceSubId() != subId) {
                            SubscriptionManager.from(getActivity()).setDefaultVoiceSubId(subId);
                        }
                    }
                    final TelecomManager telecomManager =
                            TelecomManager.from(getActivity());
                    final List<PhoneAccountHandle> phoneAccountsList =
                            telecomManager.getCallCapablePhoneAccounts();
                    telecomManager.setUserSelectedOutgoingPhoneAccount(
                            value < 1 ? null : phoneAccountsList.get(value - 1));
                } else if (simPref.getKey().equals(KEY_SMS)) {
                    if (subId == 0) {
                        SubscriptionManager.setSMSPromptEnabled(true);