102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe/*
202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe**
302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** Copyright 2008, The Android Open Source Project
402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe**
5f3e30b936ef103dc0f3d8697e0f86ba82b49609eJeff Sharkey** Licensed under the Apache License, Version 2.0 (the "License");
6f3e30b936ef103dc0f3d8697e0f86ba82b49609eJeff Sharkey** you may not use this file except in compliance with the License.
7f3e30b936ef103dc0f3d8697e0f86ba82b49609eJeff Sharkey** You may obtain a copy of the License at
802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe**
9f3e30b936ef103dc0f3d8697e0f86ba82b49609eJeff Sharkey**     http://www.apache.org/licenses/LICENSE-2.0
1002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe**
11f3e30b936ef103dc0f3d8697e0f86ba82b49609eJeff Sharkey** Unless required by applicable law or agreed to in writing, software
12f3e30b936ef103dc0f3d8697e0f86ba82b49609eJeff Sharkey** distributed under the License is distributed on an "AS IS" BASIS,
13f3e30b936ef103dc0f3d8697e0f86ba82b49609eJeff Sharkey** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14f3e30b936ef103dc0f3d8697e0f86ba82b49609eJeff Sharkey** See the License for the specific language governing permissions and
1502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** limitations under the License.
1602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe*/
1702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe
1802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#ifndef COMMANDS_H_
1902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#define COMMANDS_H_
2002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe
2102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#include <inttypes.h>
2202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#include <unistd.h>
2302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe
240274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey#include <vector>
2566b1a12e7a120f85042669bb58f1db864616b506Jeff Sharkey#include <unordered_map>
260274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey
2788ddd94834dae9c5862a07a1e4432b171b2f5d9fJeff Sharkey#include <android-base/macros.h>
280274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey#include <binder/BinderService.h>
2902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#include <cutils/multiuser.h>
3002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe
310274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey#include "android/os/BnInstalld.h"
320274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey#include "installd_constants.h"
3302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe
3402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampenamespace android {
3502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampenamespace installd {
3602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe
370274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkeyclass InstalldNativeService : public BinderService<InstalldNativeService>, public os::BnInstalld {
380274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkeypublic:
390274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey    static status_t start();
400274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey    static char const* getServiceName() { return "installd"; }
410274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey    virtual status_t dump(int fd, const Vector<String16> &args) override;
420274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey
43c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey    binder::Status createUserData(const std::unique_ptr<std::string>& uuid, int32_t userId,
44c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey            int32_t userSerial, int32_t flags);
45c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey    binder::Status destroyUserData(const std::unique_ptr<std::string>& uuid, int32_t userId,
46c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey            int32_t flags);
47c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey
480274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey    binder::Status createAppData(const std::unique_ptr<std::string>& uuid,
490274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey            const std::string& packageName, int32_t userId, int32_t flags, int32_t appId,
5036a900a0db526d63e899ed5d5b0a463ad7f9236eJeff Sharkey            const std::string& seInfo, int32_t targetSdkVersion, int64_t* _aidl_return);
51c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey    binder::Status restoreconAppData(const std::unique_ptr<std::string>& uuid,
52c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey            const std::string& packageName, int32_t userId, int32_t flags, int32_t appId,
53c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey            const std::string& seInfo);
54c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey    binder::Status migrateAppData(const std::unique_ptr<std::string>& uuid,
55c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey            const std::string& packageName, int32_t userId, int32_t flags);
56c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey    binder::Status clearAppData(const std::unique_ptr<std::string>& uuid,
57c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey            const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode);
58c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey    binder::Status destroyAppData(const std::unique_ptr<std::string>& uuid,
59c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey            const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode);
60df2d754b38796e0c49c70e0a67f7d383e3079ff2Jeff Sharkey
61e12d5964a8d14abe7f2eb6e57469cbe7f7391a19Jeff Sharkey    binder::Status fixupAppData(const std::unique_ptr<std::string>& uuid, int32_t flags);
62e12d5964a8d14abe7f2eb6e57469cbe7f7391a19Jeff Sharkey
636c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey    binder::Status getAppSize(const std::unique_ptr<std::string>& uuid,
64df2d754b38796e0c49c70e0a67f7d383e3079ff2Jeff Sharkey            const std::vector<std::string>& packageNames, int32_t userId, int32_t flags,
65df2d754b38796e0c49c70e0a67f7d383e3079ff2Jeff Sharkey            int32_t appId, const std::vector<int64_t>& ceDataInodes,
66df2d754b38796e0c49c70e0a67f7d383e3079ff2Jeff Sharkey            const std::vector<std::string>& codePaths, std::vector<int64_t>* _aidl_return);
67df2d754b38796e0c49c70e0a67f7d383e3079ff2Jeff Sharkey    binder::Status getUserSize(const std::unique_ptr<std::string>& uuid,
68df2d754b38796e0c49c70e0a67f7d383e3079ff2Jeff Sharkey            int32_t userId, int32_t flags, const std::vector<int32_t>& appIds,
69df2d754b38796e0c49c70e0a67f7d383e3079ff2Jeff Sharkey            std::vector<int64_t>* _aidl_return);
70df2d754b38796e0c49c70e0a67f7d383e3079ff2Jeff Sharkey    binder::Status getExternalSize(const std::unique_ptr<std::string>& uuid,
71a084fcdcd052d71e8205a2eea0955911b99160b9Jeff Sharkey            int32_t userId, int32_t flags, const std::vector<int32_t>& appIds,
72a084fcdcd052d71e8205a2eea0955911b99160b9Jeff Sharkey            std::vector<int64_t>* _aidl_return);
73c1e93e7d746e07791b0667c80ad43a407c515fa8Jeff Sharkey
7488ddd94834dae9c5862a07a1e4432b171b2f5d9fJeff Sharkey    binder::Status setAppQuota(const std::unique_ptr<std::string>& uuid,
7588ddd94834dae9c5862a07a1e4432b171b2f5d9fJeff Sharkey            int32_t userId, int32_t appId, int64_t cacheQuota);
7688ddd94834dae9c5862a07a1e4432b171b2f5d9fJeff Sharkey
770274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey    binder::Status moveCompleteApp(const std::unique_ptr<std::string>& fromUuid,
780274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey            const std::unique_ptr<std::string>& toUuid, const std::string& packageName,
790274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey            const std::string& dataAppName, int32_t appId, const std::string& seInfo,
800274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey            int32_t targetSdkVersion);
81475c6f9743e5f6696c38fb22b8b8e9d49a82ab56Jeff Sharkey
826c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey    binder::Status dexopt(const std::string& apkPath, int32_t uid,
836c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey            const std::unique_ptr<std::string>& packageName, const std::string& instructionSet,
846c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey            int32_t dexoptNeeded, const std::unique_ptr<std::string>& outputPath, int32_t dexFlags,
856c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey            const std::string& compilerFilter, const std::unique_ptr<std::string>& uuid,
861d66761379b54ff71094a7c722f131c591f3f897Calin Juravle            const std::unique_ptr<std::string>& classLoaderContext,
87570d398770a12613461408b767ae97b549393157David Brazdil            const std::unique_ptr<std::string>& seInfo, bool downgrade,
88cc3b8aeff19f39afb8d4f2c198ee6cd2ec132d22Calin Juravle            int32_t targetSdkVersion, const std::unique_ptr<std::string>& profileName,
89dcccd832b4a3df77bac551a118b2a35fd6f65d9bCalin Juravle            const std::unique_ptr<std::string>& dexMetadataPath,
90dcccd832b4a3df77bac551a118b2a35fd6f65d9bCalin Juravle            const std::unique_ptr<std::string>& compilationReason);
916c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey
92475c6f9743e5f6696c38fb22b8b8e9d49a82ab56Jeff Sharkey    binder::Status rmdex(const std::string& codePath, const std::string& instructionSet);
93475c6f9743e5f6696c38fb22b8b8e9d49a82ab56Jeff Sharkey
94562de815339bedd29206f5f98be44c824945b627Calin Juravle    binder::Status mergeProfiles(int32_t uid, const std::string& packageName,
95562de815339bedd29206f5f98be44c824945b627Calin Juravle            const std::string& profileName, bool* _aidl_return);
96475c6f9743e5f6696c38fb22b8b8e9d49a82ab56Jeff Sharkey    binder::Status dumpProfiles(int32_t uid, const std::string& packageName,
97562de815339bedd29206f5f98be44c824945b627Calin Juravle            const std::string& profileName, const std::string& codePath, bool* _aidl_return);
98f966f2a5af6cc2022a5af4edeb20cf4b5ede0d40Mathieu Chartier    binder::Status copySystemProfile(const std::string& systemProfile,
99562de815339bedd29206f5f98be44c824945b627Calin Juravle            int32_t uid, const std::string& packageName, const std::string& profileName,
100562de815339bedd29206f5f98be44c824945b627Calin Juravle            bool* _aidl_return);
101562de815339bedd29206f5f98be44c824945b627Calin Juravle    binder::Status clearAppProfiles(const std::string& packageName, const std::string& profileName);
102475c6f9743e5f6696c38fb22b8b8e9d49a82ab56Jeff Sharkey    binder::Status destroyAppProfiles(const std::string& packageName);
103475c6f9743e5f6696c38fb22b8b8e9d49a82ab56Jeff Sharkey
104c41dac27c540971d8877911d6a3908af2046c9ebCalin Juravle    binder::Status createProfileSnapshot(int32_t appId, const std::string& packageName,
105e61189e0ad2104360a188d36210bd1ee43803a64Calin Juravle            const std::string& profileName, const std::string& classpath, bool* _aidl_return);
10629591736958a7ed45f4b5982ca9a46756baa0f6dCalin Juravle    binder::Status destroyProfileSnapshot(const std::string& packageName,
107562de815339bedd29206f5f98be44c824945b627Calin Juravle            const std::string& profileName);
10829591736958a7ed45f4b5982ca9a46756baa0f6dCalin Juravle
1096c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey    binder::Status idmap(const std::string& targetApkPath, const std::string& overlayApkPath,
1106c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey            int32_t uid);
1115c6944c35211accd783d2584fac6421dd0af5bddMÃ¥rten Kongstad    binder::Status removeIdmap(const std::string& overlayApkPath);
112475c6f9743e5f6696c38fb22b8b8e9d49a82ab56Jeff Sharkey    binder::Status rmPackageDir(const std::string& packageDir);
113475c6f9743e5f6696c38fb22b8b8e9d49a82ab56Jeff Sharkey    binder::Status markBootComplete(const std::string& instructionSet);
11460f8a5330ca921d936ae306bf6d17596b82b518cJeff Sharkey    binder::Status freeCache(const std::unique_ptr<std::string>& uuid, int64_t targetFreeBytes,
11560f8a5330ca921d936ae306bf6d17596b82b518cJeff Sharkey            int64_t cacheReservedBytes, int32_t flags);
1166c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey    binder::Status linkNativeLibraryDirectory(const std::unique_ptr<std::string>& uuid,
1176c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey            const std::string& packageName, const std::string& nativeLibPath32, int32_t userId);
118475c6f9743e5f6696c38fb22b8b8e9d49a82ab56Jeff Sharkey    binder::Status createOatDir(const std::string& oatDir, const std::string& instructionSet);
1196c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey    binder::Status linkFile(const std::string& relativePath, const std::string& fromBase,
1206c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey            const std::string& toBase);
1216c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey    binder::Status moveAb(const std::string& apkPath, const std::string& instructionSet,
1226c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey            const std::string& outputPath);
1236c2c056193010cf93b4264810d462c120ce801c8Jeff Sharkey    binder::Status deleteOdex(const std::string& apkPath, const std::string& instructionSet,
124c523409f0fd03aa498cedc486f85e9a4b7257f3aAndreas Gampe            const std::unique_ptr<std::string>& outputPath);
12599de51619db9d23a1019354276c1385d63aa05dcVictor Hsieh    binder::Status installApkVerity(const std::string& filePath,
12618ac0279c2ea52c72a539cae340502ca0dddcbc4Victor Hsieh            const ::android::base::unique_fd& verityInput, int32_t contentSize);
127c6d738a320a612454e6c7588affcfb1f8886dd8cVictor Hsieh    binder::Status assertFsverityRootHashMatches(const std::string& filePath,
128c6d738a320a612454e6c7588affcfb1f8886dd8cVictor Hsieh            const std::vector<uint8_t>& expectedHash);
129bd9683607d391a29b1422a50f8972267e9bddc47Calin Juravle    binder::Status reconcileSecondaryDexFile(const std::string& dexPath,
130bd9683607d391a29b1422a50f8972267e9bddc47Calin Juravle        const std::string& packageName, int32_t uid, const std::vector<std::string>& isa,
131bd9683607d391a29b1422a50f8972267e9bddc47Calin Juravle        const std::unique_ptr<std::string>& volumeUuid, int32_t storage_flag, bool* _aidl_return);
132753dc71734927f86c277991be9326cb9a82202b1Alan Stokes    binder::Status hashSecondaryDexFile(const std::string& dexPath,
133753dc71734927f86c277991be9326cb9a82202b1Alan Stokes        const std::string& packageName, int32_t uid, const std::unique_ptr<std::string>& volumeUuid,
134753dc71734927f86c277991be9326cb9a82202b1Alan Stokes        int32_t storageFlag, std::vector<uint8_t>* _aidl_return);
1357a9059e8ed297a8e025c843b632c7c8571682b46Jeff Sharkey
13666b1a12e7a120f85042669bb58f1db864616b506Jeff Sharkey    binder::Status invalidateMounts();
137325b8c94a5ae47b7903ea5fe386a78466d6cb3b7Jeff Sharkey    binder::Status isQuotaSupported(const std::unique_ptr<std::string>& volumeUuid,
138325b8c94a5ae47b7903ea5fe386a78466d6cb3b7Jeff Sharkey            bool* _aidl_return);
13966b1a12e7a120f85042669bb58f1db864616b506Jeff Sharkey
140bc5ab878b56bcd3a300cc5fc0facc864421dfcb6Calin Juravle    binder::Status prepareAppProfile(const std::string& packageName,
141bc5ab878b56bcd3a300cc5fc0facc864421dfcb6Calin Juravle            int32_t userId, int32_t appId, const std::string& profileName,
142bc5ab878b56bcd3a300cc5fc0facc864421dfcb6Calin Juravle            const std::string& codePath, const std::unique_ptr<std::string>& dexMetadata,
143bc5ab878b56bcd3a300cc5fc0facc864421dfcb6Calin Juravle            bool* _aidl_return);
144bc5ab878b56bcd3a300cc5fc0facc864421dfcb6Calin Juravle
1457a9059e8ed297a8e025c843b632c7c8571682b46Jeff Sharkeyprivate:
1467a9059e8ed297a8e025c843b632c7c8571682b46Jeff Sharkey    std::recursive_mutex mLock;
14766b1a12e7a120f85042669bb58f1db864616b506Jeff Sharkey
148d712f0ccc120357e1267a04ac6de9dd732b27e76Jeff Sharkey    std::recursive_mutex mMountsLock;
149d712f0ccc120357e1267a04ac6de9dd732b27e76Jeff Sharkey    std::recursive_mutex mQuotasLock;
150d712f0ccc120357e1267a04ac6de9dd732b27e76Jeff Sharkey
151d712f0ccc120357e1267a04ac6de9dd732b27e76Jeff Sharkey    /* Map of all storage mounts from source to target */
152d712f0ccc120357e1267a04ac6de9dd732b27e76Jeff Sharkey    std::unordered_map<std::string, std::string> mStorageMounts;
153d712f0ccc120357e1267a04ac6de9dd732b27e76Jeff Sharkey    /* Map of all quota mounts from target to source */
154d712f0ccc120357e1267a04ac6de9dd732b27e76Jeff Sharkey    std::unordered_map<std::string, std::string> mQuotaReverseMounts;
155b26786d647b624498c11405075e5223d1853f30aJeff Sharkey
15688ddd94834dae9c5862a07a1e4432b171b2f5d9fJeff Sharkey    /* Map from UID to cache quota size */
15788ddd94834dae9c5862a07a1e4432b171b2f5d9fJeff Sharkey    std::unordered_map<uid_t, int64_t> mCacheQuotas;
15866b1a12e7a120f85042669bb58f1db864616b506Jeff Sharkey
159d712f0ccc120357e1267a04ac6de9dd732b27e76Jeff Sharkey    std::string findDataMediaPath(const std::unique_ptr<std::string>& uuid, userid_t userid);
16066b1a12e7a120f85042669bb58f1db864616b506Jeff Sharkey    std::string findQuotaDeviceForUuid(const std::unique_ptr<std::string>& uuid);
1610274c977e3b10b52936fd5b2eb464857f0ca6358Jeff Sharkey};
162d089ca1703769854356a263ca640d3e07ab8548dAndreas Gampe
16302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe}  // namespace installd
16402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe}  // namespace android
16502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe
16602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#endif  // COMMANDS_H_
167