194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/*
294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood**
394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood** Copyright 2008, The Android Open Source Project
494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood**
594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood** Licensed under the Apache License, Version 2.0 (the "License");
694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood** you may not use this file except in compliance with the License.
794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood** You may obtain a copy of the License at
894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood**
994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood**     http://www.apache.org/licenses/LICENSE-2.0
1094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood**
1194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood** Unless required by applicable law or agreed to in writing, software
1294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood** distributed under the License is distributed on an "AS IS" BASIS,
1394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood** See the License for the specific language governing permissions and
1594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood** limitations under the License.
1694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood*/
1794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
1894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define LOG_TAG "installd"
1994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
2094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <stdio.h>
2194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <stdlib.h>
2294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <stdint.h>
2394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <inttypes.h>
2494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <sys/stat.h>
2594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <dirent.h>
2694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <unistd.h>
2794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <ctype.h>
2894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <fcntl.h>
2994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <errno.h>
3094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <utime.h>
3194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <sys/socket.h>
3294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <sys/types.h>
3394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <sys/wait.h>
34c03de09173f98506e73e7cf7df21fe11795d4b24Jeff Sharkey#include <string>
35e36372423000a906bafae68844ebc6c42d09335aJeff Sharkey#include <vector>
3694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
3794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <cutils/fs.h>
3894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <cutils/sockets.h>
3994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <cutils/log.h>
4094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <cutils/properties.h>
4194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <cutils/multiuser.h>
4294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
4394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <private/android_filesystem_config.h>
4494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
459a4e7f492e6e80bb171111d307658be7e2132ae3Elliott Hughes#if defined(__APPLE__)
4694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <sys/mount.h>
4794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#else
4894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <sys/statfs.h>
4994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#endif
5094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
5194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define SOCKET_PATH "installd"
5294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
5394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
5494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* elements combined with a valid package name to form paths */
5594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
5694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define PRIMARY_USER_PREFIX    "data/"
5794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define SECONDARY_USER_PREFIX  "user/"
5894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
5994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define PKG_DIR_POSTFIX        ""
6094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
6194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define PKG_LIB_POSTFIX        "/lib"
6294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
6394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define CACHE_DIR_POSTFIX      "/cache"
64c796b681e52fbb792da9a5b4f30e935cc927c1d7Jeff Sharkey#define CODE_CACHE_DIR_POSTFIX "/code_cache"
6594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
6694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define APP_SUBDIR             "app/" // sub-directory under ANDROID_DATA
67770180a4dd86f8bda6af2e6db4676e99a5bb1548Jeff Sharkey#define PRIV_APP_SUBDIR        "priv-app/" // sub-directory under ANDROID_DATA
6894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
6994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define APP_LIB_SUBDIR         "app-lib/" // sub-directory under ANDROID_DATA
7094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
7194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define MEDIA_SUBDIR           "media/" // sub-directory under ANDROID_DATA
7294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
7394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* other handy constants */
7494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
7594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define PRIVATE_APP_SUBDIR     "app-private/" // sub-directory under ANDROID_DATA
7694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
7794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define DALVIK_CACHE_PREFIX    "/data/dalvik-cache/"
7894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define DALVIK_CACHE_POSTFIX   "/classes.dex"
7994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
8094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define UPDATE_COMMANDS_DIR_PREFIX  "/system/etc/updatecmds/"
8194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
8263568b1430d741f40ca008391c854ef1cc880138Mårten Kongstad#define IDMAP_PREFIX           "/data/resource-cache/"
8363568b1430d741f40ca008391c854ef1cc880138Mårten Kongstad#define IDMAP_SUFFIX           "@idmap"
8463568b1430d741f40ca008391c854ef1cc880138Mårten Kongstad
8594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define PKG_NAME_MAX  128   /* largest allowed package name */
8694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define PKG_PATH_MAX  256   /* max size of any path we use */
8794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
88c92fb6247d4c4fbc34c0a5deb26ccf538ca9ec81Richard Uhler/* dexopt needed flags matching those in dalvik.system.DexFile */
89c92fb6247d4c4fbc34c0a5deb26ccf538ca9ec81Richard Uhler#define DEXOPT_DEX2OAT_NEEDED        1
90c92fb6247d4c4fbc34c0a5deb26ccf538ca9ec81Richard Uhler#define DEXOPT_PATCHOAT_NEEDED       2
91c92fb6247d4c4fbc34c0a5deb26ccf538ca9ec81Richard Uhler#define DEXOPT_SELF_PATCHOAT_NEEDED  3
92c92fb6247d4c4fbc34c0a5deb26ccf538ca9ec81Richard Uhler
93e36372423000a906bafae68844ebc6c42d09335aJeff Sharkey#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
94e36372423000a906bafae68844ebc6c42d09335aJeff Sharkey
9594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* data structures */
9694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
9794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodtypedef struct {
9894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    char* path;
9994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    size_t len;
10094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood} dir_rec_t;
10194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
10294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodtypedef struct {
10394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    size_t count;
10494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    dir_rec_t* dirs;
10594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood} dir_rec_array_t;
10694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
10794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodextern dir_rec_t android_app_dir;
10894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodextern dir_rec_t android_app_private_dir;
10994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodextern dir_rec_t android_app_lib_dir;
11094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodextern dir_rec_t android_data_dir;
11194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodextern dir_rec_t android_asec_dir;
11294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodextern dir_rec_t android_media_dir;
113e23a13299a4f6f2488935b4786cdbb46f46e3d3cJeff Sharkeyextern dir_rec_t android_mnt_expand_dir;
11494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodextern dir_rec_array_t android_system_dirs;
11594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
11694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodtypedef struct cache_dir_struct {
11794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    struct cache_dir_struct* parent;
11894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    int32_t childCount;
11994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    int32_t hiddenCount;
12094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    int32_t deleted;
12194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    char name[];
12294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood} cache_dir_t;
12394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
12494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodtypedef struct {
12594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    cache_dir_t* dir;
12694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    time_t modTime;
12794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    char name[];
12894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood} cache_file_t;
12994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
13094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodtypedef struct {
13194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    size_t numDirs;
13294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    size_t availDirs;
13394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    cache_dir_t** dirs;
13494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    size_t numFiles;
13594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    size_t availFiles;
13694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    cache_file_t** files;
13794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    size_t numCollected;
13894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    void* memBlocks;
13994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    int8_t* curMemBlockAvail;
14094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    int8_t* curMemBlockEnd;
14194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood} cache_t;
14294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
14394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* util.c */
14494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
14594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint create_pkg_path(char path[PKG_PATH_MAX],
14694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                    const char *pkgname,
14794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                    const char *postfix,
148abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey                    userid_t userid);
14994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
15041ea424413c0381ef2aa15fc5bd5d4b88abd23c4Jeff Sharkeystd::string create_data_path(const char* volume_uuid);
15141ea424413c0381ef2aa15fc5bd5d4b88abd23c4Jeff Sharkey
152d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkeystd::string create_data_app_path(const char* volume_uuid);
153d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkey
154d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkeystd::string create_data_app_package_path(const char* volume_uuid, const char* package_name);
155d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkey
15641ea424413c0381ef2aa15fc5bd5d4b88abd23c4Jeff Sharkeystd::string create_data_user_path(const char* volume_uuid, userid_t userid);
15794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
158d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkeystd::string create_data_user_package_path(const char* volume_uuid,
159d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkey        userid_t user, const char* package_name);
160d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkey
16141ea424413c0381ef2aa15fc5bd5d4b88abd23c4Jeff Sharkeystd::string create_data_media_path(const char* volume_uuid, userid_t userid);
16294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
163e36372423000a906bafae68844ebc6c42d09335aJeff Sharkeystd::vector<userid_t> get_known_users(const char* volume_uuid);
164e36372423000a906bafae68844ebc6c42d09335aJeff Sharkey
165095c763dd9aa26a206d10ab7c1d7e1c569298fb3Robin Leeint create_user_config_path(char path[PKG_PATH_MAX], userid_t userid);
166095c763dd9aa26a206d10ab7c1d7e1c569298fb3Robin Lee
16794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint create_move_path(char path[PKG_PATH_MAX],
16894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                     const char* pkgname,
16994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                     const char* leaf,
170abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey                     userid_t userid);
17194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
17294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint is_valid_package_name(const char* pkgname);
17394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
1741b4003207750ea8fe8c7b03eb32d80f1df83979eNarayan Kamathint create_cache_path(char path[PKG_PATH_MAX], const char *src,
1751b4003207750ea8fe8c7b03eb32d80f1df83979eNarayan Kamath                      const char *instruction_set);
17694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
17794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint delete_dir_contents(const char *pathname,
17894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                        int also_delete_dir,
1793aee2c5c749dc2589f001b26fae1ec958ec89524Narayan Kamath                        int (*exclusion_predicate)(const char *name, const int is_dir));
18094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
18194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint delete_dir_contents_fd(int dfd, const char *name);
18294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
18360fd3feecab4336d964ca8e31c7c3220e1afb558Robin Leeint copy_dir_files(const char *srcname, const char *dstname, uid_t owner, gid_t group);
18460fd3feecab4336d964ca8e31c7c3220e1afb558Robin Lee
18594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint lookup_media_dir(char basepath[PATH_MAX], const char *dir);
18694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
18741ea424413c0381ef2aa15fc5bd5d4b88abd23c4Jeff Sharkeyint64_t data_disk_free(const std::string& data_path);
18894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
18994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodcache_t* start_cache_collection();
19094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
19194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid add_cache_files(cache_t* cache, const char *basepath, const char *cachedir);
19294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
19341ea424413c0381ef2aa15fc5bd5d4b88abd23c4Jeff Sharkeyvoid clear_cache_files(const std::string& data_path, cache_t* cache, int64_t free_size);
19494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
19594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid finish_cache_collection(cache_t* cache);
19694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
19794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint validate_system_app_path(const char* path);
19894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
19994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint get_path_from_env(dir_rec_t* rec, const char* var);
20094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
20194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint get_path_from_string(dir_rec_t* rec, const char* path);
20294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
20394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint copy_and_append(dir_rec_t* dst, const dir_rec_t* src, const char* suffix);
20494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
20594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint validate_apk_path(const char *path);
206d845c96128a40ca5802c0840ae190fa0af7d4735Narayan Kamathint validate_apk_path_subdirs(const char *path);
20794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
20894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint append_and_increment(char** dst, const char* src, size_t* dst_size);
20994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
21019803807cd7ae01868fcfa50305f4a7dd13765e2Jeff Sharkeychar *build_string2(const char *s1, const char *s2);
21119803807cd7ae01868fcfa50305f4a7dd13765e2Jeff Sharkeychar *build_string3(const char *s1, const char *s2, const char *s3);
21294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
21394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint ensure_dir(const char* path, mode_t mode, uid_t uid, gid_t gid);
21441ea424413c0381ef2aa15fc5bd5d4b88abd23c4Jeff Sharkeyint ensure_media_user_dirs(const char* uuid, userid_t userid);
215095c763dd9aa26a206d10ab7c1d7e1c569298fb3Robin Leeint ensure_config_user_dirs(userid_t userid);
216d93707342a61e66bc3eb2145628158452f577f42Dave Allisonint create_profile_file(const char *pkgname, gid_t gid);
217d93707342a61e66bc3eb2145628158452f577f42Dave Allisonvoid remove_profile_file(const char *pkgname);
21894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
21994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* commands.c */
22094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
221c03de09173f98506e73e7cf7df21fe11795d4b24Jeff Sharkeyint install(const char *uuid, const char *pkgname, uid_t uid, gid_t gid, const char *seinfo);
222c03de09173f98506e73e7cf7df21fe11795d4b24Jeff Sharkeyint uninstall(const char *uuid, const char *pkgname, userid_t userid);
22394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint renamepkg(const char *oldpkgname, const char *newpkgname);
224c03de09173f98506e73e7cf7df21fe11795d4b24Jeff Sharkeyint fix_uid(const char *uuid, const char *pkgname, uid_t uid, gid_t gid);
225c03de09173f98506e73e7cf7df21fe11795d4b24Jeff Sharkeyint delete_user_data(const char *uuid, const char *pkgname, userid_t userid);
226e36372423000a906bafae68844ebc6c42d09335aJeff Sharkeyint make_user_data(const char *uuid, const char *pkgname, uid_t uid,
227e36372423000a906bafae68844ebc6c42d09335aJeff Sharkey        userid_t userid, const char* seinfo);
22831f08986f83fa6f2dcf55523b2cf706460aeed7cJeff Sharkeyint copy_complete_app(const char* from_uuid, const char *to_uuid,
229d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkey        const char *package_name, const char *data_app_name, appid_t appid,
230d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkey        const char* seinfo);
2317c8bec01790087748ec7afa69a31789828b751f9Robin Leeint make_user_config(userid_t userid);
23241ea424413c0381ef2aa15fc5bd5d4b88abd23c4Jeff Sharkeyint delete_user(const char *uuid, userid_t userid);
233c03de09173f98506e73e7cf7df21fe11795d4b24Jeff Sharkeyint delete_cache(const char *uuid, const char *pkgname, userid_t userid);
234c03de09173f98506e73e7cf7df21fe11795d4b24Jeff Sharkeyint delete_code_cache(const char *uuid, const char *pkgname, userid_t userid);
2351b4003207750ea8fe8c7b03eb32d80f1df83979eNarayan Kamathint move_dex(const char *src, const char *dst, const char *instruction_set);
2361b4003207750ea8fe8c7b03eb32d80f1df83979eNarayan Kamathint rm_dex(const char *path, const char *instruction_set);
23794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint protect(char *pkgname, gid_t gid);
238d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkeyint get_size(const char *uuid, const char *pkgname, int userid,
239d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkey        const char *apkpath, const char *libdirpath,
240d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkey        const char *fwdlock_apkpath, const char *asecpath,
241d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkey        const char *instruction_set, int64_t *codesize, int64_t *datasize,
242d792118c493806eeb24a8203f508e6e18fe93bd7Jeff Sharkey        int64_t *cachesize, int64_t *asecsize);
24341ea424413c0381ef2aa15fc5bd5d4b88abd23c4Jeff Sharkeyint free_cache(const char *uuid, int64_t free_size);
244b1efac103523efccbe671e76cc0eaaeab810415bCalin Juravleint dexopt(const char *apk_path, uid_t uid, bool is_public, const char *pkgName,
245c92fb6247d4c4fbc34c0a5deb26ccf538ca9ec81Richard Uhler           const char *instruction_set, int dexopt_needed, bool vm_safe_mode,
246c92fb6247d4c4fbc34c0a5deb26ccf538ca9ec81Richard Uhler           bool debuggable, const char* oat_dir);
247091ea779d4e575856c04d51d82f45cc8a6155b5eNarayan Kamathint mark_boot_complete(const char *instruction_set);
24894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint movefiles();
2496fe28a06012250da85f808a0869f87e06e0bcce9Jeff Sharkeyint linklib(const char* uuid, const char* pkgname, const char* asecLibDir, int userId);
25063568b1430d741f40ca008391c854ef1cc880138Mårten Kongstadint idmap(const char *target_path, const char *overlay_path, uid_t uid);
251c03de09173f98506e73e7cf7df21fe11795d4b24Jeff Sharkeyint restorecon_data(const char *uuid, const char* pkgName, const char* seinfo, uid_t uid);
25288ce4ff7a95ea2008fa28f12b880ee526e331440Fyodor Kupolovint create_oat_dir(const char* oat_dir, const char *instruction_set);
25388ce4ff7a95ea2008fa28f12b880ee526e331440Fyodor Kupolovint rm_package_dir(const char* apk_path);
25488ce4ff7a95ea2008fa28f12b880ee526e331440Fyodor Kupolovint calculate_oat_file_path(char path[PKG_PATH_MAX], const char *oat_dir, const char *apk_path,
255e23a13299a4f6f2488935b4786cdbb46f46e3d3cJeff Sharkey                            const char *instruction_set);
256e36372423000a906bafae68844ebc6c42d09335aJeff Sharkeyint move_package_dir(char path[PKG_PATH_MAX], const char *oat_dir, const char *apk_path,
257e36372423000a906bafae68844ebc6c42d09335aJeff Sharkey                            const char *instruction_set);
258d845c96128a40ca5802c0840ae190fa0af7d4735Narayan Kamathint link_file(const char *relative_path, const char *from_base, const char *to_base);
259