Dumpsys support for IncrementalService.

Test: atest PackageManagerShellCommandTest
Test: adb shell dumpsys incremental
Bug: b/136132412 b/133435829
Change-Id: I8a91eddb850c68da87f56a82ca14fdf9ac5d3ce5
diff --git a/services/incremental/BinderIncrementalService.cpp b/services/incremental/BinderIncrementalService.cpp
index 91d0572..0941831 100644
--- a/services/incremental/BinderIncrementalService.cpp
+++ b/services/incremental/BinderIncrementalService.cpp
@@ -17,12 +17,14 @@
 #include "BinderIncrementalService.h"
 
 #include <binder/IResultReceiver.h>
+#include <binder/PermissionCache.h>
 #include <incfs.h>
 
 #include "ServiceWrappers.h"
 #include "jni.h"
 #include "nativehelper/JNIHelp.h"
 #include "path.h"
+#include <android-base/logging.h>
 
 using namespace std::literals;
 using namespace android::incremental;
@@ -90,8 +92,13 @@
     return self.get();
 }
 
-status_t BinderIncrementalService::dump(int fd, const Vector<String16>& args) {
-    return OK;
+status_t BinderIncrementalService::dump(int fd, const Vector<String16>&) {
+    static const String16 kDump("android.permission.DUMP");
+    if (!PermissionCache::checkCallingPermission(kDump)) {
+        return PERMISSION_DENIED;
+    }
+    mImpl.onDump(fd);
+    return NO_ERROR;
 }
 
 void BinderIncrementalService::onSystemReady() {
@@ -280,3 +287,10 @@
         ((android::os::incremental::BinderIncrementalService*)self)->onSystemReady();
     }
 }
+void Incremental_IncrementalService_OnDump(jlong self, jint fd) {
+    if (self) {
+        ((android::os::incremental::BinderIncrementalService*)self)->dump(fd, {});
+    } else {
+        dprintf(fd, "BinderIncrementalService is stopped.");
+    }
+}