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

Commit d15f275c authored by Naina Nalluri's avatar Naina Nalluri
Browse files

Add Metrics for Data connected time

Reuse the existing DATA_CALL_LIST_CHANGED event
for Data connected, disconnected metrics.

Bug: 123954930
Test: on device
Change-Id: Ie723dc273fe6403a71a19b4b7b5e03947a181136
parent ac655aac
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -619,6 +619,24 @@ message RilDataCall {

  // The network interface name e.g. wlan0, rmnet_data0.
  optional string iframe = 3;

  // State of the Data Call connection
  optional State state = 4;

  // Bitmask of APN types
  optional int32 apn_type_bitmask = 5;

  enum State {

    // Unknown event
    UNKNOWN = 0;

    // Connected event
    CONNECTED = 1;

    // Disconnected event
    DISCONNECTED = 2;
  }
}

message TelephonyEvent {
+5 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.dataconnection.DcTracker.ReleaseNetworkType;
import com.android.internal.telephony.dataconnection.DcTracker.RequestNetworkType;
import com.android.internal.telephony.metrics.TelephonyMetrics;
import com.android.internal.telephony.nano.TelephonyProto.RilDataCall;
import com.android.internal.util.AsyncChannel;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Protocol;
@@ -1842,6 +1843,8 @@ public class DataConnection extends StateMachine {
                mPhone.mCi.registerForLceInfo(
                        getHandler(), DataConnection.EVENT_LINK_CAPACITY_CHANGED, null);
            }
            TelephonyMetrics.getInstance().writeRilDataCallEvent(mPhone.getPhoneId(),
                    mCid, mApnSetting.getApnTypeBitmask(), RilDataCall.State.CONNECTED);
        }

        @Override
@@ -1876,6 +1879,8 @@ public class DataConnection extends StateMachine {
                }
                mNetworkAgent = null;
            }
            TelephonyMetrics.getInstance().writeRilDataCallEvent(mPhone.getPhoneId(),
                    mCid, mApnSetting.getApnTypeBitmask(), RilDataCall.State.DISCONNECTED);
        }

        @Override
+43 −16
Original line number Diff line number Diff line
@@ -198,6 +198,12 @@ public class TelephonyMetrics {
     */
    private final SparseArray<CarrierIdMatching> mLastCarrierId = new SparseArray<>();

    /**
     * Last RilDataCall Events (indexed by cid), indexed by phone id
     */
    private final SparseArray<SparseArray<RilDataCall>> mLastRilDataCallEvents =
            new SparseArray<>();

    /** The start system time of the TelephonyLog in milliseconds*/
    private long mStartSystemTimeMs;

@@ -606,6 +612,16 @@ public class TelephonyMetrics {
            addTelephonyEvent(event);
        }

        for (int i = 0; i < mLastRilDataCallEvents.size(); i++) {
            final int key = mLastRilDataCallEvents.keyAt(i);
            for (int j = 0; j < mLastRilDataCallEvents.get(key).size(); j++) {
                final int cidKey = mLastRilDataCallEvents.get(key).keyAt(j);
                RilDataCall[] dataCalls = new RilDataCall[1];
                dataCalls[0] = mLastRilDataCallEvents.get(key).get(cidKey);
                addTelephonyEvent(new TelephonyEventBuilder(mStartElapsedTimeMs, key)
                        .setDataCalls(dataCalls).build());
            }
        }
        addTelephonyEvent(new TelephonyEventBuilder(mStartElapsedTimeMs, -1 /* phoneId */)
                .setSimStateChange(mLastSimState).build());

@@ -1332,25 +1348,36 @@ public class TelephonyMetrics {
    }

    /**
     * Write get data call list event
     *
     * Write data call list event when connected
     * @param phoneId          Phone id
     * @param dcsList Data call list
     */
    public void writeRilDataCallList(int phoneId, ArrayList<DataCallResponse> dcsList) {

        RilDataCall[] dataCalls = new RilDataCall[dcsList.size()];

        for (int i = 0; i < dcsList.size(); i++) {
            dataCalls[i] = new RilDataCall();
            dataCalls[i].cid = dcsList.get(i).getCallId();
            if (!TextUtils.isEmpty(dcsList.get(i).getIfname())) {
                dataCalls[i].iframe = dcsList.get(i).getIfname();
     * @param cid              Context Id, uniquely identifies the call
     * @param apnTypeBitmask   Bitmask of supported APN types
     * @param state            State of the data call event
     */
    public void writeRilDataCallEvent(int phoneId, int cid,
            int apnTypeBitmask, int state) {
        RilDataCall[] dataCalls = new RilDataCall[1];
        dataCalls[0] = new RilDataCall();
        dataCalls[0].cid = cid;
        dataCalls[0].apnTypeBitmask = apnTypeBitmask;
        dataCalls[0].state = state;

        SparseArray<RilDataCall> dataCallList;
        if (mLastRilDataCallEvents.get(phoneId) != null) {
            // If the Data call event does not change, do not log it.
            if (mLastRilDataCallEvents.get(phoneId).get(cid) != null
                    && Arrays.equals(
                        RilDataCall.toByteArray(mLastRilDataCallEvents.get(phoneId).get(cid)),
                        RilDataCall.toByteArray(dataCalls[0]))) {
                return;
            }

            dataCalls[i].type = dcsList.get(i).getProtocolType() + 1;
            dataCallList =  mLastRilDataCallEvents.get(phoneId);
        } else {
            dataCallList = new SparseArray<>();
        }

        dataCallList.put(cid, dataCalls[0]);
        mLastRilDataCallEvents.put(phoneId, dataCallList);
        addTelephonyEvent(new TelephonyEventBuilder(phoneId).setDataCalls(dataCalls).build());
    }