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

Commit d98fad60 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add getSubscriptionId API" am: 67fe8174 am: 64395b3c

parents 2f4c44a0 64395b3c
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -2532,10 +2532,9 @@ public class RadioResponse extends IRadioResponse.Stub {
            ArrayList<NeighboringCellInfo> ret = new ArrayList<NeighboringCellInfo>();
            NeighboringCellInfo cell;

            int[] subId = SubscriptionManager.getSubId(mRil.mPhoneId);
            int radioType =
                    ((TelephonyManager) mRil.mContext.getSystemService(
                            Context.TELEPHONY_SERVICE)).getDataNetworkType(subId[0]);
            int radioType = ((TelephonyManager) mRil.mContext.getSystemService(
                    Context.TELEPHONY_SERVICE)).getDataNetworkType(
                            SubscriptionManager.getSubscriptionId(mRil.mPhoneId));

            if (radioType != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                for (int i = 0; i < cells.size(); i++) {
+4 −3
Original line number Diff line number Diff line
@@ -245,9 +245,10 @@ public class WapPushOverSms implements ServiceConnection {
                System.arraycopy(pdu, dataIndex, intentData, 0, intentData.length);
            }

            int[] subIds = SubscriptionManager.getSubId(phoneId);
            int subId = (subIds != null) && (subIds.length > 0) ? subIds[0]
                    : SmsManager.getDefaultSmsSubscriptionId();
            int subId = SubscriptionManager.getSubscriptionId(phoneId);
            if (!SubscriptionManager.isValidSubscriptionId(subId)) {
                subId = SmsManager.getDefaultSmsSubscriptionId();
            }

            // Continue if PDU parsing fails: the default messaging app may successfully parse the
            // same PDU.
+3 −7
Original line number Diff line number Diff line
@@ -312,7 +312,8 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
    @VisibleForTesting
    public interface SubscriptionManagerProxy {
        /**
         * Mock-able interface for {@link SubscriptionManager#getSubId(int)} used for testing.
         * Mock-able interface for {@link SubscriptionManager#getSubscriptionId(int)} used for
         * testing.
         */
        int getSubId(int slotId);
        /**
@@ -346,12 +347,7 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
    private SubscriptionManagerProxy mSubscriptionManagerProxy = new SubscriptionManagerProxy() {
        @Override
        public int getSubId(int slotId) {
            int[] subIds = SubscriptionManager.getSubId(slotId);
            if (subIds != null) {
                // This is done in all other places getSubId is used.
                return subIds[0];
            }
            return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
            return SubscriptionManager.getSubscriptionId(slotId);
        }

        @Override
+1 −6
Original line number Diff line number Diff line
@@ -1564,12 +1564,7 @@ public class RcsStats {

    @VisibleForTesting
    protected int getSubId(int slotId) {
        final int[] subIds = SubscriptionManager.getSubId(slotId);
        int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        if (subIds != null && subIds.length >= 1) {
            subId = subIds[0];
        }
        return subId;
        return SubscriptionManager.getSubscriptionId(slotId);
    }

    /** Get a enum value from pre-defined feature tag name list */
+94 −1
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * The subscription manager service is the backend service of {@link SubscriptionManager}.
@@ -59,6 +62,80 @@ public class SubscriptionManagerService extends ISub.Stub {
    /** The subscription database manager. */
    private final SubscriptionDatabaseManager mSubscriptionDatabaseManager;

    /**
     * Watched slot index to sub id map.
     */
    private static class WatchedSlotIndexToSubId {
        private final Map<Integer, Integer> mSlotIndexToSubId =
                new ConcurrentHashMap<>();

        public void clear() {
            mSlotIndexToSubId.clear();
            SubscriptionManager.invalidateDefaultSubIdCaches();
            SubscriptionManager.invalidateSlotIndexCaches();
        }

        public Set<Map.Entry<Integer, Integer>> entrySet() {
            return mSlotIndexToSubId.entrySet();
        }

        // Force all updates to data structure through wrapper.
        public int get(int slotIndex) {
            return mSlotIndexToSubId.getOrDefault(slotIndex,
                    SubscriptionManager.INVALID_SUBSCRIPTION_ID);
        }

        public void put(int slotIndex, int value) {
            mSlotIndexToSubId.put(slotIndex, value);
            SubscriptionManager.invalidateDefaultSubIdCaches();
            SubscriptionManager.invalidateSlotIndexCaches();
        }

        public void remove(int slotIndex) {
            mSlotIndexToSubId.remove(slotIndex);
            SubscriptionManager.invalidateDefaultSubIdCaches();
            SubscriptionManager.invalidateSlotIndexCaches();
        }

        public int size() {
            return mSlotIndexToSubId.size();
        }
    }

    /**
     * Watched integer.
     */
    public static class WatchedInt {
        private int mValue;

        /**
         * Constructor.
         *
         * @param initialValue The initial value.
         */
        public WatchedInt(int initialValue) {
            mValue = initialValue;
        }

        /**
         * @return The value.
         */
        public int get() {
            return mValue;
        }

        /**
         * Set the value.
         *
         * @param newValue The new value.
         */
        public void set(int newValue) {
            mValue = newValue;
        }
    }

    private final WatchedSlotIndexToSubId mSlotIndexToSubId = new WatchedSlotIndexToSubId();

    /**
     * The constructor
     *
@@ -401,9 +478,25 @@ public class SubscriptionManagerService extends ISub.Stub {
        return 0;
    }

    @Override
    public int getSubId(int slotIndex) {
        if (slotIndex == SubscriptionManager.DEFAULT_SIM_SLOT_INDEX) {
            slotIndex = getSlotIndex(getDefaultSubId());
        }

        // Check that we have a valid slotIndex or the slotIndex is for a remote SIM (remote SIM
        // uses special slot index that may be invalid otherwise)
        if (!SubscriptionManager.isValidSlotIndex(slotIndex)
                && slotIndex != SubscriptionManager.SLOT_INDEX_FOR_REMOTE_SIM_SUB) {
            return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        }

        return mSlotIndexToSubId.get(slotIndex);
    }

    @Override
    public int[] getSubIds(int slotIndex) {
        return null;
        return new int[]{getSubId(slotIndex)};
    }

    @Override