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

Commit 5563fb43 authored by Cheuksan Wang's avatar Cheuksan Wang Committed by Android Partner Code Review
Browse files

Merge "Fail SmsManager requests if SubId is not active." into m-wireless-dev

parents eb374602 6cd5ae36
Loading
Loading
Loading
Loading
+27 −34
Original line number Diff line number Diff line
@@ -46,12 +46,13 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * SubscriptionController to provide an inter-process communication to
@@ -125,7 +126,8 @@ public class SubscriptionController extends ISub.Stub {
    protected CallManager mCM;

    // FIXME: Does not allow for multiple subs in a slot and change to SparseArray
    private static HashMap<Integer, Integer> mSlotIdxToSubId = new HashMap<Integer, Integer>();
    private static Map<Integer, Integer> sSlotIdxToSubId =
            new ConcurrentHashMap<Integer, Integer>();
    private static int mDefaultFallbackSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    private static int mDefaultPhoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;

@@ -175,7 +177,7 @@ public class SubscriptionController extends ISub.Stub {
    }

    private boolean isSubInfoReady() {
        return mSlotIdxToSubId.size() > 0;
        return sSlotIdxToSubId.size() > 0;
    }

    private SubscriptionController(Phone phone) {
@@ -655,9 +657,9 @@ public class SubscriptionController extends ISub.Stub {
                do {
                    int subId = cursor.getInt(cursor.getColumnIndexOrThrow(
                            SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID));
                    // If mSlotIdToSubIdMap already has a valid subId for a slotId/phoneId,
                    // If sSlotIdxToSubId already has a valid subId for a slotId/phoneId,
                    // do not add another subId for same slotId/phoneId.
                    Integer currentSubId = mSlotIdxToSubId.get(slotId);
                    Integer currentSubId = sSlotIdxToSubId.get(slotId);
                    if (currentSubId == null
                            || !SubscriptionManager.isValidSubscriptionId(currentSubId)) {
                        // TODO While two subs active, if user deactivats first
@@ -666,12 +668,12 @@ public class SubscriptionController extends ISub.Stub {
                        // FIXME: Currently we assume phoneId == slotId which in the future
                        // may not be true, for instance with multiple subs per slot.
                        // But is true at the moment.
                        mSlotIdxToSubId.put(slotId, subId);
                        sSlotIdxToSubId.put(slotId, subId);
                        int subIdCountMax = getActiveSubInfoCountMax();
                        int defaultSubId = getDefaultSubId();
                        if (DBG) {
                            logdl("[addSubInfoRecord]"
                                + " mSlotIdxToSubId.size=" + mSlotIdxToSubId.size()
                                + " sSlotIdxToSubId.size=" + sSlotIdxToSubId.size()
                                + " slotId=" + slotId + " subId=" + subId
                                + " defaultSubId=" + defaultSubId + " simCount=" + subIdCountMax);
                        }
@@ -708,7 +710,7 @@ public class SubscriptionController extends ISub.Stub {
        // Once the records are loaded, notify DcTracker
        updateAllDataConnectionTrackers();

        if (DBG) logdl("[addSubInfoRecord]- info size=" + mSlotIdxToSubId.size());
        if (DBG) logdl("[addSubInfoRecord]- info size=" + sSlotIdxToSubId.size());
        return 0;
    }

@@ -951,7 +953,7 @@ public class SubscriptionController extends ISub.Stub {
            return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
        }

        int size = mSlotIdxToSubId.size();
        int size = sSlotIdxToSubId.size();

        if (size == 0)
        {
@@ -959,7 +961,7 @@ public class SubscriptionController extends ISub.Stub {
            return SubscriptionManager.SIM_NOT_INSERTED;
        }

        for (Entry<Integer, Integer> entry: mSlotIdxToSubId.entrySet()) {
        for (Entry<Integer, Integer> entry: sSlotIdxToSubId.entrySet()) {
            int sim = entry.getKey();
            int sub = entry.getValue();

@@ -1000,10 +1002,10 @@ public class SubscriptionController extends ISub.Stub {
        }

        // Check if we've got any SubscriptionInfo records using slotIdToSubId as a surrogate.
        int size = mSlotIdxToSubId.size();
        int size = sSlotIdxToSubId.size();
        if (size == 0) {
            if (DBG) {
                logd("[getSubId]- mSlotIdToSubIdMap.size == 0, return DummySubIds slotIdx="
                logd("[getSubId]- sSlotIdxToSubId.size == 0, return DummySubIds slotIdx="
                        + slotIdx);
            }
            return getDummySubIds(slotIdx);
@@ -1011,7 +1013,7 @@ public class SubscriptionController extends ISub.Stub {

        // Create an array of subIds that are in this slot?
        ArrayList<Integer> subIds = new ArrayList<Integer>();
        for (Entry<Integer, Integer> entry: mSlotIdxToSubId.entrySet()) {
        for (Entry<Integer, Integer> entry: sSlotIdxToSubId.entrySet()) {
            int slot = entry.getKey();
            int sub = entry.getValue();
            if (slotIdx == slot) {
@@ -1052,7 +1054,7 @@ public class SubscriptionController extends ISub.Stub {
            return SubscriptionManager.INVALID_PHONE_INDEX;
        }

        int size = mSlotIdxToSubId.size();
        int size = sSlotIdxToSubId.size();
        if (size == 0) {
            phoneId = mDefaultPhoneId;
            if (DBG) logdl("[getPhoneId]- no sims, returning default phoneId=" + phoneId);
@@ -1060,7 +1062,7 @@ public class SubscriptionController extends ISub.Stub {
        }

        // FIXME: Assumes phoneId == slotId
        for (Entry<Integer, Integer> entry: mSlotIdxToSubId.entrySet()) {
        for (Entry<Integer, Integer> entry: sSlotIdxToSubId.entrySet()) {
            int sim = entry.getKey();
            int sub = entry.getValue();

@@ -1107,14 +1109,14 @@ public class SubscriptionController extends ISub.Stub {
        enforceSubscriptionPermission();
        if (DBG) logd("[clearSubInfo]+");

        int size = mSlotIdxToSubId.size();
        int size = sSlotIdxToSubId.size();

        if (size == 0) {
            if (DBG) logdl("[clearSubInfo]- no simInfo size=" + size);
            return 0;
        }

        mSlotIdxToSubId.clear();
        sSlotIdxToSubId.clear();
        if (DBG) logdl("[clearSubInfo]- clear size=" + size);
        return size;
    }
@@ -1453,7 +1455,7 @@ public class SubscriptionController extends ISub.Stub {
     */
    @Override
    public int[] getActiveSubIdList() {
        Set<Entry<Integer, Integer>> simInfoSet = mSlotIdxToSubId.entrySet();
        Set<Entry<Integer, Integer>> simInfoSet = sSlotIdxToSubId.entrySet();
        if (DBG) logdl("[getActiveSubIdList] simInfoSet=" + simInfoSet);

        int[] subIdArr = new int[simInfoSet.size()];
@@ -1468,20 +1470,11 @@ public class SubscriptionController extends ISub.Stub {
        return subIdArr;
    }

    private boolean isActiveSubId(int subId) {
        boolean retVal = false;

        if (SubscriptionManager.isValidSubscriptionId(subId)) {
            Set<Entry<Integer, Integer>> simInfoSet = mSlotIdxToSubId.entrySet();
            if (VDBG) logdl("[isActiveSubId] simInfoSet=" + simInfoSet);
    public boolean isActiveSubId(int subId) {
        enforceSubscriptionPermission();

            for (Entry<Integer, Integer> entry: simInfoSet) {
                if (subId == entry.getValue()) {
                    retVal = true;
                    break;
                }
            }
        }
        boolean retVal = SubscriptionManager.isValidSubscriptionId(subId)
                && sSlotIdxToSubId.containsValue(subId);

        if (VDBG) logdl("[isActiveSubId]- " + retVal);
        return retVal;
@@ -1553,8 +1546,8 @@ public class SubscriptionController extends ISub.Stub {
                    .from(mContext).getDefaultSmsPhoneId());
            pw.flush();

            for (Entry<Integer, Integer> entry : mSlotIdxToSubId.entrySet()) {
                pw.println(" mSlotIdToSubIdMap[" + entry.getKey() + "]: subId=" + entry.getValue());
            for (Entry<Integer, Integer> entry : sSlotIdxToSubId.entrySet()) {
                pw.println(" sSlotIdxToSubId[" + entry.getKey() + "]: subId=" + entry.getValue());
            }
            pw.flush();
            pw.println("++++++++++++++++++++++++++++++++");
+47 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

package com.android.internal.telephony;

import android.annotation.Nullable;
import android.app.ActivityThread;
import android.app.PendingIntent;
import android.content.Context;
@@ -25,7 +26,9 @@ import android.net.Uri;
import android.os.Binder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Telephony.Sms.Intents;
import android.telephony.Rlog;
import android.telephony.SmsManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -118,8 +121,10 @@ public class UiccSmsController extends ISms.Stub {
            iccSmsIntMgr.sendData(callingPackage, destAddr, scAddr, destPort, data,
                    sentIntent, deliveryIntent);
        } else {
            Rlog.e(LOG_TAG,"sendText iccSmsIntMgr is null for" +
            Rlog.e(LOG_TAG,"sendData iccSmsIntMgr is null for" +
                          " Subscription: " + subId);
            // TODO: Use a more specific error code to replace RESULT_ERROR_GENERIC_FAILURE.
            sendErrorInPendingIntent(sentIntent, SmsManager.RESULT_ERROR_GENERIC_FAILURE);
        }
    }

@@ -138,6 +143,7 @@ public class UiccSmsController extends ISms.Stub {
        } else {
            Rlog.e(LOG_TAG,"sendText iccSmsIntMgr is null for" +
                          " Subscription: " + subId);
            sendErrorInPendingIntent(sentIntent, SmsManager.RESULT_ERROR_GENERIC_FAILURE);
        }
    }

@@ -159,6 +165,7 @@ public class UiccSmsController extends ISms.Stub {
        } else {
            Rlog.e(LOG_TAG,"sendMultipartText iccSmsIntMgr is null for" +
                          " Subscription: " + subId);
            sendErrorInPendingIntents(sentIntents, SmsManager.RESULT_ERROR_GENERIC_FAILURE);
        }
    }

@@ -322,13 +329,24 @@ public class UiccSmsController extends ISms.Stub {

    // FIXME: Add injectSmsPdu to ISms.aidl
    public void injectSmsPdu(int subId, byte[] pdu, String format, PendingIntent receivedIntent) {
        getIccSmsInterfaceManager(subId).injectSmsPdu(pdu, format, receivedIntent);
        IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId);
        if (iccSmsIntMgr != null) {
            iccSmsIntMgr.injectSmsPdu(pdu, format, receivedIntent);
        } else {
            // RESULT_SMS_GENERIC_ERROR is documented for injectSmsPdu
            sendErrorInPendingIntent(receivedIntent, Intents.RESULT_SMS_GENERIC_ERROR);
        }
    }

    /**
     * get sms interface manager object based on subscription.
     **/
    private IccSmsInterfaceManager getIccSmsInterfaceManager(int subId) {
    private @Nullable IccSmsInterfaceManager getIccSmsInterfaceManager(int subId) {
        if (!isActiveSubId(subId)) {
            Rlog.e(LOG_TAG, "Subscription " + subId + " is inactive.");
            return null;
        }

        int phoneId = SubscriptionController.getInstance().getPhoneId(subId) ;
        //Fixme: for multi-subscription case
        if (!SubscriptionManager.isValidPhoneId(phoneId)
@@ -341,11 +359,11 @@ public class UiccSmsController extends ISms.Stub {
                ((PhoneProxy)mPhone[(int)phoneId]).getIccSmsInterfaceManager();
        } catch (NullPointerException e) {
            Rlog.e(LOG_TAG, "Exception is :"+e.toString()+" For subscription :"+subId );
            e.printStackTrace(); //This will print stact trace
            e.printStackTrace();
            return null;
        } catch (ArrayIndexOutOfBoundsException e) {
            Rlog.e(LOG_TAG, "Exception is :"+e.toString()+" For subscription :"+subId );
            e.printStackTrace(); //This will print stack trace
            e.printStackTrace();
            return null;
        }
    }
@@ -372,6 +390,7 @@ public class UiccSmsController extends ISms.Stub {
                    deliveryIntent);
        } else {
            Rlog.e(LOG_TAG,"sendStoredText iccSmsIntMgr is null for subscription: " + subId);
            sendErrorInPendingIntent(sentIntent, SmsManager.RESULT_ERROR_GENERIC_FAILURE);
        }
    }

@@ -386,7 +405,29 @@ public class UiccSmsController extends ISms.Stub {
        } else {
            Rlog.e(LOG_TAG,"sendStoredMultipartText iccSmsIntMgr is null for subscription: "
                    + subId);
            sendErrorInPendingIntents(sentIntents, SmsManager.RESULT_ERROR_GENERIC_FAILURE);
        }
    }

    /*
     * @return true if the subId is active.
     */
    private boolean isActiveSubId(int subId) {
        return SubscriptionController.getInstance().isActiveSubId(subId);
    }

    private void sendErrorInPendingIntent(@Nullable PendingIntent intent, int errorCode) {
        if (intent != null) {
            try {
                intent.send(errorCode);
            } catch (PendingIntent.CanceledException ex) {
            }
        }
    }

    private void sendErrorInPendingIntents(List<PendingIntent> intents, int errorCode) {
        for (PendingIntent intent : intents) {
            sendErrorInPendingIntent(intent, errorCode);
        }
    }
}