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

Commit e810ddb0 authored by PauloftheWest's avatar PauloftheWest Committed by jianzhou
Browse files

Changed SIM calls to use PhoneAccount instead of SubInfoRecord.

+ Some import cleanup on SimSettings.

Change-Id: Ib18673f4eb0ce404bf13a58e0979401cca91385d
parent 27e434ff
Loading
Loading
Loading
Loading
+105 −50
Original line number Original line Diff line number Diff line
@@ -16,30 +16,24 @@


package com.android.settings.sim;
package com.android.settings.sim;


import android.provider.SearchIndexableResource;

import com.android.settings.R;

import android.app.AlertDialog;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.content.Intent;
import android.content.Context;
import android.content.Context;
import android.content.ContentUris;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.content.res.Resources;
import android.content.DialogInterface;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemProperties;
import android.preference.Preference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.preference.PreferenceScreen;
import android.provider.SearchIndexableResource;
import android.provider.Settings.SettingNotFoundException;
import android.provider.Settings.SettingNotFoundException;
import android.provider.Telephony;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccount;
import android.telephony.CellInfo;
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneStateListener;
import android.telephony.PhoneStateListener;
import android.text.Editable;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextUtils;
@@ -50,17 +44,21 @@ import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toast;
import com.android.settings.MultiSimSettingTab;
import android.app.Dialog;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyIntents;

import com.android.settings.RestrictedSettingsFragment;
import com.android.settings.RestrictedSettingsFragment;
import com.android.settings.Utils;
import com.android.settings.Utils;
import com.android.settings.notification.DropDownPreference;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.search.Indexable;
import com.android.settings.search.Indexable.SearchIndexProvider;
import com.android.settings.search.Indexable.SearchIndexProvider;
import com.android.settings.R;


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


public class SimSettings extends RestrictedSettingsFragment implements Indexable, TextWatcher {
public class SimSettings extends RestrictedSettingsFragment implements Indexable, TextWatcher {
@@ -382,36 +380,30 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
    }
    }


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

        if (sir != null) {
        if (sir != null) {
            simPref.setSelectedValue(sir, false);
            simPref.setSummary(sir.getDisplayName());
        } else if (sir == null) {
            simPref.setSummary(R.string.sim_selection_required_pref);
        }
        }
        if (mNumSims > 1 && !needDisableDataSub2()) {
        simPref.setEnabled(mSelectableSubInfos.size() >= 1);
            isCellularDataEnabled = true;
        }
        simPref.setEnabled(isCellularDataEnabled);
        updateCellularDataPreference();
    }
    }


    private void updateCellularDataPreference() {
    private void updateCallValues() {
        final DropDownPreference simPref = (DropDownPreference) findPreference(KEY_CELLULAR_DATA);
        final Preference simPref = findPreference(KEY_CALLS);
        boolean callStateIdle = isCallStateIdle();
        final TelecomManager telecomManager = TelecomManager.from(getActivity());
        // Enable data preference in msim mode and call state idle
        final PhoneAccountHandle phoneAccount =
        boolean disableCellulardata = getResources().getBoolean(R.bool.disbale_cellular_data);
            telecomManager.getUserSelectedOutgoingPhoneAccount();
        simPref.setEnabled((mNumSims > 1) && callStateIdle && (!disableCellulardata));

        // Display toast only once when the user enters the activity even though the call moves
        simPref.setTitle(R.string.calls_title);
        // through multiple call states (eg - ringing to offhook for incoming calls)
        simPref.setSummary(phoneAccount == null
        if (callStateIdle == false && inActivity && dataDisableToastDisplayed == false) {
                ? getResources().getString(R.string.sim_selection_required_pref)
            Toast.makeText(getActivity(), R.string.data_disabled_in_active_call,
                : (String)telecomManager.getPhoneAccount(phoneAccount).getLabel());
                    Toast.LENGTH_SHORT).show();
            dataDisableToastDisplayed = true;
        }
        // Reset dataDisableToastDisplayed
        if (callStateIdle == true) {
            dataDisableToastDisplayed = false;
        }
    }
    }


    private boolean isCallStateIdle() {
    private boolean isCallStateIdle() {
@@ -425,17 +417,6 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
        return callStateIdle;
        return callStateIdle;
    }
    }


    private void updateCallValues() {
        final DropDownPreference simPref = (DropDownPreference) findPreference(KEY_CALLS);
        int subId = SubscriptionManager.isVoicePromptEnabled() ?
                0 : SubscriptionManager.getDefaultVoiceSubId();
        final SubscriptionInfo sir = findRecordBySubId(subId);
        if (sir != null) {
            simPref.setSelectedValue(sir, false);
        }
        simPref.setEnabled(mNumSims > 1);
    }

    @Override
    @Override
    public void onPause() {
    public void onPause() {
        super.onPause();
        super.onPause();
@@ -457,6 +438,80 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
        updateAllOptions();
        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);
                            SubscriptionManager.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);
                            SubscriptionManager.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() {
    private void initLTEPreference() {
        boolean isPrimarySubFeatureEnable = SystemProperties
        boolean isPrimarySubFeatureEnable = SystemProperties
                .getBoolean("persist.radio.primarycard", false);
                .getBoolean("persist.radio.primarycard", false);