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

Commit b4bccbdc authored by Jinyoung Jeong's avatar Jinyoung Jeong Committed by Gerrit Code Review
Browse files

Merge "TransportFeatureTagStats metrics inconsistencies"

parents a16b1ab3 37d26eb3
Loading
Loading
Loading
Loading
+23 −10
Original line number Diff line number Diff line
@@ -412,10 +412,14 @@ public class RcsStats {

        private class LastFeatureTagState {
            public long timeStamp;
            public int carrierId;
            public int slotId;
            public int state;
            public int reason;

            LastFeatureTagState(int state, int reason, long timeStamp) {
            LastFeatureTagState(int carrierId, int slotId, int state, int reason, long timeStamp) {
                this.carrierId = carrierId;
                this.slotId = slotId;
                this.state = state;
                this.reason = reason;
                this.timeStamp = timeStamp;
@@ -444,17 +448,19 @@ public class RcsStats {
        /*** Create or update featureTags whenever feature Tag states are changed */
        public synchronized void updateLastFeatureTagState(String tagName, int state, int reason,
                long timeStamp) {
            int carrierId = getCarrierId(mSubId);
            int slotId = getSlotId(mSubId);
            if (mFeatureTagMap.containsKey(tagName)) {
                LastFeatureTagState lastFeatureTagState = mFeatureTagMap.get(tagName);
                if (lastFeatureTagState != null) {
                    addFeatureTagStat(tagName, lastFeatureTagState, timeStamp);
                    lastFeatureTagState.update(state, reason, timeStamp);
                } else {
                    create(tagName, state, reason, timeStamp);
                    create(tagName, carrierId, slotId, state, reason, timeStamp);
                }

            } else {
                create(tagName, state, reason, timeStamp);
                create(tagName, carrierId, slotId, state, reason, timeStamp);
            }
        }

@@ -474,8 +480,10 @@ public class RcsStats {
        private synchronized boolean addFeatureTagStat(@NonNull String tagName,
                @NonNull LastFeatureTagState lastFeatureTagState, long now) {
            long duration = now - lastFeatureTagState.timeStamp;
            if (duration < MIN_DURATION_MILLIS) {
                logd("conclude: discarding transient stats, duration= " + duration);
            if (duration < MIN_DURATION_MILLIS
                    || !isValidCarrierId(lastFeatureTagState.carrierId)) {
                logd("conclude: discarding transient stats, duration= " + duration
                        + ", carrierId = " + lastFeatureTagState.carrierId);
            } else {
                SipTransportFeatureTagStats sipFeatureTagStat = new SipTransportFeatureTagStats();
                switch (lastFeatureTagState.state) {
@@ -494,8 +502,8 @@ public class RcsStats {
                        break;
                }

                sipFeatureTagStat.carrierId = getCarrierId(mSubId);
                sipFeatureTagStat.slotId = getSlotId(mSubId);
                sipFeatureTagStat.carrierId = lastFeatureTagState.carrierId;
                sipFeatureTagStat.slotId = lastFeatureTagState.slotId;
                sipFeatureTagStat.associatedMillis = duration;
                sipFeatureTagStat.featureTagName = convertTagNameToValue(tagName);
                mAtomsStorage.addSipTransportFeatureTagStats(sipFeatureTagStat);
@@ -518,9 +526,10 @@ public class RcsStats {
            }
        }

        private LastFeatureTagState create(String tagName, int state, int reason, long timeStamp) {
            LastFeatureTagState lastFeatureTagState = new LastFeatureTagState(state, reason,
                    timeStamp);
        private LastFeatureTagState create(String tagName, int carrierId, int slotId, int state,
                int reason, long timeStamp) {
            LastFeatureTagState lastFeatureTagState = new LastFeatureTagState(carrierId, slotId,
                    state, reason, timeStamp);
            mFeatureTagMap.put(tagName, lastFeatureTagState);
            return lastFeatureTagState;
        }
@@ -1411,6 +1420,10 @@ public class RcsStats {
        return sipTransportFeatureTags;
    }

    private boolean isValidCarrierId(int carrierId) {
        return carrierId > TelephonyManager.UNKNOWN_CARRIER_ID;
    }

    @VisibleForTesting
    protected int getSlotId(int subId) {
        return SubscriptionManager.getPhoneId(subId);
+35 −2
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ public class RcsStatsTest extends TelephonyTest {
    private static final int SLOT2_ID = 1;
    private static final int CARRIER_ID = 100;
    private static final int CARRIER2_ID = 200;
    private static final int INVALID_CARRIER_ID = -1;
    private static final int INVALID_SUB_ID = Integer.MIN_VALUE;

    private class TestResult {
        public String tagName;
@@ -105,11 +107,14 @@ public class RcsStatsTest extends TelephonyTest {

        @Override
        protected int getCarrierId(int subId) {
            if (subId == mSubId) {
            if (subId == INVALID_SUB_ID) {
                return INVALID_CARRIER_ID;
            } else if (subId == mSubId) {
                return CARRIER_ID;
            }
            } else {
                return CARRIER2_ID;
            }
        }

        @Override
        protected long getWallTimeMillis() {
@@ -612,6 +617,34 @@ public class RcsStatsTest extends TelephonyTest {
        verifyNoMoreInteractions(mPersistAtomsStorage);
    }

    @Test
    @SmallTest
    public void onSipTransportFeatureTagStats_addInvalidEntries() throws Exception {
        final long timeGap = 6000L;
        Set<FeatureTagState> deniedTags = new ArraySet<>();
        Set<FeatureTagState> deRegiTags = new ArraySet<>();
        Set<String> regiTags = new ArraySet<>();

        final int invalidSubId = INVALID_SUB_ID;

        // create new featureTags with an invalidId
        regiTags.add(FeatureTags.FEATURE_TAG_STANDALONE_MSG);
        deniedTags.add(new FeatureTagState(FeatureTags.FEATURE_TAG_FILE_TRANSFER,
                SipDelegateManager.DENIED_REASON_IN_USE_BY_ANOTHER_DELEGATE));
        mRcsStats.onSipTransportFeatureTagStats(invalidSubId, deniedTags, deRegiTags, regiTags);
        mRcsStats.incTimeMillis(timeGap);

        // change status of featureTags with an invalidId
        regiTags.clear();
        deRegiTags.add(new FeatureTagState(FeatureTags.FEATURE_TAG_STANDALONE_MSG,
                DelegateRegistrationState.DEREGISTERED_REASON_NOT_REGISTERED));
        mRcsStats.onSipTransportFeatureTagStats(invalidSubId, deniedTags, deRegiTags, regiTags);
        mRcsStats.incTimeMillis(timeGap);

        verify(mPersistAtomsStorage, never()).addSipTransportFeatureTagStats(any());
    }


    @Test
    @SmallTest
    public void onSipTransportFeatureTagStats_addCustomTag() throws Exception {