| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 1 | /* | 
|  | 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 Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 17 | #define LOG_TAG "installd" | 
|  | 18 |  | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 19 | #include <globals.h> | 
|  | 20 | #include <installd_constants.h> | 
|  | 21 | #include <utils.h> | 
|  | 22 |  | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 23 | #include <android-base/logging.h> | 
|  | 24 |  | 
|  | 25 | #include <stdlib.h> | 
|  | 26 | #include <string.h> | 
|  | 27 |  | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 28 | namespace android { | 
|  | 29 | namespace installd { | 
|  | 30 |  | 
| Andreas Gampe | d089ca1 | 2016-06-27 14:25:30 -0700 | [diff] [blame] | 31 | static constexpr const char* APP_SUBDIR = "app/"; // sub-directory under ANDROID_DATA | 
|  | 32 |  | 
|  | 33 | static constexpr const char* PRIV_APP_SUBDIR = "priv-app/"; // sub-directory under ANDROID_DATA | 
|  | 34 |  | 
|  | 35 | static constexpr const char* EPHEMERAL_APP_SUBDIR = "app-ephemeral/"; // sub-directory under | 
|  | 36 | // ANDROID_DATA | 
|  | 37 |  | 
|  | 38 | static constexpr const char* APP_LIB_SUBDIR = "app-lib/"; // sub-directory under ANDROID_DATA | 
|  | 39 |  | 
|  | 40 | static constexpr const char* MEDIA_SUBDIR = "media/"; // sub-directory under ANDROID_DATA | 
|  | 41 |  | 
|  | 42 | static constexpr const char* PROFILES_SUBDIR = "misc/profiles"; // sub-directory under ANDROID_DATA | 
|  | 43 |  | 
|  | 44 | static constexpr const char* PRIVATE_APP_SUBDIR = "app-private/"; // sub-directory under | 
|  | 45 | // ANDROID_DATA | 
|  | 46 |  | 
| shafik | b43faa9 | 2019-02-19 12:19:48 +0000 | [diff] [blame] | 47 | static constexpr const char* STAGING_SUBDIR = "pkg_staging/"; // sub-directory under ANDROID_DATA | 
|  | 48 |  | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 49 | std::string android_app_dir; | 
|  | 50 | std::string android_app_ephemeral_dir; | 
|  | 51 | std::string android_app_lib_dir; | 
|  | 52 | std::string android_app_private_dir; | 
|  | 53 | std::string android_asec_dir; | 
|  | 54 | std::string android_data_dir; | 
|  | 55 | std::string android_media_dir; | 
|  | 56 | std::string android_mnt_expand_dir; | 
|  | 57 | std::string android_profiles_dir; | 
|  | 58 | std::string android_root_dir; | 
| shafik | b43faa9 | 2019-02-19 12:19:48 +0000 | [diff] [blame] | 59 | std::string android_staging_dir; | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 60 |  | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 61 | std::vector<std::string> android_system_dirs; | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 62 |  | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 63 | bool 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 Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 68 | } | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 69 | 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 Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 76 |  | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 77 | static 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 Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 83 | } | 
|  | 84 |  | 
|  | 85 | bool init_globals_from_data_and_root(const char* data, const char* root) { | 
|  | 86 | // Get the android data directory. | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 87 | android_data_dir = ensure_trailing_slash(data); | 
|  | 88 |  | 
|  | 89 | // Get the android root directory. | 
|  | 90 | android_root_dir = ensure_trailing_slash(root); | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 91 |  | 
|  | 92 | // Get the android app directory. | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 93 | android_app_dir = android_data_dir + APP_SUBDIR; | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 94 |  | 
|  | 95 | // Get the android protected app directory. | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 96 | android_app_private_dir = android_data_dir + PRIVATE_APP_SUBDIR; | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 97 |  | 
|  | 98 | // Get the android ephemeral app directory. | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 99 | android_app_ephemeral_dir = android_data_dir + EPHEMERAL_APP_SUBDIR; | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 100 |  | 
|  | 101 | // Get the android app native library directory. | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 102 | android_app_lib_dir = android_data_dir + APP_LIB_SUBDIR; | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 103 |  | 
|  | 104 | // Get the sd-card ASEC mount point. | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 105 | android_asec_dir = ensure_trailing_slash(getenv(ASEC_MOUNTPOINT_ENV_NAME)); | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 106 |  | 
|  | 107 | // Get the android media directory. | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 108 | android_media_dir = android_data_dir + MEDIA_SUBDIR; | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 109 |  | 
|  | 110 | // Get the android external app directory. | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 111 | android_mnt_expand_dir = "/mnt/expand/"; | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 112 |  | 
| Calin Juravle | 6a1648e | 2016-02-01 12:12:16 +0000 | [diff] [blame] | 113 | // Get the android profiles directory. | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 114 | android_profiles_dir = android_data_dir + PROFILES_SUBDIR; | 
| Calin Juravle | 6a1648e | 2016-02-01 12:12:16 +0000 | [diff] [blame] | 115 |  | 
| shafik | b43faa9 | 2019-02-19 12:19:48 +0000 | [diff] [blame] | 116 | // Get the android session staging directory. | 
|  | 117 | android_staging_dir = android_data_dir + STAGING_SUBDIR; | 
|  | 118 |  | 
| Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 119 | // Take note of the system and vendor directories. | 
| Jeff Sharkey | c1149c9 | 2017-09-21 14:51:09 -0600 | [diff] [blame] | 120 | 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 Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 125 |  | 
|  | 126 | return true; | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | }  // namespace installd | 
|  | 130 | }  // namespace android |