blob: 1d65b1ced14e091527ddda34b145c5d4b9262ad8 [file] [log] [blame]
Andres Morales2d08dce2015-04-03 16:40:15 -07001/*
2 * Copyright (C) 2015 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
17#define LOG_TAG "gatekeeperd"
18
Janis Danisevskis3a1eb672019-03-29 11:14:31 -070019#include <android/service/gatekeeper/BnGateKeeperService.h>
20#include <gatekeeper/GateKeeperResponse.h>
Andres Morales2d08dce2015-04-03 16:40:15 -070021
Andres Morales6a49c2f2015-04-16 13:16:24 -070022#include <errno.h>
Andres Morales6a49c2f2015-04-16 13:16:24 -070023#include <fcntl.h>
Mark Salyzyn66ce3e02016-09-28 10:07:20 -070024#include <inttypes.h>
25#include <stdint.h>
Andres Morales6a49c2f2015-04-16 13:16:24 -070026#include <unistd.h>
Justin Yun68b0ec62017-08-16 18:54:20 +090027#include <memory>
Andres Morales6a49c2f2015-04-16 13:16:24 -070028
Janis Danisevskisea893982018-11-02 15:27:51 -070029#include <android/security/keystore/IKeystoreService.h>
David Anderson97400bd2019-02-15 15:59:39 -080030#include <android-base/logging.h>
31#include <android-base/properties.h>
Andres Morales2d08dce2015-04-03 16:40:15 -070032#include <binder/IPCThreadState.h>
33#include <binder/IServiceManager.h>
34#include <binder/PermissionCache.h>
Andres Morales6a49c2f2015-04-16 13:16:24 -070035#include <gatekeeper/password_handle.h> // for password_handle_t
Andres Morales2d08dce2015-04-03 16:40:15 -070036#include <hardware/gatekeeper.h>
Andres Morales6a49c2f2015-04-16 13:16:24 -070037#include <hardware/hw_auth_token.h>
Mark Salyzyn66ce3e02016-09-28 10:07:20 -070038#include <keystore/keystore.h> // For error code
Dmitry Dementyev0dd259c2017-11-14 12:53:39 -080039#include <keystore/keystore_return_types.h>
David Anderson97400bd2019-02-15 15:59:39 -080040#include <libgsi/libgsi.h>
Mark Salyzyn30f991f2017-01-10 13:19:54 -080041#include <log/log.h>
Mark Salyzyn66ce3e02016-09-28 10:07:20 -070042#include <utils/Log.h>
43#include <utils/String16.h>
Andres Morales2d08dce2015-04-03 16:40:15 -070044
Alexey Polyudov275aece2016-10-18 13:59:26 -070045#include <hidl/HidlSupport.h>
46#include <android/hardware/gatekeeper/1.0/IGatekeeper.h>
47
48using android::sp;
49using android::hardware::gatekeeper::V1_0::IGatekeeper;
50using android::hardware::gatekeeper::V1_0::GatekeeperStatusCode;
51using android::hardware::gatekeeper::V1_0::GatekeeperResponse;
52using android::hardware::Return;
53
Janis Danisevskis3a1eb672019-03-29 11:14:31 -070054using ::android::binder::Status;
55using ::android::service::gatekeeper::BnGateKeeperService;
56using GKResponse = ::android::service::gatekeeper::GateKeeperResponse;
57using GKResponseCode = ::android::service::gatekeeper::ResponseCode;
58
Andres Morales2d08dce2015-04-03 16:40:15 -070059namespace android {
60
61static const String16 KEYGUARD_PERMISSION("android.permission.ACCESS_KEYGUARD_SECURE_STORAGE");
62static const String16 DUMP_PERMISSION("android.permission.DUMP");
63
64class GateKeeperProxy : public BnGateKeeperService {
65public:
66 GateKeeperProxy() {
Adrian Rooscb4ed1b2017-04-12 13:03:04 -070067 clear_state_if_needed_done = false;
Chris Phoenixa84ce0c2017-01-24 13:09:39 -080068 hw_device = IGatekeeper::getService();
David Anderson97400bd2019-02-15 15:59:39 -080069 is_running_gsi = android::base::GetBoolProperty(android::gsi::kGsiBootedProp, false);
Andres Moralesfef908e2015-07-07 10:28:15 -070070
Janis Danisevskis3a1eb672019-03-29 11:14:31 -070071 if (!hw_device) {
72 LOG(ERROR) << "Could not find Gatekeeper device, which makes me very sad.";
Andres Morales33dfdc72015-05-12 15:37:20 -070073 }
Andres Morales2d08dce2015-04-03 16:40:15 -070074 }
75
76 virtual ~GateKeeperProxy() {
Andres Morales2d08dce2015-04-03 16:40:15 -070077 }
78
Andres Morales6a49c2f2015-04-16 13:16:24 -070079 void store_sid(uint32_t uid, uint64_t sid) {
80 char filename[21];
George Burgess IVe7aa2b22016-03-02 14:02:55 -080081 snprintf(filename, sizeof(filename), "%u", uid);
Andres Morales6a49c2f2015-04-16 13:16:24 -070082 int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
83 if (fd < 0) {
Andres Moralesdcb3fbd2015-04-17 09:00:28 -070084 ALOGE("could not open file: %s: %s", filename, strerror(errno));
Andres Morales6a49c2f2015-04-16 13:16:24 -070085 return;
86 }
87 write(fd, &sid, sizeof(sid));
88 close(fd);
89 }
90
Adrian Rooscb4ed1b2017-04-12 13:03:04 -070091 void clear_state_if_needed() {
92 if (clear_state_if_needed_done) {
93 return;
94 }
95
David Anderson97400bd2019-02-15 15:59:39 -080096 if (mark_cold_boot() && !is_running_gsi) {
Adrian Rooscb4ed1b2017-04-12 13:03:04 -070097 ALOGI("cold boot: clearing state");
Janis Danisevskis3a1eb672019-03-29 11:14:31 -070098 if (hw_device) {
Adrian Rooscb4ed1b2017-04-12 13:03:04 -070099 hw_device->deleteAllUsers([](const GatekeeperResponse &){});
100 }
101 }
102
103 clear_state_if_needed_done = true;
104 }
105
Andres Morales3c2086d2015-06-24 10:21:16 -0700106 bool mark_cold_boot() {
107 const char *filename = ".coldboot";
108 if (access(filename, F_OK) == -1) {
109 int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
110 if (fd < 0) {
111 ALOGE("could not open file: %s : %s", filename, strerror(errno));
112 return false;
113 }
114 close(fd);
115 return true;
116 }
117 return false;
118 }
119
Andres Morales6a49c2f2015-04-16 13:16:24 -0700120 void maybe_store_sid(uint32_t uid, uint64_t sid) {
121 char filename[21];
George Burgess IVe7aa2b22016-03-02 14:02:55 -0800122 snprintf(filename, sizeof(filename), "%u", uid);
Andres Morales6a49c2f2015-04-16 13:16:24 -0700123 if (access(filename, F_OK) == -1) {
124 store_sid(uid, sid);
125 }
126 }
127
128 uint64_t read_sid(uint32_t uid) {
129 char filename[21];
130 uint64_t sid;
George Burgess IVe7aa2b22016-03-02 14:02:55 -0800131 snprintf(filename, sizeof(filename), "%u", uid);
Andres Morales6a49c2f2015-04-16 13:16:24 -0700132 int fd = open(filename, O_RDONLY);
133 if (fd < 0) return 0;
134 read(fd, &sid, sizeof(sid));
Andres Morales0b0435e2015-07-10 09:47:09 -0700135 close(fd);
Andres Morales6a49c2f2015-04-16 13:16:24 -0700136 return sid;
137 }
138
Andres Moralesdcb3fbd2015-04-17 09:00:28 -0700139 void clear_sid(uint32_t uid) {
140 char filename[21];
George Burgess IVe7aa2b22016-03-02 14:02:55 -0800141 snprintf(filename, sizeof(filename), "%u", uid);
Andres Moralesdcb3fbd2015-04-17 09:00:28 -0700142 if (remove(filename) < 0) {
143 ALOGE("%s: could not remove file [%s], attempting 0 write", __func__, strerror(errno));
144 store_sid(uid, 0);
145 }
146 }
147
David Anderson97400bd2019-02-15 15:59:39 -0800148 // This should only be called on uids being passed to the GateKeeper HAL. It ensures that
149 // secure storage shared across a GSI image and a host image will not overlap.
150 uint32_t adjust_uid(uint32_t uid) {
151 static constexpr uint32_t kGsiOffset = 1000000;
152 CHECK(uid < kGsiOffset);
153 CHECK(hw_device != nullptr);
154 if (is_running_gsi) {
155 return uid + kGsiOffset;
156 }
157 return uid;
158 }
159
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700160#define GK_ERROR *gkResponse = GKResponse::error(), Status::ok()
161
162 Status enroll(int32_t uid, const std::unique_ptr<std::vector<uint8_t>>& currentPasswordHandle,
163 const std::unique_ptr<std::vector<uint8_t>>& currentPassword,
164 const std::vector<uint8_t>& desiredPassword, GKResponse* gkResponse) override {
Andres Morales2d08dce2015-04-03 16:40:15 -0700165 IPCThreadState* ipc = IPCThreadState::self();
166 const int calling_pid = ipc->getCallingPid();
167 const int calling_uid = ipc->getCallingUid();
168 if (!PermissionCache::checkPermission(KEYGUARD_PERMISSION, calling_pid, calling_uid)) {
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700169 return GK_ERROR;
Andres Morales2d08dce2015-04-03 16:40:15 -0700170 }
171
Adrian Rooscb4ed1b2017-04-12 13:03:04 -0700172 // Make sure to clear any state from before factory reset as soon as a credential is
173 // enrolled (which may happen during device setup).
174 clear_state_if_needed();
175
Andres Morales2d08dce2015-04-03 16:40:15 -0700176 // need a desired password to enroll
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700177 if (desiredPassword.size() == 0) return GK_ERROR;
Andres Morales33dfdc72015-05-12 15:37:20 -0700178
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700179 if (!hw_device) {
180 LOG(ERROR) << "has no HAL to talk to";
181 return GK_ERROR;
182 }
Andres Morales835d96e2015-06-03 15:06:24 -0700183
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700184 android::hardware::hidl_vec<uint8_t> curPwdHandle;
185 android::hardware::hidl_vec<uint8_t> curPwd;
186
187 if (currentPasswordHandle && currentPassword) {
188 if (currentPasswordHandle->size() != sizeof(gatekeeper::password_handle_t)) {
189 LOG(INFO) << "Password handle has wrong length";
190 return GK_ERROR;
Andres Morales835d96e2015-06-03 15:06:24 -0700191 }
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700192 curPwdHandle.setToExternal(const_cast<uint8_t*>(currentPasswordHandle->data()),
193 currentPasswordHandle->size());
194 curPwd.setToExternal(const_cast<uint8_t*>(currentPassword->data()),
195 currentPassword->size());
196 }
Andres Morales835d96e2015-06-03 15:06:24 -0700197
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700198 android::hardware::hidl_vec<uint8_t> newPwd;
199 newPwd.setToExternal(const_cast<uint8_t*>(desiredPassword.data()), desiredPassword.size());
Alexey Polyudov275aece2016-10-18 13:59:26 -0700200
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700201 uint32_t hw_uid = adjust_uid(uid);
202 Return<void> hwRes = hw_device->enroll(
203 hw_uid, curPwdHandle, curPwd, newPwd, [&gkResponse](const GatekeeperResponse& rsp) {
204 if (rsp.code >= GatekeeperStatusCode::STATUS_OK) {
205 *gkResponse = GKResponse::ok({rsp.data.begin(), rsp.data.end()});
206 } else if (rsp.code == GatekeeperStatusCode::ERROR_RETRY_TIMEOUT &&
207 rsp.timeout > 0) {
208 *gkResponse = GKResponse::retry(rsp.timeout);
209 } else {
210 *gkResponse = GKResponse::error();
Alexey Polyudov275aece2016-10-18 13:59:26 -0700211 }
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700212 });
213 if (!hwRes.isOk()) {
214 LOG(ERROR) << "enroll transaction failed";
215 return GK_ERROR;
216 }
217
218 if (gkResponse->response_code() == GKResponseCode::OK && !gkResponse->should_reenroll()) {
219 if (gkResponse->payload().size() != sizeof(gatekeeper::password_handle_t)) {
220 LOG(ERROR) << "HAL returned password handle of invalid length "
221 << gkResponse->payload().size();
222 return GK_ERROR;
Alexey Polyudov275aece2016-10-18 13:59:26 -0700223 }
Andres Morales33dfdc72015-05-12 15:37:20 -0700224
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700225 const gatekeeper::password_handle_t* handle =
226 reinterpret_cast<const gatekeeper::password_handle_t*>(
227 gkResponse->payload().data());
Andres Morales6a49c2f2015-04-16 13:16:24 -0700228 store_sid(uid, handle->user_id);
Andres Morales531e3e82015-06-01 17:23:04 -0700229
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700230 GKResponse verifyResponse;
Andres Morales531e3e82015-06-01 17:23:04 -0700231 // immediately verify this password so we don't ask the user to enter it again
232 // if they just created it.
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700233 auto status = verify(uid, gkResponse->payload(), desiredPassword, &verifyResponse);
234 if (!status.isOk() || verifyResponse.response_code() != GKResponseCode::OK) {
235 LOG(ERROR) << "Failed to verify password after enrolling";
236 }
Andres Morales6a49c2f2015-04-16 13:16:24 -0700237 }
Andres Moralesae242922015-05-18 09:26:19 -0700238
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700239 return Status::ok();
Andres Morales2d08dce2015-04-03 16:40:15 -0700240 }
241
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700242 Status verify(int32_t uid, const ::std::vector<uint8_t>& enrolledPasswordHandle,
243 const ::std::vector<uint8_t>& providedPassword, GKResponse* gkResponse) override {
244 return verifyChallenge(uid, 0 /* challenge */, enrolledPasswordHandle, providedPassword,
245 gkResponse);
Andres Moralesc828ae82015-04-10 21:03:07 -0700246 }
247
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700248 Status verifyChallenge(int32_t uid, int64_t challenge,
249 const std::vector<uint8_t>& enrolledPasswordHandle,
250 const std::vector<uint8_t>& providedPassword,
251 GKResponse* gkResponse) override {
Andres Morales2d08dce2015-04-03 16:40:15 -0700252 IPCThreadState* ipc = IPCThreadState::self();
253 const int calling_pid = ipc->getCallingPid();
254 const int calling_uid = ipc->getCallingUid();
255 if (!PermissionCache::checkPermission(KEYGUARD_PERMISSION, calling_pid, calling_uid)) {
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700256 return GK_ERROR;
Andres Morales2d08dce2015-04-03 16:40:15 -0700257 }
258
259 // can't verify if we're missing either param
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700260 if (enrolledPasswordHandle.size() == 0 || providedPassword.size() == 0) return GK_ERROR;
Andres Morales2d08dce2015-04-03 16:40:15 -0700261
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700262 if (!hw_device) return GK_ERROR;
263
264 if (enrolledPasswordHandle.size() != sizeof(gatekeeper::password_handle_t)) {
265 LOG(INFO) << "Password handle has wrong length";
266 return GK_ERROR;
267 }
268 const gatekeeper::password_handle_t* handle =
269 reinterpret_cast<const gatekeeper::password_handle_t*>(
270 enrolledPasswordHandle.data());
271
272 uint32_t hw_uid = adjust_uid(uid);
273 android::hardware::hidl_vec<uint8_t> curPwdHandle;
274 curPwdHandle.setToExternal(const_cast<uint8_t*>(enrolledPasswordHandle.data()),
275 enrolledPasswordHandle.size());
276 android::hardware::hidl_vec<uint8_t> enteredPwd;
277 enteredPwd.setToExternal(const_cast<uint8_t*>(providedPassword.data()),
278 providedPassword.size());
279
280 Return<void> hwRes = hw_device->verify(
281 hw_uid, challenge, curPwdHandle, enteredPwd,
282 [&gkResponse](const GatekeeperResponse& rsp) {
283 if (rsp.code >= GatekeeperStatusCode::STATUS_OK) {
284 *gkResponse = GKResponse::ok(
285 {rsp.data.begin(), rsp.data.end()},
286 rsp.code == GatekeeperStatusCode::STATUS_REENROLL /* reenroll */);
287 } else if (rsp.code == GatekeeperStatusCode::ERROR_RETRY_TIMEOUT) {
288 *gkResponse = GKResponse::retry(rsp.timeout);
289 } else {
290 *gkResponse = GKResponse::error();
Alexey Polyudov275aece2016-10-18 13:59:26 -0700291 }
292 });
Andres Morales835d96e2015-06-03 15:06:24 -0700293
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700294 if (!hwRes.isOk()) {
295 LOG(ERROR) << "verify transaction failed";
296 return GK_ERROR;
297 }
298
299 if (gkResponse->response_code() == GKResponseCode::OK) {
300 if (gkResponse->payload().size() != 0) {
301 sp<IServiceManager> sm = defaultServiceManager();
302 sp<IBinder> binder = sm->getService(String16("android.security.keystore"));
303 sp<security::keystore::IKeystoreService> service =
304 interface_cast<security::keystore::IKeystoreService>(binder);
305
306 if (service) {
307 int result = 0;
308 auto binder_result = service->addAuthToken(gkResponse->payload(), &result);
309 if (!binder_result.isOk() ||
310 !keystore::KeyStoreServiceReturnCode(result).isOk()) {
311 LOG(ERROR) << "Failure sending auth token to KeyStore: " << result;
312 }
313 } else {
314 LOG(ERROR) << "Cannot deliver auth token. Unable to communicate with Keystore.";
Andres Morales835d96e2015-06-03 15:06:24 -0700315 }
316 }
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700317
318 maybe_store_sid(uid, handle->user_id);
Andres Morales33dfdc72015-05-12 15:37:20 -0700319 }
Andres Morales2d08dce2015-04-03 16:40:15 -0700320
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700321 return Status::ok();
Andres Morales6a49c2f2015-04-16 13:16:24 -0700322 }
323
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700324 Status getSecureUserId(int32_t uid, int64_t* sid) override {
325 *sid = read_sid(uid);
326 return Status::ok();
327 }
Andres Morales2d08dce2015-04-03 16:40:15 -0700328
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700329 Status clearSecureUserId(int32_t uid) override {
Andres Morales7c9c3bc2015-04-16 15:57:17 -0700330 IPCThreadState* ipc = IPCThreadState::self();
331 const int calling_pid = ipc->getCallingPid();
332 const int calling_uid = ipc->getCallingUid();
333 if (!PermissionCache::checkPermission(KEYGUARD_PERMISSION, calling_pid, calling_uid)) {
334 ALOGE("%s: permission denied for [%d:%d]", __func__, calling_pid, calling_uid);
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700335 return Status::ok();
Andres Morales7c9c3bc2015-04-16 15:57:17 -0700336 }
Andres Moralesdcb3fbd2015-04-17 09:00:28 -0700337 clear_sid(uid);
Andres Morales3c2086d2015-06-24 10:21:16 -0700338
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700339 if (hw_device) {
David Anderson97400bd2019-02-15 15:59:39 -0800340 uint32_t hw_uid = adjust_uid(uid);
341 hw_device->deleteUser(hw_uid, [] (const GatekeeperResponse &){});
Andres Morales3c2086d2015-06-24 10:21:16 -0700342 }
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700343 return Status::ok();
Andres Morales7c9c3bc2015-04-16 15:57:17 -0700344 }
345
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700346 Status reportDeviceSetupComplete() override {
Adrian Rooscb4ed1b2017-04-12 13:03:04 -0700347 IPCThreadState* ipc = IPCThreadState::self();
348 const int calling_pid = ipc->getCallingPid();
349 const int calling_uid = ipc->getCallingUid();
350 if (!PermissionCache::checkPermission(KEYGUARD_PERMISSION, calling_pid, calling_uid)) {
351 ALOGE("%s: permission denied for [%d:%d]", __func__, calling_pid, calling_uid);
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700352 return Status::ok();
Adrian Rooscb4ed1b2017-04-12 13:03:04 -0700353 }
354
355 clear_state_if_needed();
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700356 return Status::ok();
Adrian Rooscb4ed1b2017-04-12 13:03:04 -0700357 }
358
Janis Danisevskis3a1eb672019-03-29 11:14:31 -0700359 status_t dump(int fd, const Vector<String16>&) override {
Andres Morales2d08dce2015-04-03 16:40:15 -0700360 IPCThreadState* ipc = IPCThreadState::self();
361 const int pid = ipc->getCallingPid();
362 const int uid = ipc->getCallingUid();
363 if (!PermissionCache::checkPermission(DUMP_PERMISSION, pid, uid)) {
364 return PERMISSION_DENIED;
365 }
366
Alexey Polyudov275aece2016-10-18 13:59:26 -0700367 if (hw_device == NULL) {
Andres Morales2d08dce2015-04-03 16:40:15 -0700368 const char *result = "Device not available";
369 write(fd, result, strlen(result) + 1);
370 } else {
371 const char *result = "OK";
372 write(fd, result, strlen(result) + 1);
373 }
374
Elliott Hughes643268f2018-10-08 11:10:11 -0700375 return OK;
Andres Morales2d08dce2015-04-03 16:40:15 -0700376 }
377
378private:
Alexey Polyudov275aece2016-10-18 13:59:26 -0700379 sp<IGatekeeper> hw_device;
Adrian Rooscb4ed1b2017-04-12 13:03:04 -0700380
381 bool clear_state_if_needed_done;
David Anderson97400bd2019-02-15 15:59:39 -0800382 bool is_running_gsi;
Andres Morales2d08dce2015-04-03 16:40:15 -0700383};
384}// namespace android
385
Andres Morales6a49c2f2015-04-16 13:16:24 -0700386int main(int argc, char* argv[]) {
Andres Morales2d08dce2015-04-03 16:40:15 -0700387 ALOGI("Starting gatekeeperd...");
Andres Morales6a49c2f2015-04-16 13:16:24 -0700388 if (argc < 2) {
389 ALOGE("A directory must be specified!");
390 return 1;
391 }
392 if (chdir(argv[1]) == -1) {
393 ALOGE("chdir: %s: %s", argv[1], strerror(errno));
394 return 1;
395 }
396
Andres Morales2d08dce2015-04-03 16:40:15 -0700397 android::sp<android::IServiceManager> sm = android::defaultServiceManager();
398 android::sp<android::GateKeeperProxy> proxy = new android::GateKeeperProxy();
399 android::status_t ret = sm->addService(
400 android::String16("android.service.gatekeeper.IGateKeeperService"), proxy);
401 if (ret != android::OK) {
402 ALOGE("Couldn't register binder service!");
403 return -1;
404 }
405
406 /*
407 * We're the only thread in existence, so we're just going to process
408 * Binder transaction as a single-threaded program.
409 */
410 android::IPCThreadState::self()->joinThreadPool();
411 return 0;
412}