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::unique_ptr<std::string>& uuid, int32_t userId, 44 int32_t userSerial, int32_t flags); 45 binder::Status destroyUserData(const std::unique_ptr<std::string>& uuid, int32_t userId, 46 int32_t flags); 47 binder::Status createAppDataBatched( 48 const std::unique_ptr<std::vector<std::unique_ptr<std::string>>>& uuids, 49 const std::unique_ptr<std::vector<std::unique_ptr<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::unique_ptr<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::unique_ptr<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::unique_ptr<std::string>& uuid, 60 const std::string& packageName, int32_t userId, int32_t flags); 61 binder::Status clearAppData(const std::unique_ptr<std::string>& uuid, 62 const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode); 63 binder::Status destroyAppData(const std::unique_ptr<std::string>& uuid, 64 const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode); 65 66 binder::Status fixupAppData(const std::unique_ptr<std::string>& uuid, int32_t flags); 67 68 binder::Status snapshotAppData(const std::unique_ptr<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::unique_ptr<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::unique_ptr<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::unique_ptr<std::string> &volumeUuid, 78 const int32_t userId, const std::vector<int32_t>& retainSnapshotIds); 79 80 binder::Status getAppSize(const std::unique_ptr<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::unique_ptr<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::unique_ptr<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 getAppCrates(const std::unique_ptr<std::string>& uuid, 92 const std::vector<std::string>& packageNames, 93 int32_t userId, 94 std::unique_ptr<std::vector<std::unique_ptr<android::os::storage::CrateMetadata>>>* 95 _aidl_return); 96 binder::Status getUserCrates( 97 const std::unique_ptr<std::string>& uuid, int32_t userId, 98 std::unique_ptr<std::vector<std::unique_ptr<android::os::storage::CrateMetadata>>>* 99 _aidl_return); 100 101 binder::Status setAppQuota(const std::unique_ptr<std::string>& uuid, 102 int32_t userId, int32_t appId, int64_t cacheQuota); 103 104 binder::Status moveCompleteApp(const std::unique_ptr<std::string>& fromUuid, 105 const std::unique_ptr<std::string>& toUuid, const std::string& packageName, 106 int32_t appId, const std::string& seInfo, 107 int32_t targetSdkVersion, const std::string& fromCodePath); 108 109 binder::Status dexopt(const std::string& apkPath, int32_t uid, 110 const std::unique_ptr<std::string>& packageName, const std::string& instructionSet, 111 int32_t dexoptNeeded, const std::unique_ptr<std::string>& outputPath, int32_t dexFlags, 112 const std::string& compilerFilter, const std::unique_ptr<std::string>& uuid, 113 const std::unique_ptr<std::string>& classLoaderContext, 114 const std::unique_ptr<std::string>& seInfo, bool downgrade, 115 int32_t targetSdkVersion, const std::unique_ptr<std::string>& profileName, 116 const std::unique_ptr<std::string>& dexMetadataPath, 117 const std::unique_ptr<std::string>& compilationReason); 118 119 binder::Status compileLayouts(const std::string& apkPath, const std::string& packageName, 120 const std::string& outDexFile, int uid, bool* _aidl_return); 121 122 binder::Status rmdex(const std::string& codePath, const std::string& instructionSet); 123 124 binder::Status mergeProfiles(int32_t uid, const std::string& packageName, 125 const std::string& profileName, bool* _aidl_return); 126 binder::Status dumpProfiles(int32_t uid, const std::string& packageName, 127 const std::string& profileName, const std::string& codePath, bool* _aidl_return); 128 binder::Status copySystemProfile(const std::string& systemProfile, 129 int32_t uid, const std::string& packageName, const std::string& profileName, 130 bool* _aidl_return); 131 binder::Status clearAppProfiles(const std::string& packageName, const std::string& profileName); 132 binder::Status destroyAppProfiles(const std::string& packageName); 133 134 binder::Status createProfileSnapshot(int32_t appId, const std::string& packageName, 135 const std::string& profileName, const std::string& classpath, bool* _aidl_return); 136 binder::Status destroyProfileSnapshot(const std::string& packageName, 137 const std::string& profileName); 138 139 binder::Status rmPackageDir(const std::string& packageDir); 140 binder::Status freeCache(const std::unique_ptr<std::string>& uuid, int64_t targetFreeBytes, 141 int64_t cacheReservedBytes, int32_t flags); 142 binder::Status linkNativeLibraryDirectory(const std::unique_ptr<std::string>& uuid, 143 const std::string& packageName, const std::string& nativeLibPath32, int32_t userId); 144 binder::Status createOatDir(const std::string& oatDir, const std::string& instructionSet); 145 binder::Status linkFile(const std::string& relativePath, const std::string& fromBase, 146 const std::string& toBase); 147 binder::Status moveAb(const std::string& apkPath, const std::string& instructionSet, 148 const std::string& outputPath); 149 binder::Status deleteOdex(const std::string& apkPath, const std::string& instructionSet, 150 const std::unique_ptr<std::string>& outputPath); 151 binder::Status installApkVerity(const std::string& filePath, 152 android::base::unique_fd verityInput, int32_t contentSize); 153 binder::Status assertFsverityRootHashMatches(const std::string& filePath, 154 const std::vector<uint8_t>& expectedHash); 155 binder::Status reconcileSecondaryDexFile(const std::string& dexPath, 156 const std::string& packageName, int32_t uid, const std::vector<std::string>& isa, 157 const std::unique_ptr<std::string>& volumeUuid, int32_t storage_flag, bool* _aidl_return); 158 binder::Status hashSecondaryDexFile(const std::string& dexPath, 159 const std::string& packageName, int32_t uid, const std::unique_ptr<std::string>& volumeUuid, 160 int32_t storageFlag, std::vector<uint8_t>* _aidl_return); 161 162 binder::Status invalidateMounts(); 163 binder::Status isQuotaSupported(const std::unique_ptr<std::string>& volumeUuid, 164 bool* _aidl_return); 165 binder::Status tryMountDataMirror(const std::unique_ptr<std::string>& volumeUuid); 166 binder::Status onPrivateVolumeRemoved(const std::unique_ptr<std::string>& volumeUuid); 167 168 binder::Status prepareAppProfile(const std::string& packageName, 169 int32_t userId, int32_t appId, const std::string& profileName, 170 const std::string& codePath, const std::unique_ptr<std::string>& dexMetadata, 171 bool* _aidl_return); 172 173 binder::Status migrateLegacyObbData(); 174 175 private: 176 std::recursive_mutex mLock; 177 178 std::recursive_mutex mMountsLock; 179 std::recursive_mutex mQuotasLock; 180 181 /* Map of all storage mounts from source to target */ 182 std::unordered_map<std::string, std::string> mStorageMounts; 183 184 /* Map from UID to cache quota size */ 185 std::unordered_map<uid_t, int64_t> mCacheQuotas; 186 187 std::string findDataMediaPath(const std::unique_ptr<std::string>& uuid, userid_t userid); 188 }; 189 190 } // namespace installd 191 } // namespace android 192 193 #endif // COMMANDS_H_ 194