1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker ** Copyright 2015, The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker ** 4*38e8c45fSAndroid Build Coastguard Worker ** Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker ** you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker ** You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker ** 8*38e8c45fSAndroid Build Coastguard Worker ** http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker ** 10*38e8c45fSAndroid Build Coastguard Worker ** Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker ** distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker ** See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker ** limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #define LOG_TAG "installd" 18*38e8c45fSAndroid Build Coastguard Worker 19*38e8c45fSAndroid Build Coastguard Worker #include <globals.h> 20*38e8c45fSAndroid Build Coastguard Worker #include <installd_constants.h> 21*38e8c45fSAndroid Build Coastguard Worker #include <utils.h> 22*38e8c45fSAndroid Build Coastguard Worker 23*38e8c45fSAndroid Build Coastguard Worker #include <android-base/logging.h> 24*38e8c45fSAndroid Build Coastguard Worker 25*38e8c45fSAndroid Build Coastguard Worker #include <stdlib.h> 26*38e8c45fSAndroid Build Coastguard Worker #include <string.h> 27*38e8c45fSAndroid Build Coastguard Worker 28*38e8c45fSAndroid Build Coastguard Worker namespace android { 29*38e8c45fSAndroid Build Coastguard Worker namespace installd { 30*38e8c45fSAndroid Build Coastguard Worker 31*38e8c45fSAndroid Build Coastguard Worker static constexpr const char* APP_SUBDIR = "app/"; // sub-directory under ANDROID_DATA 32*38e8c45fSAndroid Build Coastguard Worker 33*38e8c45fSAndroid Build Coastguard Worker static constexpr const char* PRIV_APP_SUBDIR = "priv-app/"; // sub-directory under ANDROID_DATA 34*38e8c45fSAndroid Build Coastguard Worker 35*38e8c45fSAndroid Build Coastguard Worker static constexpr const char* EPHEMERAL_APP_SUBDIR = "app-ephemeral/"; // sub-directory under 36*38e8c45fSAndroid Build Coastguard Worker // ANDROID_DATA 37*38e8c45fSAndroid Build Coastguard Worker 38*38e8c45fSAndroid Build Coastguard Worker static constexpr const char* APP_LIB_SUBDIR = "app-lib/"; // sub-directory under ANDROID_DATA 39*38e8c45fSAndroid Build Coastguard Worker 40*38e8c45fSAndroid Build Coastguard Worker static constexpr const char* MEDIA_SUBDIR = "media/"; // sub-directory under ANDROID_DATA 41*38e8c45fSAndroid Build Coastguard Worker 42*38e8c45fSAndroid Build Coastguard Worker static constexpr const char* PROFILES_SUBDIR = "misc/profiles"; // sub-directory under ANDROID_DATA 43*38e8c45fSAndroid Build Coastguard Worker 44*38e8c45fSAndroid Build Coastguard Worker static constexpr const char* PRIVATE_APP_SUBDIR = "app-private/"; // sub-directory under 45*38e8c45fSAndroid Build Coastguard Worker // ANDROID_DATA 46*38e8c45fSAndroid Build Coastguard Worker 47*38e8c45fSAndroid Build Coastguard Worker static constexpr const char* STAGING_SUBDIR = "app-staging/"; // sub-directory under ANDROID_DATA 48*38e8c45fSAndroid Build Coastguard Worker 49*38e8c45fSAndroid Build Coastguard Worker std::string android_app_dir; 50*38e8c45fSAndroid Build Coastguard Worker std::string android_app_ephemeral_dir; 51*38e8c45fSAndroid Build Coastguard Worker std::string android_app_lib_dir; 52*38e8c45fSAndroid Build Coastguard Worker std::string android_app_private_dir; 53*38e8c45fSAndroid Build Coastguard Worker std::string android_asec_dir; 54*38e8c45fSAndroid Build Coastguard Worker std::string android_data_dir; 55*38e8c45fSAndroid Build Coastguard Worker std::string android_media_dir; 56*38e8c45fSAndroid Build Coastguard Worker std::string android_mnt_expand_dir; 57*38e8c45fSAndroid Build Coastguard Worker std::string android_profiles_dir; 58*38e8c45fSAndroid Build Coastguard Worker std::string android_root_dir; 59*38e8c45fSAndroid Build Coastguard Worker std::string android_staging_dir; 60*38e8c45fSAndroid Build Coastguard Worker 61*38e8c45fSAndroid Build Coastguard Worker std::vector<std::string> android_system_dirs; 62*38e8c45fSAndroid Build Coastguard Worker init_globals_from_data_and_root()63*38e8c45fSAndroid Build Coastguard Workerbool init_globals_from_data_and_root() { 64*38e8c45fSAndroid Build Coastguard Worker const char* data_path = getenv("ANDROID_DATA"); 65*38e8c45fSAndroid Build Coastguard Worker if (data_path == nullptr) { 66*38e8c45fSAndroid Build Coastguard Worker LOG(ERROR) << "Could not find ANDROID_DATA"; 67*38e8c45fSAndroid Build Coastguard Worker return false; 68*38e8c45fSAndroid Build Coastguard Worker } 69*38e8c45fSAndroid Build Coastguard Worker const char* root_path = getenv("ANDROID_ROOT"); 70*38e8c45fSAndroid Build Coastguard Worker if (root_path == nullptr) { 71*38e8c45fSAndroid Build Coastguard Worker LOG(ERROR) << "Could not find ANDROID_ROOT"; 72*38e8c45fSAndroid Build Coastguard Worker return false; 73*38e8c45fSAndroid Build Coastguard Worker } 74*38e8c45fSAndroid Build Coastguard Worker return init_globals_from_data_and_root(data_path, root_path); 75*38e8c45fSAndroid Build Coastguard Worker } 76*38e8c45fSAndroid Build Coastguard Worker ensure_trailing_slash(const std::string & path)77*38e8c45fSAndroid Build Coastguard Workerstatic std::string ensure_trailing_slash(const std::string& path) { 78*38e8c45fSAndroid Build Coastguard Worker if (path.rfind('/') != path.size() - 1) { 79*38e8c45fSAndroid Build Coastguard Worker return path + '/'; 80*38e8c45fSAndroid Build Coastguard Worker } else { 81*38e8c45fSAndroid Build Coastguard Worker return path; 82*38e8c45fSAndroid Build Coastguard Worker } 83*38e8c45fSAndroid Build Coastguard Worker } 84*38e8c45fSAndroid Build Coastguard Worker init_globals_from_data_and_root(const char * data,const char * root)85*38e8c45fSAndroid Build Coastguard Workerbool init_globals_from_data_and_root(const char* data, const char* root) { 86*38e8c45fSAndroid Build Coastguard Worker // Get the android data directory. 87*38e8c45fSAndroid Build Coastguard Worker android_data_dir = ensure_trailing_slash(data); 88*38e8c45fSAndroid Build Coastguard Worker 89*38e8c45fSAndroid Build Coastguard Worker // Get the android root directory. 90*38e8c45fSAndroid Build Coastguard Worker android_root_dir = ensure_trailing_slash(root); 91*38e8c45fSAndroid Build Coastguard Worker 92*38e8c45fSAndroid Build Coastguard Worker // Get the android app directory. 93*38e8c45fSAndroid Build Coastguard Worker android_app_dir = android_data_dir + APP_SUBDIR; 94*38e8c45fSAndroid Build Coastguard Worker 95*38e8c45fSAndroid Build Coastguard Worker // Get the android protected app directory. 96*38e8c45fSAndroid Build Coastguard Worker android_app_private_dir = android_data_dir + PRIVATE_APP_SUBDIR; 97*38e8c45fSAndroid Build Coastguard Worker 98*38e8c45fSAndroid Build Coastguard Worker // Get the android ephemeral app directory. 99*38e8c45fSAndroid Build Coastguard Worker android_app_ephemeral_dir = android_data_dir + EPHEMERAL_APP_SUBDIR; 100*38e8c45fSAndroid Build Coastguard Worker 101*38e8c45fSAndroid Build Coastguard Worker // Get the android app native library directory. 102*38e8c45fSAndroid Build Coastguard Worker android_app_lib_dir = android_data_dir + APP_LIB_SUBDIR; 103*38e8c45fSAndroid Build Coastguard Worker 104*38e8c45fSAndroid Build Coastguard Worker // Get the sd-card ASEC mount point. 105*38e8c45fSAndroid Build Coastguard Worker android_asec_dir = ensure_trailing_slash(getenv(ASEC_MOUNTPOINT_ENV_NAME)); 106*38e8c45fSAndroid Build Coastguard Worker 107*38e8c45fSAndroid Build Coastguard Worker // Get the android media directory. 108*38e8c45fSAndroid Build Coastguard Worker android_media_dir = android_data_dir + MEDIA_SUBDIR; 109*38e8c45fSAndroid Build Coastguard Worker 110*38e8c45fSAndroid Build Coastguard Worker // Get the android external app directory. 111*38e8c45fSAndroid Build Coastguard Worker android_mnt_expand_dir = "/mnt/expand/"; 112*38e8c45fSAndroid Build Coastguard Worker 113*38e8c45fSAndroid Build Coastguard Worker // Get the android profiles directory. 114*38e8c45fSAndroid Build Coastguard Worker android_profiles_dir = android_data_dir + PROFILES_SUBDIR; 115*38e8c45fSAndroid Build Coastguard Worker 116*38e8c45fSAndroid Build Coastguard Worker // Get the android session staging directory. 117*38e8c45fSAndroid Build Coastguard Worker android_staging_dir = android_data_dir + STAGING_SUBDIR; 118*38e8c45fSAndroid Build Coastguard Worker 119*38e8c45fSAndroid Build Coastguard Worker // Take note of the system and vendor directories. 120*38e8c45fSAndroid Build Coastguard Worker android_system_dirs.clear(); 121*38e8c45fSAndroid Build Coastguard Worker android_system_dirs.push_back(android_root_dir + APP_SUBDIR); 122*38e8c45fSAndroid Build Coastguard Worker android_system_dirs.push_back(android_root_dir + PRIV_APP_SUBDIR); 123*38e8c45fSAndroid Build Coastguard Worker android_system_dirs.push_back("/vendor/app/"); 124*38e8c45fSAndroid Build Coastguard Worker android_system_dirs.push_back("/oem/app/"); 125*38e8c45fSAndroid Build Coastguard Worker 126*38e8c45fSAndroid Build Coastguard Worker return true; 127*38e8c45fSAndroid Build Coastguard Worker } 128*38e8c45fSAndroid Build Coastguard Worker 129*38e8c45fSAndroid Build Coastguard Worker } // namespace installd 130*38e8c45fSAndroid Build Coastguard Worker } // namespace android 131