Add debug command to remote access HAL.

Add debug command to test remote access HAL.

Bug: 241483300
Test: Follow:
change file sytem to read-write.
m -j TestWakeupClientServer
adb push
out/target/product/emulator_car64_x86_64/vendor/bin/TestWakeupClientServer
/vendor/bin

In one adb shell:
/vendor/bin/TestWakeupClientServer

In another shell:
dumpsys android.hardware.automotive.remoteaccess.IRemoteAccess/default --start-debug-callback
dumpsys android.hardware.automotive.remoteaccess.IRemoteAccess/default --show-task
[should show no tasks]
dumpsys android.hardware.automotive.remoteaccess.IRemoteAccess/default --ready-for-remote-task 1
[wait for 5s]
dumpsys android.hardware.automotive.remoteaccess.IRemoteAccess/default --show-task
[should see all the tasks from client ID 1]
dumpsys android.hardware.automotive.remoteaccess.IRemoteAccess/default --ready-for-remote-task 0
[wait for 5s]
dumpsys android.hardware.automotive.remoteaccess.IRemoteAccess/default --show-task
[should see no new tasks]
dumpsys android.hardware.automotive.remoteaccess.IRemoteAccess/default
--ready-for-remote-task 1
dumpsys android.hardware.automotive.remoteaccess.IRemoteAccess/default --show-task
[should see new tasks]

Change-Id: I551bf9ab5b55c4de9d8382d69bd5078ec62cad51
diff --git a/automotive/remoteaccess/hal/default/include/RemoteAccessService.h b/automotive/remoteaccess/hal/default/include/RemoteAccessService.h
index 806440a..207c093 100644
--- a/automotive/remoteaccess/hal/default/include/RemoteAccessService.h
+++ b/automotive/remoteaccess/hal/default/include/RemoteAccessService.h
@@ -18,8 +18,11 @@
 
 #include <aidl/android/hardware/automotive/remoteaccess/ApState.h>
 #include <aidl/android/hardware/automotive/remoteaccess/BnRemoteAccess.h>
+#include <aidl/android/hardware/automotive/remoteaccess/BnRemoteTaskCallback.h>
 #include <aidl/android/hardware/automotive/remoteaccess/IRemoteTaskCallback.h>
 #include <android-base/thread_annotations.h>
+#include <android/binder_auto_utils.h>
+#include <utils/SystemClock.h>
 #include <wakeup_client.grpc.pb.h>
 
 #include <string>
@@ -30,6 +33,27 @@
 namespace automotive {
 namespace remoteaccess {
 
+// A IRemoteTaskCallback implementation for debug purpose.
+class DebugRemoteTaskCallback final
+    : public aidl::android::hardware::automotive::remoteaccess::BnRemoteTaskCallback {
+  public:
+    DebugRemoteTaskCallback() { mStartTimeMillis = android::uptimeMillis(); };
+
+    ndk::ScopedAStatus onRemoteTaskRequested(const std::string& clientId,
+                                             const std::vector<uint8_t>& data) override;
+    std::string printTasks();
+
+  private:
+    struct TaskData {
+        std::string clientId;
+        std::vector<uint8_t> data;
+    };
+
+    std::mutex mLock;
+    int64_t mStartTimeMillis;
+    std::vector<TaskData> mTasks;
+};
+
 class RemoteAccessService
     : public aidl::android::hardware::automotive::remoteaccess::BnRemoteAccess {
   public:
@@ -51,10 +75,14 @@
     ndk::ScopedAStatus notifyApStateChange(
             const aidl::android::hardware::automotive::remoteaccess::ApState& newState) override;
 
+    binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
+
   private:
     // For testing.
     friend class RemoteAccessServiceUnitTest;
 
+    static bool checkDumpPermission();
+
     WakeupClient::StubInterface* mGrpcStub;
     std::thread mThread;
     std::mutex mLock;
@@ -69,12 +97,14 @@
     bool mTaskLoopRunning GUARDED_BY(mStartStopTaskLoopLock);
     // Default wait time before retry connecting to remote access client is 10s.
     size_t mRetryWaitInMs = 10'000;
+    std::shared_ptr<DebugRemoteTaskCallback> mDebugCallback;
 
     void runTaskLoop();
     void maybeStartTaskLoop();
     void maybeStopTaskLoop();
 
     void setRetryWaitInMs(size_t retryWaitInMs) { mRetryWaitInMs = retryWaitInMs; }
+    void dumpHelp(int fd);
 };
 
 }  // namespace remoteaccess