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