Martijn Coenen | e6f6b8f | 2018-08-17 09:48:33 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 17 | #include "apexservice.h" |
| 18 | |
Dario Freni | 8e88b68 | 2018-10-25 13:06:21 +0100 | [diff] [blame] | 19 | #include <dirent.h> |
Dario Freni | 6ed6332 | 2018-10-03 11:37:08 +0100 | [diff] [blame] | 20 | #include <stdio.h> |
Dario Freni | 8e88b68 | 2018-10-25 13:06:21 +0100 | [diff] [blame] | 21 | #include <stdlib.h> |
Dario Freni | 6ed6332 | 2018-10-03 11:37:08 +0100 | [diff] [blame] | 22 | |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 23 | #include <android-base/file.h> |
| 24 | #include <android-base/logging.h> |
Andreas Gampe | 8eb187a | 2018-10-19 21:18:03 -0700 | [diff] [blame] | 25 | #include <android-base/properties.h> |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 26 | #include <android-base/result.h> |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 27 | #include <android-base/stringprintf.h> |
Dario Freni | 8e88b68 | 2018-10-25 13:06:21 +0100 | [diff] [blame] | 28 | #include <android-base/strings.h> |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 29 | #include <binder/IPCThreadState.h> |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 30 | #include <binder/IResultReceiver.h> |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 31 | #include <binder/IServiceManager.h> |
Jon Spivack | 1b84030 | 2020-02-06 18:34:30 -0800 | [diff] [blame] | 32 | #include <binder/LazyServiceRegistrar.h> |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 33 | #include <binder/ProcessState.h> |
Andreas Gampe | 1773914 | 2019-01-09 16:00:26 -0800 | [diff] [blame] | 34 | #include <binder/Status.h> |
Nikita Ioffe | 78d2bce | 2020-05-02 01:28:30 +0100 | [diff] [blame] | 35 | #include <private/android_filesystem_config.h> |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 36 | #include <utils/String16.h> |
Dario Freni | 6ed6332 | 2018-10-03 11:37:08 +0100 | [diff] [blame] | 37 | |
Nikita Ioffe | d49bcd1 | 2019-08-30 11:56:52 +0100 | [diff] [blame] | 38 | #include "apex_file.h" |
Dario Freni | 9d57624 | 2019-10-13 10:09:32 +0100 | [diff] [blame] | 39 | #include "apex_preinstalled_data.h" |
Andreas Gampe | b99abdd | 2018-10-19 19:59:17 -0700 | [diff] [blame] | 40 | #include "apexd.h" |
Dario Freni | d243764 | 2019-01-11 14:35:23 +0000 | [diff] [blame] | 41 | #include "apexd_session.h" |
Jiyong Park | 9b80048 | 2018-12-03 22:16:40 +0900 | [diff] [blame] | 42 | #include "string_log.h" |
Dario Freni | 6ed6332 | 2018-10-03 11:37:08 +0100 | [diff] [blame] | 43 | |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 44 | #include <android/apex/BnApexService.h> |
| 45 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 46 | using android::base::Result; |
| 47 | |
Martijn Coenen | e6f6b8f | 2018-08-17 09:48:33 +0200 | [diff] [blame] | 48 | namespace android { |
| 49 | namespace apex { |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 50 | namespace binder { |
| 51 | namespace { |
Martijn Coenen | e6f6b8f | 2018-08-17 09:48:33 +0200 | [diff] [blame] | 52 | |
Andreas Gampe | c9a01e4 | 2018-10-22 12:50:19 -0700 | [diff] [blame] | 53 | using BinderStatus = ::android::binder::Status; |
| 54 | |
Nikita Ioffe | 78d2bce | 2020-05-02 01:28:30 +0100 | [diff] [blame] | 55 | BinderStatus CheckCallerIsRoot(const std::string& name) { |
| 56 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 57 | if (uid != AID_ROOT) { |
| 58 | std::string msg = "Only root is allowed to call " + name; |
| 59 | return BinderStatus::fromExceptionCode(BinderStatus::EX_SECURITY, |
| 60 | String8(name.c_str())); |
| 61 | } |
| 62 | return BinderStatus::ok(); |
| 63 | } |
| 64 | |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 65 | class ApexService : public BnApexService { |
| 66 | public: |
| 67 | using BinderStatus = ::android::binder::Status; |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 68 | using SessionState = ::apex::proto::SessionState; |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 69 | |
| 70 | ApexService(){}; |
| 71 | |
Nikita Ioffe | d90eda0 | 2019-07-11 17:56:01 +0100 | [diff] [blame] | 72 | BinderStatus stagePackages(const std::vector<std::string>& paths) override; |
Nikita Ioffe | 496a4a4 | 2019-03-05 16:32:51 +0000 | [diff] [blame] | 73 | BinderStatus unstagePackages(const std::vector<std::string>& paths) override; |
Oli Lan | 123d9d0 | 2019-12-02 14:08:24 +0000 | [diff] [blame] | 74 | BinderStatus submitStagedSession(const ApexSessionParams& params, |
Nikita Ioffe | 7efdbd7 | 2019-07-05 15:46:38 +0100 | [diff] [blame] | 75 | ApexInfoList* apex_info_list) override; |
Nikita Ioffe | 0c1d4b1 | 2019-07-09 20:48:17 +0100 | [diff] [blame] | 76 | BinderStatus markStagedSessionReady(int session_id) override; |
Nikita Ioffe | a0c0ccb | 2019-02-12 22:00:41 +0000 | [diff] [blame] | 77 | BinderStatus markStagedSessionSuccessful(int session_id) override; |
Martijn Coenen | 4d20642 | 2019-01-31 15:58:55 +0100 | [diff] [blame] | 78 | BinderStatus getSessions(std::vector<ApexSessionInfo>* aidl_return) override; |
Dario Freni | d243764 | 2019-01-11 14:35:23 +0000 | [diff] [blame] | 79 | BinderStatus getStagedSessionInfo( |
| 80 | int session_id, ApexSessionInfo* apex_session_info) override; |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 81 | BinderStatus activatePackage(const std::string& packagePath) override; |
| 82 | BinderStatus deactivatePackage(const std::string& packagePath) override; |
Dario Freni | dded6c1 | 2018-11-19 16:02:26 +0000 | [diff] [blame] | 83 | BinderStatus getActivePackages(std::vector<ApexInfo>* aidl_return) override; |
Narayan Kamath | 5ea5778 | 2019-01-03 18:17:05 +0000 | [diff] [blame] | 84 | BinderStatus getActivePackage(const std::string& packageName, |
| 85 | ApexInfo* aidl_return) override; |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 86 | BinderStatus getAllPackages(std::vector<ApexInfo>* aidl_return) override; |
Andreas Gampe | 1773914 | 2019-01-09 16:00:26 -0800 | [diff] [blame] | 87 | BinderStatus preinstallPackages( |
| 88 | const std::vector<std::string>& paths) override; |
Andreas Gampe | f4c7e7c | 2019-01-14 12:33:34 -0800 | [diff] [blame] | 89 | BinderStatus postinstallPackages( |
| 90 | const std::vector<std::string>& paths) override; |
Mohammad Samiul Islam | 4654f77 | 2019-11-20 15:19:07 +0000 | [diff] [blame] | 91 | BinderStatus abortStagedSession(int session_id) override; |
Mohammad Samiul Islam | 2401ae1 | 2019-11-20 17:12:31 +0000 | [diff] [blame] | 92 | BinderStatus revertActiveSessions() override; |
Mohammad Samiul Islam | ca852e3 | 2019-11-20 13:37:14 +0000 | [diff] [blame] | 93 | BinderStatus resumeRevertIfNeeded() override; |
Oli Lan | 2d59dfa | 2020-01-14 20:25:09 +0000 | [diff] [blame] | 94 | BinderStatus snapshotCeData(int user_id, int rollback_id, |
| 95 | const std::string& apex_name, |
| 96 | int64_t* _aidl_return) override; |
| 97 | BinderStatus restoreCeData(int user_id, int rollback_id, |
| 98 | const std::string& apex_name) override; |
Oli Lan | 042fbcf | 2020-01-17 11:14:16 +0000 | [diff] [blame] | 99 | BinderStatus destroyDeSnapshots(int rollback_id) override; |
Oli Lan | 2993ccc | 2020-03-06 18:06:40 +0000 | [diff] [blame] | 100 | BinderStatus destroyCeSnapshotsNotSpecified( |
| 101 | int user_id, const std::vector<int>& retain_rollback_ids) override; |
Nikita Ioffe | 78d2bce | 2020-05-02 01:28:30 +0100 | [diff] [blame] | 102 | BinderStatus remountPackages() override; |
Andreas Gampe | 1773914 | 2019-01-09 16:00:26 -0800 | [diff] [blame] | 103 | |
Abhijeet Kaur | 54695d3 | 2019-01-15 13:07:20 +0000 | [diff] [blame] | 104 | status_t dump(int fd, const Vector<String16>& args) override; |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 105 | |
| 106 | // Override onTransact so we can handle shellCommand. |
| 107 | status_t onTransact(uint32_t _aidl_code, const Parcel& _aidl_data, |
Nikita Ioffe | 6bea4e5 | 2019-02-10 22:46:05 +0000 | [diff] [blame] | 108 | Parcel* _aidl_reply, uint32_t _aidl_flags) override; |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 109 | |
| 110 | status_t shellCommand(int in, int out, int err, const Vector<String16>& args); |
| 111 | }; |
Andreas Gampe | 8eb187a | 2018-10-19 21:18:03 -0700 | [diff] [blame] | 112 | |
Andreas Gampe | d6c3df8 | 2018-11-08 15:34:06 -0800 | [diff] [blame] | 113 | BinderStatus CheckDebuggable(const std::string& name) { |
Andreas Gampe | 8eb187a | 2018-10-19 21:18:03 -0700 | [diff] [blame] | 114 | if (!::android::base::GetBoolProperty("ro.debuggable", false)) { |
Andreas Gampe | d6c3df8 | 2018-11-08 15:34:06 -0800 | [diff] [blame] | 115 | std::string tmp = name + " unavailable"; |
| 116 | return BinderStatus::fromExceptionCode(BinderStatus::EX_SECURITY, |
| 117 | String8(tmp.c_str())); |
Andreas Gampe | 8eb187a | 2018-10-19 21:18:03 -0700 | [diff] [blame] | 118 | } |
| 119 | return BinderStatus::ok(); |
| 120 | } |
| 121 | |
Nikita Ioffe | d90eda0 | 2019-07-11 17:56:01 +0100 | [diff] [blame] | 122 | BinderStatus ApexService::stagePackages(const std::vector<std::string>& paths) { |
Nikita Ioffe | 6930988 | 2019-02-13 01:31:15 +0000 | [diff] [blame] | 123 | BinderStatus debugCheck = CheckDebuggable("stagePackages"); |
| 124 | if (!debugCheck.isOk()) { |
| 125 | return debugCheck; |
| 126 | } |
Andreas Gampe | a00c545 | 2018-12-10 13:38:33 -0800 | [diff] [blame] | 127 | LOG(DEBUG) << "stagePackages() received by ApexService, paths " |
| 128 | << android::base::Join(paths, ','); |
Dario Freni | 6ed6332 | 2018-10-03 11:37:08 +0100 | [diff] [blame] | 129 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 130 | Result<void> res = ::android::apex::stagePackages(paths); |
Dario Freni | 6ed6332 | 2018-10-03 11:37:08 +0100 | [diff] [blame] | 131 | |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 132 | if (res.ok()) { |
Andreas Gampe | c9a01e4 | 2018-10-22 12:50:19 -0700 | [diff] [blame] | 133 | return BinderStatus::ok(); |
Dario Freni | 6ed6332 | 2018-10-03 11:37:08 +0100 | [diff] [blame] | 134 | } |
Dario Freni | 6ed6332 | 2018-10-03 11:37:08 +0100 | [diff] [blame] | 135 | |
Andreas Gampe | b99abdd | 2018-10-19 19:59:17 -0700 | [diff] [blame] | 136 | // TODO: Get correct binder error status. |
Andreas Gampe | a00c545 | 2018-12-10 13:38:33 -0800 | [diff] [blame] | 137 | LOG(ERROR) << "Failed to stage " << android::base::Join(paths, ',') << ": " |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 138 | << res.error(); |
| 139 | return BinderStatus::fromExceptionCode( |
| 140 | BinderStatus::EX_ILLEGAL_ARGUMENT, |
| 141 | String8(res.error().message().c_str())); |
Martijn Coenen | e6f6b8f | 2018-08-17 09:48:33 +0200 | [diff] [blame] | 142 | } |
| 143 | |
Nikita Ioffe | 496a4a4 | 2019-03-05 16:32:51 +0000 | [diff] [blame] | 144 | BinderStatus ApexService::unstagePackages( |
| 145 | const std::vector<std::string>& paths) { |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 146 | Result<void> res = ::android::apex::unstagePackages(paths); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 147 | if (res.ok()) { |
Nikita Ioffe | 496a4a4 | 2019-03-05 16:32:51 +0000 | [diff] [blame] | 148 | return BinderStatus::ok(); |
| 149 | } |
| 150 | |
| 151 | // TODO: Get correct binder error status. |
| 152 | LOG(ERROR) << "Failed to unstage " << android::base::Join(paths, ',') << ": " |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 153 | << res.error(); |
| 154 | return BinderStatus::fromExceptionCode( |
| 155 | BinderStatus::EX_ILLEGAL_ARGUMENT, |
| 156 | String8(res.error().message().c_str())); |
Nikita Ioffe | 496a4a4 | 2019-03-05 16:32:51 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Oli Lan | 123d9d0 | 2019-12-02 14:08:24 +0000 | [diff] [blame] | 159 | BinderStatus ApexService::submitStagedSession(const ApexSessionParams& params, |
| 160 | ApexInfoList* apex_info_list) { |
Dario Freni | 56231b4 | 2019-01-04 11:58:17 +0000 | [diff] [blame] | 161 | LOG(DEBUG) << "submitStagedSession() received by ApexService, session id " |
Oli Lan | 123d9d0 | 2019-12-02 14:08:24 +0000 | [diff] [blame] | 162 | << params.sessionId << " child sessions: [" |
| 163 | << android::base::Join(params.childSessionIds, ',') << "]"; |
Dario Freni | 56231b4 | 2019-01-04 11:58:17 +0000 | [diff] [blame] | 164 | |
Oli Lan | 123d9d0 | 2019-12-02 14:08:24 +0000 | [diff] [blame] | 165 | Result<std::vector<ApexFile>> packages = ::android::apex::submitStagedSession( |
| 166 | params.sessionId, params.childSessionIds, params.hasRollbackEnabled, |
| 167 | params.isRollback, params.rollbackId); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 168 | if (!packages.ok()) { |
Oli Lan | 123d9d0 | 2019-12-02 14:08:24 +0000 | [diff] [blame] | 169 | LOG(ERROR) << "Failed to submit session id " << params.sessionId << ": " |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 170 | << packages.error(); |
Nikita Ioffe | 7efdbd7 | 2019-07-05 15:46:38 +0100 | [diff] [blame] | 171 | return BinderStatus::fromExceptionCode( |
| 172 | BinderStatus::EX_SERVICE_SPECIFIC, |
| 173 | String8(packages.error().message().c_str())); |
Dario Freni | 56231b4 | 2019-01-04 11:58:17 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | for (const auto& package : *packages) { |
| 177 | ApexInfo out; |
Nikita Ioffe | 2cb7f8f | 2019-06-28 15:42:51 +0100 | [diff] [blame] | 178 | out.moduleName = package.GetManifest().name(); |
| 179 | out.modulePath = package.GetPath(); |
Abhijeet Kaur | 216e36c | 2019-01-04 10:15:01 +0000 | [diff] [blame] | 180 | out.versionCode = package.GetManifest().version(); |
Dario Freni | a6ad33e | 2019-01-09 14:35:43 +0000 | [diff] [blame] | 181 | apex_info_list->apexInfos.push_back(out); |
Dario Freni | 56231b4 | 2019-01-04 11:58:17 +0000 | [diff] [blame] | 182 | } |
| 183 | return BinderStatus::ok(); |
| 184 | } |
| 185 | |
Nikita Ioffe | 0c1d4b1 | 2019-07-09 20:48:17 +0100 | [diff] [blame] | 186 | BinderStatus ApexService::markStagedSessionReady(int session_id) { |
Dario Freni | f36c962 | 2019-01-25 11:30:00 +0000 | [diff] [blame] | 187 | LOG(DEBUG) << "markStagedSessionReady() received by ApexService, session id " |
| 188 | << session_id; |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 189 | Result<void> success = ::android::apex::markStagedSessionReady(session_id); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 190 | if (!success.ok()) { |
Dario Freni | f36c962 | 2019-01-25 11:30:00 +0000 | [diff] [blame] | 191 | LOG(ERROR) << "Failed to mark session id " << session_id |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 192 | << " as ready: " << success.error(); |
Nikita Ioffe | 0c1d4b1 | 2019-07-09 20:48:17 +0100 | [diff] [blame] | 193 | return BinderStatus::fromExceptionCode( |
| 194 | BinderStatus::EX_SERVICE_SPECIFIC, |
| 195 | String8(success.error().message().c_str())); |
Dario Freni | f36c962 | 2019-01-25 11:30:00 +0000 | [diff] [blame] | 196 | } |
Dario Freni | f36c962 | 2019-01-25 11:30:00 +0000 | [diff] [blame] | 197 | return BinderStatus::ok(); |
| 198 | } |
| 199 | |
Nikita Ioffe | a0c0ccb | 2019-02-12 22:00:41 +0000 | [diff] [blame] | 200 | BinderStatus ApexService::markStagedSessionSuccessful(int session_id) { |
| 201 | LOG(DEBUG) |
| 202 | << "markStagedSessionSuccessful() received by ApexService, session id " |
| 203 | << session_id; |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 204 | Result<void> ret = ::android::apex::markStagedSessionSuccessful(session_id); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 205 | if (!ret.ok()) { |
Nikita Ioffe | a0c0ccb | 2019-02-12 22:00:41 +0000 | [diff] [blame] | 206 | LOG(ERROR) << "Failed to mark session " << session_id |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 207 | << " as SUCCESS: " << ret.error(); |
| 208 | return BinderStatus::fromExceptionCode( |
| 209 | BinderStatus::EX_ILLEGAL_ARGUMENT, |
| 210 | String8(ret.error().message().c_str())); |
Nikita Ioffe | a0c0ccb | 2019-02-12 22:00:41 +0000 | [diff] [blame] | 211 | } |
| 212 | return BinderStatus::ok(); |
| 213 | } |
| 214 | |
Nikita Ioffe | 9ae986a | 2019-02-18 22:39:27 +0000 | [diff] [blame] | 215 | static void ClearSessionInfo(ApexSessionInfo* session_info) { |
| 216 | session_info->sessionId = -1; |
Martijn Coenen | 4d20642 | 2019-01-31 15:58:55 +0100 | [diff] [blame] | 217 | session_info->isUnknown = false; |
| 218 | session_info->isVerified = false; |
| 219 | session_info->isStaged = false; |
| 220 | session_info->isActivated = false; |
Mohammad Samiul Islam | ca852e3 | 2019-11-20 13:37:14 +0000 | [diff] [blame] | 221 | session_info->isRevertInProgress = false; |
Martijn Coenen | 4d20642 | 2019-01-31 15:58:55 +0100 | [diff] [blame] | 222 | session_info->isActivationFailed = false; |
Nikita Ioffe | a0c0ccb | 2019-02-12 22:00:41 +0000 | [diff] [blame] | 223 | session_info->isSuccess = false; |
Mohammad Samiul Islam | ca852e3 | 2019-11-20 13:37:14 +0000 | [diff] [blame] | 224 | session_info->isReverted = false; |
| 225 | session_info->isRevertFailed = false; |
Nikita Ioffe | 9ae986a | 2019-02-18 22:39:27 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | void convertToApexSessionInfo(const ApexSession& session, |
| 229 | ApexSessionInfo* session_info) { |
| 230 | using SessionState = ::apex::proto::SessionState; |
| 231 | |
| 232 | ClearSessionInfo(session_info); |
| 233 | session_info->sessionId = session.GetId(); |
Gavin Corkery | 879fe9b | 2020-01-29 19:13:50 +0000 | [diff] [blame] | 234 | session_info->crashingNativeProcess = session.GetCrashingNativeProcess(); |
Martijn Coenen | 4d20642 | 2019-01-31 15:58:55 +0100 | [diff] [blame] | 235 | |
| 236 | switch (session.GetState()) { |
| 237 | case SessionState::VERIFIED: |
| 238 | session_info->isVerified = true; |
| 239 | break; |
| 240 | case SessionState::STAGED: |
| 241 | session_info->isStaged = true; |
| 242 | break; |
| 243 | case SessionState::ACTIVATED: |
| 244 | session_info->isActivated = true; |
| 245 | break; |
Martijn Coenen | 4d20642 | 2019-01-31 15:58:55 +0100 | [diff] [blame] | 246 | case SessionState::ACTIVATION_FAILED: |
| 247 | session_info->isActivationFailed = true; |
| 248 | break; |
Nikita Ioffe | a0c0ccb | 2019-02-12 22:00:41 +0000 | [diff] [blame] | 249 | case SessionState::SUCCESS: |
| 250 | session_info->isSuccess = true; |
| 251 | break; |
Mohammad Samiul Islam | ca852e3 | 2019-11-20 13:37:14 +0000 | [diff] [blame] | 252 | case SessionState::REVERT_IN_PROGRESS: |
| 253 | session_info->isRevertInProgress = true; |
Nikita Ioffe | 9ae986a | 2019-02-18 22:39:27 +0000 | [diff] [blame] | 254 | break; |
Mohammad Samiul Islam | ca852e3 | 2019-11-20 13:37:14 +0000 | [diff] [blame] | 255 | case SessionState::REVERTED: |
| 256 | session_info->isReverted = true; |
Nikita Ioffe | 9ae986a | 2019-02-18 22:39:27 +0000 | [diff] [blame] | 257 | break; |
Mohammad Samiul Islam | ca852e3 | 2019-11-20 13:37:14 +0000 | [diff] [blame] | 258 | case SessionState::REVERT_FAILED: |
| 259 | session_info->isRevertFailed = true; |
Nikita Ioffe | 54f1844 | 2019-04-09 13:09:26 +0100 | [diff] [blame] | 260 | break; |
Martijn Coenen | 4d20642 | 2019-01-31 15:58:55 +0100 | [diff] [blame] | 261 | case SessionState::UNKNOWN: |
| 262 | default: |
| 263 | session_info->isUnknown = true; |
| 264 | break; |
| 265 | } |
| 266 | } |
| 267 | |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 268 | static ApexInfo getApexInfo(const ApexFile& package) { |
| 269 | ApexInfo out; |
Nikita Ioffe | 2cb7f8f | 2019-06-28 15:42:51 +0100 | [diff] [blame] | 270 | out.moduleName = package.GetManifest().name(); |
| 271 | out.modulePath = package.GetPath(); |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 272 | out.versionCode = package.GetManifest().version(); |
Gavin Corkery | 9463856 | 2019-04-30 10:40:12 +0100 | [diff] [blame] | 273 | out.versionName = package.GetManifest().versionname(); |
Nikita Ioffe | d49bcd1 | 2019-08-30 11:56:52 +0100 | [diff] [blame] | 274 | out.isFactory = package.IsBuiltin(); |
| 275 | out.isActive = false; |
Dario Freni | 9d57624 | 2019-10-13 10:09:32 +0100 | [diff] [blame] | 276 | Result<std::string> preinstalledPath = |
| 277 | getApexPreinstalledPath(package.GetManifest().name()); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 278 | if (preinstalledPath.ok()) { |
Dario Freni | 9d57624 | 2019-10-13 10:09:32 +0100 | [diff] [blame] | 279 | out.preinstalledModulePath = *preinstalledPath; |
| 280 | } |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 281 | return out; |
| 282 | } |
| 283 | |
| 284 | static std::string toString(const ApexInfo& package) { |
| 285 | std::string msg = StringLog() |
Nikita Ioffe | 2cb7f8f | 2019-06-28 15:42:51 +0100 | [diff] [blame] | 286 | << "Module: " << package.moduleName |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 287 | << " Version: " << package.versionCode |
Gavin Corkery | 9463856 | 2019-04-30 10:40:12 +0100 | [diff] [blame] | 288 | << " VersionName: " << package.versionName |
Nikita Ioffe | 2cb7f8f | 2019-06-28 15:42:51 +0100 | [diff] [blame] | 289 | << " Path: " << package.modulePath |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 290 | << " IsActive: " << std::boolalpha << package.isActive |
| 291 | << " IsFactory: " << std::boolalpha << package.isFactory |
| 292 | << std::endl; |
| 293 | return msg; |
| 294 | } |
| 295 | |
Martijn Coenen | 4d20642 | 2019-01-31 15:58:55 +0100 | [diff] [blame] | 296 | BinderStatus ApexService::getSessions( |
| 297 | std::vector<ApexSessionInfo>* aidl_return) { |
| 298 | auto sessions = ApexSession::GetSessions(); |
| 299 | for (const auto& session : sessions) { |
| 300 | ApexSessionInfo sessionInfo; |
| 301 | convertToApexSessionInfo(session, &sessionInfo); |
| 302 | aidl_return->push_back(sessionInfo); |
| 303 | } |
| 304 | |
| 305 | return BinderStatus::ok(); |
| 306 | } |
| 307 | |
Dario Freni | d243764 | 2019-01-11 14:35:23 +0000 | [diff] [blame] | 308 | BinderStatus ApexService::getStagedSessionInfo( |
| 309 | int session_id, ApexSessionInfo* apex_session_info) { |
| 310 | LOG(DEBUG) << "getStagedSessionInfo() received by ApexService, session id " |
| 311 | << session_id; |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 312 | auto session = ApexSession::GetSession(session_id); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 313 | if (!session.ok()) { |
Dario Freni | d243764 | 2019-01-11 14:35:23 +0000 | [diff] [blame] | 314 | // Unknown session. |
Nikita Ioffe | 9ae986a | 2019-02-18 22:39:27 +0000 | [diff] [blame] | 315 | ClearSessionInfo(apex_session_info); |
Martijn Coenen | 4d20642 | 2019-01-31 15:58:55 +0100 | [diff] [blame] | 316 | apex_session_info->isUnknown = true; |
Dario Freni | d243764 | 2019-01-11 14:35:23 +0000 | [diff] [blame] | 317 | return BinderStatus::ok(); |
| 318 | } |
Martijn Coenen | 4d20642 | 2019-01-31 15:58:55 +0100 | [diff] [blame] | 319 | |
| 320 | convertToApexSessionInfo(*session, apex_session_info); |
Dario Freni | d243764 | 2019-01-11 14:35:23 +0000 | [diff] [blame] | 321 | |
| 322 | return BinderStatus::ok(); |
| 323 | } |
| 324 | |
Dario Freni | af27504 | 2018-11-06 16:50:04 +0000 | [diff] [blame] | 325 | BinderStatus ApexService::activatePackage(const std::string& packagePath) { |
Andreas Gampe | d6c3df8 | 2018-11-08 15:34:06 -0800 | [diff] [blame] | 326 | BinderStatus debugCheck = CheckDebuggable("activatePackage"); |
Andreas Gampe | 8eb187a | 2018-10-19 21:18:03 -0700 | [diff] [blame] | 327 | if (!debugCheck.isOk()) { |
| 328 | return debugCheck; |
| 329 | } |
| 330 | |
Dario Freni | af27504 | 2018-11-06 16:50:04 +0000 | [diff] [blame] | 331 | LOG(DEBUG) << "activatePackage() received by ApexService, path " |
| 332 | << packagePath; |
Andreas Gampe | 8eb187a | 2018-10-19 21:18:03 -0700 | [diff] [blame] | 333 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 334 | Result<void> res = ::android::apex::activatePackage(packagePath); |
Andreas Gampe | 8eb187a | 2018-10-19 21:18:03 -0700 | [diff] [blame] | 335 | |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 336 | if (res.ok()) { |
Andreas Gampe | 8eb187a | 2018-10-19 21:18:03 -0700 | [diff] [blame] | 337 | return BinderStatus::ok(); |
| 338 | } |
| 339 | |
| 340 | // TODO: Get correct binder error status. |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 341 | LOG(ERROR) << "Failed to activate " << packagePath << ": " << res.error(); |
| 342 | return BinderStatus::fromExceptionCode( |
| 343 | BinderStatus::EX_ILLEGAL_ARGUMENT, |
| 344 | String8(res.error().message().c_str())); |
Andreas Gampe | 8eb187a | 2018-10-19 21:18:03 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Andreas Gampe | d6c3df8 | 2018-11-08 15:34:06 -0800 | [diff] [blame] | 347 | BinderStatus ApexService::deactivatePackage(const std::string& packagePath) { |
| 348 | BinderStatus debugCheck = CheckDebuggable("deactivatePackage"); |
| 349 | if (!debugCheck.isOk()) { |
| 350 | return debugCheck; |
| 351 | } |
| 352 | |
| 353 | LOG(DEBUG) << "deactivatePackage() received by ApexService, path " |
| 354 | << packagePath; |
| 355 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 356 | Result<void> res = ::android::apex::deactivatePackage(packagePath); |
Andreas Gampe | d6c3df8 | 2018-11-08 15:34:06 -0800 | [diff] [blame] | 357 | |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 358 | if (res.ok()) { |
Andreas Gampe | d6c3df8 | 2018-11-08 15:34:06 -0800 | [diff] [blame] | 359 | return BinderStatus::ok(); |
| 360 | } |
| 361 | |
| 362 | // TODO: Get correct binder error status. |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 363 | LOG(ERROR) << "Failed to deactivate " << packagePath << ": " << res.error(); |
| 364 | return BinderStatus::fromExceptionCode( |
| 365 | BinderStatus::EX_ILLEGAL_ARGUMENT, |
| 366 | String8(res.error().message().c_str())); |
Andreas Gampe | d6c3df8 | 2018-11-08 15:34:06 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Dario Freni | 8e88b68 | 2018-10-25 13:06:21 +0100 | [diff] [blame] | 369 | BinderStatus ApexService::getActivePackages( |
Dario Freni | dded6c1 | 2018-11-19 16:02:26 +0000 | [diff] [blame] | 370 | std::vector<ApexInfo>* aidl_return) { |
Narayan Kamath | 5ea5778 | 2019-01-03 18:17:05 +0000 | [diff] [blame] | 371 | auto packages = ::android::apex::getActivePackages(); |
| 372 | for (const auto& package : packages) { |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 373 | ApexInfo apexInfo = getApexInfo(package); |
| 374 | apexInfo.isActive = true; |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 375 | aidl_return->push_back(std::move(apexInfo)); |
Narayan Kamath | 5ea5778 | 2019-01-03 18:17:05 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | return BinderStatus::ok(); |
| 379 | } |
| 380 | |
| 381 | BinderStatus ApexService::getActivePackage(const std::string& packageName, |
| 382 | ApexInfo* aidl_return) { |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 383 | Result<ApexFile> apex = ::android::apex::getActivePackage(packageName); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 384 | if (apex.ok()) { |
Nikita Ioffe | d49bcd1 | 2019-08-30 11:56:52 +0100 | [diff] [blame] | 385 | *aidl_return = getApexInfo(*apex); |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 386 | aidl_return->isActive = true; |
Dario Freni | 8e88b68 | 2018-10-25 13:06:21 +0100 | [diff] [blame] | 387 | } |
| 388 | return BinderStatus::ok(); |
| 389 | } |
| 390 | |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 391 | BinderStatus ApexService::getAllPackages(std::vector<ApexInfo>* aidl_return) { |
Nikita Ioffe | d49bcd1 | 2019-08-30 11:56:52 +0100 | [diff] [blame] | 392 | const auto& active = ::android::apex::getActivePackages(); |
| 393 | const auto& factory = ::android::apex::getFactoryPackages(); |
| 394 | for (const ApexFile& pkg : active) { |
| 395 | ApexInfo apex_info = getApexInfo(pkg); |
| 396 | apex_info.isActive = true; |
| 397 | aidl_return->push_back(std::move(apex_info)); |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 398 | } |
Nikita Ioffe | d49bcd1 | 2019-08-30 11:56:52 +0100 | [diff] [blame] | 399 | for (const ApexFile& pkg : factory) { |
| 400 | const auto& same_path = [&pkg](const auto& o) { |
| 401 | return o.GetPath() == pkg.GetPath(); |
| 402 | }; |
| 403 | if (std::find_if(active.begin(), active.end(), same_path) == active.end()) { |
| 404 | aidl_return->push_back(getApexInfo(pkg)); |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | return BinderStatus::ok(); |
| 408 | } |
| 409 | |
Andreas Gampe | 1773914 | 2019-01-09 16:00:26 -0800 | [diff] [blame] | 410 | BinderStatus ApexService::preinstallPackages( |
| 411 | const std::vector<std::string>& paths) { |
| 412 | BinderStatus debugCheck = CheckDebuggable("preinstallPackages"); |
| 413 | if (!debugCheck.isOk()) { |
| 414 | return debugCheck; |
| 415 | } |
| 416 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 417 | Result<void> res = ::android::apex::preinstallPackages(paths); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 418 | if (res.ok()) { |
Andreas Gampe | 1773914 | 2019-01-09 16:00:26 -0800 | [diff] [blame] | 419 | return BinderStatus::ok(); |
| 420 | } |
| 421 | |
| 422 | // TODO: Get correct binder error status. |
| 423 | LOG(ERROR) << "Failed to preinstall packages " |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 424 | << android::base::Join(paths, ',') << ": " << res.error(); |
| 425 | return BinderStatus::fromExceptionCode( |
| 426 | BinderStatus::EX_ILLEGAL_ARGUMENT, |
| 427 | String8(res.error().message().c_str())); |
Andreas Gampe | 1773914 | 2019-01-09 16:00:26 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Andreas Gampe | f4c7e7c | 2019-01-14 12:33:34 -0800 | [diff] [blame] | 430 | BinderStatus ApexService::postinstallPackages( |
| 431 | const std::vector<std::string>& paths) { |
| 432 | BinderStatus debugCheck = CheckDebuggable("postinstallPackages"); |
| 433 | if (!debugCheck.isOk()) { |
| 434 | return debugCheck; |
| 435 | } |
| 436 | |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 437 | Result<void> res = ::android::apex::postinstallPackages(paths); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 438 | if (res.ok()) { |
Andreas Gampe | f4c7e7c | 2019-01-14 12:33:34 -0800 | [diff] [blame] | 439 | return BinderStatus::ok(); |
| 440 | } |
| 441 | |
| 442 | // TODO: Get correct binder error status. |
| 443 | LOG(ERROR) << "Failed to postinstall packages " |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 444 | << android::base::Join(paths, ',') << ": " << res.error(); |
| 445 | return BinderStatus::fromExceptionCode( |
| 446 | BinderStatus::EX_ILLEGAL_ARGUMENT, |
| 447 | String8(res.error().message().c_str())); |
Andreas Gampe | f4c7e7c | 2019-01-14 12:33:34 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Mohammad Samiul Islam | 4654f77 | 2019-11-20 15:19:07 +0000 | [diff] [blame] | 450 | BinderStatus ApexService::abortStagedSession(int session_id) { |
| 451 | LOG(DEBUG) << "abortStagedSession() received by ApexService."; |
| 452 | Result<void> res = ::android::apex::abortStagedSession(session_id); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 453 | if (!res.ok()) { |
Mohammad Samiul Islam | 4654f77 | 2019-11-20 15:19:07 +0000 | [diff] [blame] | 454 | return BinderStatus::fromExceptionCode( |
| 455 | BinderStatus::EX_ILLEGAL_ARGUMENT, |
| 456 | String8(res.error().message().c_str())); |
| 457 | } |
| 458 | return BinderStatus::ok(); |
| 459 | } |
| 460 | |
Mohammad Samiul Islam | 2401ae1 | 2019-11-20 17:12:31 +0000 | [diff] [blame] | 461 | BinderStatus ApexService::revertActiveSessions() { |
| 462 | LOG(DEBUG) << "revertActiveSessions() received by ApexService."; |
Gavin Corkery | 92cd7b8 | 2020-01-13 12:35:38 +0000 | [diff] [blame] | 463 | Result<void> res = ::android::apex::revertActiveSessions(""); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 464 | if (!res.ok()) { |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 465 | return BinderStatus::fromExceptionCode( |
| 466 | BinderStatus::EX_ILLEGAL_ARGUMENT, |
| 467 | String8(res.error().message().c_str())); |
Andreas Gampe | 6e13ff8 | 2019-04-01 15:23:50 -0700 | [diff] [blame] | 468 | } |
| 469 | return BinderStatus::ok(); |
| 470 | } |
| 471 | |
Mohammad Samiul Islam | ca852e3 | 2019-11-20 13:37:14 +0000 | [diff] [blame] | 472 | BinderStatus ApexService::resumeRevertIfNeeded() { |
| 473 | BinderStatus debugCheck = CheckDebuggable("resumeRevertIfNeeded"); |
Andreas Gampe | 6e13ff8 | 2019-04-01 15:23:50 -0700 | [diff] [blame] | 474 | if (!debugCheck.isOk()) { |
| 475 | return debugCheck; |
| 476 | } |
| 477 | |
Mohammad Samiul Islam | ca852e3 | 2019-11-20 13:37:14 +0000 | [diff] [blame] | 478 | LOG(DEBUG) << "resumeRevertIfNeeded() received by ApexService."; |
| 479 | Result<void> res = ::android::apex::resumeRevertIfNeeded(); |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 480 | if (!res.ok()) { |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 481 | return BinderStatus::fromExceptionCode( |
| 482 | BinderStatus::EX_ILLEGAL_ARGUMENT, |
| 483 | String8(res.error().message().c_str())); |
Andreas Gampe | 6e13ff8 | 2019-04-01 15:23:50 -0700 | [diff] [blame] | 484 | } |
| 485 | return BinderStatus::ok(); |
| 486 | } |
| 487 | |
Oli Lan | 2d59dfa | 2020-01-14 20:25:09 +0000 | [diff] [blame] | 488 | BinderStatus ApexService::snapshotCeData(int user_id, int rollback_id, |
| 489 | const std::string& apex_name, |
| 490 | int64_t* _aidl_return) { |
| 491 | LOG(DEBUG) << "snapshotCeData() received by ApexService."; |
| 492 | Result<ino_t> res = |
| 493 | ::android::apex::snapshotCeData(user_id, rollback_id, apex_name); |
Bernie Innocenti | 0ca7c92 | 2020-03-05 21:46:34 +0900 | [diff] [blame] | 494 | if (!res.ok()) { |
Oli Lan | 2d59dfa | 2020-01-14 20:25:09 +0000 | [diff] [blame] | 495 | return BinderStatus::fromExceptionCode( |
| 496 | BinderStatus::EX_SERVICE_SPECIFIC, |
| 497 | String8(res.error().message().c_str())); |
| 498 | } |
| 499 | *_aidl_return = static_cast<uint64_t>(*res); |
| 500 | return BinderStatus::ok(); |
| 501 | } |
| 502 | |
| 503 | BinderStatus ApexService::restoreCeData(int user_id, int rollback_id, |
| 504 | const std::string& apex_name) { |
| 505 | LOG(DEBUG) << "restoreCeData() received by ApexService."; |
| 506 | Result<void> res = |
| 507 | ::android::apex::restoreCeData(user_id, rollback_id, apex_name); |
Bernie Innocenti | 0ca7c92 | 2020-03-05 21:46:34 +0900 | [diff] [blame] | 508 | if (!res.ok()) { |
Oli Lan | 2d59dfa | 2020-01-14 20:25:09 +0000 | [diff] [blame] | 509 | return BinderStatus::fromExceptionCode( |
| 510 | BinderStatus::EX_SERVICE_SPECIFIC, |
| 511 | String8(res.error().message().c_str())); |
| 512 | } |
| 513 | return BinderStatus::ok(); |
| 514 | } |
| 515 | |
Oli Lan | 042fbcf | 2020-01-17 11:14:16 +0000 | [diff] [blame] | 516 | BinderStatus ApexService::destroyDeSnapshots(int rollback_id) { |
| 517 | LOG(DEBUG) << "destroyDeSnapshots() received by ApexService."; |
| 518 | Result<void> res = ::android::apex::destroyDeSnapshots(rollback_id); |
| 519 | if (!res) { |
| 520 | return BinderStatus::fromExceptionCode( |
| 521 | BinderStatus::EX_SERVICE_SPECIFIC, |
| 522 | String8(res.error().message().c_str())); |
| 523 | } |
| 524 | return BinderStatus::ok(); |
| 525 | } |
| 526 | |
Oli Lan | 2993ccc | 2020-03-06 18:06:40 +0000 | [diff] [blame] | 527 | BinderStatus ApexService::destroyCeSnapshotsNotSpecified( |
| 528 | int user_id, const std::vector<int>& retain_rollback_ids) { |
| 529 | LOG(DEBUG) << "destroyCeSnapshotsNotSpecified() received by ApexService."; |
| 530 | Result<void> res = ::android::apex::destroyCeSnapshotsNotSpecified( |
| 531 | user_id, retain_rollback_ids); |
| 532 | if (!res) { |
| 533 | return BinderStatus::fromExceptionCode( |
| 534 | BinderStatus::EX_SERVICE_SPECIFIC, |
| 535 | String8(res.error().message().c_str())); |
| 536 | } |
| 537 | return BinderStatus::ok(); |
| 538 | } |
| 539 | |
Nikita Ioffe | 78d2bce | 2020-05-02 01:28:30 +0100 | [diff] [blame] | 540 | BinderStatus ApexService::remountPackages() { |
| 541 | LOG(DEBUG) << "remountPackages() received by ApexService"; |
| 542 | if (auto debug = CheckDebuggable("remountPackages"); !debug.isOk()) { |
| 543 | return debug; |
| 544 | } |
| 545 | if (auto root = CheckCallerIsRoot("remountPackages"); !root.isOk()) { |
| 546 | return root; |
| 547 | } |
| 548 | if (auto res = ::android::apex::remountPackages(); !res.ok()) { |
| 549 | return BinderStatus::fromExceptionCode( |
| 550 | BinderStatus::EX_SERVICE_SPECIFIC, |
| 551 | String8(res.error().message().c_str())); |
| 552 | } |
| 553 | return BinderStatus::ok(); |
| 554 | } |
| 555 | |
Dario Freni | 8e88b68 | 2018-10-25 13:06:21 +0100 | [diff] [blame] | 556 | status_t ApexService::onTransact(uint32_t _aidl_code, const Parcel& _aidl_data, |
| 557 | Parcel* _aidl_reply, uint32_t _aidl_flags) { |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 558 | switch (_aidl_code) { |
| 559 | case IBinder::SHELL_COMMAND_TRANSACTION: { |
| 560 | int in = _aidl_data.readFileDescriptor(); |
| 561 | int out = _aidl_data.readFileDescriptor(); |
| 562 | int err = _aidl_data.readFileDescriptor(); |
| 563 | int argc = _aidl_data.readInt32(); |
| 564 | Vector<String16> args; |
| 565 | for (int i = 0; i < argc && _aidl_data.dataAvail() > 0; i++) { |
| 566 | args.add(_aidl_data.readString16()); |
| 567 | } |
| 568 | sp<IBinder> unusedCallback; |
| 569 | sp<IResultReceiver> resultReceiver; |
| 570 | status_t status; |
| 571 | if ((status = _aidl_data.readNullableStrongBinder(&unusedCallback)) != OK) |
| 572 | return status; |
| 573 | if ((status = _aidl_data.readNullableStrongBinder(&resultReceiver)) != OK) |
| 574 | return status; |
| 575 | status = shellCommand(in, out, err, args); |
| 576 | if (resultReceiver != nullptr) { |
| 577 | resultReceiver->send(status); |
| 578 | } |
| 579 | return OK; |
| 580 | } |
| 581 | } |
Dario Freni | 8e88b68 | 2018-10-25 13:06:21 +0100 | [diff] [blame] | 582 | return BnApexService::onTransact(_aidl_code, _aidl_data, _aidl_reply, |
| 583 | _aidl_flags); |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 584 | } |
Nikita Ioffe | 11fa689 | 2019-06-18 05:24:24 +0100 | [diff] [blame] | 585 | status_t ApexService::dump(int fd, const Vector<String16>& /*args*/) { |
Abhijeet Kaur | 54695d3 | 2019-01-15 13:07:20 +0000 | [diff] [blame] | 586 | std::vector<ApexInfo> list; |
| 587 | BinderStatus status = getActivePackages(&list); |
Martijn Coenen | a418d31 | 2019-01-30 12:03:38 +0100 | [diff] [blame] | 588 | dprintf(fd, "ACTIVE PACKAGES:\n"); |
| 589 | if (!status.isOk()) { |
| 590 | std::string msg = StringLog() << "Failed to retrieve packages: " |
| 591 | << status.toString8().string() << std::endl; |
| 592 | dprintf(fd, "%s", msg.c_str()); |
| 593 | return BAD_VALUE; |
| 594 | } else { |
Abhijeet Kaur | 54695d3 | 2019-01-15 13:07:20 +0000 | [diff] [blame] | 595 | for (const auto& item : list) { |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 596 | std::string msg = toString(item); |
Abhijeet Kaur | 54695d3 | 2019-01-15 13:07:20 +0000 | [diff] [blame] | 597 | dprintf(fd, "%s", msg.c_str()); |
| 598 | } |
Abhijeet Kaur | 54695d3 | 2019-01-15 13:07:20 +0000 | [diff] [blame] | 599 | } |
Martijn Coenen | a418d31 | 2019-01-30 12:03:38 +0100 | [diff] [blame] | 600 | |
| 601 | dprintf(fd, "SESSIONS:\n"); |
| 602 | std::vector<ApexSession> sessions = ApexSession::GetSessions(); |
| 603 | |
| 604 | for (const auto& session : sessions) { |
| 605 | std::string child_ids_str = ""; |
| 606 | auto child_ids = session.GetChildSessionIds(); |
| 607 | if (child_ids.size() > 0) { |
| 608 | child_ids_str = "Child IDs:"; |
| 609 | for (auto childSessionId : session.GetChildSessionIds()) { |
| 610 | child_ids_str += " " + std::to_string(childSessionId); |
| 611 | } |
| 612 | } |
Gavin Corkery | 879fe9b | 2020-01-29 19:13:50 +0000 | [diff] [blame] | 613 | std::string revert_reason = ""; |
| 614 | std::string crashing_native_process = session.GetCrashingNativeProcess(); |
| 615 | if (!crashing_native_process.empty()) { |
| 616 | revert_reason = " Revert Reason: " + crashing_native_process; |
| 617 | } |
Martijn Coenen | a418d31 | 2019-01-30 12:03:38 +0100 | [diff] [blame] | 618 | std::string msg = |
| 619 | StringLog() << "Session ID: " << session.GetId() << child_ids_str |
| 620 | << " State: " << SessionState_State_Name(session.GetState()) |
Gavin Corkery | 879fe9b | 2020-01-29 19:13:50 +0000 | [diff] [blame] | 621 | << revert_reason << std::endl; |
Martijn Coenen | a418d31 | 2019-01-30 12:03:38 +0100 | [diff] [blame] | 622 | dprintf(fd, "%s", msg.c_str()); |
| 623 | } |
| 624 | |
| 625 | return OK; |
Abhijeet Kaur | 54695d3 | 2019-01-15 13:07:20 +0000 | [diff] [blame] | 626 | } |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 627 | |
Dario Freni | 8e88b68 | 2018-10-25 13:06:21 +0100 | [diff] [blame] | 628 | status_t ApexService::shellCommand(int in, int out, int err, |
| 629 | const Vector<String16>& args) { |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 630 | if (in == BAD_TYPE || out == BAD_TYPE || err == BAD_TYPE) { |
| 631 | return BAD_VALUE; |
| 632 | } |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 633 | auto print_help = [](int fd, const char* prefix = nullptr) { |
| 634 | StringLog log; |
| 635 | if (prefix != nullptr) { |
| 636 | log << prefix << std::endl; |
| 637 | } |
| 638 | log << "ApexService:" << std::endl |
| 639 | << " help - display this help" << std::endl |
Dario Freni | 56231b4 | 2019-01-04 11:58:17 +0000 | [diff] [blame] | 640 | << " stagePackages [packagePath1] ([packagePath2]...) - stage " |
| 641 | "multiple packages from the given path" |
| 642 | << std::endl |
| 643 | << " getActivePackage [packageName] - return info for active package " |
| 644 | "with given name, if present" |
| 645 | << std::endl |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 646 | << " getAllPackages - return the list of all packages" << std::endl |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 647 | << " getActivePackages - return the list of active packages" |
| 648 | << std::endl |
| 649 | << " activatePackage [packagePath] - activate package from the " |
| 650 | "given path" |
| 651 | << std::endl |
| 652 | << " deactivatePackage [packagePath] - deactivate package from the " |
| 653 | "given path" |
Dario Freni | 56231b4 | 2019-01-04 11:58:17 +0000 | [diff] [blame] | 654 | << std::endl |
Andreas Gampe | 1a48b1b | 2019-02-05 16:12:25 -0800 | [diff] [blame] | 655 | << " preinstallPackages [packagePath1] ([packagePath2]...) - run " |
| 656 | "pre-install hooks of the given packages" |
| 657 | << std::endl |
| 658 | << " postinstallPackages [packagePath1] ([packagePath2]...) - run " |
| 659 | "post-install hooks of the given packages" |
| 660 | << std::endl |
Dario Freni | d243764 | 2019-01-11 14:35:23 +0000 | [diff] [blame] | 661 | << " getStagedSessionInfo [sessionId] - displays information about a " |
| 662 | "given session previously submitted" |
Nikita Ioffe | 78d2bce | 2020-05-02 01:28:30 +0100 | [diff] [blame] | 663 | << std::endl |
Dario Freni | 56231b4 | 2019-01-04 11:58:17 +0000 | [diff] [blame] | 664 | << " submitStagedSession [sessionId] - attempts to submit the " |
| 665 | "installer session with given id" |
Nikita Ioffe | 78d2bce | 2020-05-02 01:28:30 +0100 | [diff] [blame] | 666 | << std::endl |
| 667 | << " remountPackages - Force apexd to remount active packages. This " |
| 668 | "call can be used to speed up development workflow of an APEX " |
| 669 | "package. Example of usage:\n" |
| 670 | " 1. adb shell stop\n" |
| 671 | " 2. adb sync\n" |
| 672 | " 3. adb shell cmd -w apexservice remountPackages\n" |
| 673 | " 4. adb shell start\n" |
| 674 | "\n" |
| 675 | "Note: APEX package will be successfully remounted only if there " |
| 676 | "are no alive processes holding a reference to it" |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 677 | << std::endl; |
| 678 | dprintf(fd, "%s", log.operator std::string().c_str()); |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 679 | }; |
| 680 | |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 681 | if (args.size() == 0) { |
| 682 | print_help(err, "No command given"); |
| 683 | return BAD_VALUE; |
| 684 | } |
| 685 | |
| 686 | const String16& cmd = args[0]; |
| 687 | |
Nikita Ioffe | 1b01b37 | 2019-07-03 16:37:08 +0100 | [diff] [blame] | 688 | if (cmd == String16("stagePackages")) { |
Andreas Gampe | 59ec1d9 | 2018-12-19 14:43:24 -0800 | [diff] [blame] | 689 | if (args.size() < 2) { |
Nikita Ioffe | 1b01b37 | 2019-07-03 16:37:08 +0100 | [diff] [blame] | 690 | print_help(err, "stagePackages requires at least one packagePath"); |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 691 | return BAD_VALUE; |
| 692 | } |
Andreas Gampe | 59ec1d9 | 2018-12-19 14:43:24 -0800 | [diff] [blame] | 693 | std::vector<std::string> pkgs; |
| 694 | pkgs.reserve(args.size() - 1); |
| 695 | for (size_t i = 1; i != args.size(); ++i) { |
| 696 | pkgs.emplace_back(String8(args[i]).string()); |
| 697 | } |
Nikita Ioffe | d90eda0 | 2019-07-11 17:56:01 +0100 | [diff] [blame] | 698 | BinderStatus status = stagePackages(pkgs); |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 699 | if (status.isOk()) { |
| 700 | return OK; |
| 701 | } |
Andreas Gampe | 59ec1d9 | 2018-12-19 14:43:24 -0800 | [diff] [blame] | 702 | std::string msg = StringLog() << "Failed to stage package(s): " |
| 703 | << status.toString8().string() << std::endl; |
Jiyong Park | 9b80048 | 2018-12-03 22:16:40 +0900 | [diff] [blame] | 704 | dprintf(err, "%s", msg.c_str()); |
Dario Freni | 8e88b68 | 2018-10-25 13:06:21 +0100 | [diff] [blame] | 705 | return BAD_VALUE; |
| 706 | } |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 707 | if (cmd == String16("getAllPackages")) { |
| 708 | if (args.size() != 1) { |
| 709 | print_help(err, "Unrecognized options"); |
| 710 | return BAD_VALUE; |
| 711 | } |
| 712 | std::vector<ApexInfo> list; |
| 713 | BinderStatus status = getAllPackages(&list); |
| 714 | if (status.isOk()) { |
| 715 | for (const auto& item : list) { |
| 716 | std::string msg = toString(item); |
| 717 | dprintf(out, "%s", msg.c_str()); |
| 718 | } |
| 719 | return OK; |
| 720 | } |
| 721 | std::string msg = StringLog() << "Failed to retrieve packages: " |
| 722 | << status.toString8().string() << std::endl; |
| 723 | dprintf(err, "%s", msg.c_str()); |
| 724 | return BAD_VALUE; |
| 725 | } |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 726 | |
| 727 | if (cmd == String16("getActivePackages")) { |
| 728 | if (args.size() != 1) { |
| 729 | print_help(err, "Unrecognized options"); |
| 730 | return BAD_VALUE; |
| 731 | } |
Dario Freni | dded6c1 | 2018-11-19 16:02:26 +0000 | [diff] [blame] | 732 | std::vector<ApexInfo> list; |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 733 | BinderStatus status = getActivePackages(&list); |
Dario Freni | 8e88b68 | 2018-10-25 13:06:21 +0100 | [diff] [blame] | 734 | if (status.isOk()) { |
Chih-Hung Hsieh | 43bb023 | 2018-12-12 14:30:01 -0800 | [diff] [blame] | 735 | for (const auto& item : list) { |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 736 | std::string msg = toString(item); |
Jiyong Park | 9b80048 | 2018-12-03 22:16:40 +0900 | [diff] [blame] | 737 | dprintf(out, "%s", msg.c_str()); |
Dario Freni | 8e88b68 | 2018-10-25 13:06:21 +0100 | [diff] [blame] | 738 | } |
| 739 | return OK; |
| 740 | } |
Andreas Gampe | 1773914 | 2019-01-09 16:00:26 -0800 | [diff] [blame] | 741 | std::string msg = StringLog() << "Failed to retrieve packages: " |
| 742 | << status.toString8().string() << std::endl; |
Jiyong Park | 9b80048 | 2018-12-03 22:16:40 +0900 | [diff] [blame] | 743 | dprintf(err, "%s", msg.c_str()); |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 744 | return BAD_VALUE; |
| 745 | } |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 746 | |
Narayan Kamath | 5ea5778 | 2019-01-03 18:17:05 +0000 | [diff] [blame] | 747 | if (cmd == String16("getActivePackage")) { |
| 748 | if (args.size() != 2) { |
| 749 | print_help(err, "Unrecognized options"); |
| 750 | return BAD_VALUE; |
| 751 | } |
| 752 | |
| 753 | ApexInfo package; |
| 754 | BinderStatus status = getActivePackage(String8(args[1]).string(), &package); |
| 755 | if (status.isOk()) { |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 756 | std::string msg = toString(package); |
| 757 | dprintf(out, "%s", msg.c_str()); |
Narayan Kamath | 5ea5778 | 2019-01-03 18:17:05 +0000 | [diff] [blame] | 758 | return OK; |
| 759 | } |
| 760 | |
| 761 | std::string msg = StringLog() << "Failed to fetch active package: " |
| 762 | << String8(args[1]).string() |
| 763 | << ", error: " << status.toString8().string() |
| 764 | << std::endl; |
| 765 | dprintf(err, "%s", msg.c_str()); |
| 766 | return BAD_VALUE; |
| 767 | } |
| 768 | |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 769 | if (cmd == String16("activatePackage")) { |
| 770 | if (args.size() != 2) { |
| 771 | print_help(err, "activatePackage requires one packagePath"); |
| 772 | return BAD_VALUE; |
| 773 | } |
| 774 | BinderStatus status = activatePackage(String8(args[1]).string()); |
Andreas Gampe | 8eb187a | 2018-10-19 21:18:03 -0700 | [diff] [blame] | 775 | if (status.isOk()) { |
| 776 | return OK; |
| 777 | } |
Andreas Gampe | 1773914 | 2019-01-09 16:00:26 -0800 | [diff] [blame] | 778 | std::string msg = StringLog() << "Failed to activate package: " |
| 779 | << status.toString8().string() << std::endl; |
Jiyong Park | 9b80048 | 2018-12-03 22:16:40 +0900 | [diff] [blame] | 780 | dprintf(err, "%s", msg.c_str()); |
Andreas Gampe | 8eb187a | 2018-10-19 21:18:03 -0700 | [diff] [blame] | 781 | return BAD_VALUE; |
| 782 | } |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 783 | |
| 784 | if (cmd == String16("deactivatePackage")) { |
| 785 | if (args.size() != 2) { |
| 786 | print_help(err, "deactivatePackage requires one packagePath"); |
| 787 | return BAD_VALUE; |
| 788 | } |
| 789 | BinderStatus status = deactivatePackage(String8(args[1]).string()); |
Andreas Gampe | a4fe113 | 2018-11-16 11:14:31 -0800 | [diff] [blame] | 790 | if (status.isOk()) { |
| 791 | return OK; |
| 792 | } |
Andreas Gampe | 1773914 | 2019-01-09 16:00:26 -0800 | [diff] [blame] | 793 | std::string msg = StringLog() << "Failed to deactivate package: " |
| 794 | << status.toString8().string() << std::endl; |
Jiyong Park | 9b80048 | 2018-12-03 22:16:40 +0900 | [diff] [blame] | 795 | dprintf(err, "%s", msg.c_str()); |
Andreas Gampe | a4fe113 | 2018-11-16 11:14:31 -0800 | [diff] [blame] | 796 | return BAD_VALUE; |
| 797 | } |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 798 | |
Dario Freni | d243764 | 2019-01-11 14:35:23 +0000 | [diff] [blame] | 799 | if (cmd == String16("getStagedSessionInfo")) { |
| 800 | if (args.size() != 2) { |
| 801 | print_help(err, "getStagedSessionInfo requires one session id"); |
| 802 | return BAD_VALUE; |
| 803 | } |
| 804 | int session_id = strtol(String8(args[1]).c_str(), nullptr, 10); |
| 805 | if (session_id < 0) { |
| 806 | std::string msg = StringLog() |
| 807 | << "Failed to parse session id. Must be an integer."; |
| 808 | dprintf(err, "%s", msg.c_str()); |
| 809 | return BAD_VALUE; |
| 810 | } |
| 811 | |
| 812 | ApexSessionInfo session_info; |
| 813 | BinderStatus status = getStagedSessionInfo(session_id, &session_info); |
| 814 | if (status.isOk()) { |
Gavin Corkery | 879fe9b | 2020-01-29 19:13:50 +0000 | [diff] [blame] | 815 | std::string revert_reason = ""; |
| 816 | std::string crashing_native_process = session_info.crashingNativeProcess; |
| 817 | if (!crashing_native_process.empty()) { |
| 818 | revert_reason = " revertReason: " + crashing_native_process; |
| 819 | } |
Dario Freni | d243764 | 2019-01-11 14:35:23 +0000 | [diff] [blame] | 820 | std::string msg = StringLog() |
| 821 | << "session_info: " |
| 822 | << " isUnknown: " << session_info.isUnknown |
| 823 | << " isVerified: " << session_info.isVerified |
| 824 | << " isStaged: " << session_info.isStaged |
| 825 | << " isActivated: " << session_info.isActivated |
Dario Freni | d243764 | 2019-01-11 14:35:23 +0000 | [diff] [blame] | 826 | << " isActivationFailed: " |
Gavin Corkery | 879fe9b | 2020-01-29 19:13:50 +0000 | [diff] [blame] | 827 | << session_info.isActivationFailed << revert_reason |
| 828 | << std::endl; |
Dario Freni | d243764 | 2019-01-11 14:35:23 +0000 | [diff] [blame] | 829 | dprintf(out, "%s", msg.c_str()); |
| 830 | return OK; |
| 831 | } |
| 832 | std::string msg = StringLog() << "Failed to query session: " |
| 833 | << status.toString8().string() << std::endl; |
| 834 | dprintf(err, "%s", msg.c_str()); |
| 835 | return BAD_VALUE; |
| 836 | } |
| 837 | |
Dario Freni | 56231b4 | 2019-01-04 11:58:17 +0000 | [diff] [blame] | 838 | if (cmd == String16("submitStagedSession")) { |
| 839 | if (args.size() != 2) { |
| 840 | print_help(err, "submitStagedSession requires one session id"); |
| 841 | return BAD_VALUE; |
| 842 | } |
| 843 | int session_id = strtol(String8(args[1]).c_str(), nullptr, 10); |
| 844 | if (session_id < 0) { |
| 845 | std::string msg = StringLog() |
| 846 | << "Failed to parse session id. Must be an integer."; |
| 847 | dprintf(err, "%s", msg.c_str()); |
| 848 | return BAD_VALUE; |
| 849 | } |
| 850 | |
Dario Freni | ab5b6c4 | 2019-01-15 11:53:57 +0000 | [diff] [blame] | 851 | ApexInfoList list; |
| 852 | std::vector<int> empty_child_session_ids; |
Oli Lan | 123d9d0 | 2019-12-02 14:08:24 +0000 | [diff] [blame] | 853 | ApexSessionParams params; |
| 854 | params.sessionId = session_id; |
| 855 | params.childSessionIds = empty_child_session_ids; |
| 856 | BinderStatus status = submitStagedSession(params, &list); |
Dario Freni | 56231b4 | 2019-01-04 11:58:17 +0000 | [diff] [blame] | 857 | if (status.isOk()) { |
Dario Freni | ab5b6c4 | 2019-01-15 11:53:57 +0000 | [diff] [blame] | 858 | for (const auto& item : list.apexInfos) { |
Gavin Corkery | d6ef030 | 2019-03-21 11:52:06 +0000 | [diff] [blame] | 859 | std::string msg = toString(item); |
Dario Freni | a6ad33e | 2019-01-09 14:35:43 +0000 | [diff] [blame] | 860 | dprintf(out, "%s", msg.c_str()); |
| 861 | } |
Dario Freni | 56231b4 | 2019-01-04 11:58:17 +0000 | [diff] [blame] | 862 | return OK; |
| 863 | } |
| 864 | std::string msg = StringLog() << "Failed to submit session: " |
| 865 | << status.toString8().string() << std::endl; |
| 866 | dprintf(err, "%s", msg.c_str()); |
| 867 | return BAD_VALUE; |
| 868 | } |
| 869 | |
Andreas Gampe | 1a48b1b | 2019-02-05 16:12:25 -0800 | [diff] [blame] | 870 | if (cmd == String16("preinstallPackages") || |
| 871 | cmd == String16("postinstallPackages")) { |
| 872 | if (args.size() < 2) { |
| 873 | print_help(err, |
| 874 | "preinstallPackages/postinstallPackages requires at least" |
| 875 | " one packagePath"); |
| 876 | return BAD_VALUE; |
| 877 | } |
| 878 | std::vector<std::string> pkgs; |
| 879 | pkgs.reserve(args.size() - 1); |
| 880 | for (size_t i = 1; i != args.size(); ++i) { |
| 881 | pkgs.emplace_back(String8(args[i]).string()); |
| 882 | } |
| 883 | BinderStatus status = cmd == String16("preinstallPackages") |
| 884 | ? preinstallPackages(pkgs) |
| 885 | : postinstallPackages(pkgs); |
| 886 | if (status.isOk()) { |
| 887 | return OK; |
| 888 | } |
| 889 | std::string msg = StringLog() << "Failed to pre/postinstall package(s): " |
| 890 | << status.toString8().string() << std::endl; |
| 891 | dprintf(err, "%s", msg.c_str()); |
| 892 | return BAD_VALUE; |
| 893 | } |
| 894 | |
Nikita Ioffe | 78d2bce | 2020-05-02 01:28:30 +0100 | [diff] [blame] | 895 | if (cmd == String16("remountPackages")) { |
| 896 | BinderStatus status = remountPackages(); |
| 897 | if (status.isOk()) { |
| 898 | return OK; |
| 899 | } |
| 900 | std::string msg = StringLog() << "remountPackages failed: " |
| 901 | << status.toString8().string() << std::endl; |
| 902 | dprintf(err, "%s", msg.c_str()); |
| 903 | return BAD_VALUE; |
| 904 | } |
| 905 | |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 906 | if (cmd == String16("help")) { |
| 907 | if (args.size() != 1) { |
| 908 | print_help(err, "Help has no options"); |
| 909 | return BAD_VALUE; |
| 910 | } |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 911 | print_help(out); |
| 912 | return OK; |
| 913 | } |
Andreas Gampe | e386480 | 2018-12-19 14:12:59 -0800 | [diff] [blame] | 914 | |
Andreas Gampe | 66b5dcd | 2018-10-17 19:20:00 -0700 | [diff] [blame] | 915 | print_help(err); |
| 916 | return BAD_VALUE; |
| 917 | } |
| 918 | |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 919 | } // namespace |
| 920 | |
| 921 | static constexpr const char* kApexServiceName = "apexservice"; |
| 922 | |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 923 | using android::IPCThreadState; |
| 924 | using android::ProcessState; |
| 925 | using android::sp; |
Jon Spivack | 1b84030 | 2020-02-06 18:34:30 -0800 | [diff] [blame] | 926 | using android::binder::LazyServiceRegistrar; |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 927 | |
| 928 | void CreateAndRegisterService() { |
| 929 | sp<ProcessState> ps(ProcessState::self()); |
| 930 | |
Jon Spivack | 1b84030 | 2020-02-06 18:34:30 -0800 | [diff] [blame] | 931 | // Create binder service and register with LazyServiceRegistrar |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 932 | sp<ApexService> apexService = new ApexService(); |
Jon Spivack | 1b84030 | 2020-02-06 18:34:30 -0800 | [diff] [blame] | 933 | auto lazyRegistrar = LazyServiceRegistrar::getInstance(); |
| 934 | lazyRegistrar.forcePersist(true); |
| 935 | lazyRegistrar.registerService(apexService, kApexServiceName); |
| 936 | } |
| 937 | |
| 938 | void AllowServiceShutdown() { |
| 939 | auto lazyRegistrar = LazyServiceRegistrar::getInstance(); |
| 940 | lazyRegistrar.forcePersist(false); |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 941 | } |
| 942 | |
Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 943 | void StartThreadPool() { |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 944 | sp<ProcessState> ps(ProcessState::self()); |
| 945 | |
| 946 | // Start threadpool, wait for IPC |
| 947 | ps->startThreadPool(); |
Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | void JoinThreadPool() { |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 951 | IPCThreadState::self()->joinThreadPool(); // should not return |
| 952 | } |
| 953 | |
| 954 | } // namespace binder |
Andreas Gampe | b99abdd | 2018-10-19 19:59:17 -0700 | [diff] [blame] | 955 | } // namespace apex |
| 956 | } // namespace android |