Merge commit '5c3b2b4267ad0ba4f7e7e8e38b91a8aeb1eb30a0' into dec6

Change-Id: I28754671bdbe34c768f5babd4e8028a93391f45e
diff --git a/cmds/installd/Android.mk b/cmds/installd/Android.mk
index 1f5ae65..4ddbc8b 100644
--- a/cmds/installd/Android.mk
+++ b/cmds/installd/Android.mk
@@ -24,13 +24,15 @@
 LOCAL_CFLAGS += -DART_BASE_ADDRESS_MIN_DELTA=$(LOCAL_LIBART_IMG_HOST_MIN_BASE_ADDRESS_DELTA)
 LOCAL_CFLAGS += -DART_BASE_ADDRESS_MAX_DELTA=$(LOCAL_LIBART_IMG_HOST_MAX_BASE_ADDRESS_DELTA)
 
-LOCAL_SRC_FILES := otapreopt.cpp commands.cpp globals.cpp utils.cpp
+LOCAL_SRC_FILES := otapreopt.cpp commands.cpp globals.cpp utils.cpp binder/android/os/IInstalld.aidl
 LOCAL_SHARED_LIBRARIES := \
     libbase \
+    libbinder \
     libcutils \
     liblog \
     liblogwrap \
     libselinux \
+    libutils \
 
 LOCAL_STATIC_LIBRARIES := libdiskusage
 LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
@@ -62,7 +64,7 @@
 
 include $(BUILD_PREBUILT)
 
-common_src_files := commands.cpp globals.cpp utils.cpp
+common_src_files := commands.cpp globals.cpp utils.cpp binder/android/os/IInstalld.aidl
 common_cflags := -Wall -Werror
 
 #
@@ -76,8 +78,10 @@
 LOCAL_CFLAGS := $(common_cflags)
 LOCAL_SHARED_LIBRARIES := \
     libbase \
+    libbinder \
     liblogwrap \
     libselinux \
+    libutils \
 
 LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk
 LOCAL_CLANG := true
@@ -91,10 +95,7 @@
 LOCAL_MODULE := installd
 LOCAL_MODULE_TAGS := optional
 LOCAL_CFLAGS := $(common_cflags)
