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

Commit a0a0d94a authored by Hakjun Choi's avatar Hakjun Choi
Browse files

Add carrier roaming atom should be reported per subscription ID

Currently carrier roaming metrics has only on snapshot, it is needed to distinguish atom per subscription

Bug: 366329504
Flag: com.android.internal.telephony.flags.carrier_roaming_nb_iot_ntn
Test: atest PersistAtomsStorageTest, SatelliteStatsTest
      manually run and get the DB to verify whether atoms are reported as expected
Change-Id: If48652f97363c6467c007752da241825199e28a1
parent 937f7e25
Loading
Loading
Loading
Loading
+32 −19
Original line number Diff line number Diff line
@@ -861,26 +861,24 @@ public class PersistAtomsStorage {
    /** Adds a new {@link CarrierRoamingSatelliteControllerStats} to the storage. */
    public synchronized void addCarrierRoamingSatelliteControllerStats(
            CarrierRoamingSatelliteControllerStats stats) {
        // CarrierRoamingSatelliteController is a single data point
        CarrierRoamingSatelliteControllerStats[] atomArray =
                mAtoms.carrierRoamingSatelliteControllerStats;
        if (atomArray == null || atomArray.length == 0) {
            atomArray = new CarrierRoamingSatelliteControllerStats[] {new
                    CarrierRoamingSatelliteControllerStats()};
        }

        CarrierRoamingSatelliteControllerStats atom = atomArray[0];
        atom.configDataSource = stats.configDataSource;
        atom.countOfEntitlementStatusQueryRequest += stats.countOfEntitlementStatusQueryRequest;
        atom.countOfSatelliteConfigUpdateRequest += stats.countOfSatelliteConfigUpdateRequest;
        atom.countOfSatelliteNotificationDisplayed += stats.countOfSatelliteNotificationDisplayed;
        atom.satelliteSessionGapMinSec = stats.satelliteSessionGapMinSec;
        atom.satelliteSessionGapAvgSec = stats.satelliteSessionGapAvgSec;
        atom.satelliteSessionGapMaxSec = stats.satelliteSessionGapMaxSec;
        atom.carrierId = stats.carrierId;
        atom.isDeviceEntitled = stats.isDeviceEntitled;
        CarrierRoamingSatelliteControllerStats existingStats = find(stats);
        if (existingStats != null) {
            existingStats.configDataSource = stats.configDataSource;
            existingStats.countOfEntitlementStatusQueryRequest +=
                    stats.countOfEntitlementStatusQueryRequest;
            existingStats.countOfSatelliteConfigUpdateRequest +=
                    stats.countOfSatelliteConfigUpdateRequest;
            existingStats.countOfSatelliteNotificationDisplayed +=
                    stats.countOfSatelliteNotificationDisplayed;
            existingStats.satelliteSessionGapMinSec = stats.satelliteSessionGapMinSec;
            existingStats.satelliteSessionGapAvgSec = stats.satelliteSessionGapAvgSec;
            existingStats.satelliteSessionGapMaxSec = stats.satelliteSessionGapMaxSec;
            existingStats.isDeviceEntitled = stats.isDeviceEntitled;
        } else {
            mAtoms.carrierRoamingSatelliteControllerStats = insertAtRandomPlace(
                    mAtoms.carrierRoamingSatelliteControllerStats, stats, mMaxNumSatelliteStats);
        }

        mAtoms.carrierRoamingSatelliteControllerStats = atomArray;
        saveAtomsToFile(SAVE_TO_FILE_DELAY_FOR_UPDATE_MILLIS);
    }

@@ -2391,6 +2389,21 @@ public class PersistAtomsStorage {
        return null;
    }

    /**
     * Returns CarrierRoamingSatelliteControllerStats atom that has same carrier_id value or
     * {@code null} if does not exist.
     */
    private @Nullable CarrierRoamingSatelliteControllerStats find(
            CarrierRoamingSatelliteControllerStats key) {
        for (CarrierRoamingSatelliteControllerStats stats :
                mAtoms.carrierRoamingSatelliteControllerStats) {
            if (stats.carrierId == key.carrierId) {
                return stats;
            }
        }
        return null;
    }

    /**
     * Returns SatelliteEntitlement atom that has same values or {@code null} if it does not exist.
     */
+55 −33
Original line number Diff line number Diff line
@@ -4974,43 +4974,56 @@ public class PersistAtomsStorageTest extends TelephonyTest {
    }

    @Test
    public void addCarrierRoamingSatelliteControllerStats_withExistingEntries() throws Exception {
    public void addCarrierRoamingSatelliteControllerStats_withExistingCarrierId() throws Exception {
        createEmptyTestFile();
        mPersistAtomsStorage = new TestablePersistAtomsStorage(mContext);
        mPersistAtomsStorage.addCarrierRoamingSatelliteControllerStats(
                mCarrierRoamingSatelliteControllerStats1);
                copyOf(mCarrierRoamingSatelliteControllerStats1));
        mPersistAtomsStorage.addCarrierRoamingSatelliteControllerStats(
                mCarrierRoamingSatelliteControllerStats2);
                copyOf(mCarrierRoamingSatelliteControllerStats1));
        mPersistAtomsStorage.incTimeMillis(100L);

        CarrierRoamingSatelliteControllerStats expected =
                new CarrierRoamingSatelliteControllerStats();
        expected.configDataSource = mCarrierRoamingSatelliteControllerStats2.configDataSource;
        expected.configDataSource = mCarrierRoamingSatelliteControllerStats1.configDataSource;
        expected.countOfEntitlementStatusQueryRequest =
                mCarrierRoamingSatelliteControllerStats1.countOfEntitlementStatusQueryRequest
                        + mCarrierRoamingSatelliteControllerStats2
                        .countOfEntitlementStatusQueryRequest;
                mCarrierRoamingSatelliteControllerStats1.countOfEntitlementStatusQueryRequest * 2;
        expected.countOfSatelliteConfigUpdateRequest =
                mCarrierRoamingSatelliteControllerStats1.countOfSatelliteConfigUpdateRequest
                        + mCarrierRoamingSatelliteControllerStats2
                        .countOfSatelliteConfigUpdateRequest;
                mCarrierRoamingSatelliteControllerStats1.countOfSatelliteConfigUpdateRequest * 2;
        expected.countOfSatelliteNotificationDisplayed =
                mCarrierRoamingSatelliteControllerStats1.countOfSatelliteNotificationDisplayed
                + mCarrierRoamingSatelliteControllerStats2
                        .countOfSatelliteNotificationDisplayed;
                mCarrierRoamingSatelliteControllerStats1.countOfSatelliteNotificationDisplayed * 2;
        expected.satelliteSessionGapMinSec =
                mCarrierRoamingSatelliteControllerStats2.satelliteSessionGapMinSec;
                mCarrierRoamingSatelliteControllerStats1.satelliteSessionGapMinSec;
        expected.satelliteSessionGapAvgSec =
                mCarrierRoamingSatelliteControllerStats2.satelliteSessionGapAvgSec;
                mCarrierRoamingSatelliteControllerStats1.satelliteSessionGapAvgSec;
        expected.satelliteSessionGapMaxSec =
                mCarrierRoamingSatelliteControllerStats2.satelliteSessionGapMaxSec;
        expected.carrierId = mCarrierRoamingSatelliteControllerStats2.carrierId;
        expected.isDeviceEntitled = mCarrierRoamingSatelliteControllerStats2.isDeviceEntitled;

                mCarrierRoamingSatelliteControllerStats1.satelliteSessionGapMaxSec;
        expected.carrierId = mCarrierRoamingSatelliteControllerStats1.carrierId;
        expected.isDeviceEntitled = mCarrierRoamingSatelliteControllerStats1.isDeviceEntitled;
        verifyCurrentStateSavedToFileOnce();
        CarrierRoamingSatelliteControllerStats[] output =
                mPersistAtomsStorage.getCarrierRoamingSatelliteControllerStats(0L);
        assertHasStats(output, expected);
        assertHasStats(output, expected, 1);
    }

    @Test
    public void addCarrierRoamingSatelliteControllerStats_addNewCarrierId() throws Exception {
        createEmptyTestFile();
        mPersistAtomsStorage = new TestablePersistAtomsStorage(mContext);
        mPersistAtomsStorage.addCarrierRoamingSatelliteControllerStats(
                copyOf(mCarrierRoamingSatelliteControllerStats1));
        mPersistAtomsStorage.addCarrierRoamingSatelliteControllerStats(
                copyOf(mCarrierRoamingSatelliteControllerStats2));
        mPersistAtomsStorage.incTimeMillis(100L);

        CarrierRoamingSatelliteControllerStats expected1 = mCarrierRoamingSatelliteControllerStats1;
        CarrierRoamingSatelliteControllerStats expected2 = mCarrierRoamingSatelliteControllerStats2;

        CarrierRoamingSatelliteControllerStats[] output =
                mPersistAtomsStorage.getCarrierRoamingSatelliteControllerStats(0L);

        assertHasStats(output, expected1, 1);
        assertHasStats(output, expected2, 1);
    }

    @Test
