blob: e4ca6bcc4733f99a69a2eae27c5f15127e89c396 [file] [log] [blame]
Jesse Hallfc038bd2016-03-26 22:20:22 -07001/*
2 * Copyright 2016 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 "GpuService.h"
18
Jesse Hallc0b15772016-12-20 14:47:45 -080019#include <binder/IResultReceiver.h>
Jesse Hallfc038bd2016-03-26 22:20:22 -070020#include <binder/Parcel.h>
Jesse Hall8b0d55e2016-03-31 19:29:36 -070021#include <utils/String8.h>
22#include <vkjson.h>
Jesse Hallfc038bd2016-03-26 22:20:22 -070023
24namespace android {
25
Peiyong Lin2da74652018-11-01 10:34:57 -070026class BpGpuService : public BpInterface<IGpuService> {
Jesse Hallfc038bd2016-03-26 22:20:22 -070027public:
Chih-Hung Hsiehc4067912016-05-03 14:03:27 -070028 explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {}
Jesse Hallfc038bd2016-03-26 22:20:22 -070029};
30
31IMPLEMENT_META_INTERFACE(GpuService, "android.ui.IGpuService");
32
33status_t BnGpuService::onTransact(uint32_t code, const Parcel& data,
Peiyong Lin2da74652018-11-01 10:34:57 -070034 Parcel* reply, uint32_t flags) {
Jesse Hallc0b15772016-12-20 14:47:45 -080035 status_t status;
Jesse Hallfc038bd2016-03-26 22:20:22 -070036 switch (code) {
37 case SHELL_COMMAND_TRANSACTION: {
38 int in = data.readFileDescriptor();
39 int out = data.readFileDescriptor();
40 int err = data.readFileDescriptor();
Peiyong Lin2da74652018-11-01 10:34:57 -070041 std::vector<String16> args;
42 data.readString16Vector(&args);
Jesse Hallc0b15772016-12-20 14:47:45 -080043 sp<IBinder> unusedCallback;
44 sp<IResultReceiver> resultReceiver;
45 if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK)
46 return status;
47 if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK)
48 return status;
49 status = shellCommand(in, out, err, args);
50 if (resultReceiver != nullptr)
51 resultReceiver->send(status);
52 return OK;
Jesse Hallfc038bd2016-03-26 22:20:22 -070053 }
54
55 default:
56 return BBinder::onTransact(code, data, reply, flags);
57 }
58}
59
Jesse Hall8b0d55e2016-03-31 19:29:36 -070060namespace {
61 status_t cmd_help(int out);
62 status_t cmd_vkjson(int out, int err);
63}
64
Peiyong Lin2da74652018-11-01 10:34:57 -070065const char* const GpuService::SERVICE_NAME = "gpuservice";
Jesse Hallfc038bd2016-03-26 22:20:22 -070066
Peiyong Lin2da74652018-11-01 10:34:57 -070067GpuService::GpuService() = default;
Jesse Hallfc038bd2016-03-26 22:20:22 -070068
Jesse Hall8b0d55e2016-03-31 19:29:36 -070069status_t GpuService::shellCommand(int /*in*/, int out, int err,
Peiyong Lin2da74652018-11-01 10:34:57 -070070 std::vector<String16>& args) {
Jesse Hall8b0d55e2016-03-31 19:29:36 -070071 ALOGV("GpuService::shellCommand");
72 for (size_t i = 0, n = args.size(); i < n; i++)
73 ALOGV(" arg[%zu]: '%s'", i, String8(args[i]).string());
74
Jesse Hall3e26b132016-12-20 14:31:28 -080075 if (args.size() >= 1) {
76 if (args[0] == String16("vkjson"))
77 return cmd_vkjson(out, err);
78 if (args[0] == String16("help"))
79 return cmd_help(out);
80 }
81 // no command, or unrecognized command
82 cmd_help(err);
83 return BAD_VALUE;
Jesse Hallfc038bd2016-03-26 22:20:22 -070084}
85
Jesse Hall8b0d55e2016-03-31 19:29:36 -070086namespace {
87
88status_t cmd_help(int out) {
89 FILE* outs = fdopen(out, "w");
90 if (!outs) {
91 ALOGE("vkjson: failed to create out stream: %s (%d)", strerror(errno),
92 errno);
93 return BAD_VALUE;
94 }
95 fprintf(outs,
96 "GPU Service commands:\n"
Jesse Hall3841bf42016-06-12 15:08:28 -070097 " vkjson dump Vulkan properties as JSON\n");
Jesse Hall8b0d55e2016-03-31 19:29:36 -070098 fclose(outs);
99 return NO_ERROR;
100}
101
Jesse Hall3841bf42016-06-12 15:08:28 -0700102void vkjsonPrint(FILE* out) {
103 std::string json = VkJsonInstanceToJson(VkJsonGetInstance());
104 fwrite(json.data(), 1, json.size(), out);
105 fputc('\n', out);
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700106}
107
Jesse Hall3841bf42016-06-12 15:08:28 -0700108status_t cmd_vkjson(int out, int /*err*/) {
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700109 FILE* outs = fdopen(out, "w");
110 if (!outs) {
Jesse Hall3841bf42016-06-12 15:08:28 -0700111 int errnum = errno;
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700112 ALOGE("vkjson: failed to create output stream: %s", strerror(errnum));
113 return -errnum;
114 }
Jesse Hall3841bf42016-06-12 15:08:28 -0700115 vkjsonPrint(outs);
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700116 fclose(outs);
Jesse Hall3841bf42016-06-12 15:08:28 -0700117 return NO_ERROR;
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700118}
119
120} // anonymous namespace
121
Jesse Hallfc038bd2016-03-26 22:20:22 -0700122} // namespace android