3 ** Copyright 2008, The Android Open Source Project
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
9 ** http://www.apache.org/licenses/LICENSE-2.0
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.
18 #define LOG_TAG "installd"
31 #include <sys/socket.h>
32 #include <sys/types.h>
35 #include <cutils/fs.h>
36 #include <cutils/sockets.h>
37 #include <cutils/log.h>
38 #include <cutils/properties.h>
39 #include <cutils/multiuser.h>
41 #include <private/android_filesystem_config.h>
43 #if INCLUDE_SYS_MOUNT_FOR_STATFS
44 #include <sys/mount.h>
46 #include <sys/statfs.h>
49 #define SOCKET_PATH "installd"
52 /* elements combined with a valid package name to form paths */
54 #define PRIMARY_USER_PREFIX "data/"
55 #define SECONDARY_USER_PREFIX "user/"
57 #define PKG_DIR_POSTFIX ""
59 #define PKG_LIB_POSTFIX "/lib"
61 #define CACHE_DIR_POSTFIX "/cache"
63 #define APP_SUBDIR "app/" // sub-directory under ANDROID_DATA
65 #define APP_LIB_SUBDIR "app-lib/" // sub-directory under ANDROID_DATA
67 #define MEDIA_SUBDIR "media/" // sub-directory under ANDROID_DATA
69 /* other handy constants */
71 #define PRIVATE_APP_SUBDIR "app-private/" // sub-directory under ANDROID_DATA
73 #define DALVIK_CACHE_PREFIX "/data/dalvik-cache/"
74 #define DALVIK_CACHE_POSTFIX "/classes.dex"
76 #define UPDATE_COMMANDS_DIR_PREFIX "/system/etc/updatecmds/"
78 #define PKG_NAME_MAX 128 /* largest allowed package name */
79 #define PKG_PATH_MAX 256 /* max size of any path we use */
81 #define PER_USER_RANGE ((uid_t)100000) /* range of uids per user
82 uid = persona * PER_USER_RANGE + appid */
96 extern dir_rec_t android_app_dir;
97 extern dir_rec_t android_app_private_dir;
98 extern dir_rec_t android_app_lib_dir;
99 extern dir_rec_t android_data_dir;
100 extern dir_rec_t android_asec_dir;
101 extern dir_rec_t android_media_dir;
102 extern dir_rec_array_t android_system_dirs;
104 typedef struct cache_dir_struct {
105 struct cache_dir_struct* parent;
124 cache_file_t** files;
127 int8_t* curMemBlockAvail;
128 int8_t* curMemBlockEnd;
133 int create_pkg_path_in_dir(char path[PKG_PATH_MAX],
134 const dir_rec_t* dir,
136 const char* postfix);
138 int create_pkg_path(char path[PKG_PATH_MAX],
143 int create_persona_path(char path[PKG_PATH_MAX],
146 int create_persona_media_path(char path[PKG_PATH_MAX], userid_t userid);
148 int create_move_path(char path[PKG_PATH_MAX],
153 int is_valid_package_name(const char* pkgname);
155 int create_cache_path(char path[PKG_PATH_MAX], const char *src);
157 int delete_dir_contents(const char *pathname,
161 int delete_dir_contents_fd(int dfd, const char *name);
163 int lookup_media_dir(char basepath[PATH_MAX], const char *dir);
165 int64_t data_disk_free();
167 cache_t* start_cache_collection();
169 void add_cache_files(cache_t* cache, const char *basepath, const char *cachedir);
171 void clear_cache_files(cache_t* cache, int64_t free_size);
173 void finish_cache_collection(cache_t* cache);
175 int validate_system_app_path(const char* path);
177 int get_path_from_env(dir_rec_t* rec, const char* var);
179 int get_path_from_string(dir_rec_t* rec, const char* path);
181 int copy_and_append(dir_rec_t* dst, const dir_rec_t* src, const char* suffix);
183 int validate_apk_path(const char *path);
185 int append_and_increment(char** dst, const char* src, size_t* dst_size);
187 char *build_string2(char *s1, char *s2);
188 char *build_string3(char *s1, char *s2, char *s3);
190 int ensure_dir(const char* path, mode_t mode, uid_t uid, gid_t gid);
191 int ensure_media_user_dirs(userid_t userid);
195 int install(const char *pkgname, uid_t uid, gid_t gid, const char *seinfo);
196 int uninstall(const char *pkgname, uid_t persona);
197 int renamepkg(const char *oldpkgname, const char *newpkgname);
198 int fix_uid(const char *pkgname, uid_t uid, gid_t gid);
199 int delete_user_data(const char *pkgname, uid_t persona);
200 int make_user_data(const char *pkgname, uid_t uid, uid_t persona);
201 int delete_persona(uid_t persona);
202 int delete_cache(const char *pkgname, uid_t persona);
203 int move_dex(const char *src, const char *dst);
204 int rm_dex(const char *path);
205 int protect(char *pkgname, gid_t gid);
206 int get_size(const char *pkgname, int persona, const char *apkpath, const char *libdirpath,
207 const char *fwdlock_apkpath, const char *asecpath, int64_t *codesize,
208 int64_t *datasize, int64_t *cachesize, int64_t *asecsize);
209 int free_cache(int64_t free_size);
210 int dexopt(const char *apk_path, uid_t uid, int is_public);
212 int linklib(const char* target, const char* source, int userId);