Skip to content

Commit 3efb014

Browse files
committed
Remove IVibrator HIDL dependencies from idlcli
Android Q is now no longer supported for launching or upgrading devices in Android V so the vibrator HIDL HAL versions no longer needs to be supported by the platform. Bug: 308452413 Test: manually using the command line Flag: EXEMPT internal command line tools Change-Id: I5ac0d7d895996d095f990e3b78d9c80e73bcaf97
1 parent 69e737f commit 3efb014

34 files changed

Lines changed: 253 additions & 461 deletions

cmds/idlcli/Android.bp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@ cc_defaults {
2525
name: "idlcli-defaults",
2626
shared_libs: [
2727
"android.hardware.vibrator-V3-ndk",
28-
"android.hardware.vibrator@1.0",
29-
"android.hardware.vibrator@1.1",
30-
"android.hardware.vibrator@1.2",
31-
"android.hardware.vibrator@1.3",
3228
"libbase",
3329
"libbinder_ndk",
34-
"libhidlbase",
3530
"liblog",
3631
"libutils",
3732
],

cmds/idlcli/utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define FRAMEWORK_NATIVE_CMDS_IDLCLI_UTILS_H_
1919

2020
#include <android/binder_enums.h>
21-
#include <hidl/HidlSupport.h>
2221

2322
#include <iomanip>
2423
#include <iostream>

cmds/idlcli/vibrator.h

Lines changed: 6 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -22,102 +22,30 @@
2222
#include <aidl/android/hardware/vibrator/IVibratorManager.h>
2323
#include <android/binder_manager.h>
2424
#include <android/binder_process.h>
25-
#include <android/hardware/vibrator/1.3/IVibrator.h>
2625

2726
#include "IdlCli.h"
2827
#include "utils.h"
2928

3029
namespace android {
3130

32-
using hardware::Return;
31+
using ::aidl::android::hardware::vibrator::IVibrator;
3332
using idlcli::IdlCli;
3433

35-
static constexpr int NUM_TRIES = 2;
36-
37-
// Creates a Return<R> with STATUS::EX_NULL_POINTER.
38-
template <class R>
39-
inline R NullptrStatus() {
40-
using ::android::hardware::Status;
41-
return Status::fromExceptionCode(Status::EX_NULL_POINTER);
42-
}
43-
44-
template <>
45-
inline ndk::ScopedAStatus NullptrStatus() {
46-
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_NULL_POINTER));
47-
}
48-
49-
template <typename I>
5034
inline auto getService(std::string name) {
51-
const auto instance = std::string() + I::descriptor + "/" + name;
35+
const auto instance = std::string() + IVibrator::descriptor + "/" + name;
5236
auto vibBinder = ndk::SpAIBinder(AServiceManager_checkService(instance.c_str()));
53-
return I::fromBinder(vibBinder);
54-
}
55-
56-
template <>
57-
inline auto getService<android::hardware::vibrator::V1_0::IVibrator>(std::string name) {
58-
return android::hardware::vibrator::V1_0::IVibrator::getService(name);
59-
}
60-
61-
template <>
62-
inline auto getService<android::hardware::vibrator::V1_1::IVibrator>(std::string name) {
63-
return android::hardware::vibrator::V1_1::IVibrator::getService(name);
64-
}
65-
66-
template <>
67-
inline auto getService<android::hardware::vibrator::V1_2::IVibrator>(std::string name) {
68-
return android::hardware::vibrator::V1_2::IVibrator::getService(name);
69-
}
70-
71-
template <>
72-
inline auto getService<android::hardware::vibrator::V1_3::IVibrator>(std::string name) {
73-
return android::hardware::vibrator::V1_3::IVibrator::getService(name);
37+
return IVibrator::fromBinder(vibBinder);
7438
}
7539

76-
template <typename I>
77-
using shared_ptr = std::invoke_result_t<decltype(getService<I>)&, std::string>;
78-
79-
template <typename I>
80-
class HalWrapper {
81-
public:
82-
static std::unique_ptr<HalWrapper> Create() {
83-
// Assume that if getService returns a nullptr, HAL is not available on the
84-
// device.
85-
const auto name = IdlCli::Get().getName();
86-
auto hal = getService<I>(name.empty() ? "default" : name);
87-
return hal ? std::unique_ptr<HalWrapper>(new HalWrapper(std::move(hal))) : nullptr;
88-
}
89-
90-
template <class R, class... Args0, class... Args1>
91-
R call(R (I::*fn)(Args0...), Args1&&... args1) {
92-
return (*mHal.*fn)(std::forward<Args1>(args1)...);
93-
}
94-
95-
private:
96-
HalWrapper(shared_ptr<I>&& hal) : mHal(std::move(hal)) {}
97-
98-
private:
99-
shared_ptr<I> mHal;
100-
};
101-
102-
template <typename I>
10340
static auto getHal() {
104-
static auto sHalWrapper = HalWrapper<I>::Create();
105-
return sHalWrapper.get();
106-
}
107-
108-
template <class R, class I, class... Args0, class... Args1>
109-
R halCall(R (I::*fn)(Args0...), Args1&&... args1) {
110-
auto hal = getHal<I>();
111-
return hal ? hal->call(fn, std::forward<Args1>(args1)...) : NullptrStatus<R>();
41+
// Assume that if getService returns a nullptr, HAL is not available on the device.
42+
const auto name = IdlCli::Get().getName();
43+
return getService(name.empty() ? "default" : name);
11244
}
11345

