Skip to content

Commit 69c85a2

Browse files
author
Android Build Coastguard Worker
committed
Snap for 12748980 from f09d630 to 25Q1-release
Change-Id: I5357423ba9f8f005a218089011c7b63c570af729
2 parents 18ceff0 + f09d630 commit 69c85a2

29 files changed

Lines changed: 1237 additions & 38 deletions

cmds/idlcli/Android.bp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ cc_library {
5050
"vibrator/CommandAlwaysOnEnable.cpp",
5151
"vibrator/CommandCompose.cpp",
5252
"vibrator/CommandComposePwle.cpp",
53+
"vibrator/CommandGetFrequencyToOutputAccelerationMap.cpp",
5354
"vibrator/CommandGetBandwidthAmplitudeMap.cpp",
5455
"vibrator/CommandGetCapabilities.cpp",
5556
"vibrator/CommandGetCompositionDelayMax.cpp",
@@ -72,6 +73,11 @@ cc_library {
7273
"vibrator/CommandSetExternalControl.cpp",
7374
"vibrator/CommandSupportsAmplitudeControl.cpp",
7475
"vibrator/CommandSupportsExternalControl.cpp",
76+
"vibrator/CommandGetPwleV2PrimitiveDurationMaxMillis.cpp",
77+
"vibrator/CommandGetPwleV2CompositionSizeMax.cpp",
78+
"vibrator/CommandGetPwleV2PrimitiveDurationMinMillis.cpp",
79+
"vibrator/CommandComposePwleV2.cpp",
80+
"vibrator/CommandPerformVendorEffect.cpp",
7581
],
7682
visibility: [":__subpackages__"],
7783
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Copyright (C) 2024 The Android Open Source Project *
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
#include <stdlib.h>
17+
18+
#include <charconv>
19+
20+
#include "utils.h"
21+
#include "vibrator.h"
22+
23+
namespace android {
24+
namespace idlcli {
25+
26+
class CommandVibrator;
27+
28+
namespace vibrator {
29+
30+
using aidl::CompositePwleV2;
31+
using aidl::PwleV2Primitive;
32+
33+
class CommandComposePwleV2 : public Command {
34+
std::string getDescription() const override { return "Compose normalized PWLE vibration."; }
35+
36+
std::string getUsageSummary() const override {
37+
return "[options] <time> <frequency> <amplitude> ...";
38+
}
39+
40+
UsageDetails getUsageDetails() const override {
41+
UsageDetails details{
42+
{"-b", {"Block for duration of vibration."}},
43+
{"<time>", {"Segment duration in milliseconds"}},
44+
{"<frequency>", {"Target frequency in Hz"}},
45+
{"<amplitude>", {"Target amplitude in [0.0, 1.0]"}},
46+
{"...", {"May repeat multiple times."}},
47+
};
48+
return details;
49+
}
50+
51+
Status doArgs(Args& args) override {
52+
while (args.get<std::string>().value_or("").find("-") == 0) {
53+
auto opt = *args.pop<std::string>();
54+
if (opt == "--") {
55+
break;
56+
} else if (opt == "-b") {
57+
mBlocking = true;
58+
} else {
59+
std::cerr << "Invalid Option '" << opt << "'!" << std::endl;
60+
return USAGE;
61+
}
62+
}
63+
64+
if (args.empty()) {
65+
std::cerr << "Missing arguments! Please see usage" << std::endl;
66+
return USAGE;
67+
}
68+
69+
while (!args.empty()) {
70+
PwleV2Primitive segment;
71+
72+
if (auto timeMs = args.pop<decltype(segment.timeMillis)>();
73+
timeMs && *timeMs >= 0 && *timeMs <= 0x7ffff) {
74+
segment.timeMillis = *timeMs;
75+
std::cout << "Time: " << segment.timeMillis << std::endl;
76+
} else {
77+
std::cerr << "Missing or Invalid Time!" << std::endl;
78+
return USAGE;
79+
}
80+
81+
if (auto frequencyHz = args.pop<decltype(segment.frequencyHz)>();
82+
frequencyHz && *frequencyHz >= 30 && *frequencyHz <= 300) {
83+
segment.frequencyHz = *frequencyHz;
84+
std::cout << "Frequency: " << segment.frequencyHz << std::endl;
85+
} else {
86+
std::cerr << "Missing or Invalid Frequency!" << std::endl;
87+
return USAGE;
88+
}
89+
90+
if (auto amplitude = args.pop<decltype(segment.amplitude)>();
91+
amplitude && *amplitude >= 0 && *amplitude <= 1.0) {
92+
segment.amplitude = *amplitude;
93+
std::cout << "Amplitude: " << segment.amplitude << std::endl;
94+
} else {
95+
std::cerr << "Missing or Invalid Amplitude!" << std::endl;
96+
return USAGE;
97+
}
98+
99+
mCompositePwle.pwlePrimitives.emplace_back(std::move(segment));
100+
}
101+
102+
if (!args.empty()) {
103+
std::cerr << "Unexpected Arguments!" << std::endl;
104+
return USAGE;
105+
}
106+
107+
return OK;
108+
}
109+
110+
Status doMain(Args&& /*args*/) override {
111+
auto hal = getHal<aidl::IVibrator>();
112+
113+
if (!hal) {
114+
return UNAVAILABLE;
115+
}
116+
117+
ABinderProcess_setThreadPoolMaxThreadCount(1);
118+
ABinderProcess_startThreadPool();
119+
120+
std::shared_ptr<VibratorCallback> callback;
121+
122+
if (mBlocking) {
123+
callback = ndk::SharedRefBase::make<VibratorCallback>();
124+
}
125+
126+
auto status = hal->call(&aidl::IVibrator::composePwleV2, mCompositePwle, callback);
127+
128+
if (status.isOk() && callback) {
129+
callback->waitForComplete();
130+
}
131+
132+
std::cout << "Status: " << status.getDescription() << std::endl;
133+
134+
return status.isOk() ? OK : ERROR;
135+
}
136+
137+
bool mBlocking;
138+
CompositePwleV2 mCompositePwle;
139+
};
140+
141+
static const auto Command =
142+
CommandRegistry<CommandVibrator>::Register<CommandComposePwleV2>("composePwleV2");
143+
144+
} // namespace vibrator
145+
} // namespace idlcli
146+
} // namespace android
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (C) 2024 The Android Open Source Project *
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
#include "utils.h"
17+
#include "vibrator.h"
18+
19+
namespace android {
20+
namespace idlcli {
21+
22+
class CommandVibrator;
23+
24+
namespace vibrator {
25+
26+
using aidl::FrequencyAccelerationMapEntry;
27+
28+
class CommandGetFrequencyToOutputAccelerationMap : public Command {
29+
std::string getDescription() const override {
30+
return "Retrieves vibrator frequency to output acceleration map.";
31+
}
32+
33+
std::string getUsageSummary() const override { return ""; }
34+
35+
UsageDetails getUsageDetails() const override {
36+
UsageDetails details{};
37+
return details;
38+
}
39+
40+
Status doArgs(Args& args) override {
41+
if (!args.empty()) {
42+
std::cerr << "Unexpected Arguments!" << std::endl;
43+
return USAGE;
44+
}
45+
return OK;
46+
}
47+
48+
Status doMain(Args&& /*args*/) override {
49+
std::string statusStr;
50+
std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap;
51+
Status ret;
52+
53+
if (auto hal = getHal<aidl::IVibrator>()) {
54+
auto status = hal->call(&aidl::IVibrator::getFrequencyToOutputAccelerationMap,
55+
&frequencyToOutputAccelerationMap);
56+
statusStr = status.getDescription();
57+
ret = (status.isOk() ? OK : ERROR);
58+
} else {
59+
return UNAVAILABLE;
60+
}
61+
62+
std::cout << "Status: " << statusStr << std::endl;
63+
std::cout << "Frequency to Output Amplitude Map: " << std::endl;
64+
for (auto& entry : frequencyToOutputAccelerationMap) {
65+
std::cout << entry.frequencyHz << " " << entry.maxOutputAccelerationGs << std::endl;
66+
}
67+
68+
return ret;
69+
}
70+
};
71+
72+
static const auto Command =
73+
CommandRegistry<CommandVibrator>::Register<CommandGetFrequencyToOutputAccelerationMap>(
74+
"getFrequencyToOutputAccelerationMap");
75+
76+
} // namespace vibrator
77+
} // namespace idlcli
78+
} // namespace android
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (C) 2024 The Android Open Source Project *
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
#include "utils.h"
17+
#include "vibrator.h"
18+
19+
namespace android {
20+
namespace idlcli {
21+
22+
class CommandVibrator;
23+
24+
namespace vibrator {
25+
26+
class CommandGetPwleV2CompositionSizeMax : public Command {
27+
std::string getDescription() const override {
28+
return "Retrieves vibrator PwleV2 max composition size.";
29+
}
30+
31+
std::string getUsageSummary() const override { return ""; }
32+
33+
UsageDetails getUsageDetails() const override {
34+
UsageDetails details{};
35+
return details;
36+
}
37+
38+
Status doArgs(Args& args) override {
39+
if (!args.empty()) {
40+
std::cerr << "Unexpected Arguments!" << std::endl;
41+
return USAGE;
42+
}
43+
return OK;
44+
}
45+
46+
Status doMain(Args&& /*args*/) override {
47+
std::string statusStr;
48+
int32_t maxSize;
49+
Status ret;
50+
51+
if (auto hal = getHal<aidl::IVibrator>()) {
52+
auto status = hal->call(&aidl::IVibrator::getPwleV2CompositionSizeMax, &maxSize);
53+
statusStr = status.getDescription();
54+
ret = status.isOk() ? OK : ERROR;
55+
} else {
56+
return UNAVAILABLE;
57+
}
58+
59+
std::cout << "Status: " << statusStr << std::endl;
60+
std::cout << "Max Size: " << maxSize << std::endl;
61+
62+
return ret;
63+
}
64+
};
65+
66+
static const auto Command =
67+
CommandRegistry<CommandVibrator>::Register<CommandGetPwleV2CompositionSizeMax>(
68+
"getPwleV2CompositionSizeMax");
69+
70+
} // namespace vibrator
71+
} // namespace idlcli
72+
} // namespace android
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (C) 2024 The Android Open Source Project *
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
#include "utils.h"
17+
#include "vibrator.h"
18+
19+
namespace android {
20+
namespace idlcli {
21+
22+
class CommandVibrator;
23+
24+
namespace vibrator {
25+
26+
class CommandGetPwleV2PrimitiveDurationMaxMillis : public Command {
27+
std::string getDescription() const override {
28+
return "Retrieves vibrator PwleV2 max primitive duration in milliseconds.";
29+
}
30+
31+
std::string getUsageSummary() const override { return ""; }
32+
33+
UsageDetails getUsageDetails() const override {
34+
UsageDetails details{};
35+
return details;
36+
}
37+
38+
Status doArgs(Args& args) override {
39+
if (!args.empty()) {
40+
std::cerr << "Unexpected Arguments!" << std::endl;
41+
return USAGE;
42+
}
43+
return OK;
44+
}
45+
46+
Status doMain(Args&& /*args*/) override {
47+
std::string statusStr;
48+
int32_t maxDurationMs;
49+
Status ret;
50+
51+
if (auto hal = getHal<aidl::IVibrator>()) {
52+
auto status = hal->call(&aidl::IVibrator::getPwleV2PrimitiveDurationMaxMillis,
53+
&maxDurationMs);
54+
statusStr = status.getDescription();
55+
ret = status.isOk() ? OK : ERROR;
56+
} else {
57+
return UNAVAILABLE;
58+
}
59+
60+
std::cout << "Status: " << statusStr << std::endl;
61+
std::cout << "Primitive duration max: " << maxDurationMs << " ms" << std::endl;
62+
63+
return ret;
64+
}
65+
};
66+
67+
static const auto Command =
68+
CommandRegistry<CommandVibrator>::Register<CommandGetPwleV2PrimitiveDurationMaxMillis>(
69+
"getPwleV2PrimitiveDurationMaxMillis");
70+
71+
} // namespace vibrator
72+
} // namespace idlcli
73+
} // namespace android

0 commit comments

Comments
 (0)