Add support to query modem activity info in ril

Implement RIL_REQUEST_GET_ACTIVITY_INFO to pass testModemActivityInfo.

Bug: 78235709
Test: ./android-cts/tools/cts-tradefed run cts -m CtsStatsdHostTestCases \
          -t android.cts.statsd.atom.HostAtomTests#testModemActivityInfo
Signed-off-by: Roman Kiryanov <rkir@google.com>

Merged-In: I4df288f270d896027a19a495874e125ac5def359
(cherry picked from commit 9cd132b0458e0615d100cf0e1316870567155125)
diff --git a/ril/reference-ril.c b/ril/reference-ril.c
index 4503e1b..0f56a19 100644
--- a/ril/reference-ril.c
+++ b/ril/reference-ril.c
@@ -2414,6 +2414,44 @@
     free(p_response);
 }
 
+static void requestModemActivityInfo(RIL_Token t)
+{
+    int err;
+    char *line;
+    ATResponse *p_response = NULL;
+    RIL_ActivityStatsInfo info;
+
+    err = at_send_command_singleline("AT+MAI", "+MAI:", &p_response);
+    if (err < 0 || p_response == NULL || p_response->success == 0) {
+        ALOGE("Error transmitting AT+MAI, err=%d, success=%d",
+            err, (p_response ? p_response->success : 0));
+        goto error;
+    }
+
+    memset(&info, 0, sizeof(info));
+    if (sscanf(p_response->p_intermediates->line,
+               "+MAI: sleep=%u idle=%u rx=%u tx0=%u tx1=%u tx2=%u tx3=%u tx4=%u",
+               &info.sleep_mode_time_ms,
+               &info.idle_mode_time_ms,
+               &info.rx_mode_time_ms,
+               &info.tx_mode_time_ms[0],
+               &info.tx_mode_time_ms[1],
+               &info.tx_mode_time_ms[2],
+               &info.tx_mode_time_ms[3],
+               &info.tx_mode_time_ms[4]) == 8) {
+        RIL_onRequestComplete(t, RIL_E_SUCCESS, &info, sizeof(info));
+        at_response_free(p_response);
+        return;
+    } else {
+        ALOGE("Unexpected response for AT+MAI: '%s'",
+            p_response->p_intermediates->line);
+    }
+
+error:
+    at_response_free(p_response);
+    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
+}
+
 /*** Callback methods from the RIL library to us ***/
 
 /**
@@ -2874,6 +2912,10 @@
             }
             break;
 
+        case RIL_REQUEST_GET_ACTIVITY_INFO:
+            requestModemActivityInfo(t);
+            break;
+
         default:
             RLOGD("Request not supported. Tech: %d",TECH(sMdmInfo));
             RIL_onRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);