blob: 8e7d98b9a125f8e8073b385f27bff9739ddea379 [file] [log] [blame]
Andreas Gampe02d0de52015-11-11 20:43:16 -08001/*
2**
3** Copyright 2008, The Android Open Source Project
4**
Jeff Sharkeyf3e30b92016-12-09 17:06:57 -07005** 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
Andreas Gampe02d0de52015-11-11 20:43:16 -08008**
Jeff Sharkeyf3e30b92016-12-09 17:06:57 -07009** http://www.apache.org/licenses/LICENSE-2.0
Andreas Gampe02d0de52015-11-11 20:43:16 -080010**
Jeff Sharkeyf3e30b92016-12-09 17:06:57 -070011** 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
Andreas Gampe02d0de52015-11-11 20:43:16 -080015** limitations under the License.
16*/
17
18#ifndef COMMANDS_H_
19#define COMMANDS_H_
20
21#include <inttypes.h>
22#include <unistd.h>
23
Jeff Sharkey0274c972016-12-06 09:32:04 -070024#include <vector>
Jeff Sharkey66b1a122017-01-16 20:57:45 -070025#include <unordered_map>
Jeff Sharkey0274c972016-12-06 09:32:04 -070026
Jeff Sharkey88ddd942017-01-17 18:05:54 -070027#include <android-base/macros.h>
Jeff Sharkey0274c972016-12-06 09:32:04 -070028#include <binder/BinderService.h>
Andreas Gampe02d0de52015-11-11 20:43:16 -080029#include <cutils/multiuser.h>
30
Jeff Sharkey0274c972016-12-06 09:32:04 -070031#include "android/os/BnInstalld.h"
32#include "installd_constants.h"
Andreas Gampe02d0de52015-11-11 20:43:16 -080033
34namespace android {
35namespace installd {
36
Jeff Sharkey0274c972016-12-06 09:32:04 -070037class InstalldNativeService : public BinderService<InstalldNativeService>, public os::BnInstalld {
38public:
39 static status_t start();
40 static char const* getServiceName() { return "installd"; }
41 virtual status_t dump(int fd, const Vector<String16> &args) override;
Andreas Gamped089ca12016-06-27 14:25:30 -070042
Jeff Sharkeyc1e93e72016-12-05 23:39:32 -070043 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);
Ben Murdoch872d2af2020-04-15 12:46:23 +010047 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);
Jeff Sharkey0274c972016-12-06 09:32:04 -070053 binder::Status createAppData(const std::unique_ptr<std::string>& uuid,
54 const std::string& packageName, int32_t userId, int32_t flags, int32_t appId,
Jeff Sharkey36a900a2016-12-19 16:39:18 -070055 const std::string& seInfo, int32_t targetSdkVersion, int64_t* _aidl_return);
Jeff Sharkeyc1e93e72016-12-05 23:39:32 -070056 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);
Jeff Sharkeydf2d7542017-01-07 09:19:35 -070065
Jeff Sharkeye12d5962017-04-03 16:41:02 -060066 binder::Status fixupAppData(const std::unique_ptr<std::string>& uuid, int32_t flags);
67
Narayan Kamathe63ca7d2019-01-14 15:21:52 +000068 binder::Status snapshotAppData(const std::unique_ptr<std::string>& volumeUuid,
Nikita Ioffeb68f0d12019-02-04 11:06:37 +000069 const std::string& packageName, const int32_t user, const int32_t snapshotId,
70 int32_t storageFlags, int64_t* _aidl_return);
Narayan Kamathe63ca7d2019-01-14 15:21:52 +000071 binder::Status restoreAppDataSnapshot(const std::unique_ptr<std::string>& volumeUuid,
Nikita Ioffeb68f0d12019-02-04 11:06:37 +000072 const std::string& packageName, const int32_t appId, const std::string& seInfo,
73 const int32_t user, const int32_t snapshotId, int32_t storageFlags);
Nikita Ioffe77be2ed2019-01-25 13:54:43 +000074 binder::Status destroyAppDataSnapshot(const std::unique_ptr<std::string> &volumeUuid,
75 const std::string& packageName, const int32_t user, const int64_t ceSnapshotInode,
Nikita Ioffeb68f0d12019-02-04 11:06:37 +000076 const int32_t snapshotId, int32_t storageFlags);
Oli Lan23839622020-03-16 18:18:41 +000077 binder::Status destroyCeSnapshotsNotSpecified(const std::unique_ptr<std::string> &volumeUuid,
78 const int32_t userId, const std::vector<int32_t>& retainSnapshotIds);
Narayan Kamathe63ca7d2019-01-14 15:21:52 +000079
Jeff Sharkey6c2c0562016-12-07 12:12:00 -070080 binder::Status getAppSize(const std::unique_ptr<std::string>& uuid,
Jeff Sharkeydf2d7542017-01-07 09:19:35 -070081 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,
Jeff Sharkeya084fcd2017-04-17 16:44:41 -060088 int32_t userId, int32_t flags, const std::vector<int32_t>& appIds,
89 std::vector<int64_t>* _aidl_return);
Jeff Sharkeyc1e93e72016-12-05 23:39:32 -070090
Felka Chang2a0a2462019-11-20 14:20:40 +080091 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
Jeff Sharkey88ddd942017-01-17 18:05:54 -0700101 binder::Status setAppQuota(const std::unique_ptr<std::string>& uuid,
102 int32_t userId, int32_t appId, int64_t cacheQuota);
103
Jeff Sharkey0274c972016-12-06 09:32:04 -0700104 binder::Status moveCompleteApp(const std::unique_ptr<std::string>& fromUuid,
105 const std::unique_ptr<std::string>& toUuid, const std::string& packageName,
Songchun Fandc2083f2020-02-18 17:45:46 -0800106 int32_t appId, const std::string& seInfo,
Songchun Fanaed33372020-02-05 12:02:22 -0800107 int32_t targetSdkVersion, const std::string& fromCodePath);
Jeff Sharkey475c6f92016-12-07 10:37:27 -0700108
Jeff Sharkey6c2c0562016-12-07 12:12:00 -0700109 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,
Calin Juravle1d667612017-07-13 22:50:21 -0700113 const std::unique_ptr<std::string>& classLoaderContext,
David Brazdil570d3982018-01-16 20:15:43 +0000114 const std::unique_ptr<std::string>& seInfo, bool downgrade,
Calin Juravlecc3b8ae2018-02-01 17:03:23 +0000115 int32_t targetSdkVersion, const std::unique_ptr<std::string>& profileName,
Calin Juravledcccd832018-02-13 18:31:32 -0800116 const std::unique_ptr<std::string>& dexMetadataPath,
117 const std::unique_ptr<std::string>& compilationReason);
Jeff Sharkey6c2c0562016-12-07 12:12:00 -0700118
Eric Holk0ebbe0f2019-01-09 18:17:27 -0800119 binder::Status compileLayouts(const std::string& apkPath, const std::string& packageName,
120 const std::string& outDexFile, int uid, bool* _aidl_return);
121
Jeff Sharkey475c6f92016-12-07 10:37:27 -0700122 binder::Status rmdex(const std::string& codePath, const std::string& instructionSet);
123
Calin Juravle562de812018-01-20 23:34:18 -0800124 binder::Status mergeProfiles(int32_t uid, const std::string& packageName,
125 const std::string& profileName, bool* _aidl_return);
Jeff Sharkey475c6f92016-12-07 10:37:27 -0700126 binder::Status dumpProfiles(int32_t uid, const std::string& packageName,
Calin Juravle562de812018-01-20 23:34:18 -0800127 const std::string& profileName, const std::string& codePath, bool* _aidl_return);
Mathieu Chartierf966f2a2017-05-10 12:48:37 -0700128 binder::Status copySystemProfile(const std::string& systemProfile,
Calin Juravle562de812018-01-20 23:34:18 -0800129 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);
Jeff Sharkey475c6f92016-12-07 10:37:27 -0700132 binder::Status destroyAppProfiles(const std::string& packageName);
133
Calin Juravlec41dac22017-12-05 12:29:15 -0800134 binder::Status createProfileSnapshot(int32_t appId, const std::string& packageName,
Calin Juravlee61189e2018-01-23 19:54:11 -0800135 const std::string& profileName, const std::string& classpath, bool* _aidl_return);
Calin Juravle29591732017-11-20 17:46:19 -0800136 binder::Status destroyProfileSnapshot(const std::string& packageName,
Calin Juravle562de812018-01-20 23:34:18 -0800137 const std::string& profileName);
Calin Juravle29591732017-11-20 17:46:19 -0800138
Jeff Sharkey475c6f92016-12-07 10:37:27 -0700139 binder::Status rmPackageDir(const std::string& packageDir);
Jeff Sharkey60f8a532017-05-30 14:38:42 -0600140 binder::Status freeCache(const std::unique_ptr<std::string>& uuid, int64_t targetFreeBytes,
141 int64_t cacheReservedBytes, int32_t flags);
Jeff Sharkey6c2c0562016-12-07 12:12:00 -0700142 binder::Status linkNativeLibraryDirectory(const std::unique_ptr<std::string>& uuid,
143 const std::string& packageName, const std::string& nativeLibPath32, int32_t userId);
Jeff Sharkey475c6f92016-12-07 10:37:27 -0700144 binder::Status createOatDir(const std::string& oatDir, const std::string& instructionSet);
Jeff Sharkey6c2c0562016-12-07 12:12:00 -0700145 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,
Andreas Gampec5234092017-05-31 16:39:58 -0700150 const std::unique_ptr<std::string>& outputPath);
Victor Hsieh99de5162017-10-06 14:44:14 -0700151 binder::Status installApkVerity(const std::string& filePath,
Jiyong Park3b25ae12019-11-25 11:06:16 +0900152 android::base::unique_fd verityInput, int32_t contentSize);
Victor Hsiehc6d738a2018-01-20 15:06:39 -0800153 binder::Status assertFsverityRootHashMatches(const std::string& filePath,
154 const std::vector<uint8_t>& expectedHash);
Calin Juravlebd968362017-01-25 01:17:17 -0800155 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);
Alan Stokes753dc712017-10-16 10:56:00 +0100158 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);
Jeff Sharkey7a9059e2017-01-16 19:07:18 -0700161
Jeff Sharkey66b1a122017-01-16 20:57:45 -0700162 binder::Status invalidateMounts();
Jeff Sharkey325b8c92017-02-21 10:00:53 -0700163 binder::Status isQuotaSupported(const std::unique_ptr<std::string>& volumeUuid,
164 bool* _aidl_return);
Ricky Wai2a4983f2020-02-07 14:25:45 +0000165 binder::Status tryMountDataMirror(const std::unique_ptr<std::string>& volumeUuid);
Ricky Waiff9d3ea2019-11-18 18:18:24 +0000166 binder::Status onPrivateVolumeRemoved(const std::unique_ptr<std::string>& volumeUuid);
Jeff Sharkey66b1a122017-01-16 20:57:45 -0700167
Calin Juravlebc5ab872018-01-18 22:32:58 -0800168 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
Narayan Kamath28ab93b2019-05-15 18:29:44 +0100173 binder::Status migrateLegacyObbData();
174
Jeff Sharkey7a9059e2017-01-16 19:07:18 -0700175private:
176 std::recursive_mutex mLock;
Jeff Sharkey66b1a122017-01-16 20:57:45 -0700177
Jeff Sharkeyd712f0c2017-05-03 11:36:42 -0600178 std::recursive_mutex mMountsLock;
179 std::recursive_mutex mQuotasLock;
Jeff Sharkeyb26786d2017-03-11 19:40:29 -0700180
Jeff Sharkeyd712f0c2017-05-03 11:36:42 -0600181 /* Map of all storage mounts from source to target */
182 std::unordered_map<std::string, std::string> mStorageMounts;
Jeff Sharkeyd712f0c2017-05-03 11:36:42 -0600183
Jeff Sharkey88ddd942017-01-17 18:05:54 -0700184 /* Map from UID to cache quota size */
185 std::unordered_map<uid_t, int64_t> mCacheQuotas;
Jeff Sharkey66b1a122017-01-16 20:57:45 -0700186
Jeff Sharkeyd712f0c2017-05-03 11:36:42 -0600187 std::string findDataMediaPath(const std::unique_ptr<std::string>& uuid, userid_t userid);
Jeff Sharkey0274c972016-12-06 09:32:04 -0700188};
189
Andreas Gampe02d0de52015-11-11 20:43:16 -0800190} // namespace installd
191} // namespace android
192
193#endif // COMMANDS_H_