The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "installd" |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
Kenny Root | 3e319a9 | 2010-09-07 13:58:28 -0700 | [diff] [blame] | 22 | #include <stdint.h> |
| 23 | #include <inttypes.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <sys/stat.h> |
| 25 | #include <dirent.h> |
| 26 | #include <unistd.h> |
| 27 | #include <ctype.h> |
| 28 | #include <fcntl.h> |
| 29 | #include <errno.h> |
| 30 | #include <utime.h> |
| 31 | #include <sys/socket.h> |
| 32 | #include <sys/types.h> |
| 33 | #include <sys/wait.h> |
| 34 | |
| 35 | #include <cutils/sockets.h> |
| 36 | #include <cutils/log.h> |
| 37 | #include <cutils/properties.h> |
| 38 | |
| 39 | #include <private/android_filesystem_config.h> |
| 40 | |
| 41 | #if INCLUDE_SYS_MOUNT_FOR_STATFS |
| 42 | #include <sys/mount.h> |
| 43 | #else |
| 44 | #include <sys/statfs.h> |
| 45 | #endif |
| 46 | |
| 47 | #define SOCKET_PATH "installd" |
| 48 | |
| 49 | |
| 50 | /* elements combined with a valid package name to form paths */ |
| 51 | |
| 52 | #define PKG_DIR_PREFIX "/data/data/" |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 53 | #define PKG_SEC_DIR_PREFIX "/data/secure/data/" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | #define PKG_DIR_POSTFIX "" |
| 55 | |
| 56 | #define PKG_LIB_PREFIX "/data/data/" |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 57 | #define PKG_SEC_LIB_PREFIX "/data/secure/data/" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | #define PKG_LIB_POSTFIX "/lib" |
| 59 | |
| 60 | #define CACHE_DIR_PREFIX "/data/data/" |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 61 | #define CACHE_SEC_DIR_PREFIX "/data/secure/data/" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | #define CACHE_DIR_POSTFIX "/cache" |
| 63 | |
| 64 | #define APK_DIR_PREFIX "/data/app/" |
| 65 | |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 66 | /* Encrypted File SYstems constants */ |
| 67 | #define USE_ENCRYPTED_FS 1 |
| 68 | #define USE_UNENCRYPTED_FS 0 |
| 69 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | /* other handy constants */ |
| 71 | |
| 72 | #define PROTECTED_DIR_PREFIX "/data/app-private/" |
Oscar Montemayor | 8fe5c9e | 2010-02-25 00:06:41 -0800 | [diff] [blame] | 73 | #define SDCARD_DIR_PREFIX getenv("ASEC_MOUNTPOINT") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | |
| 75 | #define DALVIK_CACHE_PREFIX "/data/dalvik-cache/" |
| 76 | #define DALVIK_CACHE_POSTFIX "/classes.dex" |
| 77 | |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 78 | #define UPDATE_COMMANDS_DIR_PREFIX "/system/etc/updatecmds/" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | |
| 80 | #define PKG_NAME_MAX 128 /* largest allowed package name */ |
| 81 | #define PKG_PATH_MAX 256 /* max size of any path we use */ |
| 82 | |
| 83 | |
| 84 | /* util.c */ |
| 85 | |
| 86 | int create_pkg_path(char path[PKG_PATH_MAX], |
| 87 | const char *prefix, |
| 88 | const char *pkgname, |
| 89 | const char *postfix); |
| 90 | |
| 91 | int create_cache_path(char path[PKG_PATH_MAX], const char *src); |
| 92 | |
| 93 | int delete_dir_contents(const char *pathname, |
| 94 | int also_delete_dir, |
| 95 | const char *ignore); |
| 96 | |
| 97 | int delete_dir_contents_fd(int dfd, const char *name); |
| 98 | |
| 99 | /* commands.c */ |
| 100 | |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 101 | int install(const char *pkgname, int encrypted_fs_flag, uid_t uid, gid_t gid); |
| 102 | int uninstall(const char *pkgname, int encrypted_fs_flag); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 103 | int renamepkg(const char *oldpkgname, const char *newpkgname, int encrypted_fs_flag); |
Oscar Montemayor | a8529f6 | 2009-11-18 10:14:20 -0800 | [diff] [blame] | 104 | int delete_user_data(const char *pkgname, int encrypted_fs_flag); |
| 105 | int delete_cache(const char *pkgname, int encrypted_fs_flag); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | int move_dex(const char *src, const char *dst); |
| 107 | int rm_dex(const char *path); |
| 108 | int protect(char *pkgname, gid_t gid); |
| 109 | int get_size(const char *pkgname, const char *apkpath, const char *fwdlock_apkpath, |
Kenny Root | 3e319a9 | 2010-09-07 13:58:28 -0700 | [diff] [blame] | 110 | int64_t *codesize, int64_t *datasize, int64_t *cachesize, int encrypted_fs_flag); |
| 111 | int free_cache(int64_t free_size); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | int dexopt(const char *apk_path, uid_t uid, int is_public); |
Dianne Hackborn | b858dfd | 2010-02-02 10:49:14 -0800 | [diff] [blame] | 113 | int movefiles(); |