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

Commit 4e4b2a90 authored by Karthick M J's avatar Karthick M J
Browse files

Add validation checks for maxAllowedDataMode

On SatelliteConfig OTA, we need to validate if the incoming
SatelliteConfig has valid maxAllowedDataMode i.e. whether the
dataMode values are within the accepted range (0 to 2 =>
SATELLITE_DATA_SUPPORT_ONLY_RESTRICTED to SATELLITE_DATA_SUPPORT_ALL)
Only then, accept the incoming OTA

Bug: 417164189
Test: atest frameworks/opt/telephony/tests/telephonytests/src/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiverTest.java
Flag: EXEMPT bug fix
Change-Id: I305974719ada896d7a74d203884c3e38d6ec50e4
parent ba0934ef
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.util.Log;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.data.DataUtils;
import com.android.internal.telephony.satellite.SatelliteConfig;
import com.android.internal.telephony.satellite.SatelliteConfigParser;
import com.android.internal.telephony.satellite.SatelliteConstants;
@@ -140,6 +141,37 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec
        return true;
    }

    /**
     * Validates if the max allowed datamode is valid
     *
     * @param parser target of validation.
     * @return {@code true} if max allowed datamode is valid, {@code false} otherwise.
     */
    public boolean isValidMaxAllowedDataMode(@NonNull ConfigParser parser) {
        SatelliteConfig satelliteConfig = (SatelliteConfig) parser.getConfig();
        if (satelliteConfig == null) {
            Log.e(TAG, "satelliteConfig is null");
            mConfigUpdaterMetricsStats.reportOemAndCarrierConfigError(
                    SatelliteConstants.CONFIG_UPDATE_RESULT_NO_SATELLITE_DATA);
            return false;
        }

        Integer maxAllowedDataMode = satelliteConfig.getSatelliteMaxAllowedDataMode();
        if (maxAllowedDataMode == null) {
            Log.d(TAG, "maxAllowedDataMode is not set");
            return true;
        }

        if (!DataUtils.isValidDataMode(maxAllowedDataMode)) {
            Log.e(TAG, "found invalid maxAllowedDataMode : " + maxAllowedDataMode);
            mConfigUpdaterMetricsStats.reportCarrierConfigError(
                    SatelliteConstants
                            .CONFIG_UPDATE_RESULT_CARRIER_DATA_INVALID_MAX_ALLOWED_DATA_MODE);
            return false;
        }
        Log.d(TAG, "maxAllowedDataMode is valid");
        return true;
    }

    @Override
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED)
@@ -163,6 +195,11 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec
            return;
        }

        if (!isValidMaxAllowedDataMode(newConfigParser)) {
            Log.e(TAG, "received config data has invalid max allowed data mode");
            return;
        }

        synchronized (getInstance().mConfigParserLock) {
            if (getInstance().mConfigParser != null) {
                int updatedVersion = newConfigParser.mVersion;
+22 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.telephony.Annotation.DataActivityType;
import android.telephony.Annotation.NetCapability;
import android.telephony.Annotation.NetworkType;
import android.telephony.Annotation.ValidationStatus;
import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
import android.telephony.data.ApnSetting.ApnType;
@@ -502,4 +503,25 @@ public class DataUtils {
    private static void loge(String msg) {
        Rlog.e(TAG, msg);
    }

    /**
     * Checks if a given dataMode is valid or not.
     *
     * @param dataMode the data mode that needs to be validated.
     * @return {@code true} if data mode is valid, {@code false} otherwise.
     */
    public static boolean isValidDataMode(int dataMode) {
        if (dataMode < CarrierConfigManager.SATELLITE_DATA_SUPPORT_ONLY_RESTRICTED
                || CarrierConfigManager.SATELLITE_DATA_SUPPORT_ALL < dataMode) {
            loge(
                    "Invalid data mode: "
                            + dataMode
                            + ". It's not within the allowed range of data mode: "
                            + CarrierConfigManager.SATELLITE_DATA_SUPPORT_ONLY_RESTRICTED
                            + " - "
                            + CarrierConfigManager.SATELLITE_DATA_SUPPORT_ALL);
            return false;
        }
        return true;
    }
}
+22 −0
Original line number Diff line number Diff line
@@ -423,4 +423,26 @@ public class SatelliteConfig {
    private static void loge(@NonNull String log) {
        Log.e(TAG, log);
    }

    @Override
    public String toString() {
        return "SatelliteConfig{"
                + "mVersion="
                + mVersion
                + ", mSupportedServicesPerCarrier="
                + mSupportedServicesPerCarrier
                + ", mCarrierRoamingMaxAllowedDataMode="
                + mCarrierRoamingMaxAllowedDataMode
                + ", mSatelliteRegionCountryCodes="
                + mSatelliteRegionCountryCodes
                + ", mIsSatelliteRegionAllowed="
                + mIsSatelliteRegionAllowed
                + ", mSatS2File="
                + mSatS2File
                + ", mSatelliteAccessConfigJsonFile="
                + mSatelliteAccessConfigJsonFile
                + ", mConfigData="
                + mConfigData
                + "}";
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;


/**
 * SatelliteConfigParser parses the config data and create SatelliteConfig.
 * The config data is located at "/data/misc/telephonyconfig/telephony_config.pb".
@@ -83,7 +82,7 @@ public class SatelliteConfigParser extends ConfigParser<SatelliteConfig> {
            Log.d(TAG, "SatelliteConfig is created");
        } catch (Exception e) {
            parseError = true;
            Log.e(TAG, "Parse Error : " + e.getMessage());
            Log.e(TAG, "Parse Error", e);
        } finally {
            if (parseError) {
                mVersion = VERSION_UNKNOWN;
+19 −15
Original line number Diff line number Diff line
@@ -67,8 +67,11 @@ public class SatelliteConstants {
    public static final int CONFIG_UPDATE_RESULT_DEVICE_DATA_INVALID_S2_CELL_FILE = 10;
    public static final int CONFIG_UPDATE_RESULT_IO_ERROR = 11;
    public static final int CONFIG_UPDATE_RESULT_INVALID_SATELLITE_ACCESS_CONFIG_FILE = 12;
    public static final int CONFIG_UPDATE_RESULT_CARRIER_DATA_INVALID_MAX_ALLOWED_DATA_MODE = 13;

    @IntDef(prefix = {"CONFIG_UPDATE_RESULT_"}, value = {
    @IntDef(
            prefix = {"CONFIG_UPDATE_RESULT_"},
            value = {
                CONFIG_UPDATE_RESULT_UNKNOWN,
                CONFIG_UPDATE_RESULT_SUCCESS,
                CONFIG_UPDATE_RESULT_INVALID_DOMAIN,
@@ -81,7 +84,8 @@ public class SatelliteConstants {
                CONFIG_UPDATE_RESULT_DEVICE_DATA_INVALID_COUNTRY_CODE,
                CONFIG_UPDATE_RESULT_DEVICE_DATA_INVALID_S2_CELL_FILE,
                CONFIG_UPDATE_RESULT_IO_ERROR,
            CONFIG_UPDATE_RESULT_INVALID_SATELLITE_ACCESS_CONFIG_FILE
                CONFIG_UPDATE_RESULT_INVALID_SATELLITE_ACCESS_CONFIG_FILE,
                CONFIG_UPDATE_RESULT_CARRIER_DATA_INVALID_MAX_ALLOWED_DATA_MODE
            })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ConfigUpdateResult {}
Loading