-LOCAL_SRC_FILES := $(common_src_files) \
-    installd.cpp \
-    InstalldNativeService.cpp \
-    binder/android/os/IInstalld.aidl \
+LOCAL_SRC_FILES := $(common_src_files) installd.cpp
 
 LOCAL_SHARED_LIBRARIES := \
     libbase \
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp
deleted file mode 100644
index d68035f..0000000
--- a/cmds/installd/InstalldNativeService.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/**
- * Copyright (c) 2016, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "installd"
-
-#include <vector>
-#include <fstream>
-
-#include <android-base/stringprintf.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-#include <cutils/log.h>
-#include <cutils/properties.h>
-#include <private/android_filesystem_config.h>
-#include <utils/Errors.h>
-#include <utils/String16.h>
-
-#include "InstalldNativeService.h"
-
-#include "commands.h"
-
-using android::base::StringPrintf;
-
-namespace android {
-namespace installd {
-
-namespace {
-
-constexpr const char* kDump = "android.permission.DUMP";
-
-binder::Status checkPermission(const char* permission) {
-    pid_t pid;
-    uid_t uid;
-
-    if (checkCallingPermission(String16(permission), reinterpret_cast<int32_t*>(&pid),
-            reinterpret_cast<int32_t*>(&uid))) {
-        return binder::Status::ok();
-    } else {
-        auto err = StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission);
-        return binder::Status::fromExceptionCode(binder::Status::EX_SECURITY, String8(err.c_str()));
-    }
-}
-
-binder::Status checkUid(uid_t expectedUid) {
-    uid_t uid = IPCThreadState::self()->getCallingUid();
-    if (uid == expectedUid) {
-        return binder::Status::ok();
-    } else {
-        auto err = StringPrintf("UID %d is not expected UID %d", uid, expectedUid);
-        return binder::Status::fromExceptionCode(binder::Status::EX_SECURITY, String8(err.c_str()));
-    }
-}
-
-#define ENFORCE_UID(uid) {                                  \
-    binder::Status status = checkUid((uid));                \
-    if (!status.isOk()) {                                   \
-        return status;                                      \
-    }                                                       \
-}
-
-}  // namespace
-
-status_t InstalldNativeService::start() {
-    IPCThreadState::self()->disableBackgroundScheduling(true);
-    status_t ret = BinderService<InstalldNativeService>::publish();
-    if (ret != android::OK) {
-        return ret;
-    }
-    sp<ProcessState> ps(ProcessState::self());
-    ps->startThreadPool();
-    ps->giveThreadPoolName();
-    return android::OK;
-}
-
-status_t InstalldNativeService::dump(int fd, const Vector<String16> & /* args */) {
-    const binder::Status dump_permission = checkPermission(kDump);
-    if (!dump_permission.isOk()) {
-        const String8 msg(dump_permission.toString8());
-        write(fd, msg.string(), msg.size());
-        return PERMISSION_DENIED;
-    }
-
-    std::string msg = "installd is happy\n";
-    write(fd, msg.c_str(), strlen(msg.c_str()));
-    return NO_ERROR;
-}
-
-static binder::Status translateStatus(int ret) {
-    if (ret != 0) {
-        auto err = StringPrintf("Failed with error %d", ret);
-        return binder::Status::fromServiceSpecificError(ret, String8(err.c_str()));
-    } else {
-        return binder::Status::ok();
-    }
-}
-
-binder::Status InstalldNativeService::createAppData(const std::unique_ptr<std::string>& uuid,
-        const std::string& pkgname, int32_t userid, int32_t flags, int32_t appid,
-        const std::string& seinfo, int32_t targetSdkVersion) {
-    ENFORCE_UID(AID_SYSTEM);
-    const char* _uuid = uuid ? (*uuid).c_str() : nullptr;
-    return translateStatus(create_app_data(_uuid, pkgname.c_str(), userid, flags, appid,
-            seinfo.c_str(), targetSdkVersion));
-}
-
-}  // namespace installd
-}  // namespace android
diff --git a/cmds/installd/InstalldNativeService.h b/cmds/installd/InstalldNativeService.h
deleted file mode 100644
index 64973bf..0000000
--- a/cmds/installd/InstalldNativeService.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Copyright (c) 2016, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _INSTALLD_NATIVE_SERVICE_H_
-#define _INSTALLD_NATIVE_SERVICE_H_
-
-#include <vector>
-
-#include <binder/BinderService.h>
-
-#include "android/os/BnInstalld.h"
-
-namespace android {
-namespace installd {
-
-class InstalldNativeService : public BinderService<InstalldNativeService>, public os::BnInstalld {
-  public:
-    static status_t start();
-    static char const* getServiceName() { return "installd"; }
-    virtual status_t dump(int fd, const Vector<String16> &args) override;
-
-    binder::Status createAppData(const std::unique_ptr<std::string>& uuid,
-            const std::string& pkgname, int32_t userid, int32_t flags, int32_t appid,
-            const std::string& seinfo, int32_t targetSdkVersion);
-};
-
-}  // namespace installd
-}  // namespace android
-
-#endif  // _INSTALLD_NATIVE_SERVICE_H_
diff --git a/cmds/installd/binder/android/os/IInstalld.aidl b/cmds/installd/binder/android/os/IInstalld.aidl
index 5e36244..924a172 100644
--- a/cmds/installd/binder/android/os/IInstalld.aidl
+++ b/cmds/installd/binder/android/os/IInstalld.aidl
@@ -17,6 +17,9 @@
 package android.os;
 
 interface IInstalld {
-    void createAppData(in @nullable @utf8InCpp String uuid, in @utf8InCpp String pkgname,
-            int userid, int flags, int appid, in @utf8InCpp String seinfo, int targetSdkVersion);
+    void createAppData(in @nullable @utf8InCpp String uuid, in @utf8InCpp String packageName,
+            int userId, int flags, int appId, in @utf8InCpp String seInfo, int targetSdkVersion);
+    void moveCompleteApp(@nullable @utf8InCpp String fromUuid, @nullable @utf8InCpp String toUuid,
+            @utf8InCpp String packageName, @utf8InCpp String dataAppName, int appId,
+            @utf8InCpp String seInfo, int targetSdkVersion);
 }
