Switch ShellCommand usage into BasicShellCommandHandler

- Removed hidden API access

Bug: 197356318
Test: run shell command: adb shell cmd car_service
      run tests with shell access:
        atest CarUILibUnitTests:com.android.car.ui.toolbar.ToolbarSearchTest
Change-Id: I71bc645f8f8cdf80baf24b9891ac17336cfac55b
diff --git a/service/src/com/android/car/CarShellCommand.java b/service/src/com/android/car/CarShellCommand.java
index ea5f3e5..27d48f6 100644
--- a/service/src/com/android/car/CarShellCommand.java
+++ b/service/src/com/android/car/CarShellCommand.java
@@ -85,7 +85,6 @@
 import android.os.Build;
 import android.os.Process;
 import android.os.RemoteException;
-import android.os.ShellCommand;
 import android.os.SystemClock;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -111,6 +110,7 @@
 import com.android.car.user.UserHandleHelper;
 import com.android.car.watchdog.CarWatchdogService;
 import com.android.internal.util.Preconditions;
+import com.android.modules.utils.BasicShellCommandHandler;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -123,7 +123,7 @@
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-final class CarShellCommand extends ShellCommand {
+final class CarShellCommand extends BasicShellCommandHandler {
 
     private static final String NO_INITIAL_USER = "N/A";
 
diff --git a/service/src/com/android/car/ICarImpl.java b/service/src/com/android/car/ICarImpl.java
index 6b571b1..37542e6 100644
--- a/service/src/com/android/car/ICarImpl.java
+++ b/service/src/com/android/car/ICarImpl.java
@@ -747,11 +747,16 @@
         writer.println("\t  runs the given command (use --h to see the available commands)");
     }
 
+    // Override Binder.onShellCommand and there is no shell id check.
+    // All critical operations should be protected with permissions inside CarShellCommand.
     @Override
     public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
             String[] args, ShellCallback callback, ResultReceiver resultReceiver)
                     throws RemoteException {
-        newCarShellCommand().exec(this, in, out, err, args, callback, resultReceiver);
+        int result = newCarShellCommand().exec(this, in, out, err, args);
+        if (resultReceiver != null) {
+            resultReceiver.send(result, null);
+        }
     }
 
     private CarShellCommand newCarShellCommand() {