Merge "Switch installd to compile as C++."

This commit is contained in:
Jeff Sharkey 2015-04-07 21:04:28 +00:00 committed by Gerrit Code Review
commit 1cd030be59
6 changed files with 43 additions and 41 deletions

View File

@ -1,6 +1,6 @@
LOCAL_PATH := $(call my-dir)
common_src_files := commands.c utils.c
common_src_files := commands.cpp utils.cpp
common_cflags := -Wall -Werror
#
@ -23,7 +23,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := installd
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := $(common_cflags)
LOCAL_SRC_FILES := installd.c $(common_src_files)
LOCAL_SRC_FILES := installd.cpp $(common_src_files)
LOCAL_SHARED_LIBRARIES := libcutils liblog libselinux
LOCAL_STATIC_LIBRARIES := libdiskusage
LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk

View File

@ -205,7 +205,7 @@ struct cmdinfo cmds[] = {
static int readx(int s, void *_buf, int count)
{
char *buf = _buf;
char *buf = (char *) _buf;
int n = 0, r;
if (count < 0) return -1;
while (n < count) {
@ -226,7 +226,7 @@ static int readx(int s, void *_buf, int count)
static int writex(int s, const void *_buf, int count)
{
const char *buf = _buf;
const char *buf = (const char *) _buf;
int n = 0, r;
if (count < 0) return -1;
while (n < count) {
@ -353,14 +353,14 @@ int initialize_globals() {
}
// Get the android external app directory.
if (get_path_from_string(&android_mnt_expand_dir, "/mnt/expand") < 0) {
if (get_path_from_string(&android_mnt_expand_dir, "/mnt/expand/") < 0) {
return -1;
}
// Take note of the system and vendor directories.
android_system_dirs.count = 4;
android_system_dirs.dirs = calloc(android_system_dirs.count, sizeof(dir_rec_t));
android_system_dirs.dirs = (dir_rec_t*) calloc(android_system_dirs.count, sizeof(dir_rec_t));
if (android_system_dirs.dirs == NULL) {
ALOGE("Couldn't allocate array for dirs; aborting\n");
return -1;
@ -378,10 +378,10 @@ int initialize_globals() {
android_system_dirs.dirs[1].path = build_string2(android_root_dir.path, PRIV_APP_SUBDIR);
android_system_dirs.dirs[1].len = strlen(android_system_dirs.dirs[1].path);
android_system_dirs.dirs[2].path = "/vendor/app/";
android_system_dirs.dirs[2].path = strdup("/vendor/app/");
android_system_dirs.dirs[2].len = strlen(android_system_dirs.dirs[2].path);
android_system_dirs.dirs[3].path = "/oem/app/";
android_system_dirs.dirs[3].path = strdup("/oem/app/");
android_system_dirs.dirs[3].len = strlen(android_system_dirs.dirs[3].path);
return 0;

View File

@ -192,8 +192,8 @@ int validate_apk_path(const char *path);
int append_and_increment(char** dst, const char* src, size_t* dst_size);
char *build_string2(char *s1, char *s2);
char *build_string3(char *s1, char *s2, char *s3);
char *build_string2(const char *s1, const char *s2);
char *build_string3(const char *s1, const char *s2, const char *s3);
int ensure_dir(const char* path, mode_t mode, uid_t uid, gid_t gid);
int ensure_media_user_dirs(userid_t userid);
@ -227,7 +227,7 @@ int mark_boot_complete(const char *instruction_set);
int movefiles();
int linklib(const char* target, const char* source, int userId);
int idmap(const char *target_path, const char *overlay_path, uid_t uid);
int restorecon_data();
int restorecon_data(const char* pkgName, const char* seinfo, uid_t uid);
int create_oat_dir(const char* oat_dir, const char *instruction_set);
int rm_package_dir(const char* apk_path);
int calculate_oat_file_path(char path[PKG_PATH_MAX], const char *oat_dir, const char *apk_path,

View File

@ -17,19 +17,18 @@
#include <stdlib.h>
#include <string.h>
#define LOG_TAG "utils_test"
#include <utils/Log.h>
#include <gtest/gtest.h>
extern "C" {
#include "installd.h"
}
#undef LOG_TAG
#define LOG_TAG "utils_test"
#define TEST_DATA_DIR "/data/"
#define TEST_APP_DIR "/data/app/"
#define TEST_APP_PRIVATE_DIR "/data/app-private/"
#define TEST_ASEC_DIR "/mnt/asec/"
#define TEST_EXPAND_DIR "/mnt/expand/"
#define TEST_SYSTEM_DIR1 "/system/app/"
#define TEST_SYSTEM_DIR2 "/vendor/app/"
@ -49,25 +48,28 @@ namespace android {
class UtilsTest : public testing::Test {
protected:
virtual void SetUp() {
android_app_dir.path = TEST_APP_DIR;
android_app_dir.path = (char*) TEST_APP_DIR;
android_app_dir.len = strlen(TEST_APP_DIR);
android_app_private_dir.path = TEST_APP_PRIVATE_DIR;
android_app_private_dir.path = (char*) TEST_APP_PRIVATE_DIR;
android_app_private_dir.len = strlen(TEST_APP_PRIVATE_DIR);
android_data_dir.path = TEST_DATA_DIR;
android_data_dir.path = (char*) TEST_DATA_DIR;
android_data_dir.len = strlen(TEST_DATA_DIR);
android_asec_dir.path = TEST_ASEC_DIR;
android_asec_dir.path = (char*) TEST_ASEC_DIR;
android_asec_dir.len = strlen(TEST_ASEC_DIR);
android_mnt_expand_dir.path = (char*) TEST_EXPAND_DIR;
android_mnt_expand_dir.len = strlen(TEST_EXPAND_DIR);
android_system_dirs.count = 2;
android_system_dirs.dirs = (dir_rec_t*) calloc(android_system_dirs.count, sizeof(dir_rec_t));
android_system_dirs.dirs[0].path = TEST_SYSTEM_DIR1;
android_system_dirs.dirs[0].path = (char*) TEST_SYSTEM_DIR1;
android_system_dirs.dirs[0].len = strlen(TEST_SYSTEM_DIR1);
android_system_dirs.dirs[1].path = TEST_SYSTEM_DIR2;
android_system_dirs.dirs[1].path = (char*) TEST_SYSTEM_DIR2;
android_system_dirs.dirs[1].len = strlen(TEST_SYSTEM_DIR2);
}
@ -373,7 +375,7 @@ TEST_F(UtilsTest, CreatePkgPathInDir_ProtectedDir) {
char path[PKG_PATH_MAX];
dir_rec_t dir;
dir.path = "/data/app-private/";
dir.path = (char*) "/data/app-private/";
dir.len = strlen(dir.path);
EXPECT_EQ(0, create_pkg_path_in_dir(path, &dir, "com.example.package", ".apk"))
@ -432,7 +434,7 @@ TEST_F(UtilsTest, CopyAndAppend_Normal) {
dir_rec_t dst;
dir_rec_t src;
src.path = "/data/";
src.path = (char*) "/data/";
src.len = strlen(src.path);
EXPECT_EQ(0, copy_and_append(&dst, &src, "app/"))

View File

@ -61,7 +61,7 @@ int create_pkg_path(char path[PKG_PATH_MAX],
userid_t userid)
{
size_t userid_len;
char* userid_prefix;
const char* userid_prefix;
if (userid == 0) {
userid_prefix = PRIMARY_USER_PREFIX;
userid_len = 0;
@ -106,7 +106,7 @@ int create_user_path(char path[PKG_PATH_MAX],
userid_t userid)
{
size_t userid_len;
char* userid_prefix;
const char* userid_prefix;
if (userid == 0) {
userid_prefix = PRIMARY_USER_PREFIX;
userid_len = 0;
@ -516,7 +516,7 @@ static void* _cache_malloc(cache_t* cache, size_t len)
int8_t* res = cache->curMemBlockAvail;
int8_t* nextPos = res + len;
if (cache->memBlocks == NULL || nextPos > cache->curMemBlockEnd) {
int8_t* newBlock = malloc(CACHE_BLOCK_SIZE);
int8_t* newBlock = (int8_t*) malloc(CACHE_BLOCK_SIZE);
if (newBlock == NULL) {
return NULL;
}
@ -1000,7 +1000,7 @@ int get_path_from_string(dir_rec_t* rec, const char* path) {
// Add space for slash and terminating null.
size_t dst_size = path_len + 2;
rec->path = malloc(dst_size);
rec->path = (char*) malloc(dst_size);
if (rec->path == NULL) {
return -1;
}
@ -1070,13 +1070,13 @@ int append_and_increment(char** dst, const char* src, size_t* dst_size) {
return 0;
}
char *build_string2(char *s1, char *s2) {
char *build_string2(const char *s1, const char *s2) {
if (s1 == NULL || s2 == NULL) return NULL;
int len_s1 = strlen(s1);
int len_s2 = strlen(s2);
int len = len_s1 + len_s2 + 1;
char *result = malloc(len);
char *result = (char *) malloc(len);
if (result == NULL) return NULL;
strcpy(result, s1);
@ -1085,14 +1085,14 @@ char *build_string2(char *s1, char *s2) {
return result;
}
char *build_string3(char *s1, char *s2, char *s3) {
char *build_string3(const char *s1, const char *s2, const char *s3) {
if (s1 == NULL || s2 == NULL || s3 == NULL) return NULL;
int len_s1 = strlen(s1);
int len_s2 = strlen(s2);
int len_s3 = strlen(s3);
int len = len_s1 + len_s2 + len_s3 + 1;
char *result = malloc(len);
char *result = (char *) malloc(len);
if (result == NULL) return NULL;
strcpy(result, s1);