blob: cbca135c30437e9e11f2110a309a77f943e8f976 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Root3e319a92010-09-07 13:58:28 -070022#include <stdint.h>
23#include <inttypes.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024#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
Kenny Root86c95842011-03-31 13:16:12 -070052#define PRIMARY_USER_PREFIX "data/"
53#define SECONDARY_USER_PREFIX "user/"
54
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055#define PKG_DIR_POSTFIX ""
56
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057#define PKG_LIB_POSTFIX "/lib"
58
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059#define CACHE_DIR_POSTFIX "/cache"
60
Kenny Root86c95842011-03-31 13:16:12 -070061#define APP_SUBDIR "app/" // sub-directory under ANDROID_DATA
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
63/* other handy constants */
64
Kenny Root86c95842011-03-31 13:16:12 -070065#define PRIVATE_APP_SUBDIR "app-private/" // sub-directory under ANDROID_DATA
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066
Kenny Root86c95842011-03-31 13:16:12 -070067#define DALVIK_CACHE_PREFIX "/data/dalvik-cache/"
68#define DALVIK_CACHE_POSTFIX "/classes.dex"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
Dianne Hackbornb858dfd2010-02-02 10:49:14 -080070#define UPDATE_COMMANDS_DIR_PREFIX "/system/etc/updatecmds/"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071
72#define PKG_NAME_MAX 128 /* largest allowed package name */
73#define PKG_PATH_MAX 256 /* max size of any path we use */
74
Kenny Root86c95842011-03-31 13:16:12 -070075/* data structures */
76
77typedef struct {
78 char* path;
79 size_t len;
80} dir_rec_t;
81
82typedef struct {
83 size_t count;
84 dir_rec_t* dirs;
85} dir_rec_array_t;
86
87extern dir_rec_t android_app_dir;
88extern dir_rec_t android_app_private_dir;
89extern dir_rec_t android_data_dir;
90extern dir_rec_t android_asec_dir;
91extern dir_rec_array_t android_system_dirs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
93/* util.c */
94
Kenny Root86c95842011-03-31 13:16:12 -070095int create_pkg_path_in_dir(char path[PKG_PATH_MAX],
96 const dir_rec_t* dir,
97 const char* pkgname,
98 const char* postfix);
99
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100int create_pkg_path(char path[PKG_PATH_MAX],
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 const char *pkgname,
Kenny Root86c95842011-03-31 13:16:12 -0700102 const char *postfix,
103 uid_t persona);
104
105int is_valid_package_name(const char* pkgname);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106
107int create_cache_path(char path[PKG_PATH_MAX], const char *src);
108
109int delete_dir_contents(const char *pathname,
110 int also_delete_dir,
111 const char *ignore);
112
113int delete_dir_contents_fd(int dfd, const char *name);
114
Kenny Root86c95842011-03-31 13:16:12 -0700115int validate_system_app_path(const char* path);
116
117int get_path_from_env(dir_rec_t* rec, const char* var);
118
119int get_path_from_string(dir_rec_t* rec, const char* path);
120
121int copy_and_append(dir_rec_t* dst, const dir_rec_t* src, const char* suffix);
122
123int validate_apk_path(const char *path);
124
125int append_and_increment(char** dst, const char* src, size_t* dst_size);
126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127/* commands.c */
128
Kenny Root35ab3ad2011-02-02 16:42:14 -0800129int install(const char *pkgname, uid_t uid, gid_t gid);
130int uninstall(const char *pkgname);
131int renamepkg(const char *oldpkgname, const char *newpkgname);
132int delete_user_data(const char *pkgname);
133int delete_cache(const char *pkgname);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134int move_dex(const char *src, const char *dst);
135int rm_dex(const char *path);
136int protect(char *pkgname, gid_t gid);
137int get_size(const char *pkgname, const char *apkpath, const char *fwdlock_apkpath,
Kenny Root35ab3ad2011-02-02 16:42:14 -0800138 int64_t *codesize, int64_t *datasize, int64_t *cachesize);
Kenny Root3e319a92010-09-07 13:58:28 -0700139int free_cache(int64_t free_size);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140int dexopt(const char *apk_path, uid_t uid, int is_public);
Dianne Hackbornb858dfd2010-02-02 10:49:14 -0800141int movefiles();
Kenny Root6a6b0072010-10-07 16:46:10 -0700142int linklib(const char* target, const char* source);
143int unlinklib(const char* libPath);