@@ -6251,20 +6264,29 @@ public class PersistAtomsStorageTest extends TelephonyTest {
    }

    private static void assertHasStats(CarrierRoamingSatelliteControllerStats[] tested,
            @Nullable CarrierRoamingSatelliteControllerStats expectedStats) {
            @Nullable CarrierRoamingSatelliteControllerStats expectedStats, int expectedCount) {
        assertNotNull(tested);
        assertEquals(tested[0].configDataSource, expectedStats.configDataSource);
        assertEquals(tested[0].countOfEntitlementStatusQueryRequest,
                expectedStats.countOfEntitlementStatusQueryRequest);
        assertEquals(tested[0].countOfSatelliteConfigUpdateRequest,
                expectedStats.countOfSatelliteConfigUpdateRequest);
        assertEquals(tested[0].countOfSatelliteNotificationDisplayed,
                expectedStats.countOfSatelliteNotificationDisplayed);
        assertEquals(tested[0].satelliteSessionGapMinSec, expectedStats.satelliteSessionGapMinSec);
        assertEquals(tested[0].satelliteSessionGapAvgSec, expectedStats.satelliteSessionGapAvgSec);
        assertEquals(tested[0].satelliteSessionGapMaxSec, expectedStats.satelliteSessionGapMaxSec);
        assertEquals(tested[0].carrierId, expectedStats.carrierId);
        assertEquals(tested[0].isDeviceEntitled, expectedStats.isDeviceEntitled);
        int count = 0;
        for (CarrierRoamingSatelliteControllerStats stats : tested) {
            if (expectedStats.carrierId == stats.carrierId) {
                assertEquals(expectedStats.configDataSource, stats.configDataSource);
                assertEquals(expectedStats.countOfEntitlementStatusQueryRequest,
                        stats.countOfEntitlementStatusQueryRequest);
                assertEquals(expectedStats.countOfSatelliteConfigUpdateRequest,
                        stats.countOfSatelliteConfigUpdateRequest);
                assertEquals(expectedStats.countOfSatelliteNotificationDisplayed,
                        stats.countOfSatelliteNotificationDisplayed);
                assertEquals(expectedStats.satelliteSessionGapMinSec,
                        stats.satelliteSessionGapMinSec);
                assertEquals(expectedStats.satelliteSessionGapAvgSec,
                        stats.satelliteSessionGapAvgSec);
                assertEquals(expectedStats.satelliteSessionGapMaxSec,
                        stats.satelliteSessionGapMaxSec);
                assertEquals(expectedStats.isDeviceEntitled, stats.isDeviceEntitled);
                count++;
            }
        }
        assertEquals(expectedCount, count);
    }

    private static void assertHasStatsAndCount(