blob: 1394701f55cb5ee4321b8ac24b92d8ef96ddb7b6 [file] [log] [blame]
Andreas Gampe02d0de52015-11-11 20:43:16 -08001/*
2** Copyright 2015, The Android Open Source Project
3**
4** Licensed under the Apache License, Version 2.0 (the "License");
5** you may not use this file except in compliance with the License.
6** You may obtain a copy of the License at
7**
8** http://www.apache.org/licenses/LICENSE-2.0
9**
10** Unless required by applicable law or agreed to in writing, software
11** distributed under the License is distributed on an "AS IS" BASIS,
12** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13** See the License for the specific language governing permissions and
14** limitations under the License.
15*/
16
Mark Salyzyna5e161b2016-09-29 08:08:05 -070017#define LOG_TAG "installd"
18
Andreas Gampe02d0de52015-11-11 20:43:16 -080019#include <globals.h>
20#include <installd_constants.h>
21#include <utils.h>
22
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060023#include <android-base/logging.h>
24
25#include <stdlib.h>
26#include <string.h>
27
Andreas Gampe02d0de52015-11-11 20:43:16 -080028namespace android {
29namespace installd {
30
Andreas Gamped089ca12016-06-27 14:25:30 -070031static constexpr const char* APP_SUBDIR = "app/"; // sub-directory under ANDROID_DATA
32
33static constexpr const char* PRIV_APP_SUBDIR = "priv-app/"; // sub-directory under ANDROID_DATA
34
35static constexpr const char* EPHEMERAL_APP_SUBDIR = "app-ephemeral/"; // sub-directory under
36 // ANDROID_DATA
37
38static constexpr const char* APP_LIB_SUBDIR = "app-lib/"; // sub-directory under ANDROID_DATA
39
40static constexpr const char* MEDIA_SUBDIR = "media/"; // sub-directory under ANDROID_DATA
41
42static constexpr const char* PROFILES_SUBDIR = "misc/profiles"; // sub-directory under ANDROID_DATA
43
44static constexpr const char* PRIVATE_APP_SUBDIR = "app-private/"; // sub-directory under
45 // ANDROID_DATA
46
Gavin Corkery950d5b42019-02-27 12:24:19 +000047static constexpr const char* STAGING_SUBDIR = "app-staging/"; // sub-directory under ANDROID_DATA
shafikb43faa92019-02-19 12:19:48 +000048
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060049std::string android_app_dir;
50std::string android_app_ephemeral_dir;
51std::string android_app_lib_dir;
52std::string android_app_private_dir;
53std::string android_asec_dir;
54std::string android_data_dir;
55std::string android_media_dir;
56std::string android_mnt_expand_dir;
57std::string android_profiles_dir;
58std::string android_root_dir;
shafikb43faa92019-02-19 12:19:48 +000059std::string android_staging_dir;
Andreas Gampe02d0de52015-11-11 20:43:16 -080060
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060061std::vector<std::string> android_system_dirs;
Andreas Gampe02d0de52015-11-11 20:43:16 -080062
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060063bool init_globals_from_data_and_root() {
64 const char* data_path = getenv("ANDROID_DATA");
65 if (data_path == nullptr) {
66 LOG(ERROR) << "Could not find ANDROID_DATA";
67 return false;
Andreas Gampe02d0de52015-11-11 20:43:16 -080068 }
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060069 const char* root_path = getenv("ANDROID_ROOT");
70 if (root_path == nullptr) {
71 LOG(ERROR) << "Could not find ANDROID_ROOT";
72 return false;
73 }
74 return init_globals_from_data_and_root(data_path, root_path);
75}
Andreas Gampe02d0de52015-11-11 20:43:16 -080076
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060077static std::string ensure_trailing_slash(const std::string& path) {
78 if (path.rfind('/') != path.size() - 1) {
79 return path + '/';
80 } else {
81 return path;
82 }
Andreas Gampe02d0de52015-11-11 20:43:16 -080083}
84
85bool init_globals_from_data_and_root(const char* data, const char* root) {
86 // Get the android data directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060087 android_data_dir = ensure_trailing_slash(data);
88
89 // Get the android root directory.
90 android_root_dir = ensure_trailing_slash(root);
Andreas Gampe02d0de52015-11-11 20:43:16 -080091
92 // Get the android app directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060093 android_app_dir = android_data_dir + APP_SUBDIR;
Andreas Gampe02d0de52015-11-11 20:43:16 -080094
95 // Get the android protected app directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060096 android_app_private_dir = android_data_dir + PRIVATE_APP_SUBDIR;
Andreas Gampe02d0de52015-11-11 20:43:16 -080097
98 // Get the android ephemeral app directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060099 android_app_ephemeral_dir = android_data_dir + EPHEMERAL_APP_SUBDIR;
Andreas Gampe02d0de52015-11-11 20:43:16 -0800100
101 // Get the android app native library directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600102 android_app_lib_dir = android_data_dir + APP_LIB_SUBDIR;
Andreas Gampe02d0de52015-11-11 20:43:16 -0800103
104 // Get the sd-card ASEC mount point.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600105 android_asec_dir = ensure_trailing_slash(getenv(ASEC_MOUNTPOINT_ENV_NAME));
Andreas Gampe02d0de52015-11-11 20:43:16 -0800106
107 // Get the android media directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600108 android_media_dir = android_data_dir + MEDIA_SUBDIR;
Andreas Gampe02d0de52015-11-11 20:43:16 -0800109
110 // Get the android external app directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600111 android_mnt_expand_dir = "/mnt/expand/";
Andreas Gampe02d0de52015-11-11 20:43:16 -0800112
Calin Juravle6a1648e2016-02-01 12:12:16 +0000113 // Get the android profiles directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600114 android_profiles_dir = android_data_dir + PROFILES_SUBDIR;
Calin Juravle6a1648e2016-02-01 12:12:16 +0000115
shafikb43faa92019-02-19 12:19:48 +0000116 // Get the android session staging directory.
117 android_staging_dir = android_data_dir + STAGING_SUBDIR;
118
Andreas Gampe02d0de52015-11-11 20:43:16 -0800119 // Take note of the system and vendor directories.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600120 android_system_dirs.clear();
121 android_system_dirs.push_back(android_root_dir + APP_SUBDIR);
122 android_system_dirs.push_back(android_root_dir + PRIV_APP_SUBDIR);
123 android_system_dirs.push_back("/vendor/app/");
124 android_system_dirs.push_back("/oem/app/");
Andreas Gampe02d0de52015-11-11 20:43:16 -0800125
126 return true;
127}
128
129} // namespace installd
130} // namespace android