diff --git a/cmds/installd/commands.cpp b/cmds/installd/commands.cpp
index 4e78f3e..bbc5160 100644
--- a/cmds/installd/commands.cpp
+++ b/cmds/installd/commands.cpp
@@ -86,6 +86,67 @@
 
 typedef int fd_t;
 
+namespace {
+
+constexpr const char* kDump = "android.permission.DUMP";
+
+binder::Status checkPermission(const char* permission) {
+    pid_t pid;
+    uid_t uid;
+
+    if (checkCallingPermission(String16(permission), reinterpret_cast<int32_t*>(&pid),
+            reinterpret_cast<int32_t*>(&uid))) {
+        return binder::Status::ok();
+    } else {
+        auto err = StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission);
+        return binder::Status::fromExceptionCode(binder::Status::EX_SECURITY, String8(err.c_str()));
+    }
+}
+
+binder::Status checkUid(uid_t expectedUid) {
+    uid_t uid = IPCThreadState::self()->getCallingUid();
+    if (uid == expectedUid || uid == AID_ROOT) {
+        return binder::Status::ok();
+    } else {
+        auto err = StringPrintf("UID %d is not expected UID %d", uid, expectedUid);
+        return binder::Status::fromExceptionCode(binder::Status::EX_SECURITY, String8(err.c_str()));
+    }
+}
+
+#define ENFORCE_UID(uid) {                                  \
+    binder::Status status = checkUid((uid));                \
+    if (!status.isOk()) {                                   \
+        return status;                                      \
+    }                                                       \
+}
+
+}  // namespace
+
+status_t InstalldNativeService::start() {
+    IPCThreadState::self()->disableBackgroundScheduling(true);
+    status_t ret = BinderService<InstalldNativeService>::publish();
+    if (ret != android::OK) {
+        return ret;
+    }
+    sp<ProcessState> ps(ProcessState::self());
+    ps->startThreadPool();
+    ps->giveThreadPoolName();
+    return android::OK;
+}
+
+status_t InstalldNativeService::dump(int fd, const Vector<String16> & /* args */) {
+    const binder::Status dump_permission = checkPermission(kDump);
+    if (!dump_permission.isOk()) {
+        const String8 msg(dump_permission.toString8());
+        write(fd, msg.string(), msg.size());
+        return PERMISSION_DENIED;
+    }
+
+    std::string msg = "installd is happy\n";
+    write(fd, msg.c_str(), strlen(msg.c_str()));
+    return NO_ERROR;
+}
+
 static bool property_get_bool(const char* property_name, bool default_value = false) {
     char tmp_property_value[kPropertyValueMax];
     bool have_property = get_property(property_name, tmp_property_value, nullptr) > 0;
@@ -106,7 +167,7 @@
  * if the label of that top-level file actually changed.  This can save us
  * significant time by avoiding no-op traversals of large filesystem trees.
  */
-static int restorecon_app_data_lazy(const std::string& path, const char* seinfo, uid_t uid) {
+static int restorecon_app_data_lazy(const std::string& path, const std::string& seInfo, uid_t uid) {
     int res = 0;
     char* before = nullptr;
     char* after = nullptr;
@@ -118,7 +179,7 @@
         PLOG(ERROR) << "Failed before getfilecon for " << path;
         goto fail;
     }
-    if (selinux_android_restorecon_pkgdir(path.c_str(), seinfo, uid, 0) < 0) {
+    if (selinux_android_restorecon_pkgdir(path.c_str(), seInfo.c_str(), uid, 0) < 0) {
         PLOG(ERROR) << "Failed top-level restorecon for " << path;
         goto fail;
     }
@@ -132,7 +193,7 @@
     if (strcmp(before, after)) {
         LOG(DEBUG) << "Detected label change from " << before << " to " << after << " at " << path
                 << "; running recursive restorecon";
-        if (selinux_android_restorecon_pkgdir(path.c_str(), seinfo, uid,
+        if (selinux_android_restorecon_pkgdir(path.c_str(), seInfo.c_str(), uid,
                 SELINUX_ANDROID_RESTORECON_RECURSE) < 0) {
             PLOG(ERROR) << "Failed recursive restorecon for " << path;
             goto fail;
@@ -148,9 +209,9 @@
     return res;
 }
 
-static int restorecon_app_data_lazy(const std::string& parent, const char* name, const char* seinfo,
-        uid_t uid) {
-    return restorecon_app_data_lazy(StringPrintf("%s/%s", parent.c_str(), name), seinfo, uid);
+static int restorecon_app_data_lazy(const std::string& parent, const char* name,
+        const std::string& seInfo, uid_t uid) {
+    return restorecon_app_data_lazy(StringPrintf("%s/%s", parent.c_str(), name), seInfo, uid);
 }
 
 static int prepare_app_dir(const std::string& path, mode_t target_mode, uid_t uid) {
@@ -166,56 +227,62 @@
     return prepare_app_dir(StringPrintf("%s/%s", parent.c_str(), name), target_mode, uid);
 }
 
-int create_app_data(const char *uuid, const char *pkgname, userid_t userid, int flags,
-        appid_t appid, const char* seinfo, int target_sdk_version) {
-    uid_t uid = multiuser_get_uid(userid, appid);
-    mode_t target_mode = target_sdk_version >= MIN_RESTRICTED_HOME_SDK_VERSION ? 0700 : 0751;
+binder::Status InstalldNativeService::createAppData(const std::unique_ptr<std::string>& uuid,
+        const std::string& packageName, int32_t userId, int32_t flags, int32_t appId,
+        const std::string& seInfo, int32_t targetSdkVersion) {
+    ENFORCE_UID(AID_SYSTEM);
+
+    const char* uuid_ = uuid ? uuid->c_str() : nullptr;
+    const char* pkgname = packageName.c_str();
+
+    uid_t uid = multiuser_get_uid(userId, appId);
+    mode_t target_mode = targetSdkVersion >= MIN_RESTRICTED_HOME_SDK_VERSION ? 0700 : 0751;
     if (flags & FLAG_STORAGE_CE) {
-        auto path = create_data_user_ce_package_path(uuid, userid, pkgname);
+        auto path = create_data_user_ce_package_path(uuid_, userId, pkgname);
         if (prepare_app_dir(path, target_mode, uid) ||
                 prepare_app_dir(path, "cache", 0771, uid) ||
                 prepare_app_dir(path, "code_cache", 0771, uid)) {
-            return -1;
+            return binder::Status::fromServiceSpecificError(-1);
         }
 
         // Consider restorecon over contents if label changed
-        if (restorecon_app_data_lazy(path, seinfo, uid) ||
-                restorecon_app_data_lazy(path, "cache", seinfo, uid) ||
-                restorecon_app_data_lazy(path, "code_cache", seinfo, uid)) {
-            return -1;
+        if (restorecon_app_data_lazy(path, seInfo, uid) ||
+                restorecon_app_data_lazy(path, "cache", seInfo, uid) ||
+                restorecon_app_data_lazy(path, "code_cache", seInfo, uid)) {
+            return binder::Status::fromServiceSpecificError(-1);
         }
 
         // Remember inode numbers of cache directories so that we can clear
         // contents while CE storage is locked
         if (write_path_inode(path, "cache", kXattrInodeCache) ||
                 write_path_inode(path, "code_cache", kXattrInodeCodeCache)) {
-            return -1;
+            return binder::Status::fromServiceSpecificError(-1);
         }
     }
     if (flags & FLAG_STORAGE_DE) {
-        auto path = create_data_user_de_package_path(uuid, userid, pkgname);
+        auto path = create_data_user_de_package_path(uuid_, userId, pkgname);
         if (prepare_app_dir(path, target_mode, uid)) {
             // TODO: include result once 25796509 is fixed
-            return 0;
+            return binder::Status::ok();
         }
 
         // Consider restorecon over contents if label changed
-        if (restorecon_app_data_lazy(path, seinfo, uid)) {
-            return -1;
+        if (restorecon_app_data_lazy(path, seInfo, uid)) {
+            return binder::Status::fromServiceSpecificError(-1);
         }
 
         if (property_get_bool("dalvik.vm.usejitprofiles")) {
-            const std::string profile_path = create_data_user_profile_package_path(userid, pkgname);
+            const std::string profile_path = create_data_user_profile_package_path(userId, pkgname);
             // read-write-execute only for the app user.
             if (fs_prepare_dir_strict(profile_path.c_str(), 0700, uid, uid) != 0) {
                 PLOG(ERROR) << "Failed to prepare " << profile_path;
-                return -1;
+                return binder::Status::fromServiceSpecificError(-1);
             }
             std::string profile_file = create_primary_profile(profile_path);
             // read-write only for the app user.
             if (fs_prepare_file_strict(profile_file.c_str(), 0600, uid, uid) != 0) {
                 PLOG(ERROR) << "Failed to prepare " << profile_path;
-                return -1;
+                return binder::Status::fromServiceSpecificError(-1);
             }
             const std::string ref_profile_path = create_data_ref_profile_package_path(pkgname);
             // dex2oat/profman runs under the shared app gid and it needs to read/write reference
@@ -224,11 +291,11 @@
             if (fs_prepare_dir_strict(
                     ref_profile_path.c_str(), 0700, shared_app_gid, shared_app_gid) != 0) {
                 PLOG(ERROR) << "Failed to prepare " << ref_profile_path;
-                return -1;
+                return binder::Status::fromServiceSpecificError(-1);
             }
         }
     }
-    return 0;
+    return binder::Status::ok();
 }
 
 int migrate_app_data(const char *uuid, const char *pkgname, userid_t userid, int flags) {
@@ -421,8 +488,17 @@
     return res;
 }
 
-int move_complete_app(const char *from_uuid, const char *to_uuid, const char *package_name,
-        const char *data_app_name, appid_t appid, const char* seinfo, int target_sdk_version) {
+binder::Status InstalldNativeService::moveCompleteApp(const std::unique_ptr<std::string>& fromUuid,
+        const std::unique_ptr<std::string>& toUuid, const std::string& packageName,
+        const std::string& dataAppName, int32_t appId, const std::string& seInfo,
+        int32_t targetSdkVersion) {
+
+    const char* from_uuid = fromUuid ? fromUuid->c_str() : nullptr;
+    const char* to_uuid = toUuid ? toUuid->c_str() : nullptr;
+    const char* package_name = packageName.c_str();
+    const char* data_app_name = dataAppName.c_str();
+    const char* seinfo = seInfo.c_str();
+
     std::vector<userid_t> users = get_known_users(from_uuid);
 
     // Copy app
@@ -467,8 +543,8 @@
             continue;
         }
 
-        if (create_app_data(to_uuid, package_name, user, FLAG_STORAGE_CE | FLAG_STORAGE_DE,
-                appid, seinfo, target_sdk_version) != 0) {
+        if (!createAppData(toUuid, packageName, user, FLAG_STORAGE_CE | FLAG_STORAGE_DE, appId,
+                seInfo, targetSdkVersion).isOk()) {
             LOG(ERROR) << "Failed to create package target on " << to_uuid;
             goto fail;
         }
@@ -512,7 +588,7 @@
         }
 
         if (restorecon_app_data(to_uuid, package_name, user, FLAG_STORAGE_CE | FLAG_STORAGE_DE,
-                appid, seinfo) != 0) {
+                appId, seinfo) != 0) {
             LOG(ERROR) << "Failed to restorecon";
             goto fail;
         }
@@ -521,7 +597,7 @@
     // We let the framework scan the new location and persist that before
     // deleting the data in the old location; this ordering ensures that
     // we can recover from things like battery pulls.
-    return 0;
+    return binder::Status::ok();
 
 fail:
     // Nuke everything we might have already copied
@@ -545,7 +621,7 @@
             }
         }
     }
-    return -1;
+    return binder::Status::fromServiceSpecificError(-1);
 }
 
 int create_user_data(const char *uuid, userid_t userid, int user_serial ATTRIBUTE_UNUSED,
diff --git a/cmds/installd/commands.h b/cmds/installd/commands.h
index ba27517..47c68c8 100644
--- a/cmds/installd/commands.h
+++ b/cmds/installd/commands.h
@@ -21,17 +21,32 @@
 #include <inttypes.h>
 #include <unistd.h>
 
+#include <vector>
+
+#include <binder/BinderService.h>
 #include <cutils/multiuser.h>
 
-#include <installd_constants.h>
+#include "android/os/BnInstalld.h"
+#include "installd_constants.h"
 
 namespace android {
 namespace installd {
 
-static constexpr size_t DEXOPT_PARAM_COUNT = 10U;
+class InstalldNativeService : public BinderService<InstalldNativeService>, public os::BnInstalld {
+public:
+    static status_t start();
+    static char const* getServiceName() { return "installd"; }
+    virtual status_t dump(int fd, const Vector<String16> &args) override;
 
-int create_app_data(const char *uuid, const char *pkgname, userid_t userid, int flags,
-        appid_t appid, const char* seinfo, int target_sdk_version);
+    binder::Status createAppData(const std::unique_ptr<std::string>& uuid,
+            const std::string& packageName, int32_t userId, int32_t flags, int32_t appId,
+            const std::string& seInfo, int32_t targetSdkVersion);
+    binder::Status moveCompleteApp(const std::unique_ptr<std::string>& fromUuid,
+            const std::unique_ptr<std::string>& toUuid, const std::string& packageName,
+            const std::string& dataAppName, int32_t appId, const std::string& seInfo,
+            int32_t targetSdkVersion);
+};
+
 int restorecon_app_data(const char* uuid, const char* pkgName, userid_t userid, int flags,
         appid_t appid, const char* seinfo);
 int migrate_app_data(const char *uuid, const char *pkgname, userid_t userid, int flags);
@@ -40,9 +55,6 @@
 int destroy_app_data(const char *uuid, const char *pkgname, userid_t userid, int flags,
         ino_t ce_data_inode);
 
-int move_complete_app(const char* from_uuid, const char *to_uuid, const char *package_name,
-        const char *data_app_name, appid_t appid, const char* seinfo, int target_sdk_version);
-
 int get_app_size(const char *uuid, const char *pkgname, int userid, int flags, ino_t ce_data_inode,
         const char* code_path, int64_t *codesize, int64_t *datasize, int64_t *cachesize,
         int64_t *asecsize);
diff --git a/cmds/installd/globals.h b/cmds/installd/globals.h
index c90beec..fc502c0 100644
--- a/cmds/installd/globals.h
+++ b/cmds/installd/globals.h
@@ -18,6 +18,7 @@
 #ifndef GLOBALS_H_
 #define GLOBALS_H_
 
+#include <commands.h>
 #include <inttypes.h>
 
 namespace android {
diff --git a/cmds/installd/installd.cpp b/cmds/installd/installd.cpp
index 332bc5e..f892548 100644
--- a/cmds/installd/installd.cpp
+++ b/cmds/installd/installd.cpp
@@ -30,8 +30,6 @@
 #include <cutils/sockets.h>
 #include <private/android_filesystem_config.h>
 
-#include <InstalldNativeService.h>
-
 #include <commands.h>
 #include <globals.h>
 #include <installd_constants.h>
@@ -190,13 +188,6 @@
     return 0;
 }
 
-static int do_create_app_data(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) {
-    /* const char *uuid, const char *pkgname, userid_t userid, int flags,
-            appid_t appid, const char* seinfo, int target_sdk_version */
-    return create_app_data(parse_null(arg[0]), arg[1], atoi(arg[2]), atoi(arg[3]),
-                           atoi(arg[4]), arg[5], atoi(arg[6]));
-}
-
 static int do_restorecon_app_data(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) {
     /* const char* uuid, const char* pkgName, userid_t userid, int flags,
             appid_t appid, const char* seinfo */
@@ -355,14 +346,6 @@
     return res;
 }
 
-static int do_move_complete_app(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED) {
-    /* const char* from_uuid, const char *to_uuid, const char *package_name,
-            const char *data_app_name, appid_t appid, const char* seinfo,
-            int target_sdk_version */
-    return move_complete_app(parse_null(arg[0]), parse_null(arg[1]), arg[2], arg[3],
-                             atoi(arg[4]), arg[5], atoi(arg[6]));
-}
-
 static int do_create_user_data(char **arg, char reply[REPLY_MAX] ATTRIBUTE_UNUSED)
 {
     /* const char *uuid, userid_t userid, int user_serial, int flags */
@@ -434,12 +417,10 @@
 struct cmdinfo cmds[] = {
     { "ping",                 0, do_ping },
 
-    { "create_app_data",      7, do_create_app_data },
     { "restorecon_app_data",  6, do_restorecon_app_data },
     { "migrate_app_data",     4, do_migrate_app_data },
     { "clear_app_data",       5, do_clear_app_data },
     { "destroy_app_data",     5, do_destroy_app_data },
-    { "move_complete_app",    7, do_move_complete_app },
     { "get_app_size",         6, do_get_app_size },
     { "get_app_data_inode",   4, do_get_app_data_inode },
 
diff --git a/cmds/installd/installd_constants.h b/cmds/installd/installd_constants.h
index b0bcce9..4a6143f 100644
--- a/cmds/installd/installd_constants.h
+++ b/cmds/installd/installd_constants.h
@@ -30,6 +30,8 @@
 #define DALVIK_CACHE "dalvik-cache"
 constexpr const char* DALVIK_CACHE_POSTFIX = "@classes.dex";
 
+static constexpr size_t DEXOPT_PARAM_COUNT = 10U;
+
 constexpr size_t PKG_NAME_MAX = 128u;   /* largest allowed package name */
 constexpr size_t PKG_PATH_MAX = 256u;   /* max size of any path we use */
 
diff --git a/cmds/installd/otapreopt_chroot.cpp b/cmds/installd/otapreopt_chroot.cpp
index 5ea89e6..924600a 100644
--- a/cmds/installd/otapreopt_chroot.cpp
+++ b/cmds/installd/otapreopt_chroot.cpp
@@ -25,8 +25,8 @@
 #include <android-base/macros.h>
 #include <android-base/stringprintf.h>
 
-#include <commands.h>
-#include <otapreopt_utils.h>
+#include "installd_constants.h"
+#include "otapreopt_utils.h"
 
 #ifndef LOG_TAG
 #define LOG_TAG "otapreopt"
diff --git a/cmds/installd/tests/Android.mk b/cmds/installd/tests/Android.mk
index 38a9f69..1aaef3d 100644
--- a/cmds/installd/tests/Android.mk
+++ b/cmds/installd/tests/Android.mk
@@ -9,6 +9,7 @@
 
 shared_libraries := \
     libbase \
+    liblog \
     libutils \
     libcutils \
 
diff --git a/cmds/installd/utils.h b/cmds/installd/utils.h
index 8123e9b..ead73fe 100644
--- a/cmds/installd/utils.h
+++ b/cmds/installd/utils.h
@@ -73,7 +73,6 @@
 std::string create_data_path(const char* volume_uuid);
 
 std::string create_data_app_path(const char* volume_uuid);
-
 std::string create_data_app_package_path(const char* volume_uuid, const char* package_name);
 
 std::string create_data_user_ce_path(const char* volume_uuid, userid_t userid);