Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 1 | /* |
Mathias Agopian | 002e1e5 | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 2 | * Copyright 2013 The Android Open Source Project |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 3 | * |
Mathias Agopian | 002e1e5 | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 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. |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 15 | */ |
Mathias Agopian | 002e1e5 | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 16 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 17 | #include <binder/Parcel.h> |
| 18 | #include <binder/ProcessState.h> |
| 19 | #include <binder/IServiceManager.h> |
Mathias Agopian | 002e1e5 | 2013-05-06 20:20:50 -0700 | [diff] [blame] | 20 | #include <binder/TextOutput.h> |
Marco Nelissen | b9ec70e | 2018-06-07 11:31:03 -0700 | [diff] [blame] | 21 | #include <cutils/ashmem.h> |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 22 | |
| 23 | #include <getopt.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <stdio.h> |
| 26 | #include <string.h> |
| 27 | #include <unistd.h> |
Marco Nelissen | b9ec70e | 2018-06-07 11:31:03 -0700 | [diff] [blame] | 28 | #include <sys/mman.h> |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 29 | #include <sys/time.h> |
Marco Nelissen | b9ec70e | 2018-06-07 11:31:03 -0700 | [diff] [blame] | 30 | #include <sys/types.h> |
| 31 | #include <sys/stat.h> |
| 32 | #include <fcntl.h> |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 33 | |
| 34 | using namespace android; |
| 35 | |
| 36 | void writeString16(Parcel& parcel, const char* string) |
| 37 | { |
Yi Kong | 19d5c00 | 2018-07-20 13:39:55 -0700 | [diff] [blame] | 38 | if (string != nullptr) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 39 | { |
| 40 | parcel.writeString16(String16(string)); |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | parcel.writeInt32(-1); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // get the name of the generic interface we hold a reference to |
| 49 | static String16 get_interface_name(sp<IBinder> service) |
| 50 | { |
Yi Kong | 19d5c00 | 2018-07-20 13:39:55 -0700 | [diff] [blame] | 51 | if (service != nullptr) { |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 52 | Parcel data, reply; |
Yifan Hong | 86cf053 | 2021-06-16 22:56:50 -0700 | [diff] [blame] | 53 | data.markForBinder(service); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 54 | status_t err = service->transact(IBinder::INTERFACE_TRANSACTION, data, &reply); |
| 55 | if (err == NO_ERROR) { |
| 56 | return reply.readString16(); |
| 57 | } |
| 58 | } |
| 59 | return String16(); |
| 60 | } |
| 61 | |
| 62 | static String8 good_old_string(const String16& src) |
| 63 | { |
| 64 | String8 name8; |
| 65 | char ch8[2]; |
| 66 | ch8[1] = 0; |
| 67 | for (unsigned j = 0; j < src.size(); j++) { |
| 68 | char16_t ch = src[j]; |
| 69 | if (ch < 128) ch8[0] = (char)ch; |
| 70 | name8.append(ch8); |
| 71 | } |
| 72 | return name8; |
| 73 | } |
| 74 | |
| 75 | int main(int argc, char* const argv[]) |
| 76 | { |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 77 | bool wantsUsage = false; |
| 78 | int result = 0; |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 79 | |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 80 | /* Strip path off the program name. */ |
| 81 | char* prog_name = basename(argv[0]); |
| 82 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 83 | while (1) { |
Martijn Coenen | 3def1f2 | 2017-04-07 10:46:57 -0700 | [diff] [blame] | 84 | int ic = getopt(argc, argv, "h?"); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 85 | if (ic < 0) |
| 86 | break; |
| 87 | |
| 88 | switch (ic) { |
| 89 | case 'h': |
| 90 | case '?': |
| 91 | wantsUsage = true; |
| 92 | break; |
| 93 | default: |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 94 | aerr << prog_name << ": Unknown option -" << ic << endl; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 95 | wantsUsage = true; |
| 96 | result = 10; |
| 97 | break; |
| 98 | } |
| 99 | } |
Martijn Coenen | 3def1f2 | 2017-04-07 10:46:57 -0700 | [diff] [blame] | 100 | #ifdef VENDORSERVICES |
| 101 | ProcessState::initWithDriver("/dev/vndbinder"); |
| 102 | #endif |
Yifan Hong | 86cf053 | 2021-06-16 22:56:50 -0700 | [diff] [blame] | 103 | #ifndef __ANDROID__ |
| 104 | setDefaultServiceManager(createRpcDelegateServiceManager({.maxOutgoingThreads = 1})); |
| 105 | #endif |
Martijn Coenen | d6480ca | 2017-04-05 14:16:12 -0700 | [diff] [blame] | 106 | sp<IServiceManager> sm = defaultServiceManager(); |
| 107 | fflush(stdout); |
Yi Kong | 19d5c00 | 2018-07-20 13:39:55 -0700 | [diff] [blame] | 108 | if (sm == nullptr) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 109 | aerr << prog_name << ": Unable to get default service manager!" << endl; |
Martijn Coenen | d6480ca | 2017-04-05 14:16:12 -0700 | [diff] [blame] | 110 | return 20; |
| 111 | } |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 112 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 113 | if (optind >= argc) { |
| 114 | wantsUsage = true; |
| 115 | } else if (!wantsUsage) { |
| 116 | if (strcmp(argv[optind], "check") == 0) { |
| 117 | optind++; |
| 118 | if (optind < argc) { |
| 119 | sp<IBinder> service = sm->checkService(String16(argv[optind])); |
| 120 | aout << "Service " << argv[optind] << |
Yi Kong | 19d5c00 | 2018-07-20 13:39:55 -0700 | [diff] [blame] | 121 | (service == nullptr ? ": not found" : ": found") << endl; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 122 | } else { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 123 | aerr << prog_name << ": No service specified for check" << endl; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 124 | wantsUsage = true; |
| 125 | result = 10; |
| 126 | } |
| 127 | } |
| 128 | else if (strcmp(argv[optind], "list") == 0) { |
| 129 | Vector<String16> services = sm->listServices(); |
| 130 | aout << "Found " << services.size() << " services:" << endl; |
| 131 | for (unsigned i = 0; i < services.size(); i++) { |
| 132 | String16 name = services[i]; |
| 133 | sp<IBinder> service = sm->checkService(name); |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 134 | aout << i |
| 135 | << "\t" << good_old_string(name) |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 136 | << ": [" << good_old_string(get_interface_name(service)) << "]" |
| 137 | << endl; |
| 138 | } |
| 139 | } else if (strcmp(argv[optind], "call") == 0) { |
| 140 | optind++; |
| 141 | if (optind+1 < argc) { |
| 142 | int serviceArg = optind; |
| 143 | sp<IBinder> service = sm->checkService(String16(argv[optind++])); |
| 144 | String16 ifName = get_interface_name(service); |
| 145 | int32_t code = atoi(argv[optind++]); |
Yi Kong | 19d5c00 | 2018-07-20 13:39:55 -0700 | [diff] [blame] | 146 | if (service != nullptr && ifName.size() > 0) { |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 147 | Parcel data, reply; |
Yifan Hong | 86cf053 | 2021-06-16 22:56:50 -0700 | [diff] [blame] | 148 | data.markForBinder(service); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 149 | |
| 150 | // the interface name is first |
| 151 | data.writeInterfaceToken(ifName); |
| 152 | |
| 153 | // then the rest of the call arguments |
| 154 | while (optind < argc) { |
| 155 | if (strcmp(argv[optind], "i32") == 0) { |
| 156 | optind++; |
| 157 | if (optind >= argc) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 158 | aerr << prog_name << ": no integer supplied for 'i32'" << endl; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 159 | wantsUsage = true; |
| 160 | result = 10; |
| 161 | break; |
| 162 | } |
| 163 | data.writeInt32(atoi(argv[optind++])); |
Jeff Brown | d46898f | 2015-04-06 19:42:43 -0700 | [diff] [blame] | 164 | } else if (strcmp(argv[optind], "i64") == 0) { |
| 165 | optind++; |
| 166 | if (optind >= argc) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 167 | aerr << prog_name << ": no integer supplied for 'i64'" << endl; |
Jeff Brown | d46898f | 2015-04-06 19:42:43 -0700 | [diff] [blame] | 168 | wantsUsage = true; |
| 169 | result = 10; |
| 170 | break; |
| 171 | } |
| 172 | data.writeInt64(atoll(argv[optind++])); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 173 | } else if (strcmp(argv[optind], "s16") == 0) { |
| 174 | optind++; |
| 175 | if (optind >= argc) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 176 | aerr << prog_name << ": no string supplied for 's16'" << endl; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 177 | wantsUsage = true; |
| 178 | result = 10; |
| 179 | break; |
| 180 | } |
| 181 | data.writeString16(String16(argv[optind++])); |
Jeff Brown | d46898f | 2015-04-06 19:42:43 -0700 | [diff] [blame] | 182 | } else if (strcmp(argv[optind], "f") == 0) { |
| 183 | optind++; |
| 184 | if (optind >= argc) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 185 | aerr << prog_name << ": no number supplied for 'f'" << endl; |
Jeff Brown | d46898f | 2015-04-06 19:42:43 -0700 | [diff] [blame] | 186 | wantsUsage = true; |
| 187 | result = 10; |
| 188 | break; |
| 189 | } |
| 190 | data.writeFloat(atof(argv[optind++])); |
| 191 | } else if (strcmp(argv[optind], "d") == 0) { |
| 192 | optind++; |
| 193 | if (optind >= argc) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 194 | aerr << prog_name << ": no number supplied for 'd'" << endl; |
Jeff Brown | d46898f | 2015-04-06 19:42:43 -0700 | [diff] [blame] | 195 | wantsUsage = true; |
| 196 | result = 10; |
| 197 | break; |
| 198 | } |
| 199 | data.writeDouble(atof(argv[optind++])); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 200 | } else if (strcmp(argv[optind], "null") == 0) { |
| 201 | optind++; |
Yi Kong | 19d5c00 | 2018-07-20 13:39:55 -0700 | [diff] [blame] | 202 | data.writeStrongBinder(nullptr); |
Marco Nelissen | b9ec70e | 2018-06-07 11:31:03 -0700 | [diff] [blame] | 203 | } else if (strcmp(argv[optind], "fd") == 0) { |
| 204 | optind++; |
| 205 | if (optind >= argc) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 206 | aerr << prog_name << ": no path supplied for 'fd'" << endl; |
Marco Nelissen | b9ec70e | 2018-06-07 11:31:03 -0700 | [diff] [blame] | 207 | wantsUsage = true; |
| 208 | result = 10; |
| 209 | break; |
| 210 | } |
| 211 | const char *path = argv[optind++]; |
| 212 | int fd = open(path, O_RDONLY); |
| 213 | if (fd < 0) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 214 | aerr << prog_name << ": could not open '" << path << "'" << endl; |
Marco Nelissen | b9ec70e | 2018-06-07 11:31:03 -0700 | [diff] [blame] | 215 | wantsUsage = true; |
| 216 | result = 10; |
| 217 | break; |
| 218 | } |
| 219 | data.writeFileDescriptor(fd, true /* take ownership */); |
| 220 | } else if (strcmp(argv[optind], "afd") == 0) { |
| 221 | optind++; |
| 222 | if (optind >= argc) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 223 | aerr << prog_name << ": no path supplied for 'afd'" << endl; |
Marco Nelissen | b9ec70e | 2018-06-07 11:31:03 -0700 | [diff] [blame] | 224 | wantsUsage = true; |
| 225 | result = 10; |
| 226 | break; |
| 227 | } |
| 228 | const char *path = argv[optind++]; |
| 229 | int fd = open(path, O_RDONLY); |
| 230 | struct stat statbuf; |
| 231 | if (fd < 0 || fstat(fd, &statbuf) != 0) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 232 | aerr << prog_name << ": could not open or stat" |
| 233 | << " '" << path << "'" << endl; |
Marco Nelissen | b9ec70e | 2018-06-07 11:31:03 -0700 | [diff] [blame] | 234 | wantsUsage = true; |
| 235 | result = 10; |
| 236 | break; |
| 237 | } |
| 238 | int afd = ashmem_create_region("test", statbuf.st_size); |
| 239 | void* ptr = mmap(NULL, statbuf.st_size, |
| 240 | PROT_READ | PROT_WRITE, MAP_SHARED, afd, 0); |
Yifan Hong | 86cf053 | 2021-06-16 22:56:50 -0700 | [diff] [blame] | 241 | (void)read(fd, ptr, statbuf.st_size); |
Marco Nelissen | b9ec70e | 2018-06-07 11:31:03 -0700 | [diff] [blame] | 242 | close(fd); |
| 243 | data.writeFileDescriptor(afd, true /* take ownership */); |
| 244 | } else if (strcmp(argv[optind], "nfd") == 0) { |
| 245 | optind++; |
| 246 | if (optind >= argc) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 247 | aerr << prog_name << ": no file descriptor supplied for" |
| 248 | << " 'nfd'" << endl; |
Marco Nelissen | b9ec70e | 2018-06-07 11:31:03 -0700 | [diff] [blame] | 249 | wantsUsage = true; |
| 250 | result = 10; |
| 251 | break; |
| 252 | } |
| 253 | data.writeFileDescriptor( |
| 254 | atoi(argv[optind++]), true /* take ownership */); |
| 255 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 256 | } else if (strcmp(argv[optind], "intent") == 0) { |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 257 | |
| 258 | char* action = nullptr; |
| 259 | char* dataArg = nullptr; |
| 260 | char* type = nullptr; |
| 261 | int launchFlags = 0; |
| 262 | char* component = nullptr; |
| 263 | int categoryCount = 0; |
| 264 | char* categories[16]; |
| 265 | |
| 266 | char* context1 = nullptr; |
| 267 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 268 | optind++; |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 269 | |
| 270 | while (optind < argc) |
| 271 | { |
| 272 | char* key = strtok_r(argv[optind], "=", &context1); |
| 273 | char* value = strtok_r(nullptr, "=", &context1); |
| 274 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 275 | // we have reached the end of the XXX=XXX args. |
Yi Kong | 19d5c00 | 2018-07-20 13:39:55 -0700 | [diff] [blame] | 276 | if (key == nullptr) break; |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 277 | |
| 278 | if (strcmp(key, "action") == 0) |
| 279 | { |
| 280 | action = value; |
| 281 | } |
| 282 | else if (strcmp(key, "data") == 0) |
| 283 | { |
| 284 | dataArg = value; |
| 285 | } |
| 286 | else if (strcmp(key, "type") == 0) |
| 287 | { |
| 288 | type = value; |
| 289 | } |
| 290 | else if (strcmp(key, "launchFlags") == 0) |
| 291 | { |
| 292 | launchFlags = atoi(value); |
| 293 | } |
| 294 | else if (strcmp(key, "component") == 0) |
| 295 | { |
| 296 | component = value; |
| 297 | } |
| 298 | else if (strcmp(key, "categories") == 0) |
| 299 | { |
| 300 | char* context2 = nullptr; |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 301 | categories[categoryCount] = strtok_r(value, ",", &context2); |
| 302 | |
| 303 | while (categories[categoryCount] != nullptr) |
| 304 | { |
| 305 | categoryCount++; |
| 306 | categories[categoryCount] = strtok_r(nullptr, ",", &context2); |
| 307 | } |
| 308 | } |
| 309 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 310 | optind++; |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 313 | writeString16(data, action); |
| 314 | writeString16(data, dataArg); |
| 315 | writeString16(data, type); |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 316 | data.writeInt32(launchFlags); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 317 | writeString16(data, component); |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 318 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 319 | if (categoryCount > 0) |
| 320 | { |
| 321 | data.writeInt32(categoryCount); |
| 322 | for (int i = 0 ; i < categoryCount ; i++) |
| 323 | { |
| 324 | writeString16(data, categories[i]); |
| 325 | } |
| 326 | } |
| 327 | else |
| 328 | { |
| 329 | data.writeInt32(0); |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 332 | // for now just set the extra field to be null. |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 333 | data.writeInt32(-1); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 334 | } else { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 335 | aerr << prog_name << ": unknown option " << argv[optind] << endl; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 336 | wantsUsage = true; |
| 337 | result = 10; |
| 338 | break; |
| 339 | } |
| 340 | } |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 341 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 342 | service->transact(code, data, &reply); |
| 343 | aout << "Result: " << reply << endl; |
| 344 | } else { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 345 | aerr << prog_name << ": Service " << argv[serviceArg] |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 346 | << " does not exist" << endl; |
| 347 | result = 10; |
| 348 | } |
| 349 | } else { |
| 350 | if (optind < argc) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 351 | aerr << prog_name << ": No service specified for call" << endl; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 352 | } else { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 353 | aerr << prog_name << ": No code specified for call" << endl; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 354 | } |
| 355 | wantsUsage = true; |
| 356 | result = 10; |
| 357 | } |
| 358 | } else { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 359 | aerr << prog_name << ": Unknown command " << argv[optind] << endl; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 360 | wantsUsage = true; |
| 361 | result = 10; |
| 362 | } |
| 363 | } |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 364 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 365 | if (wantsUsage) { |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 366 | aout << "Usage: " << prog_name << " [-h|-?]\n" |
| 367 | " " << prog_name << " list\n" |
| 368 | " " << prog_name << " check SERVICE\n" |
| 369 | " " << prog_name << " call SERVICE CODE [i32 N | i64 N | f N | d N | s16 STR" |
| 370 | " | null | fd f | nfd n | afd f ] ...\n" |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 371 | "Options:\n" |
Jeff Brown | d46898f | 2015-04-06 19:42:43 -0700 | [diff] [blame] | 372 | " i32: Write the 32-bit integer N into the send parcel.\n" |
| 373 | " i64: Write the 64-bit integer N into the send parcel.\n" |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 374 | " f: Write the 32-bit single-precision number N into the send parcel.\n" |
| 375 | " d: Write the 64-bit double-precision number N into the send parcel.\n" |
Marco Nelissen | b9ec70e | 2018-06-07 11:31:03 -0700 | [diff] [blame] | 376 | " s16: Write the UTF-16 string STR into the send parcel.\n" |
| 377 | " null: Write a null binder into the send parcel.\n" |
Tony Guo | 51cbe7e | 2021-10-15 14:00:07 +0800 | [diff] [blame^] | 378 | " fd: Write a file descriptor for the file f into the send parcel.\n" |
| 379 | " nfd: Write the file descriptor n into the send parcel.\n" |
| 380 | " afd: Write an ashmem file descriptor for a region containing the data from\n" |
| 381 | " file f into the send parcel.\n"; |
| 382 | // " intent: Write an Intent into the send parcel. ARGS can be\n" |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 383 | // " action=STR data=STR type=STR launchFlags=INT component=STR categories=STR[,STR,...]\n"; |
| 384 | return result; |
| 385 | } |
Marco Nelissen | 07e95a8 | 2019-07-16 08:50:21 -0700 | [diff] [blame] | 386 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 387 | return result; |
| 388 | } |
| 389 | |