11446
namespace idlcli {
11547
namespace vibrator {
11648

117-
namespace V1_0 = ::android::hardware::vibrator::V1_0;
118-
namespace V1_1 = ::android::hardware::vibrator::V1_1;
119-
namespace V1_2 = ::android::hardware::vibrator::V1_2;
120-
namespace V1_3 = ::android::hardware::vibrator::V1_3;
12149
namespace aidl = ::aidl::android::hardware::vibrator;
12250

12351
class VibratorCallback : public aidl::BnVibratorCallback {

cmds/idlcli/vibrator/CommandAlwaysOnDisable.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,17 @@ class CommandAlwaysOnDisable : public Command {
5151
}
5252

5353
Status doMain(Args && /*args*/) override {
54-
std::string statusStr;
55-
Status ret;
54+
auto hal = getHal();
5655

57-
if (auto hal = getHal<aidl::IVibrator>()) {
58-
auto status = hal->call(&aidl::IVibrator::alwaysOnDisable, mId);
59-
60-
statusStr = status.getDescription();
61-
ret = status.isOk() ? OK : ERROR;
62-
} else {
56+
if (!hal) {
6357
return UNAVAILABLE;
6458
}
6559

66-
std::cout << "Status: " << statusStr << std::endl;
60+
auto status = hal->alwaysOnDisable(mId);
61+
62+
std::cout << "Status: " << status.getDescription() << std::endl;
6763

68-
return ret;
64+
return status.isOk() ? OK : ERROR;
6965
}
7066

7167
int32_t mId;

cmds/idlcli/vibrator/CommandAlwaysOnEnable.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,17 @@ class CommandAlwaysOnEnable : public Command {
7272
}
7373

7474
Status doMain(Args && /*args*/) override {
75-
std::string statusStr;
76-
Status ret;
75+
auto hal = getHal();
7776

78-
if (auto hal = getHal<aidl::IVibrator>()) {
79-
auto status = hal->call(&aidl::IVibrator::alwaysOnEnable, mId, mEffect, mStrength);
80-
81-
statusStr = status.getDescription();
82-
ret = status.isOk() ? OK : ERROR;
83-
} else {
77+
if (!hal) {
8478
return UNAVAILABLE;
8579
}
8680

87-
std::cout << "Status: " << statusStr << std::endl;
81+
auto status = hal->alwaysOnEnable(mId, mEffect, mStrength);
82+
83+
std::cout << "Status: " << status.getDescription() << std::endl;
8884

89-
return ret;
85+
return status.isOk() ? OK : ERROR;
9086
}
9187

9288
int32_t mId;

cmds/idlcli/vibrator/CommandCompose.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class CommandCompose : public Command {
8989
}
9090

9191
Status doMain(Args && /*args*/) override {
92-
auto hal = getHal<aidl::IVibrator>();
92+
auto hal = getHal();
9393

9494
if (!hal) {
9595
return UNAVAILABLE;
@@ -104,7 +104,7 @@ class CommandCompose : public Command {
104104
callback = ndk::SharedRefBase::make<VibratorCallback>();
105105
}
106106

107-
auto status = hal->call(&aidl::IVibrator::compose, mComposite, callback);
107+
auto status = hal->compose(mComposite, callback);
108108

109109
if (status.isOk() && callback) {
110110
callback->waitForComplete();

cmds/idlcli/vibrator/CommandComposePwle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class CommandComposePwle : public Command {
163163
}
164164

165165
Status doMain(Args && /*args*/) override {
166-
auto hal = getHal<aidl::IVibrator>();
166+
auto hal = getHal();
167167

168168
if (!hal) {
169169
return UNAVAILABLE;
@@ -178,7 +178,7 @@ class CommandComposePwle : public Command {
178178
callback = ndk::SharedRefBase::make<VibratorCallback>();
179179
}
180180

181-
auto status = hal->call(&aidl::IVibrator::composePwle, mCompositePwle, callback);
181+
auto status = hal->composePwle(mCompositePwle, callback);
182182

183183
if (status.isOk() && callback) {
184184
callback->waitForComplete();

cmds/idlcli/vibrator/CommandComposePwleV2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class CommandComposePwleV2 : public Command {
108108
}
109109

110110
Status doMain(Args&& /*args*/) override {
111-
auto hal = getHal<aidl::IVibrator>();
111+
auto hal = getHal();
112112

113113
if (!hal) {
114114
return UNAVAILABLE;
@@ -123,7 +123,7 @@ class CommandComposePwleV2 : public Command {
123123
callback = ndk::SharedRefBase::make<VibratorCallback>();
124124
}
125125

126-
auto status = hal->call(&aidl::IVibrator::composePwleV2, mCompositePwle, callback);
126+
auto status = hal->composePwleV2(mCompositePwle, callback);
127127

128128
if (status.isOk() && callback) {
129129
callback->waitForComplete();

cmds/idlcli/vibrator/CommandGetBandwidthAmplitudeMap.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,46 @@ class CommandGetBandwidthAmplitudeMap : public Command {
4444
}
4545

4646
Status doMain(Args && /*args*/) override {
47-
std::string statusStr;
47+
auto hal = getHal();
48+
49+
if (!hal) {
50+
return UNAVAILABLE;
51+
}
52+
4853
std::vector<float> bandwidthAmplitude;
4954
float frequencyMinimumHz;
5055
float frequencyResolutionHz;
51-
Status ret;
5256

53-
if (auto hal = getHal<aidl::IVibrator>()) {
54-
auto status =
55-
hal->call(&aidl::IVibrator::getBandwidthAmplitudeMap, &bandwidthAmplitude);
56-
statusStr = status.getDescription();
57-
ret = (status.isOk() ? OK : ERROR);
57+
auto status = hal->getBandwidthAmplitudeMap(&bandwidthAmplitude);
5858

59-
status = hal->call(&aidl::IVibrator::getFrequencyMinimum, &frequencyMinimumHz);
60-
ret = (status.isOk() ? OK : ERROR);
59+
if (!status.isOk()) {
60+
std::cout << "Status: " << status.getDescription() << std::endl;
61+
return ERROR;
62+
}
6163

62-
status =
63-
hal->call(&aidl::IVibrator::getFrequencyResolution, &frequencyResolutionHz);
64-
ret = (status.isOk() ? OK : ERROR);
65-
} else {
66-
return UNAVAILABLE;
64+
status = hal->getFrequencyMinimum(&frequencyMinimumHz);
65+
66+
if (!status.isOk()) {
67+
std::cout << "Status: " << status.getDescription() << std::endl;
68+
return ERROR;
6769
}
6870

69-
std::cout << "Status: " << statusStr << std::endl;
71+
status = hal->getFrequencyResolution(&frequencyResolutionHz);
72+
73+
if (!status.isOk()) {
74+
std::cout << "Status: " << status.getDescription() << std::endl;
75+
return ERROR;
76+
}
77+
78+
std::cout << "Status: " << status.getDescription() << std::endl;
7079
std::cout << "Bandwidth Amplitude Map: " << std::endl;
7180
float frequency = frequencyMinimumHz;
7281
for (auto &e : bandwidthAmplitude) {
7382
std::cout << frequency << ":" << e << std::endl;
7483
frequency += frequencyResolutionHz;
7584
}
7685

77-
return ret;
86+
return OK;
7887
}
7988
};
8089

cmds/idlcli/vibrator/CommandGetCapabilities.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,19 @@ class CommandGetCapabilities : public Command {
4242
}
4343

4444
Status doMain(Args && /*args*/) override {
45-
std::string statusStr;
46-
int32_t cap;
47-
Status ret;
45+
auto hal = getHal();
4846

49-
if (auto hal = getHal<aidl::IVibrator>()) {
50-
auto status = hal->call(&aidl::IVibrator::getCapabilities, &cap);
51-
statusStr = status.getDescription();
52-
ret = status.isOk() ? OK : ERROR;
53-
} else {
47+
if (!hal) {
5448
return UNAVAILABLE;
5549
}
5650

57-
std::cout << "Status: " << statusStr << std::endl;
51+
int32_t cap;
52+
auto status = hal->getCapabilities(&cap);
53+
54+
std::cout << "Status: " << status.getDescription() << std::endl;
5855
std::cout << "Capabilities: " << std::bitset<32>(cap) << std::endl;
5956

60-
return ret;
57+
return status.isOk() ? OK : ERROR;
6158
}
6259
};
6360

0 commit comments

Comments
 (0)