Add ScheduleInfo validity check.

Define the max task data size. Requires remote access HAL to return
invalid arg if ScheduleInfo is not valid.

Updated the reference impl to add the checks.

Test: atest RemoteAccessServiceUnitTest
Bug: 317405128
Change-Id: Ia17dda2683c3bcc861542cb2fbd812ce8bd368aa
diff --git a/automotive/remoteaccess/hal/default/src/RemoteAccessService.cpp b/automotive/remoteaccess/hal/default/src/RemoteAccessService.cpp
index 2a7f209..1b42a1f 100644
--- a/automotive/remoteaccess/hal/default/src/RemoteAccessService.cpp
+++ b/automotive/remoteaccess/hal/default/src/RemoteAccessService.cpp
@@ -331,6 +331,24 @@
     ClientContext context;
     ScheduleTaskRequest request = {};
     ScheduleTaskResponse response = {};
+
+    if (scheduleInfo.count < 0) {
+        return ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
+                                                           "count must be >= 0");
+    }
+    if (scheduleInfo.startTimeInEpochSeconds < 0) {
+        return ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
+                                                           "startTimeInEpochSeconds must be >= 0");
+    }
+    if (scheduleInfo.periodicInSeconds < 0) {
+        return ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
+                                                           "periodicInSeconds must be >= 0");
+    }
+    if (scheduleInfo.taskData.size() > scheduleInfo.MAX_TASK_DATA_SIZE_IN_BYTES) {
+        return ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
+                                                           "task data too big");
+    }
+
     request.mutable_scheduleinfo()->set_clientid(scheduleInfo.clientId);
     request.mutable_scheduleinfo()->set_scheduleid(scheduleInfo.scheduleId);
     request.mutable_scheduleinfo()->set_data(scheduleInfo.taskData.data(),
@@ -348,7 +366,8 @@
         case ErrorCode::OK:
             return ScopedAStatus::ok();
         case ErrorCode::INVALID_ARG:
-            return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
+            return ScopedAStatus::fromExceptionCodeWithMessage(
+                    EX_ILLEGAL_ARGUMENT, "received invalid_arg from grpc server");
         default:
             // Should not happen.
             return ScopedAStatus::fromServiceSpecificErrorWithMessage(