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

Commit 2786017f authored by kaiyiz's avatar kaiyiz
Browse files

Dialer: Add account selection support when set voicemail

Use the default voice subscription to set voicemail.

If there isn't default outgoing phone account, show
a select account dialog, let user chooses a sub to set
the voicemail number.

CRs-Fixed: 753098

Change-Id: I765f5d491155bc5a4604803dc3b3b76e14c4949a
parent 956c9393
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -204,6 +204,7 @@
    <string name="respond_via_sms_setting_title" msgid="1318281521087951580">"快速回复"</string>
    <string name="call_settings_label" msgid="7416182166943714852">"通话设置"</string>
    <string name="call_settings_description" msgid="2756622428019213052">"语音信箱、来电等待及其他"</string>
    <string name="select_account_dialog_title">选择账户</string>

    <string name="device_id">设备标识符</string>

+2 −0
Original line number Diff line number Diff line
@@ -600,6 +600,8 @@
         [CHAR LIMIT=30] -->
    <string name="call_log_voicemail_title">Voicemail</string>

    <string name="select_account_dialog_title">Select Account</string>

    <string name="tab_speed_dial">Speed Dial</string>

    <string name="tab_recents">Recents</string>
+57 −4
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.ActivityNotFoundException;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
@@ -45,6 +46,8 @@ import android.provider.ContactsContract.Contacts.Data;
import android.provider.ContactsContract.RawContacts;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
@@ -58,6 +61,7 @@ import android.widget.ListView;
import android.widget.Toast;

import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
import java.util.List;

public class SpeedDialListActivity extends ListActivity
        implements OnItemClickListener {
@@ -172,10 +176,15 @@ public class SpeedDialListActivity extends ListActivity
        if (position == 0) {
            Intent intent = new Intent(ACTION_ADD_VOICEMAIL);
            if (TelephonyManager.getDefault().getPhoneCount() > 1) {
                if (isMultiAccountAvailable()) {
                    showSelectAccountDialog(this);
                    return;
                } else {
                    long sub = SubscriptionManager.getDefaultVoiceSubId();
                    intent.setClassName("com.android.phone",
                            "com.android.phone.MSimCallFeaturesSubSetting");
                    intent.putExtra(SUBSCRIPTION_KEY, sub);
                }
            } else {
                intent.setClassName("com.android.phone",
                        "com.android.phone.CallFeaturesSetting");
@@ -229,6 +238,50 @@ public class SpeedDialListActivity extends ListActivity
        }
    }

    private boolean isMultiAccountAvailable() {
        TelecomManager telecomManager = getTelecomManager(this);
        return (telecomManager.getUserSelectedOutgoingPhoneAccount() == null)
                && (telecomManager.getAllPhoneAccountsCount() > 1);
    }

    private void showSelectAccountDialog(Context context) {
        TelecomManager telecomManager = getTelecomManager(context);
        List<PhoneAccountHandle> accountsList = telecomManager
                .getCallCapablePhoneAccounts();
        final PhoneAccountHandle[] accounts = accountsList
                .toArray(new PhoneAccountHandle[accountsList.size()]);
        CharSequence[] accountEntries = new CharSequence[accounts.length];
        for (int i = 0; i < accounts.length; i++) {
            CharSequence label = telecomManager.getPhoneAccount(accounts[i])
                    .getLabel();
            accountEntries[i] = (label == null) ? null : label.toString();
        }
        AlertDialog dialog = new AlertDialog.Builder(context)
                .setTitle(R.string.select_account_dialog_title)
                .setItems(accountEntries, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(ACTION_ADD_VOICEMAIL);
                        long sub = Long.parseLong(accounts[which].getId());
                        intent.setClassName("com.android.phone",
                                "com.android.phone.MSimCallFeaturesSubSetting");
                        intent.putExtra(SUBSCRIPTION_KEY, sub);
                        try {
                            startActivity(intent);
                        } catch (ActivityNotFoundException e) {
                            Log.w(TAG, "can not find activity deal with voice mail");
                        }
                    }
                })
                .create();
        dialog.show();
    }

    private TelecomManager getTelecomManager(Context context) {
        return TelecomManager.from(context);
    }

    /*
     * goto contacts, used to set or replace speed number
     */