InstalldNativeService.h 9.1 KB

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