From 452e464ee9506f2e8b4cd66cbd3e56c443534210 Mon Sep 17 00:00:00 2001
From: Junyu Lai <junyulai@google.com>
Date: Thu, 5 Oct 2023 17:21:19 +0800
Subject: [PATCH] Support shell command to get bpf program id

Test: atest NetworkStatsIntegrationTest#testBpfProgramAttachStatus
Bug: 292156770

Change-Id: I815be0f3f3592442939872f98e3ad9d224a6aeb6
---
 .../src/com/android/server/ConnectivityService.java   | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java
index 86f49d35bb..338a4f308e 100755
--- a/service/src/com/android/server/ConnectivityService.java
+++ b/service/src/com/android/server/ConnectivityService.java
@@ -10784,6 +10784,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
                         Log.d(TAG, "Reevaluating network " + nai.network);
                         reportNetworkConnectivity(nai.network, !nai.isValidated());
                         return 0;
+                    case "bpf-get-cgroup-program-id": {
+                        // Usage : adb shell cmd connectivity bpf-get-cgroup-program-id <type>
+                        // Get cgroup bpf program Id for the given type. See BpfUtils#getProgramId
+                        // for more detail.
+                        // If type can't be parsed, this throws NumberFormatException, which
+                        // is passed back to adb who prints it.
+                        final int type = Integer.parseInt(getNextArg());
+                        final int ret = BpfUtils.getProgramId(type, BpfUtils.CGROUP_PATH);
+                        pw.println(ret);
+                        return 0;
+                    }
                     default:
                         return handleDefaultCommands(cmd);
                 }
-- 
GitLab