blob: d3ee6a6b8a0ab84e23f09dcf8bbccd7e6dbb5e5e [file] [log] [blame]
Steven Moreland5553ac42020-11-11 02:14:45 +00001/*
2 * Copyright (C) 2020 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 "RpcServer"
18
Steven Moreland798e0d12021-07-14 23:19:25 +000019#include <poll.h>
Steven Moreland5553ac42020-11-11 02:14:45 +000020#include <sys/socket.h>
21#include <sys/un.h>
22
Steven Morelandf137de92021-04-24 01:54:26 +000023#include <thread>
Steven Moreland5553ac42020-11-11 02:14:45 +000024#include <vector>
25
Steven Moreland5802c2b2021-05-12 20:13:04 +000026#include <android-base/scopeguard.h>
Steven Moreland5553ac42020-11-11 02:14:45 +000027#include <binder/Parcel.h>
28#include <binder/RpcServer.h>
29#include <log/log.h>
Steven Moreland5553ac42020-11-11 02:14:45 +000030
Steven Moreland611d15f2021-05-01 01:28:27 +000031#include "RpcSocketAddress.h"
Yifan Hong1a235852021-05-13 16:07:47 -070032#include "RpcState.h"
Steven Moreland5553ac42020-11-11 02:14:45 +000033#include "RpcWireFormat.h"
34
35namespace android {
36
Steven Moreland5802c2b2021-05-12 20:13:04 +000037using base::ScopeGuard;
Steven Moreland611d15f2021-05-01 01:28:27 +000038using base::unique_fd;
39
Steven Moreland5553ac42020-11-11 02:14:45 +000040RpcServer::RpcServer() {}
Yifan Hong436f0e62021-05-19 15:25:34 -070041RpcServer::~RpcServer() {
42 (void)shutdown();
43}
Steven Moreland5553ac42020-11-11 02:14:45 +000044
45sp<RpcServer> RpcServer::make() {
Steven Moreland1a3a8ef2021-04-02 02:52:46 +000046 return sp<RpcServer>::make();
Steven Moreland5553ac42020-11-11 02:14:45 +000047}
48
49void RpcServer::iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction() {
50 mAgreedExperimental = true;
51}
52
Steven Moreland611d15f2021-05-01 01:28:27 +000053bool RpcServer::setupUnixDomainServer(const char* path) {
54 return setupSocketServer(UnixSocketAddress(path));
55}
56
Steven Moreland611d15f2021-05-01 01:28:27 +000057bool RpcServer::setupVsockServer(unsigned int port) {
58 // realizing value w/ this type at compile time to avoid ubsan abort
59 constexpr unsigned int kAnyCid = VMADDR_CID_ANY;
60
61 return setupSocketServer(VsockSocketAddress(kAnyCid, port));
62}
63
Steven Moreland611d15f2021-05-01 01:28:27 +000064bool RpcServer::setupInetServer(unsigned int port, unsigned int* assignedPort) {
65 const char* kAddr = "127.0.0.1";
66
67 if (assignedPort != nullptr) *assignedPort = 0;
68 auto aiStart = InetSocketAddress::getAddrInfo(kAddr, port);
69 if (aiStart == nullptr) return false;
70 for (auto ai = aiStart.get(); ai != nullptr; ai = ai->ai_next) {
71 InetSocketAddress socketAddress(ai->ai_addr, ai->ai_addrlen, kAddr, port);
72 if (!setupSocketServer(socketAddress)) {
73 continue;
74 }
75
76 LOG_ALWAYS_FATAL_IF(socketAddress.addr()->sa_family != AF_INET, "expecting inet");
77 sockaddr_in addr{};
78 socklen_t len = sizeof(addr);
79 if (0 != getsockname(mServer.get(), reinterpret_cast<sockaddr*>(&addr), &len)) {
80 int savedErrno = errno;
81 ALOGE("Could not getsockname at %s: %s", socketAddress.toString().c_str(),
82 strerror(savedErrno));
83 return false;
84 }
85 LOG_ALWAYS_FATAL_IF(len != sizeof(addr), "Wrong socket type: len %zu vs len %zu",
86 static_cast<size_t>(len), sizeof(addr));
87 unsigned int realPort = ntohs(addr.sin_port);
88 LOG_ALWAYS_FATAL_IF(port != 0 && realPort != port,
89 "Requesting inet server on %s but it is set up on %u.",
90 socketAddress.toString().c_str(), realPort);
91
92 if (assignedPort != nullptr) {
93 *assignedPort = realPort;
94 }
95
96 return true;
97 }
98 ALOGE("None of the socket address resolved for %s:%u can be set up as inet server.", kAddr,
99 port);
100 return false;
101}
102
Steven Morelandf137de92021-04-24 01:54:26 +0000103void RpcServer::setMaxThreads(size_t threads) {
104 LOG_ALWAYS_FATAL_IF(threads <= 0, "RpcServer is useless without threads");
Yifan Hong1a235852021-05-13 16:07:47 -0700105 LOG_ALWAYS_FATAL_IF(mJoinThreadRunning, "Cannot set max threads while running");
Steven Morelandf137de92021-04-24 01:54:26 +0000106 mMaxThreads = threads;
107}
108
109size_t RpcServer::getMaxThreads() {
110 return mMaxThreads;
Steven Moreland5553ac42020-11-11 02:14:45 +0000111}
112
113void RpcServer::setRootObject(const sp<IBinder>& binder) {
Steven Morelandebafe332021-04-24 00:24:35 +0000114 std::lock_guard<std::mutex> _l(mLock);
Yifan Hong4ffb0c72021-05-07 18:35:14 -0700115 mRootObjectWeak = mRootObject = binder;
116}
117
118void RpcServer::setRootObjectWeak(const wp<IBinder>& binder) {
119 std::lock_guard<std::mutex> _l(mLock);
120 mRootObject.clear();
121 mRootObjectWeak = binder;
Steven Moreland5553ac42020-11-11 02:14:45 +0000122}
123
124sp<IBinder> RpcServer::getRootObject() {
Steven Morelandebafe332021-04-24 00:24:35 +0000125 std::lock_guard<std::mutex> _l(mLock);
Yifan Hong4ffb0c72021-05-07 18:35:14 -0700126 bool hasWeak = mRootObjectWeak.unsafe_get();
127 sp<IBinder> ret = mRootObjectWeak.promote();
128 ALOGW_IF(hasWeak && ret == nullptr, "RpcServer root object is freed, returning nullptr");
129 return ret;
Steven Moreland5553ac42020-11-11 02:14:45 +0000130}
131
Yifan Hong326afd12021-05-19 15:24:54 -0700132static void joinRpcServer(sp<RpcServer>&& thiz) {
133 thiz->join();
134}
135
136void RpcServer::start() {
137 LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
138 std::lock_guard<std::mutex> _l(mLock);
139 LOG_ALWAYS_FATAL_IF(mJoinThread.get(), "Already started!");
140 mJoinThread = std::make_unique<std::thread>(&joinRpcServer, sp<RpcServer>::fromExisting(this));
141}
142
Steven Moreland611d15f2021-05-01 01:28:27 +0000143void RpcServer::join() {
Yifan Hong1a235852021-05-13 16:07:47 -0700144 LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
145
146 {
147 std::lock_guard<std::mutex> _l(mLock);
148 LOG_ALWAYS_FATAL_IF(!mServer.ok(), "RpcServer must be setup to join.");
149 LOG_ALWAYS_FATAL_IF(mShutdownTrigger != nullptr, "Already joined");
150 mJoinThreadRunning = true;
Steven Morelande47511f2021-05-20 00:07:41 +0000151 mShutdownTrigger = RpcSession::FdTrigger::make();
Yifan Hong1a235852021-05-13 16:07:47 -0700152 LOG_ALWAYS_FATAL_IF(mShutdownTrigger == nullptr, "Cannot create join signaler");
Steven Morelandd539fbf2021-05-05 23:40:25 +0000153 }
Yifan Hong1a235852021-05-13 16:07:47 -0700154
Steven Moreland2b4f3802021-05-22 01:46:27 +0000155 status_t status;
Steven Moreland798e0d12021-07-14 23:19:25 +0000156 while ((status = mShutdownTrigger->triggerablePoll(mServer, POLLIN)) == OK) {
Steven Moreland410325a2021-06-02 18:37:42 +0000157 unique_fd clientFd(TEMP_FAILURE_RETRY(
158 accept4(mServer.get(), nullptr, nullptr /*length*/, SOCK_CLOEXEC)));
159
160 if (clientFd < 0) {
161 ALOGE("Could not accept4 socket: %s", strerror(errno));
162 continue;
163 }
164 LOG_RPC_DETAIL("accept4 on fd %d yields fd %d", mServer.get(), clientFd.get());
165
166 {
167 std::lock_guard<std::mutex> _l(mLock);
168 std::thread thread =
169 std::thread(&RpcServer::establishConnection, sp<RpcServer>::fromExisting(this),
170 std::move(clientFd));
171 mConnectingThreads[thread.get_id()] = std::move(thread);
172 }
Yifan Hong1a235852021-05-13 16:07:47 -0700173 }
Steven Moreland2b4f3802021-05-22 01:46:27 +0000174 LOG_RPC_DETAIL("RpcServer::join exiting with %s", statusToString(status).c_str());
Yifan Hong1a235852021-05-13 16:07:47 -0700175
176 {
177 std::lock_guard<std::mutex> _l(mLock);
178 mJoinThreadRunning = false;
179 }
180 mShutdownCv.notify_all();
Steven Morelandd539fbf2021-05-05 23:40:25 +0000181}
182
Yifan Hong1a235852021-05-13 16:07:47 -0700183bool RpcServer::shutdown() {
Yifan Hong1a235852021-05-13 16:07:47 -0700184 std::unique_lock<std::mutex> _l(mLock);
Steven Moreland9d11b922021-05-20 01:22:58 +0000185 if (mShutdownTrigger == nullptr) {
186 LOG_RPC_DETAIL("Cannot shutdown. No shutdown trigger installed.");
187 return false;
188 }
Yifan Hong1a235852021-05-13 16:07:47 -0700189
190 mShutdownTrigger->trigger();
Steven Morelanda8b44292021-06-08 01:27:53 +0000191 for (auto& [id, session] : mSessions) {
192 (void)id;
193 session->mShutdownTrigger->trigger();
194 }
195
Steven Morelandee3f4662021-05-22 01:07:33 +0000196 while (mJoinThreadRunning || !mConnectingThreads.empty() || !mSessions.empty()) {
Steven Morelandaf4ca712021-05-24 23:22:08 +0000197 if (std::cv_status::timeout == mShutdownCv.wait_for(_l, std::chrono::seconds(1))) {
198 ALOGE("Waiting for RpcServer to shut down (1s w/o progress). Join thread running: %d, "
199 "Connecting threads: "
200 "%zu, Sessions: %zu. Is your server deadlocked?",
201 mJoinThreadRunning, mConnectingThreads.size(), mSessions.size());
202 }
Steven Moreland9d11b922021-05-20 01:22:58 +0000203 }
Yifan Hong1a235852021-05-13 16:07:47 -0700204
Yifan Hong326afd12021-05-19 15:24:54 -0700205 // At this point, we know join() is about to exit, but the thread that calls
206 // join() may not have exited yet.
207 // If RpcServer owns the join thread (aka start() is called), make sure the thread exits;
208 // otherwise ~thread() may call std::terminate(), which may crash the process.
209 // If RpcServer does not own the join thread (aka join() is called directly),
210 // then the owner of RpcServer is responsible for cleaning up that thread.
211 if (mJoinThread.get()) {
212 mJoinThread->join();
213 mJoinThread.reset();
214 }
215
Yifan Hong1a235852021-05-13 16:07:47 -0700216 mShutdownTrigger = nullptr;
217 return true;
218}
219
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000220std::vector<sp<RpcSession>> RpcServer::listSessions() {
Steven Moreland611d15f2021-05-01 01:28:27 +0000221 std::lock_guard<std::mutex> _l(mLock);
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000222 std::vector<sp<RpcSession>> sessions;
223 for (auto& [id, session] : mSessions) {
Steven Moreland736664b2021-05-01 04:27:25 +0000224 (void)id;
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000225 sessions.push_back(session);
Steven Moreland736664b2021-05-01 04:27:25 +0000226 }
Steven Morelandbdb53ab2021-05-05 17:57:41 +0000227 return sessions;
Steven Moreland611d15f2021-05-01 01:28:27 +0000228}
229
Steven Morelandd539fbf2021-05-05 23:40:25 +0000230size_t RpcServer::numUninitializedSessions() {
231 std::lock_guard<std::mutex> _l(mLock);
232 return mConnectingThreads.size();
233}
234
Steven Morelanda63ff932021-05-12 00:03:15 +0000235void RpcServer::establishConnection(sp<RpcServer>&& server, base::unique_fd clientFd) {
Steven Morelanda63ff932021-05-12 00:03:15 +0000236 // TODO(b/183988761): cannot trust this simple ID
Yifan Hongb3005502021-05-19 15:37:00 -0700237 LOG_ALWAYS_FATAL_IF(!server->mAgreedExperimental, "no!");
Steven Moreland9d11b922021-05-20 01:22:58 +0000238
239 // mShutdownTrigger can only be cleared once connection threads have joined.
240 // It must be set before this thread is started
241 LOG_ALWAYS_FATAL_IF(server->mShutdownTrigger == nullptr);
242
Steven Moreland659416d2021-05-11 00:47:50 +0000243 RpcConnectionHeader header;
244 status_t status = server->mShutdownTrigger->interruptableReadFully(clientFd.get(), &header,
245 sizeof(header));
Steven Moreland2b4f3802021-05-22 01:46:27 +0000246 bool idValid = status == OK;
Steven Moreland9d11b922021-05-20 01:22:58 +0000247 if (!idValid) {
Steven Moreland2b4f3802021-05-22 01:46:27 +0000248 ALOGE("Failed to read ID for client connecting to RPC server: %s",
249 statusToString(status).c_str());
250 // still need to cleanup before we can return
Steven Morelanda63ff932021-05-12 00:03:15 +0000251 }
Steven Moreland1b304292021-07-15 22:59:34 +0000252 bool incoming = header.options & RPC_CONNECTION_OPTION_INCOMING;
Steven Morelanda63ff932021-05-12 00:03:15 +0000253
254 std::thread thisThread;
255 sp<RpcSession> session;
256 {
Steven Moreland9d11b922021-05-20 01:22:58 +0000257 std::unique_lock<std::mutex> _l(server->mLock);
Steven Morelanda63ff932021-05-12 00:03:15 +0000258
Yifan Hongb3005502021-05-19 15:37:00 -0700259 auto threadId = server->mConnectingThreads.find(std::this_thread::get_id());
260 LOG_ALWAYS_FATAL_IF(threadId == server->mConnectingThreads.end(),
Steven Morelanda63ff932021-05-12 00:03:15 +0000261 "Must establish connection on owned thread");
262 thisThread = std::move(threadId->second);
Steven Morelandadc5dca2021-05-25 02:06:03 +0000263 ScopeGuard detachGuard = [&]() {
264 thisThread.detach();
Steven Moreland9d11b922021-05-20 01:22:58 +0000265 _l.unlock();
266 server->mShutdownCv.notify_all();
267 };
Steven Morelandadc5dca2021-05-25 02:06:03 +0000268 server->mConnectingThreads.erase(threadId);
Steven Moreland9d11b922021-05-20 01:22:58 +0000269
Steven Morelanda8b44292021-06-08 01:27:53 +0000270 if (!idValid || server->mShutdownTrigger->isTriggered()) {
Steven Moreland5802c2b2021-05-12 20:13:04 +0000271 return;
272 }
273
Steven Moreland01a6bad2021-06-11 00:59:20 +0000274 RpcAddress sessionId = RpcAddress::fromRawEmbedded(&header.sessionId);
275
276 if (sessionId.isZero()) {
Steven Moreland1b304292021-07-15 22:59:34 +0000277 if (incoming) {
278 ALOGE("Cannot create a new session with an incoming connection, would leak");
Steven Moreland659416d2021-05-11 00:47:50 +0000279 return;
280 }
281
Yifan Hong6fe19632021-06-24 15:50:12 -0700282 sessionId = RpcAddress::zero();
Steven Moreland01a6bad2021-06-11 00:59:20 +0000283 size_t tries = 0;
284 do {
285 // don't block if there is some entropy issue
286 if (tries++ > 5) {
287 ALOGE("Cannot find new address: %s", sessionId.toString().c_str());
288 return;
289 }
290
291 sessionId = RpcAddress::random(true /*forServer*/);
292 } while (server->mSessions.end() != server->mSessions.find(sessionId));
Steven Morelanda63ff932021-05-12 00:03:15 +0000293
294 session = RpcSession::make();
Steven Moreland103424e2021-06-02 18:16:19 +0000295 session->setMaxThreads(server->mMaxThreads);
Steven Morelanda8b44292021-06-08 01:27:53 +0000296 if (!session->setForServer(server,
297 sp<RpcServer::EventListener>::fromExisting(
298 static_cast<RpcServer::EventListener*>(
299 server.get())),
Steven Moreland01a6bad2021-06-11 00:59:20 +0000300 sessionId)) {
Steven Morelanda8b44292021-06-08 01:27:53 +0000301 ALOGE("Failed to attach server to session");
302 return;
303 }
Steven Morelanda63ff932021-05-12 00:03:15 +0000304
Steven Moreland01a6bad2021-06-11 00:59:20 +0000305 server->mSessions[sessionId] = session;
Steven Morelanda63ff932021-05-12 00:03:15 +0000306 } else {
Steven Moreland01a6bad2021-06-11 00:59:20 +0000307 auto it = server->mSessions.find(sessionId);
Yifan Hongb3005502021-05-19 15:37:00 -0700308 if (it == server->mSessions.end()) {
Steven Moreland01a6bad2021-06-11 00:59:20 +0000309 ALOGE("Cannot add thread, no record of session with ID %s",
310 sessionId.toString().c_str());
Steven Morelanda63ff932021-05-12 00:03:15 +0000311 return;
312 }
313 session = it->second;
314 }
Steven Moreland5802c2b2021-05-12 20:13:04 +0000315
Steven Moreland1b304292021-07-15 22:59:34 +0000316 if (incoming) {
Steven Morelandb86e26b2021-06-12 00:35:58 +0000317 LOG_ALWAYS_FATAL_IF(!session->addOutgoingConnection(std::move(clientFd), true),
Steven Moreland659416d2021-05-11 00:47:50 +0000318 "server state must already be initialized");
319 return;
320 }
321
Steven Moreland5802c2b2021-05-12 20:13:04 +0000322 detachGuard.Disable();
Steven Morelandc88b7fc2021-06-10 00:40:39 +0000323 session->preJoinThreadOwnership(std::move(thisThread));
Steven Morelanda63ff932021-05-12 00:03:15 +0000324 }
325
Steven Morelandc88b7fc2021-06-10 00:40:39 +0000326 auto setupResult = session->preJoinSetup(std::move(clientFd));
327
Steven Morelanda63ff932021-05-12 00:03:15 +0000328 // avoid strong cycle
329 server = nullptr;
Steven Morelanda63ff932021-05-12 00:03:15 +0000330
Steven Morelandc88b7fc2021-06-10 00:40:39 +0000331 RpcSession::join(std::move(session), std::move(setupResult));
Steven Morelanda63ff932021-05-12 00:03:15 +0000332}
333
Steven Moreland611d15f2021-05-01 01:28:27 +0000334bool RpcServer::setupSocketServer(const RpcSocketAddress& addr) {
Steven Moreland704fc1a2021-05-04 23:13:14 +0000335 LOG_RPC_DETAIL("Setting up socket server %s", addr.toString().c_str());
Yifan Hong0eb5a672021-05-12 18:00:25 -0700336 LOG_ALWAYS_FATAL_IF(hasServer(), "Each RpcServer can only have one server.");
Steven Moreland611d15f2021-05-01 01:28:27 +0000337
338 unique_fd serverFd(
339 TEMP_FAILURE_RETRY(socket(addr.addr()->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)));
340 if (serverFd == -1) {
341 ALOGE("Could not create socket: %s", strerror(errno));
342 return false;
343 }
344
345 if (0 != TEMP_FAILURE_RETRY(bind(serverFd.get(), addr.addr(), addr.addrSize()))) {
346 int savedErrno = errno;
347 ALOGE("Could not bind socket at %s: %s", addr.toString().c_str(), strerror(savedErrno));
348 return false;
349 }
350
351 if (0 != TEMP_FAILURE_RETRY(listen(serverFd.get(), 1 /*backlog*/))) {
352 int savedErrno = errno;
353 ALOGE("Could not listen socket at %s: %s", addr.toString().c_str(), strerror(savedErrno));
354 return false;
355 }
356
Steven Moreland704fc1a2021-05-04 23:13:14 +0000357 LOG_RPC_DETAIL("Successfully setup socket server %s", addr.toString().c_str());
358
Yifan Hongc276f8d2021-05-13 17:13:44 -0700359 if (!setupExternalServer(std::move(serverFd))) {
360 ALOGE("Another thread has set up server while calling setupSocketServer. Race?");
361 return false;
362 }
Steven Moreland611d15f2021-05-01 01:28:27 +0000363 return true;
364}
365
Steven Moreland19fc9f72021-06-10 03:57:30 +0000366void RpcServer::onSessionLockedAllIncomingThreadsEnded(const sp<RpcSession>& session) {
Steven Morelandee78e762021-05-05 21:12:51 +0000367 auto id = session->mId;
368 LOG_ALWAYS_FATAL_IF(id == std::nullopt, "Server sessions must be initialized with ID");
Steven Moreland01a6bad2021-06-11 00:59:20 +0000369 LOG_RPC_DETAIL("Dropping session with address %s", id->toString().c_str());
Steven Morelandee78e762021-05-05 21:12:51 +0000370
371 std::lock_guard<std::mutex> _l(mLock);
372 auto it = mSessions.find(*id);
Steven Moreland01a6bad2021-06-11 00:59:20 +0000373 LOG_ALWAYS_FATAL_IF(it == mSessions.end(), "Bad state, unknown session id %s",
374 id->toString().c_str());
375 LOG_ALWAYS_FATAL_IF(it->second != session, "Bad state, session has id mismatch %s",
376 id->toString().c_str());
Steven Morelandee78e762021-05-05 21:12:51 +0000377 (void)mSessions.erase(it);
378}
379
Steven Moreland19fc9f72021-06-10 03:57:30 +0000380void RpcServer::onSessionIncomingThreadEnded() {
Steven Morelandee3f4662021-05-22 01:07:33 +0000381 mShutdownCv.notify_all();
382}
383
Yifan Hong0eb5a672021-05-12 18:00:25 -0700384bool RpcServer::hasServer() {
Yifan Hong00aeb762021-05-12 17:07:36 -0700385 LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
Yifan Hong0eb5a672021-05-12 18:00:25 -0700386 std::lock_guard<std::mutex> _l(mLock);
387 return mServer.ok();
388}
389
Yifan Hong00aeb762021-05-12 17:07:36 -0700390unique_fd RpcServer::releaseServer() {
391 LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
392 std::lock_guard<std::mutex> _l(mLock);
393 return std::move(mServer);
394}
395
396bool RpcServer::setupExternalServer(base::unique_fd serverFd) {
397 LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
398 std::lock_guard<std::mutex> _l(mLock);
399 if (mServer.ok()) {
400 ALOGE("Each RpcServer can only have one server.");
401 return false;
402 }
403 mServer = std::move(serverFd);
404 return true;
405}
406
Steven Moreland5553ac42020-11-11 02:14:45 +0000407} // namespace android