• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
48     binder::Status createAppData(const std::unique_ptr<std::string>& uuid,
49             const std::string& packageName, int32_t userId, int32_t flags, int32_t appId,
50             const std::string& seInfo, int32_t targetSdkVersion, int64_t* _aidl_return);
51     binder::Status restoreconAppData(const std::unique_ptr<std::string>& uuid,
52             const std::string& packageName, int32_t userId, int32_t flags, int32_t appId,
53             const std::string& seInfo);
54     binder::Status migrateAppData(const std::unique_ptr<std::string>& uuid,
55             const std::string& packageName, int32_t userId, int32_t flags);
56     binder::Status clearAppData(const std::unique_ptr<std::string>& uuid,
57             const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode);
58     binder::Status destroyAppData(const std::unique_ptr<std::string>& uuid,
59             const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode);
60 
61     binder::Status fixupAppData(const std::unique_ptr<std::string>& uuid, int32_t flags);
62 
63     binder::Status snapshotAppData(const std::unique_ptr<std::string>& volumeUuid,
64             const std::string& packageName, const int32_t user, const int32_t snapshotId,
65             int32_t storageFlags, int64_t* _aidl_return);
66     binder::Status restoreAppDataSnapshot(const std::unique_ptr<std::string>& volumeUuid,
67             const std::string& packageName, const int32_t appId, const std::string& seInfo,
68             const int32_t user, const int32_t snapshotId, int32_t storageFlags);
69     binder::Status destroyAppDataSnapshot(const std::unique_ptr<std::string> &volumeUuid,
70             const std::string& packageName, const int32_t user, const int64_t ceSnapshotInode,
71             const int32_t snapshotId, int32_t storageFlags);
72 
73     binder::Status getAppSize(const std::unique_ptr<std::string>& uuid,
74             const std::vector<std::string>& packageNames, int32_t userId, int32_t flags,
75             int32_t appId, const std::vector<int64_t>& ceDataInodes,
76             const std::vector<std::string>& codePaths, std::vector<int64_t>* _aidl_return);
77     binder::Status getUserSize(const std::unique_ptr<std::string>& uuid,
78             int32_t userId, int32_t flags, const std::vector<int32_t>& appIds,
79             std::vector<int64_t>* _aidl_return);
80     binder::Status getExternalSize(const std::unique_ptr<std::string>& uuid,
81             int32_t userId, int32_t flags, const std::vector<int32_t>& appIds,
82             std::vector<int64_t>* _aidl_return);
83 
84     binder::Status setAppQuota(const std::unique_ptr<std::string>& uuid,
85             int32_t userId, int32_t appId, int64_t cacheQuota);
86 
87     binder::Status moveCompleteApp(const std::unique_ptr<std::string>& fromUuid,
88             const std::unique_ptr<std::string>& toUuid, const std::string& packageName,
89             const std::string& dataAppName, int32_t appId, const std::string& seInfo,
90             int32_t targetSdkVersion);
91 
92     binder::Status dexopt(const std::string& apkPath, int32_t uid,
93             const std::unique_ptr<std::string>& packageName, const std::string& instructionSet,
94             int32_t dexoptNeeded, const std::unique_ptr<std::string>& outputPath, int32_t dexFlags,
95             const std::string& compilerFilter, const std::unique_ptr<std::string>& uuid,
96             const std::unique_ptr<std::string>& classLoaderContext,
97             const std::unique_ptr<std::string>& seInfo, bool downgrade,
98             int32_t targetSdkVersion, const std::unique_ptr<std::string>& profileName,
99             const std::unique_ptr<std::string>& dexMetadataPath,
100             const std::unique_ptr<std::string>& compilationReason);
101 
102     binder::Status compileLayouts(const std::string& apkPath, const std::string& packageName,
103                                   const std::string& outDexFile, int uid, bool* _aidl_return);
104 
105     binder::Status rmdex(const std::string& codePath, const std::string& instructionSet);
106 
107     binder::Status mergeProfiles(int32_t uid, const std::string& packageName,
108             const std::string& profileName, bool* _aidl_return);
109     binder::Status dumpProfiles(int32_t uid, const std::string& packageName,
110             const std::string& profileName, const std::string& codePath, bool* _aidl_return);
111     binder::Status copySystemProfile(const std::string& systemProfile,
112             int32_t uid, const std::string& packageName, const std::string& profileName,
113             bool* _aidl_return);
114     binder::Status clearAppProfiles(const std::string& packageName, const std::string& profileName);
115     binder::Status destroyAppProfiles(const std::string& packageName);
116 
117     binder::Status createProfileSnapshot(int32_t appId, const std::string& packageName,
118             const std::string& profileName, const std::string& classpath, bool* _aidl_return);
119     binder::Status destroyProfileSnapshot(const std::string& packageName,
120             const std::string& profileName);
121 
122     binder::Status idmap(const std::string& targetApkPath, const std::string& overlayApkPath,
123             int32_t uid);
124     binder::Status removeIdmap(const std::string& overlayApkPath);
125     binder::Status rmPackageDir(const std::string& packageDir);
126     binder::Status markBootComplete(const std::string& instructionSet);
127     binder::Status freeCache(const std::unique_ptr<std::string>& uuid, int64_t targetFreeBytes,
128             int64_t cacheReservedBytes, int32_t flags);
129     binder::Status linkNativeLibraryDirectory(const std::unique_ptr<std::string>& uuid,
130             const std::string& packageName, const std::string& nativeLibPath32, int32_t userId);
131     binder::Status createOatDir(const std::string& oatDir, const std::string& instructionSet);
132     binder::Status linkFile(const std::string& relativePath, const std::string& fromBase,
133             const std::string& toBase);
134     binder::Status moveAb(const std::string& apkPath, const std::string& instructionSet,
135             const std::string& outputPath);
136     binder::Status deleteOdex(const std::string& apkPath, const std::string& instructionSet,
137             const std::unique_ptr<std::string>& outputPath);
138     binder::Status installApkVerity(const std::string& filePath,
139             const ::android::base::unique_fd& verityInput, int32_t contentSize);
140     binder::Status assertFsverityRootHashMatches(const std::string& filePath,
141             const std::vector<uint8_t>& expectedHash);
142     binder::Status reconcileSecondaryDexFile(const std::string& dexPath,
143         const std::string& packageName, int32_t uid, const std::vector<std::string>& isa,
144         const std::unique_ptr<std::string>& volumeUuid, int32_t storage_flag, bool* _aidl_return);
145     binder::Status hashSecondaryDexFile(const std::string& dexPath,
146         const std::string& packageName, int32_t uid, const std::unique_ptr<std::string>& volumeUuid,
147         int32_t storageFlag, std::vector<uint8_t>* _aidl_return);
148 
149     binder::Status invalidateMounts();
150     binder::Status isQuotaSupported(const std::unique_ptr<std::string>& volumeUuid,
151             bool* _aidl_return);
152 
153     binder::Status prepareAppProfile(const std::string& packageName,
154             int32_t userId, int32_t appId, const std::string& profileName,
155             const std::string& codePath, const std::unique_ptr<std::string>& dexMetadata,
156             bool* _aidl_return);
157 
158     binder::Status migrateLegacyObbData();
159 
160 private:
161     std::recursive_mutex mLock;
162 
163     std::recursive_mutex mMountsLock;
164     std::recursive_mutex mQuotasLock;
165 
166     /* Map of all storage mounts from source to target */
167     std::unordered_map<std::string, std::string> mStorageMounts;
168 
169     /* Map from UID to cache quota size */
170     std::unordered_map<uid_t, int64_t> mCacheQuotas;
171 
172     std::string findDataMediaPath(const std::unique_ptr<std::string>& uuid, userid_t userid);
173 };
174 
175 }  // namespace installd
176 }  // namespace android
177 
178 #endif  // COMMANDS_H_
179