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

Commit ab02f0ce authored by Sridhar Dubbaka's avatar Sridhar Dubbaka Committed by Linux Build Service Account
Browse files

Telephony(MSIM): Add Sms Prompt support

In Msim, Whenver user selects Ask every time option in Sim settings,
Mms app will prompt for slection of sub from
composemessageactivity, on which SMS to be sent.

Change-Id: I39b1e1e3963779c717ea2aa49de94b6f0088984b
parent d6cbd3ea
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5887,6 +5887,8 @@
    <string name="sim_pref_divider">Preferred SIM for</string>
    <!-- When a user chooses this "Ask first" preference for the SIM to use for phone calls, they'll be prompted to choose a SIM every time they initiate a call [CHAR LIMIT=50] -->
    <string name="sim_calls_ask_first_prefs_title">Ask every time</string>
    <!-- When a user chooses this "Ask first" preference for the SIM to use for send SMS, they'll be prompted to choose a SIM every time they initiate a SMS [CHAR LIMIT=50] -->
    <string name="sim_sms_ask_first_prefs_title">Ask every time</string>
    <!-- When a SIM preference hasn't been selected yet, this string is displayed as the pref summary until the user chooses a SIM subscription from the preference list [CHAR LIMIT=50] -->
    <string name="sim_selection_required_pref">Selection required</string>
+42 −3
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
@@ -33,12 +35,14 @@ import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.android.internal.telephony.IExtTelephony;
import com.android.settings.R;
import com.android.settings.Utils;
import java.util.ArrayList;
@@ -56,6 +60,9 @@ public class SimDialogActivity extends Activity {
    public static final int SMS_PICK = 2;
    public static final int PREFERRED_PICK = 3;

    private IExtTelephony mExtTelephony = IExtTelephony.Stub.
            asInterface(ServiceManager.getService("extphone"));

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -152,6 +159,7 @@ public class SimDialogActivity extends Activity {
    public Dialog createDialog(final Context context, final int id) {
        final ArrayList<String> list = new ArrayList<String>();
        final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
        final ArrayList<SubscriptionInfo> smsSubInfoList = new ArrayList<SubscriptionInfo>();
        final List<SubscriptionInfo> subInfoList =
            subscriptionManager.getActiveSubscriptionInfoList();
        final int selectableSubInfoLength = subInfoList == null ? 0 : subInfoList.size();
@@ -177,8 +185,26 @@ public class SimDialogActivity extends Activity {
                                        value < 1 ? null : phoneAccountsList.get(value - 1));
                                break;
                            case SMS_PICK:
                                sir = subInfoList.get(value);
                                boolean isSmsPrompt = false;
                                if (value < 1) {
                                    isSmsPrompt = true;
                                } else {
                                    sir = smsSubInfoList.get(value);
                                    if ( sir != null) {
                                        setDefaultSmsSubId(context, sir.getSubscriptionId());
                                    } else {
                                        isSmsPrompt = true;
                                    }
                                    Log.d(TAG, "SubscriptionInfo:" + sir);
                                }
                                Log.d(TAG, "isSmsPrompt: " + isSmsPrompt);
                                try {
                                    mExtTelephony.setSMSPromptEnabled(isSmsPrompt);
                                } catch (RemoteException ex) {
                                    Log.e(TAG, "RemoteException @setSMSPromptEnabled" + ex);
                                } catch (NullPointerException ex) {
                                    Log.e(TAG, "NullPointerException @setSMSPromptEnabled" + ex);
                                }
                                break;
                            default:
                                throw new IllegalArgumentException("Invalid dialog type "
@@ -222,6 +248,18 @@ public class SimDialogActivity extends Activity {
                    callsSubInfoList.add(null);
                }
            }
        } else if ((id == SMS_PICK)){
            list.add(getResources().getString(R.string.sim_sms_ask_first_prefs_title));
            smsSubInfoList.add(null);
            for (int i = 0; i < selectableSubInfoLength; ++i) {
                final SubscriptionInfo sir = subInfoList.get(i);
                smsSubInfoList.add(sir);
                CharSequence displayName = sir.getDisplayName();
                if (displayName == null) {
                    displayName = "";
                }
                list.add(displayName.toString());
            }
        } else {
            for (int i = 0; i < selectableSubInfoLength; ++i) {
                final SubscriptionInfo sir = subInfoList.get(i);
@@ -238,7 +276,8 @@ public class SimDialogActivity extends Activity {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);

        ListAdapter adapter = new SelectAccountListAdapter(
                id == CALLS_PICK ? callsSubInfoList : subInfoList,
                id == CALLS_PICK ? callsSubInfoList :
                (id == SMS_PICK ? smsSubInfoList: subInfoList),
                builder.getContext(),
                R.layout.select_account_list_item,
                arr, id);
+22 −7
Original line number Diff line number Diff line
@@ -85,6 +85,9 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
    private static final String SIM_ACTIVITIES_CATEGORY = "sim_activities";
    private static final String KEY_PRIMARY_SUB_SELECT = "select_primary_sub";

    private IExtTelephony mExtTelephony = IExtTelephony.Stub.
            asInterface(ServiceManager.getService("extphone"));

    /**
     * By UX design we use only one Subscription Information(SubInfo) record per SIM slot.
     * mAvalableSubInfos is the list of SubInfos we present to the user.
@@ -210,14 +213,23 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable

    private void updateSmsValues() {
        final Preference simPref = findPreference(KEY_SMS);
        final SubscriptionInfo sir = mSubscriptionManager.getDefaultSmsSubscriptionInfo();
        simPref.setTitle(R.string.sms_messages_title);
        if (DBG) log("[updateSmsValues] mSubInfoList=" + mSubInfoList);

        if (sir != null) {
        boolean isSMSPrompt = false;
        SubscriptionInfo sir = mSubscriptionManager.getActiveSubscriptionInfo(
                mSubscriptionManager.getDefaultSmsSubId());
        try {
            isSMSPrompt = mExtTelephony.isSMSPromptEnabled();
        } catch (RemoteException ex) {
            loge("RemoteException @isSMSPromptEnabled" + ex);
        } catch (NullPointerException ex) {
            loge("NullPointerException @isSMSPromptEnabled" + ex);
        }
        log("[updateSmsValues] isSMSPrompt: " + isSMSPrompt);
        if (isSMSPrompt || sir == null) {
            simPref.setSummary(mContext.getResources().getString(
                    R.string.sim_sms_ask_first_prefs_title));
        } else {
            simPref.setSummary(sir.getDisplayName());
        } else if (sir == null) {
            simPref.setSummary(R.string.sim_selection_required_pref);
        }
        simPref.setEnabled(mSelectableSubInfos.size() > 1);
    }
@@ -322,6 +334,9 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable

        return true;
    }
    private void loge(String msg) {
        if (DBG) Log.e(TAG + "message", msg);
    }

    private void simEnablerUpdate() {
        if (isAdded()) {
@@ -846,7 +861,7 @@ public class SimSettings extends RestrictedSettingsFragment implements Indexable
        }

        private void loge(String msg) {
            if (DBG) Log.e(TAG + "(" + mSlotId + ")", msg);
            Log.e(TAG + "(" + mSlotId + ")", msg);
        }
    }