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

Commit f024de84 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[satellite] Added onCarrierRoamingNtnAvailableServicesChanged callback" into main

parents 4ca28a01 f68d518b
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.telephony.CallQuality;
import android.telephony.CellIdentity;
import android.telephony.CellInfo;
import android.telephony.LinkCapacityEstimate;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneCapability;
import android.telephony.PhysicalChannelConfig;
import android.telephony.PreciseCallState;
@@ -340,6 +341,13 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
                sender.getSubId(), eligible);
    }

    @Override
    public void notifyCarrierRoamingNtnAvailableServicesChanged(
            Phone sender, @NetworkRegistrationInfo.ServiceType int[] availableServices) {
        mTelephonyRegistryMgr.notifyCarrierRoamingNtnAvailableServicesChanged(
                sender.getSubId(), availableServices);
    }

    /**
     * Convert the {@link Call.State} enum into the PreciseCallState.PRECISE_CALL_STATE_* constants
     * for the public API.
+9 −0
Original line number Diff line number Diff line
@@ -5368,6 +5368,15 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        mNotifier.notifyCarrierRoamingNtnEligibleStateChanged(this, eligible);
    }

    /**
     * Notify external listeners that carrier roaming non-terrestrial available services changed.
     * @param availableServices The list of the supported services.
     */
    public void notifyCarrierRoamingNtnAvailableServicesChanged(
            @NetworkRegistrationInfo.ServiceType int[] availableServices) {
        mNotifier.notifyCarrierRoamingNtnAvailableServicesChanged(this, availableServices);
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("Phone: subId=" + getSubId());
        pw.println(" mPhoneId=" + mPhoneId);
+5 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.telephony.CallQuality;
import android.telephony.CellIdentity;
import android.telephony.CellInfo;
import android.telephony.LinkCapacityEstimate;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneCapability;
import android.telephony.PhysicalChannelConfig;
import android.telephony.PreciseDataConnectionState;
@@ -164,4 +165,8 @@ public interface PhoneNotifier {

    /** Notify eligibility to connect to carrier roaming non-terrestrial network changed. */
    void notifyCarrierRoamingNtnEligibleStateChanged(Phone sender, boolean eligible);

    /** Notify carrier roaming non-terrestrial available services changed. */
    void notifyCarrierRoamingNtnAvailableServicesChanged(
            Phone sender, @NetworkRegistrationInfo.ServiceType int[] availableServices);
}
+2 −1
Original line number Diff line number Diff line
@@ -52,7 +52,8 @@ public class NtnCapabilityResolver {
                logd("Registered to satellite PLMN " + satellitePlmn);
                networkRegistrationInfo.setIsNonTerrestrialNetwork(true);
                networkRegistrationInfo.setAvailableServices(
                        satelliteController.getSupportedSatelliteServices(subId, satellitePlmn));
                        satelliteController.getSupportedSatelliteServicesForPlmn(
                                subId, satellitePlmn));
                break;
            }
        }
