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

Commit 1162635a authored by Thomas Nguyen's avatar Thomas Nguyen Committed by Android (Google) Code Review
Browse files

Merge "Fix for NPE when subscription is not found" into main

parents 526c50b1 acb8c9c4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -638,7 +638,7 @@ public class DatagramController {
                    }
                };
                pollPendingSatelliteDatagrams(
                        SatelliteController.getInstance().getHighestPrioritySubscrption(),
                        SatelliteController.getInstance().getSelectedSatelliteSubId(),
                        internalCallback);
            }
        }
+4 −16
Original line number Diff line number Diff line
@@ -781,7 +781,7 @@ public class DatagramDispatcher extends Handler {
        mSendingInProgress = false;
        mIsEmergencyCommunicationEstablished = false;

        int subId = SatelliteController.getInstance().getHighestPrioritySubscrption();
        int subId = SatelliteController.getInstance().getSelectedSatelliteSubId();
        if (getPendingMessagesCount() > 0) {
            mDatagramController.updateSendStatus(subId,
                    mLastSendRequestDatagramType,
@@ -867,7 +867,7 @@ public class DatagramDispatcher extends Handler {
            @SatelliteManager.DatagramType int datagramType) {
        plogw("Timed out to wait for satellite connected before sending datagrams");
        synchronized (mLock) {
            int subId = SatelliteController.getInstance().getHighestPrioritySubscrption();
            int subId = SatelliteController.getInstance().getSelectedSatelliteSubId();
            // Update send status
            mDatagramController.updateSendStatus(subId,
                    datagramType,
@@ -1051,15 +1051,9 @@ public class DatagramDispatcher extends Handler {
     *                    carrier roaming nb iot ntn SMS.
     */
    public void sendSms(@NonNull PendingRequest pendingSms) {
        Phone satellitePhone = SatelliteController.getInstance().getSatellitePhone();
        if (satellitePhone == null) {
            ploge("sendSms: satellitePhone is null.");
            return;
        }

        SatelliteController.getInstance().startPointingUI();

        int subId = satellitePhone.getSubId();
        int subId = SatelliteController.getInstance().getSelectedSatelliteSubId();
        long messageId = pendingSms.uniqueMessageId;
        plogd("sendSms: subId=" + subId + " messageId:" + messageId);

@@ -1098,13 +1092,7 @@ public class DatagramDispatcher extends Handler {
            return;
        }

        Phone satellitePhone = SatelliteController.getInstance().getSatellitePhone();
        if (satellitePhone == null) {
            ploge("sendPendingSms: satellitePhone is null.");
            return;
        }
        int subId = satellitePhone.getSubId();

        int subId = SatelliteController.getInstance().getSelectedSatelliteSubId();
        Set<Entry<Long, PendingRequest>> pendingSms = null;
        if (!mSendingInProgress) {
            pendingSms = mPendingSmsMap.entrySet();
+1 −1
Original line number Diff line number Diff line
@@ -703,7 +703,7 @@ public class DatagramReceiver extends Handler {
            stopDatagramWaitForConnectedStateTimer();
        }

        int subId = SatelliteController.getInstance().getHighestPrioritySubscrption();
        int subId = SatelliteController.getInstance().getSelectedSatelliteSubId();
        if (mDatagramController.isReceivingDatagrams()) {
            mDatagramController.updateReceiveStatus(subId,
                    SatelliteManager.DATAGRAM_TYPE_SOS_MESSAGE,
+79 −47
Original line number Diff line number Diff line
@@ -1310,8 +1310,20 @@ public class SatelliteController extends Handler {
                    }
                }
                onCompleted = obtainMessage(EVENT_UPDATE_SATELLITE_ENABLE_ATTRIBUTES_DONE, request);
                SatelliteModemEnableRequestAttributes enableRequestAttributes =
                    createModemEnableRequest(argument);
                if (enableRequestAttributes == null) {
                    plogw("UpdateEnableAttributes: enableRequestAttributes is null");
                    sendErrorAndReportSessionMetrics(
                        SatelliteManager.SATELLITE_RESULT_INVALID_TELEPHONY_STATE,
                        argument.callback);
                    synchronized (mSatelliteEnabledRequestLock) {
                        mSatelliteEnableAttributesUpdateRequest = null;
                    }
                    break;
                }
                mSatelliteModemInterface.requestSatelliteEnabled(
                        createModemEnableRequest(argument), onCompleted);
                        enableRequestAttributes, onCompleted);
                startWaitForUpdateSatelliteEnableAttributesResponseTimer(argument);
                break;
            }
@@ -1739,15 +1751,22 @@ public class SatelliteController extends Handler {
                onCompleted = obtainMessage(EVENT_UPDATE_PROVISION_SATELLITE_TOKEN_DONE, request);
                boolean provisionChanged = updateSatelliteSubscriptionProvisionState(
                        argument.mSatelliteSubscriberInfoList, argument.mProvisioned);
                selectBindingSatelliteSubscription();
                int subId = getSelectedSatelliteSubId();
                setSatellitePhone(subId);
                String iccId = mSubscriptionManagerService.getSubscriptionInfo(subId).getIccId();
                SubscriptionInfo subscriptionInfo =
                    mSubscriptionManagerService.getSubscriptionInfo(subId);
                if (subscriptionInfo == null) {
                    logw("updateSatelliteToken subId=" + subId + " is not found");
                } else {
                    String iccId = subscriptionInfo.getIccId();
                    argument.setIccId(iccId);
                    synchronized (mSatelliteTokenProvisionedLock) {
                        if (!iccId.equals(mLastConfiguredIccId)) {
                        logd("updateSatelliteSubscription subId=" + subId + ", iccId=" + iccId
                                + " to modem");
                        mSatelliteModemInterface.updateSatelliteSubscription(iccId, onCompleted);
                            logd("updateSatelliteSubscription subId=" + subId
                                    + ", iccId=" + iccId + " to modem");
                            mSatelliteModemInterface.updateSatelliteSubscription(
                                iccId, onCompleted);
                        }
                    }
                }
                if (provisionChanged) {
@@ -2227,7 +2246,7 @@ public class SatelliteController extends Handler {
                /* We have already successfully queried the satellite modem. */
                Bundle bundle = new Bundle();
                bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported);
                bundle.putInt(SATELLITE_SUBSCRIPTION_ID, getHighestPrioritySubscrption());
                bundle.putInt(SATELLITE_SUBSCRIPTION_ID, getSelectedSatelliteSubId());
                result.send(SATELLITE_RESULT_SUCCESS, bundle);
                return;
            }
@@ -2280,7 +2299,7 @@ public class SatelliteController extends Handler {
            return;
        }

        final int validSubId = getHighestPrioritySubscrption();
        final int validSubId = getSelectedSatelliteSubId();
        mPointingAppController.registerForSatelliteTransmissionUpdates(validSubId, callback);
        sendRequestAsync(CMD_START_SATELLITE_TRANSMISSION_UPDATES,
                new SatelliteTransmissionUpdateArgument(result, callback, validSubId), null);
@@ -2298,7 +2317,7 @@ public class SatelliteController extends Handler {
            @NonNull ISatelliteTransmissionUpdateCallback callback) {
        Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
        mPointingAppController.unregisterForSatelliteTransmissionUpdates(
                getHighestPrioritySubscrption(), result, callback);
                getSelectedSatelliteSubId(), result, callback);

        // Even if handler is null - which means there are no listeners, the modem command to stop
        // satellite transmission updates might have failed. The callers might want to retry
@@ -2328,7 +2347,7 @@ public class SatelliteController extends Handler {
            return null;
        }

        final int validSubId = getHighestPrioritySubscrption();
        final int validSubId = getSelectedSatelliteSubId();
        if (mSatelliteProvisionCallbacks.containsKey(validSubId)) {
            result.accept(SatelliteManager.SATELLITE_RESULT_SERVICE_PROVISION_IN_PROGRESS);
            return null;
@@ -2380,7 +2399,7 @@ public class SatelliteController extends Handler {

        sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
                new ProvisionSatelliteServiceArgument(token, null,
                        result, getHighestPrioritySubscrption()),
                        result, getSelectedSatelliteSubId()),
                null);
    }

@@ -2528,7 +2547,7 @@ public class SatelliteController extends Handler {
        }
        plogd("registerForIncomingDatagram: callback=" + callback);
        return mDatagramController.registerForSatelliteDatagram(
                getHighestPrioritySubscrption(), callback);
                getSelectedSatelliteSubId(), callback);
    }

    /**
@@ -2549,7 +2568,7 @@ public class SatelliteController extends Handler {
        }
        plogd("unregisterForIncomingDatagram: callback=" + callback);
        mDatagramController.unregisterForSatelliteDatagram(
                getHighestPrioritySubscrption(), callback);
                getSelectedSatelliteSubId(), callback);
    }

    /**
@@ -2571,7 +2590,7 @@ public class SatelliteController extends Handler {
        }

        mDatagramController.pollPendingSatelliteDatagrams(
                getHighestPrioritySubscrption(), result);
                getSelectedSatelliteSubId(), result);
    }

    /**
@@ -2611,7 +2630,7 @@ public class SatelliteController extends Handler {
                    mIsEmergency);
        }

        mDatagramController.sendSatelliteDatagram(getHighestPrioritySubscrption(), datagramType,
        mDatagramController.sendSatelliteDatagram(getSelectedSatelliteSubId(), datagramType,
                datagram, needFullScreenPointingUI, result);
    }

@@ -3272,7 +3291,7 @@ public class SatelliteController extends Handler {
            return;
        }

        int satelliteSubId = getHighestPrioritySubscrption();
        int satelliteSubId = getSelectedSatelliteSubId();
        if (subId != satelliteSubId) {
            logd("onSmsReceived: SMS received " + subId
                    + ", but not satellite subscription " + satelliteSubId);
@@ -3947,6 +3966,23 @@ public class SatelliteController extends Handler {
        RequestSatelliteEnabledArgument argument =
                (RequestSatelliteEnabledArgument) request.argument;
        handlePersistentLoggingOnSessionStart(argument);
        selectBindingSatelliteSubscription();
        SatelliteModemEnableRequestAttributes enableRequestAttributes =
                    createModemEnableRequest(argument);
        if (enableRequestAttributes == null) {
            plogw("handleSatelliteEnabled: enableRequestAttributes is null");
            sendErrorAndReportSessionMetrics(
                    SatelliteManager.SATELLITE_RESULT_INVALID_TELEPHONY_STATE, argument.callback);
            synchronized (mSatelliteEnabledRequestLock) {
                if (argument.enableSatellite) {
                    mSatelliteEnabledRequest = null;
                } else {
                    mSatelliteDisabledRequest = null;
                }
            }
            return;
        }

        if (mSatelliteSessionController != null) {
            mSatelliteSessionController.onSatelliteEnablementStarted(argument.enableSatellite);
        } else {
@@ -3966,8 +4002,7 @@ public class SatelliteController extends Handler {

        Message onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request);
        mSatelliteModemInterface.requestSatelliteEnabled(
                createModemEnableRequest(argument),
                onCompleted);
                enableRequestAttributes, onCompleted);
        startWaitForSatelliteEnablingResponseTimer(argument);
        // Logs satellite session timestamps for session metrics
        if (argument.enableSatellite) {
@@ -3977,11 +4012,15 @@ public class SatelliteController extends Handler {
    }

    /** Get the request attributes that modem needs to enable/disable satellite */
    private SatelliteModemEnableRequestAttributes createModemEnableRequest(
    @Nullable private SatelliteModemEnableRequestAttributes createModemEnableRequest(
            @NonNull RequestSatelliteEnabledArgument arg) {
        int subId = getHighestPrioritySubscrption();
        int subId = getSelectedSatelliteSubId();
        SubscriptionInfo subInfo = mSubscriptionManagerService.getSubscriptionInfo(subId);
        String iccid = subInfo != null ? subInfo.getIccId() : "";
        if (subInfo == null) {
            loge("createModemEnableRequest: no SubscriptionInfo found for subId=" + subId);
            return null;
        }
        String iccid = subInfo.getIccId();
        String apn = getConfigForSubId(subId).getString(KEY_SATELLITE_NIDD_APN_NAME_STRING, "");
        return new SatelliteModemEnableRequestAttributes(
                arg.enableSatellite, arg.enableDemoMode, arg.isEmergency,
@@ -4794,13 +4833,13 @@ public class SatelliteController extends Handler {
        resetCarrierRoamingSatelliteModeParams(subId);
        handleStateChangedForCarrierRoamingNtnEligibility();
        sendMessageDelayed(obtainMessage(CMD_EVALUATE_ESOS_PROFILES_PRIORITIZATION),
                TimeUnit.MINUTES.toMillis(1));
                mEvaluateEsosProfilesPrioritizationDurationMillis);
    }

    // imsi, msisdn, default sms subId change
    private void handleSubscriptionsChanged() {
        sendMessageDelayed(obtainMessage(CMD_EVALUATE_ESOS_PROFILES_PRIORITIZATION),
                TimeUnit.MINUTES.toMillis(1));
                mEvaluateEsosProfilesPrioritizationDurationMillis);
    }

    private void processNewCarrierConfigData(int subId) {
@@ -5432,7 +5471,7 @@ public class SatelliteController extends Handler {
                return;
            }

            int subId = getHighestPrioritySubscrption();
            int subId = getSelectedSatelliteSubId();
            long timeout = getCarrierSupportedSatelliteNotificationHysteresisTimeMillis(subId);
            mNtnEligibilityHysteresisTimedOut = false;
            plogd("startNtnEligibilityHysteresisTimer: sendMessageDelayed subId=" + subId
@@ -5471,7 +5510,7 @@ public class SatelliteController extends Handler {
                    || mLastNotifiedNtnEligibility != currentNtnEligibility) {
                mLastNotifiedNtnEligibility = currentNtnEligibility;
                mSatellitePhone.notifyCarrierRoamingNtnEligibleStateChanged(currentNtnEligibility);
                updateSatelliteSystemNotification(getHighestPrioritySubscrption(),
                updateSatelliteSystemNotification(getSelectedSatelliteSubId(),
                        CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL,
                        currentNtnEligibility);
            }
@@ -6295,6 +6334,7 @@ public class SatelliteController extends Handler {
                mContext.getOpPackageName(), mContext.getAttributionTag());
        // Key : priority - lower value has higher priority; Value : List<SubscriptionInfo>
        TreeMap<Integer, List<SubscriptionInfo>> newSubsInfoListPerPriority = new TreeMap<>();
        plogd("evaluateESOSProfilesPrioritization: allSubInfos.size()=" + allSubInfos.size());
        synchronized (mSatelliteTokenProvisionedLock) {
            for (SubscriptionInfo info : allSubInfos) {
                int subId = info.getSubscriptionId();
@@ -6333,6 +6373,8 @@ public class SatelliteController extends Handler {
                }
            }
        }
        plogd("evaluateESOSProfilesPrioritization: newSubsInfoListPerPriority.size()="
                  + newSubsInfoListPerPriority.size());

        if (!mHasSentBroadcast && newSubsInfoListPerPriority.size() == 0) {
            logd("evaluateESOSProfilesPrioritization: no satellite subscription available");
@@ -6506,7 +6548,7 @@ public class SatelliteController extends Handler {
        return list;
    }

    private int getSelectedSatelliteSubId() {
    public int getSelectedSatelliteSubId() {
        synchronized (mSatelliteTokenProvisionedLock) {
            return mSelectedSatelliteSubId;
        }
@@ -6535,13 +6577,11 @@ public class SatelliteController extends Handler {
        synchronized (mSatelliteTokenProvisionedLock) {
            if (selectedSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID
                    && isSatelliteSupportedViaOem()) {
                mSelectedSatelliteSubId = SatelliteServiceUtils.getNtnOnlySubscriptionId(mContext);
                selectedSubId = SatelliteServiceUtils.getNtnOnlySubscriptionId(mContext);
            }
            if (selectedSubId != mSelectedSatelliteSubId) {
            mSelectedSatelliteSubId = selectedSubId;
            setSatellitePhone(selectedSubId);
        }
        }
        plogd("selectBindingSatelliteSubscription: SelectedSatelliteSubId="
                + mSelectedSatelliteSubId);
    }
@@ -6647,13 +6687,14 @@ public class SatelliteController extends Handler {
    /** Return the carrier ID of the binding satellite subscription. */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public int getSatelliteCarrierId() {
        synchronized (mSatellitePhoneLock) {
            if (mSatellitePhone != null) {
                return mSatellitePhone.getCarrierId();
            } else {
        synchronized (mSatelliteTokenProvisionedLock) {
            SubscriptionInfo subInfo = mSubscriptionManagerService.getSubscriptionInfo(
                    mSelectedSatelliteSubId);
            if (subInfo == null) {
                logd("getSatelliteCarrierId: returns UNKNOWN_CARRIER_ID");
                return UNKNOWN_CARRIER_ID;
            }
            return subInfo.getCarrierId();
        }
    }

@@ -6756,15 +6797,6 @@ public class SatelliteController extends Handler {
        }
    }

    /**
     * Return the highest priority satellite subscirption ID.
     */
    public int getHighestPrioritySubscrption() {
        synchronized (mSatellitePhoneLock) {
            return mSatellitePhone.getSubId();
        }
    }

    /** Start PointingUI if it is required. */
    public void startPointingUI() {
        synchronized (mNeedsSatellitePointingLock) {
+2 −24
Original line number Diff line number Diff line
@@ -415,7 +415,7 @@ public class SatelliteSOSMessageRecommender extends Handler {
                        .setRecommendingHandoverType(getEmergencyCallToSatelliteHandoverType())
                        .setIsSatelliteAllowedInCurrentLocation(isSatelliteAllowed())
                        .setIsWifiConnected(mCountryDetector.isWifiNetworkConnected())
                        .setCarrierId(getAvailableNtnCarrierID()).build());
                        .setCarrierId(mSatelliteController.getSatelliteCarrierId()).build());
    }

    private void cleanUpResources(boolean isDialerNotified) {
@@ -739,12 +739,7 @@ public class SatelliteSOSMessageRecommender extends Handler {
    public int getEmergencyCallToSatelliteHandoverType() {
        if (Flags.carrierRoamingNbIotNtn() && isSatelliteViaOemAvailable()
                && isSatelliteConnectedViaCarrierWithinHysteresisTime()) {
            Phone satellitePhone = mSatelliteController.getSatellitePhone();
            if (satellitePhone == null) {
                ploge("getEmergencyCallToSatelliteHandoverType: satellitePhone is null");
                return EMERGENCY_CALL_TO_SATELLITE_HANDOVER_TYPE_T911;
            }
            int satelliteSubId = satellitePhone.getSubId();
            int satelliteSubId = mSatelliteController.getSelectedSatelliteSubId();
            return mSatelliteController.getCarrierRoamingNtnEmergencyCallToSatelliteHandoverType(
                    satelliteSubId);
        } else if (isSatelliteConnectedViaCarrierWithinHysteresisTime()) {
@@ -833,23 +828,6 @@ public class SatelliteSOSMessageRecommender extends Handler {
        }
    }

    /** Returns the carrier ID of NTN subscription */
    private int getAvailableNtnCarrierID() {
        Pair<Boolean, Integer> ntnSubInfo =
                mSatelliteController.isUsingNonTerrestrialNetworkViaCarrier();
        if (ntnSubInfo.first) {
            TelephonyManager tm = mContext.getSystemService(TelephonyManager.class);
            return tm.createForSubscriptionId(ntnSubInfo.second).getSimCarrierId();
        }

        Phone satellitePhone = mSatelliteController.getSatellitePhone();
        if (satellitePhone != null) {
            return satellitePhone.getCarrierId();
        }

        return TelephonyManager.UNKNOWN_CARRIER_ID;
    }

    private void plogd(@NonNull String log) {
        Rlog.d(TAG, log);
        if (mPersistentLogger != null) {
Loading