1 /* 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 #ifndef COMMANDS_H_ 19 #define COMMANDS_H_ 20 21 #include <inttypes.h> 22 #include <unistd.h> 23 24 #include <vector> 25 #include <unordered_map> 26 27 #include <android-base/macros.h> 28 #include <binder/BinderService.h> 29 #include <cutils/multiuser.h> 30 31 #include "android/os/BnInstalld.h" 32 #include "installd_constants.h" 33 34 namespace android { 35 namespace installd { 36 37 class InstalldNativeService : public BinderService<InstalldNativeService>, public os::BnInstalld { 38 public: 39 static status_t start(); getServiceName()40 static char const* getServiceName() { return "installd"; } 41 virtual status_t dump(int fd, const Vector<String16> &args) override; 42 43 binder::Status createUserData(const std::optional<std::string>& uuid, int32_t userId, 44 int32_t userSerial, int32_t flags); 45 binder::Status destroyUserData(const std::optional<std::string>& uuid, int32_t userId, 46 int32_t flags); 47 binder::Status createAppDataBatched( 48 const std::optional<std::vector<std::optional<std::string>>>& uuids, 49 const std::optional<std::vector<std::optional<std::string>>>& packageNames, 50 int32_t userId, int32_t flags, const std::vector<int32_t>& appIds, 51 const std::vector<std::string>& seInfos, const std::vector<int32_t>& targetSdkVersions, 52 int64_t* _aidl_return); 53 binder::Status createAppData(const std::optional<std::string>& uuid, 54 const std::string& packageName, int32_t userId, int32_t flags, int32_t appId, 55 const std::string& seInfo, int32_t targetSdkVersion, int64_t* _aidl_return); 56 binder::Status restoreconAppData(const std::optional<std::string>& uuid, 57 const std::string& packageName, int32_t userId, int32_t flags, int32_t appId, 58 const std::string& seInfo); 59 binder::Status migrateAppData(const std::optional<std::string>& uuid, 60 const std::string& packageName, int32_t userId, int32_t flags); 61 binder::Status clearAppData(const std::optional<std::string>& uuid, 62 const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode); 63 binder::Status destroyAppData(const std::optional<std::string>& uuid, 64 const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode); 65 66 binder::Status fixupAppData(const std::optional<std::string>& uuid, int32_t flags); 67 68 binder::Status snapshotAppData(const std::optional<std::string>& volumeUuid, 69 const std::string& packageName, const int32_t user, const int32_t snapshotId, 70 int32_t storageFlags, int64_t* _aidl_return); 71 binder::Status restoreAppDataSnapshot(const std::optional<std::string>& volumeUuid, 72 const std::string& packageName, const int32_t appId, const std::string& seInfo, 73 const int32_t user, const int32_t snapshotId, int32_t storageFlags); 74 binder::Status destroyAppDataSnapshot(const std::optional<std::string> &volumeUuid, 75 const std::string& packageName, const int32_t user, const int64_t ceSnapshotInode, 76 const int32_t snapshotId, int32_t storageFlags); 77 binder::Status destroyCeSnapshotsNotSpecified(const std::optional<std::string> &volumeUuid, 78 const int32_t user, const std::vector<int32_t>& retainSnapshotIds); 79 80 binder::Status getAppSize(const std::optional<std::string>& uuid, 81 const std::vector<std::string>& packageNames, int32_t userId, int32_t flags, 82 int32_t appId, const std::vector<int64_t>& ceDataInodes, 83 const std::vector<std::string>& codePaths, std::vector<int64_t>* _aidl_return); 84 binder::Status getUserSize(const std::optional<std::string>& uuid, 85 int32_t userId, int32_t flags, const std::vector<int32_t>& appIds, 86 std::vector<int64_t>* _aidl_return); 87 binder::Status getExternalSize(const std::optional<std::string>& uuid, 88 int32_t userId, int32_t flags, const std::vector<int32_t>& appIds, 89 std::vector<int64_t>* _aidl_return); 90 91 binder::Status setAppQuota(const std::optional<std::string>& uuid, 92 int32_t userId, int32_t appId, int64_t cacheQuota); 93 94 binder::Status moveCompleteApp(const std::optional<std::string>& fromUuid, 95 const std::optional<std::string>& toUuid, const std::string& packageName, 96 const std::string& dataAppName, int32_t appId, const std::string& seInfo, 97 int32_t targetSdkVersion); 98 99 binder::Status dexopt(const std::string& apkPath, int32_t uid, 100 const std::optional<std::string>& packageName, const std::string& instructionSet, 101 int32_t dexoptNeeded, const std::optional<std::string>& outputPath, int32_t dexFlags, 102 const std::string& compilerFilter, const std::optional<std::string>& uuid, 103 const std::optional<std::string>& classLoaderContext, 104 const std::optional<std::string>& seInfo, bool downgrade, 105 int32_t targetSdkVersion, const std::optional<std::string>& profileName, 106 const std::optional<std::string>& dexMetadataPath, 107 const std::optional<std::string>& compilationReason); 108 109 binder::Status compileLayouts(const std::string& apkPath, const std::string& packageName, 110 const std::string& outDexFile, int uid, bool* _aidl_return); 111 112 binder::Status rmdex(const std::string& codePath, const std::string& instructionSet); 113 114 binder::Status mergeProfiles(int32_t uid, const std::string& packageName, 115 const std::string& profileName, bool* _aidl_return); 116 binder::Status dumpProfiles(int32_t uid, const std::string& packageName, 117 const std::string& profileName, const std::string& codePath, bool* _aidl_return); 118 binder::Status copySystemProfile(const std::string& systemProfile, 119 int32_t uid, const std::string& packageName, const std::string& profileName, 120 bool* _aidl_return); 121 binder::Status clearAppProfiles(const std::string& packageName, const std::string& profileName); 122 binder::Status destroyAppProfiles(const std::string& packageName); 123 124 binder::Status createProfileSnapshot(int32_t appId, const std::string& packageName, 125 const std::string& profileName, const std::string& classpath, bool* _aidl_return); 126 binder::Status destroyProfileSnapshot(const std::string& packageName, 127 const std::string& profileName); 128 129 binder::Status idmap(const std::string& targetApkPath, const std::string& overlayApkPath, 130 int32_t uid); 131 binder::Status removeIdmap(const std::string& overlayApkPath); 132 binder::Status rmPackageDir(const std::string& packageDir); 133 binder::Status freeCache(const std::optional<std::string>& uuid, int64_t targetFreeBytes, 134 int64_t cacheReservedBytes, int32_t flags); 135 binder::Status linkNativeLibraryDirectory(const std::optional<std::string>& uuid, 136 const std::string& packageName, const std::string& nativeLibPath32, int32_t userId); 137 binder::Status createOatDir(const std::string& oatDir, const std::string& instructionSet); 138 binder::Status linkFile(const std::string& relativePath, const std::string& fromBase, 139 const std::string& toBase); 140 binder::Status moveAb(const std::string& apkPath, const std::string& instructionSet, 141 const std::string& outputPath); 142 binder::Status deleteOdex(const std::string& apkPath, const std::string& instructionSet, 143 const std::optional<std::string>& outputPath); 144 binder::Status installApkVerity(const std::string& filePath, 145 android::base::unique_fd verityInput, int32_t contentSize); 146 binder::Status assertFsverityRootHashMatches(const std::string& filePath, 147 const std::vector<uint8_t>& expectedHash); 148 binder::Status reconcileSecondaryDexFile(const std::string& dexPath, 149 const std::string& packageName, int32_t uid, const std::vector<std::string>& isa, 150 const std::optional<std::string>& volumeUuid, int32_t storage_flag, bool* _aidl_return); 151 binder::Status hashSecondaryDexFile(const std::string& dexPath, 152 const std::string& packageName, int32_t uid, const std::optional<std::string>& volumeUuid, 153 int32_t storageFlag, std::vector<uint8_t>* _aidl_return); 154 155 binder::Status invalidateMounts(); 156 binder::Status isQuotaSupported(const std::optional<std::string>& volumeUuid, 157 bool* _aidl_return); 158 159 binder::Status prepareAppProfile(const std::string& packageName, 160 int32_t userId, int32_t appId, const std::string& profileName, 161 const std::string& codePath, const std::optional<std::string>& dexMetadata, 162 bool* _aidl_return); 163 164 binder::Status migrateLegacyObbData(); 165 166 private: 167 std::recursive_mutex mLock; 168 169 std::recursive_mutex mMountsLock; 170 std::recursive_mutex mQuotasLock; 171 172 /* Map of all storage mounts from source to target */ 173 std::unordered_map<std::string, std::string> mStorageMounts; 174 175 /* Map from UID to cache quota size */ 176 std::unordered_map<uid_t, int64_t> mCacheQuotas; 177 178 std::string findDataMediaPath(const std::optional<std::string>& uuid, userid_t userid); 179 }; 180 181 } // namespace installd 182 } // namespace android 183 184 #endif // COMMANDS_H_ 185