+106 −5
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.ContentObserver;
@@ -3349,7 +3350,7 @@ public class SatelliteController extends Handler {
     * the satellite network {@code plmn}.
     */
    @NonNull
    public List<Integer> getSupportedSatelliteServices(int subId, String plmn) {
    public List<Integer> getSupportedSatelliteServicesForPlmn(int subId, String plmn) {
        if (!mFeatureFlags.carrierEnabledSatelliteFlag()) {
            logd("getSupportedSatelliteServices: carrierEnabledSatelliteFlag is disabled");
            return new ArrayList<>();
@@ -4676,6 +4677,7 @@ public class SatelliteController extends Handler {
            if (activeSubIds != null) {
                for (int subId : activeSubIds) {
                    updateSupportedSatelliteServices(subId);
                    handleCarrierRoamingNtnAvailableServicesChanged(subId);
                }
            } else {
                loge("updateSupportedSatelliteServicesForActiveSubscriptions: "
@@ -6789,7 +6791,7 @@ public class SatelliteController extends Handler {
            @NetworkRegistrationInfo.ServiceType int serviceType) {
        List<String> satellitePlmnList = getSatellitePlmnsForCarrier(subId);
        for (String satellitePlmn : satellitePlmnList) {
            if (getSupportedSatelliteServices(subId, satellitePlmn).contains(serviceType)) {
            if (getSupportedSatelliteServicesForPlmn(subId, satellitePlmn).contains(serviceType)) {
                return true;
            }
        }
@@ -6941,7 +6943,8 @@ public class SatelliteController extends Handler {
        return result;
    }

    private String getConfigSatelliteGatewayServicePackage() {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected String getConfigSatelliteGatewayServicePackage() {
        if (!mChangeIntentComponent) {
            return getStringFromOverlayConfig(
                    R.string.config_satellite_gateway_service_package);
@@ -7012,10 +7015,12 @@ public class SatelliteController extends Handler {
            } else {
                mOverrideNtnEligibility.set(state);
            }
            synchronized (mSatellitePhoneLock) {
                if (this.mSatellitePhone != null) {
                    updateLastNotifiedNtnEligibilityAndNotify(state);
                }
            }
        }
        return true;
    }

@@ -7040,4 +7045,100 @@ public class SatelliteController extends Handler {
            }
        }
    }

    private void handleCarrierRoamingNtnAvailableServicesChanged(int subId) {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            plogd("handleCarrierRoamingNtnAvailableServicesChanged: "
                    + "carrierRoamingNbIotNtn flag is disabled");
            return;
        }
        updateLastNotifiedNtnAvailableServicesAndNotify(subId);
    }

    private void updateLastNotifiedNtnAvailableServicesAndNotify(int subId) {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            plogd("notifyNtnAvailableServices: carrierRoamingNbIotNtn flag is disabled");
            return;
        }
        synchronized (mSatellitePhoneLock) {
            if (mSatellitePhone == null) {
                plogd("updateLastNotifiedNtnAvailableServicesAndNotify: phone is null");
                return;
            }
            if (isSatelliteSupportedViaCarrier(subId)) {
                int[] services = getSupportedSatelliteServicesForCarrier(subId);
                if (isP2PSmsDisallowedOnCarrierRoamingNtn(mSatellitePhone)) {
                    services = Arrays.stream(services).filter(
                            value -> value != NetworkRegistrationInfo.SERVICE_TYPE_SMS).toArray();
                }
                mSatellitePhone.notifyCarrierRoamingNtnAvailableServicesChanged(services);
            } else {
                mSatellitePhone.notifyCarrierRoamingNtnAvailableServicesChanged(new int[0]);
            }
        }
    }

    /**
     * Whether the P2P SMS over carrier roaming satellite is disallowed or not.
     *
     * @param phone phone object
     * return {@code true} when the phone does not support P2P SMS over carrier roaming satellite
     *        {@code false} otherwise
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public boolean isP2PSmsDisallowedOnCarrierRoamingNtn(@NonNull Phone phone) {
        int subId = phone.getSubId();
        int carrierRoamingNtnConnectType = getCarrierRoamingNtnConnectType(subId);
        if (carrierRoamingNtnConnectType == CARRIER_ROAMING_NTN_CONNECT_MANUAL) {
            // Manual Connected
            plogd("isP2PSmsDisallowedOnCarrierRoamingNtn: manual connect");
            String msgPackageName = Telephony.Sms.getDefaultSmsPackage(mContext);
            String sgPackageName = getConfigSatelliteGatewayServicePackage();
            if (!isApplicationSupportsP2P(msgPackageName)
                    || !isApplicationSupportsP2P(sgPackageName)) {
                plogd("isP2PSmsSupportedOnCarrierRoamingNtn APKs do not supports P2P");
                return true;
            }
        }
        plogd("isP2PSmsDisallowedOnCarrierRoamingNtn [phoneId="
                + phone.getPhoneId() + "]: P2P is supported");
        return false;
    }

    @NonNull
    private int[] getSupportedSatelliteServicesForCarrier(int subId) {
        PersistableBundle config = getPersistableBundle(subId);
        int[] availableServices = config.getIntArray(
                KEY_CARRIER_ROAMING_SATELLITE_DEFAULT_SERVICES_INT_ARRAY);
        if (availableServices == null) {
            logd("getSupportedSatelliteServicesForCarrier: defaultCapabilities is null");
            return new int[0];
        }
        logd("getSupportedSatelliteServicesForCarrier: subId=" + subId
                + ", return default values " + Arrays.toString(availableServices));
        return availableServices;
    }

/**
 * Whether application supports the P2P SMS to connect to carrier roaming non-terrestrial network.
 *
 * @param packageName application's default package name
 * return {@code true} when the application supports P2P SMS over the roaming satellite
 */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public boolean isApplicationSupportsP2P(String packageName) {
        PackageManager pm = mContext.getPackageManager();
        ApplicationInfo applicationInfo = new ApplicationInfo();
        try {
            applicationInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        } catch (PackageManager.NameNotFoundException e) {
            logd("isApplicationSupportsP2P pkgName: " + packageName + " is not installed.");
        }
        if (applicationInfo == null || applicationInfo.metaData == null) {
            logd("isApplicationSupportsP2P pkgName: " + packageName + " meta-data info is empty.");
            return false;
        }
        return applicationInfo.metaData.getBoolean(
                SatelliteManager.METADATA_SATELLITE_MANUAL_CONNECT_P2P_SUPPORT);
    }
}
Loading