blob: b3a6dafa9a9c5fdc6c86ee80acf1ff780c0afcdc [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
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060047std::string android_app_dir;
48std::string android_app_ephemeral_dir;
49std::string android_app_lib_dir;
50std::string android_app_private_dir;
51std::string android_asec_dir;
52std::string android_data_dir;
53std::string android_media_dir;
54std::string android_mnt_expand_dir;
55std::string android_profiles_dir;
56std::string android_root_dir;
Andreas Gampe02d0de52015-11-11 20:43:16 -080057
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060058std::vector<std::string> android_system_dirs;
Andreas Gampe02d0de52015-11-11 20:43:16 -080059
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060060bool init_globals_from_data_and_root() {
61 const char* data_path = getenv("ANDROID_DATA");
62 if (data_path == nullptr) {
63 LOG(ERROR) << "Could not find ANDROID_DATA";
64 return false;
Andreas Gampe02d0de52015-11-11 20:43:16 -080065 }
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060066 const char* root_path = getenv("ANDROID_ROOT");
67 if (root_path == nullptr) {
68 LOG(ERROR) << "Could not find ANDROID_ROOT";
69 return false;
70 }
71 return init_globals_from_data_and_root(data_path, root_path);
72}
Andreas Gampe02d0de52015-11-11 20:43:16 -080073
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060074static std::string ensure_trailing_slash(const std::string& path) {
75 if (path.rfind('/') != path.size() - 1) {
76 return path + '/';
77 } else {
78 return path;
79 }
Andreas Gampe02d0de52015-11-11 20:43:16 -080080}
81
82bool init_globals_from_data_and_root(const char* data, const char* root) {
83 // Get the android data directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060084 android_data_dir = ensure_trailing_slash(data);
85
86 // Get the android root directory.
87 android_root_dir = ensure_trailing_slash(root);
Andreas Gampe02d0de52015-11-11 20:43:16 -080088
89 // Get the android app directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060090 android_app_dir = android_data_dir + APP_SUBDIR;
Andreas Gampe02d0de52015-11-11 20:43:16 -080091
92 // Get the android protected app directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060093 android_app_private_dir = android_data_dir + PRIVATE_APP_SUBDIR;
Andreas Gampe02d0de52015-11-11 20:43:16 -080094
95 // Get the android ephemeral app directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060096 android_app_ephemeral_dir = android_data_dir + EPHEMERAL_APP_SUBDIR;
Andreas Gampe02d0de52015-11-11 20:43:16 -080097
98 // Get the android app native library directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -060099 android_app_lib_dir = android_data_dir + APP_LIB_SUBDIR;
Andreas Gampe02d0de52015-11-11 20:43:16 -0800100
101 // Get the sd-card ASEC mount point.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600102 android_asec_dir = ensure_trailing_slash(getenv(ASEC_MOUNTPOINT_ENV_NAME));
Andreas Gampe02d0de52015-11-11 20:43:16 -0800103
104 // Get the android media directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600105 android_media_dir = android_data_dir + MEDIA_SUBDIR;
Andreas Gampe02d0de52015-11-11 20:43:16 -0800106
107 // Get the android external app directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600108 android_mnt_expand_dir = "/mnt/expand/";
Andreas Gampe02d0de52015-11-11 20:43:16 -0800109
Calin Juravle6a1648e2016-02-01 12:12:16 +0000110 // Get the android profiles directory.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600111 android_profiles_dir = android_data_dir + PROFILES_SUBDIR;
Calin Juravle6a1648e2016-02-01 12:12:16 +0000112
Andreas Gampe02d0de52015-11-11 20:43:16 -0800113 // Take note of the system and vendor directories.
Jeff Sharkeyc1149c92017-09-21 14:51:09 -0600114 android_system_dirs.clear();
115 android_system_dirs.push_back(android_root_dir + APP_SUBDIR);
116 android_system_dirs.push_back(android_root_dir + PRIV_APP_SUBDIR);
117 android_system_dirs.push_back("/vendor/app/");
118 android_system_dirs.push_back("/oem/app/");
Andreas Gampe02d0de52015-11-11 20:43:16 -0800119
120 return true;
121}
122
123} // namespace installd
124} // namespace android