Vibrator.cpp 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  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. #include "Vibrator.h"
  17. #include <glob.h>
  18. #include <hardware/hardware.h>
  19. #include <hardware/vibrator.h>
  20. #include <log/log.h>
  21. #include <stdio.h>
  22. #include <utils/Trace.h>
  23. #include <cinttypes>
  24. #include <cmath>
  25. #include <fstream>
  26. #include <iostream>
  27. #include <sstream>
  28. #include <ctime>
  29. #include <chrono>
  30. #include "CapoDetector.h"
  31. #ifndef ARRAY_SIZE
  32. #define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0]))
  33. #endif
  34. #ifdef LOG_TAG
  35. #undef LOG_TAG
  36. #define LOG_TAG "Vibrator"
  37. #endif
  38. using CapoDetector = android::chre::CapoDetector;
  39. namespace aidl {
  40. namespace android {
  41. namespace hardware {
  42. namespace vibrator {
  43. static constexpr uint8_t FF_CUSTOM_DATA_LEN = 2;
  44. static constexpr uint16_t FF_CUSTOM_DATA_LEN_MAX_COMP = 2044; // (COMPOSE_SIZE_MAX + 1) * 8 + 4
  45. static constexpr uint16_t FF_CUSTOM_DATA_LEN_MAX_PWLE = 2302;
  46. static constexpr uint32_t WAVEFORM_DOUBLE_CLICK_SILENCE_MS = 100;
  47. static constexpr uint32_t WAVEFORM_LONG_VIBRATION_THRESHOLD_MS = 50;
  48. static constexpr uint8_t VOLTAGE_SCALE_MAX = 100;
  49. static constexpr int8_t MAX_COLD_START_LATENCY_MS = 6; // I2C Transaction + DSP Return-From-Standby
  50. static constexpr uint32_t MIN_ON_OFF_INTERVAL_US = 8500; // SVC initialization time
  51. static constexpr int8_t MAX_PAUSE_TIMING_ERROR_MS = 1; // ALERT Irq Handling
  52. static constexpr uint32_t MAX_TIME_MS = UINT16_MAX;
  53. static constexpr auto ASYNC_COMPLETION_TIMEOUT = std::chrono::milliseconds(100);
  54. static constexpr auto POLLING_TIMEOUT = 20;
  55. static constexpr int32_t COMPOSE_DELAY_MAX_MS = 10000;
  56. /* nsections is 8 bits. Need to preserve 1 section for the first delay before the first effect. */
  57. static constexpr int32_t COMPOSE_SIZE_MAX = 254;
  58. static constexpr int32_t COMPOSE_PWLE_SIZE_MAX_DEFAULT = 127;
  59. // Measured resonant frequency, f0_measured, is represented by Q10.14 fixed
  60. // point format on cs40l26 devices. The expression to calculate f0 is:
  61. // f0 = f0_measured / 2^Q14_BIT_SHIFT
  62. // See the LRA Calibration Support documentation for more details.
  63. static constexpr int32_t Q14_BIT_SHIFT = 14;
  64. // Measured Q factor, q_measured, is represented by Q8.16 fixed
  65. // point format on cs40l26 devices. The expression to calculate q is:
  66. // q = q_measured / 2^Q16_BIT_SHIFT
  67. // See the LRA Calibration Support documentation for more details.
  68. static constexpr int32_t Q16_BIT_SHIFT = 16;
  69. static constexpr int32_t COMPOSE_PWLE_PRIMITIVE_DURATION_MAX_MS = 16383;
  70. static constexpr uint32_t WT_LEN_CALCD = 0x00800000;
  71. static constexpr uint8_t PWLE_CHIRP_BIT = 0x8; // Dynamic/static frequency and voltage
  72. static constexpr uint8_t PWLE_BRAKE_BIT = 0x4;
  73. static constexpr uint8_t PWLE_AMP_REG_BIT = 0x2;
  74. static constexpr float PWLE_LEVEL_MIN = 0.0;
  75. static constexpr float PWLE_LEVEL_MAX = 1.0;
  76. static constexpr float CS40L26_PWLE_LEVEL_MIX = -1.0;
  77. static constexpr float CS40L26_PWLE_LEVEL_MAX = 0.9995118;
  78. static constexpr float PWLE_FREQUENCY_RESOLUTION_HZ = 1.00;
  79. static constexpr float PWLE_FREQUENCY_MIN_HZ = 1.00;
  80. static constexpr float PWLE_FREQUENCY_MAX_HZ = 1000.00;
  81. static constexpr float PWLE_BW_MAP_SIZE =
  82. 1 + ((PWLE_FREQUENCY_MAX_HZ - PWLE_FREQUENCY_MIN_HZ) / PWLE_FREQUENCY_RESOLUTION_HZ);
  83. #ifndef DISABLE_ADAPTIVE_HAPTICS_FEATURE
  84. static constexpr bool mAdaptiveHapticsEnable = true;
  85. #else
  86. static constexpr bool mAdaptiveHapticsEnable = false;
  87. #endif /* DISABLE_ADAPTIVE_HAPTICS_FEATURE */
  88. static sp<CapoDetector> vibeContextListener;
  89. uint8_t mCapoDeviceState = 0;
  90. uint32_t mLastFaceUpEvent = 0;
  91. uint32_t mLastEffectPlayedTime = 0;
  92. float mLastPlayedScale = 0;
  93. static uint32_t getCurrentTimeInMs(void) {
  94. return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  95. }
  96. static void capoEventCallback(uint8_t eventId) {
  97. ALOGD("Vibrator %s, From: 0x%x To: 0x%x", __func__, mCapoDeviceState, (uint32_t)eventId);
  98. // Record the last moment we were in FACE_UP state
  99. if (mCapoDeviceState == capo::PositionType::ON_TABLE_FACE_UP ||
  100. eventId == capo::PositionType::ON_TABLE_FACE_UP) {
  101. mLastFaceUpEvent = getCurrentTimeInMs();
  102. }
  103. mCapoDeviceState = eventId;
  104. }
  105. static uint8_t getDeviceState(void) {
  106. return mCapoDeviceState;
  107. }
  108. enum WaveformBankID : uint8_t {
  109. RAM_WVFRM_BANK,
  110. ROM_WVFRM_BANK,
  111. OWT_WVFRM_BANK,
  112. };
  113. enum WaveformIndex : uint16_t {
  114. /* Physical waveform */
  115. WAVEFORM_LONG_VIBRATION_EFFECT_INDEX = 0,
  116. WAVEFORM_RESERVED_INDEX_1 = 1,
  117. WAVEFORM_CLICK_INDEX = 2,
  118. WAVEFORM_SHORT_VIBRATION_EFFECT_INDEX = 3,
  119. WAVEFORM_THUD_INDEX = 4,
  120. WAVEFORM_SPIN_INDEX = 5,
  121. WAVEFORM_QUICK_RISE_INDEX = 6,
  122. WAVEFORM_SLOW_RISE_INDEX = 7,
  123. WAVEFORM_QUICK_FALL_INDEX = 8,
  124. WAVEFORM_LIGHT_TICK_INDEX = 9,
  125. WAVEFORM_LOW_TICK_INDEX = 10,
  126. WAVEFORM_RESERVED_MFG_1,
  127. WAVEFORM_RESERVED_MFG_2,
  128. WAVEFORM_RESERVED_MFG_3,
  129. WAVEFORM_MAX_PHYSICAL_INDEX,
  130. /* OWT waveform */
  131. WAVEFORM_COMPOSE = WAVEFORM_MAX_PHYSICAL_INDEX,
  132. WAVEFORM_PWLE,
  133. /*
  134. * Refer to <linux/input.h>, the WAVEFORM_MAX_INDEX must not exceed 96.
  135. * #define FF_GAIN 0x60 // 96 in decimal
  136. * #define FF_MAX_EFFECTS FF_GAIN
  137. */
  138. WAVEFORM_MAX_INDEX,
  139. };
  140. std::vector<CompositePrimitive> defaultSupportedPrimitives = {
  141. ndk::enum_range<CompositePrimitive>().begin(), ndk::enum_range<CompositePrimitive>().end()};
  142. enum vibe_state {
  143. VIBE_STATE_STOPPED = 0,
  144. VIBE_STATE_HAPTIC,
  145. VIBE_STATE_ASP,
  146. };
  147. std::mutex mActiveId_mutex; // protects mActiveId
  148. static int min(int x, int y) {
  149. return x < y ? x : y;
  150. }
  151. static int floatToUint16(float input, uint16_t *output, float scale, float min, float max) {
  152. if (input < min || input > max)
  153. return -ERANGE;
  154. *output = roundf(input * scale);
  155. return 0;
  156. }
  157. struct dspmem_chunk {
  158. uint8_t *head;
  159. uint8_t *current;
  160. uint8_t *max;
  161. int bytes;
  162. uint32_t cache;
  163. int cachebits;
  164. };
  165. static dspmem_chunk *dspmem_chunk_create(void *data, int size) {
  166. auto ch = new dspmem_chunk{
  167. .head = reinterpret_cast<uint8_t *>(data),
  168. .current = reinterpret_cast<uint8_t *>(data),
  169. .max = reinterpret_cast<uint8_t *>(data) + size,
  170. };
  171. return ch;
  172. }
  173. static bool dspmem_chunk_end(struct dspmem_chunk *ch) {
  174. return ch->current == ch->max;
  175. }
  176. static int dspmem_chunk_bytes(struct dspmem_chunk *ch) {
  177. return ch->bytes;
  178. }
  179. static int dspmem_chunk_write(struct dspmem_chunk *ch, int nbits, uint32_t val) {
  180. int nwrite, i;
  181. nwrite = min(24 - ch->cachebits, nbits);
  182. ch->cache <<= nwrite;
  183. ch->cache |= val >> (nbits - nwrite);
  184. ch->cachebits += nwrite;
  185. nbits -= nwrite;
  186. if (ch->cachebits == 24) {
  187. if (dspmem_chunk_end(ch))
  188. return -ENOSPC;
  189. ch->cache &= 0xFFFFFF;
  190. for (i = 0; i < sizeof(ch->cache); i++, ch->cache <<= 8)
  191. *ch->current++ = (ch->cache & 0xFF000000) >> 24;
  192. ch->bytes += sizeof(ch->cache);
  193. ch->cachebits = 0;
  194. }
  195. if (nbits)
  196. return dspmem_chunk_write(ch, nbits, val);
  197. return 0;
  198. }
  199. static int dspmem_chunk_flush(struct dspmem_chunk *ch) {
  200. if (!ch->cachebits)
  201. return 0;
  202. return dspmem_chunk_write(ch, 24 - ch->cachebits, 0);
  203. }
  204. Vibrator::Vibrator(std::unique_ptr<HwApi> hwapi, std::unique_ptr<HwCal> hwcal)
  205. : mHwApi(std::move(hwapi)), mHwCal(std::move(hwcal)), mAsyncHandle(std::async([] {})) {
  206. int32_t longFrequencyShift;
  207. std::string caldata{8, '0'};
  208. uint32_t calVer;
  209. const char *inputEventName = std::getenv("INPUT_EVENT_NAME");
  210. const char *inputEventPathName = std::getenv("INPUT_EVENT_PATH");
  211. if ((strstr(inputEventName, "cs40l26") != nullptr) ||
  212. (strstr(inputEventName, "cs40l26_dual_input") != nullptr)) {
  213. glob_t inputEventPaths;
  214. int fd = -1;
  215. int ret;
  216. uint32_t val = 0;
  217. char str[20] = {0x00};
  218. for (uint8_t retry = 0; retry < 10; retry++) {
  219. ret = glob(inputEventPathName, 0, nullptr, &inputEventPaths);
  220. if (ret) {
  221. ALOGE("Fail to get input event paths (%d): %s", errno, strerror(errno));
  222. } else {
  223. for (int i = 0; i < inputEventPaths.gl_pathc; i++) {
  224. fd = TEMP_FAILURE_RETRY(open(inputEventPaths.gl_pathv[i], O_RDWR));
  225. if (fd > 0) {
  226. if (ioctl(fd, EVIOCGBIT(0, sizeof(val)), &val) > 0 &&
  227. (val & (1 << EV_FF)) && ioctl(fd, EVIOCGNAME(sizeof(str)), &str) > 0 &&
  228. strstr(str, inputEventName) != nullptr) {
  229. mInputFd.reset(fd);
  230. ALOGI("Control %s through %s", inputEventName,
  231. inputEventPaths.gl_pathv[i]);
  232. break;
  233. }
  234. close(fd);
  235. }
  236. }
  237. }
  238. if (ret == 0) {
  239. globfree(&inputEventPaths);
  240. }
  241. if (mInputFd.ok()) {
  242. break;
  243. }
  244. sleep(1);
  245. ALOGW("Retry #%d to search in %zu input devices.", retry, inputEventPaths.gl_pathc);
  246. }
  247. if (!mInputFd.ok()) {
  248. ALOGE("Fail to get an input event with name %s", inputEventName);
  249. }
  250. } else {
  251. ALOGE("The input name %s is not cs40l26_input or cs40l26_dual_input", inputEventName);
  252. }
  253. mFfEffects.resize(WAVEFORM_MAX_INDEX);
  254. mEffectDurations.resize(WAVEFORM_MAX_INDEX);
  255. mEffectDurations = {
  256. 1000, 100, 30, 1000, 300, 130, 150, 500, 100, 15, 20, 1000, 1000, 1000,
  257. }; /* 11+3 waveforms. The duration must < UINT16_MAX */
  258. uint8_t effectIndex;
  259. for (effectIndex = 0; effectIndex < WAVEFORM_MAX_INDEX; effectIndex++) {
  260. if (effectIndex < WAVEFORM_MAX_PHYSICAL_INDEX) {
  261. /* Initialize physical waveforms. */
  262. mFfEffects[effectIndex] = {
  263. .type = FF_PERIODIC,
  264. .id = -1,
  265. .replay.length = static_cast<uint16_t>(mEffectDurations[effectIndex]),
  266. .u.periodic.waveform = FF_CUSTOM,
  267. .u.periodic.custom_data = new int16_t[2]{RAM_WVFRM_BANK, effectIndex},
  268. .u.periodic.custom_len = FF_CUSTOM_DATA_LEN,
  269. };
  270. // Bypass the waveform update due to different input name
  271. if ((strstr(inputEventName, "cs40l26") != nullptr) ||
  272. (strstr(inputEventName, "cs40l26_dual_input") != nullptr)) {
  273. if (!mHwApi->setFFEffect(
  274. mInputFd, &mFfEffects[effectIndex],
  275. static_cast<uint16_t>(mFfEffects[effectIndex].replay.length))) {
  276. ALOGE("Failed upload effect %d (%d): %s", effectIndex, errno, strerror(errno));
  277. }
  278. }
  279. if (mFfEffects[effectIndex].id != effectIndex) {
  280. ALOGW("Unexpected effect index: %d -> %d", effectIndex, mFfEffects[effectIndex].id);
  281. }
  282. } else {
  283. /* Initiate placeholders for OWT effects. */
  284. mFfEffects[effectIndex] = {
  285. .type = FF_PERIODIC,
  286. .id = -1,
  287. .replay.length = 0,
  288. .u.periodic.waveform = FF_CUSTOM,
  289. .u.periodic.custom_data = nullptr,
  290. .u.periodic.custom_len = 0,
  291. };
  292. }
  293. }
  294. if (mHwCal->getF0(&caldata)) {
  295. mHwApi->setF0(caldata);
  296. }
  297. if (mHwCal->getRedc(&caldata)) {
  298. mHwApi->setRedc(caldata);
  299. }
  300. if (mHwCal->getQ(&caldata)) {
  301. mHwApi->setQ(caldata);
  302. }
  303. mHwCal->getLongFrequencyShift(&longFrequencyShift);
  304. if (longFrequencyShift > 0) {
  305. mF0Offset = longFrequencyShift * std::pow(2, 14);
  306. } else if (longFrequencyShift < 0) {
  307. mF0Offset = std::pow(2, 24) - std::abs(longFrequencyShift) * std::pow(2, 14);
  308. } else {
  309. mF0Offset = 0;
  310. }
  311. mHwCal->getVersion(&calVer);
  312. if (calVer == 2) {
  313. mHwCal->getTickVolLevels(&mTickEffectVol);
  314. mHwCal->getClickVolLevels(&mClickEffectVol);
  315. mHwCal->getLongVolLevels(&mLongEffectVol);
  316. } else {
  317. ALOGD("Unsupported calibration version: %u!", calVer);
  318. }
  319. mHwApi->setF0CompEnable(mHwCal->isF0CompEnabled());
  320. mHwApi->setRedcCompEnable(mHwCal->isRedcCompEnabled());
  321. mIsUnderExternalControl = false;
  322. mIsChirpEnabled = mHwCal->isChirpEnabled();
  323. mHwCal->getSupportedPrimitives(&mSupportedPrimitivesBits);
  324. if (mSupportedPrimitivesBits > 0) {
  325. for (auto e : defaultSupportedPrimitives) {
  326. if (mSupportedPrimitivesBits & (1 << uint32_t(e))) {
  327. mSupportedPrimitives.emplace_back(e);
  328. }
  329. }
  330. } else {
  331. for (auto e : defaultSupportedPrimitives) {
  332. mSupportedPrimitivesBits |= (1 << uint32_t(e));
  333. }
  334. mSupportedPrimitives = defaultSupportedPrimitives;
  335. }
  336. mHwApi->setMinOnOffInterval(MIN_ON_OFF_INTERVAL_US);
  337. if (mAdaptiveHapticsEnable) {
  338. vibeContextListener = CapoDetector::start();
  339. if (vibeContextListener == nullptr) {
  340. ALOGE("%s, CapoDetector failed to start", __func__);
  341. } else {
  342. ALOGD("%s, CapoDetector started successfully! NanoAppID: 0x%x", __func__,
  343. (uint32_t)vibeContextListener->getNanoppAppId());
  344. vibeContextListener->setCallback(capoEventCallback);
  345. ALOGD("%s, CapoDetector Set Callback function from vibe", __func__);
  346. }
  347. }
  348. }
  349. ndk::ScopedAStatus Vibrator::getCapabilities(int32_t *_aidl_return) {
  350. ATRACE_NAME("Vibrator::getCapabilities");
  351. int32_t ret = IVibrator::CAP_ON_CALLBACK | IVibrator::CAP_PERFORM_CALLBACK |
  352. IVibrator::CAP_AMPLITUDE_CONTROL | IVibrator::CAP_GET_RESONANT_FREQUENCY |
  353. IVibrator::CAP_GET_Q_FACTOR;
  354. if (hasHapticAlsaDevice()) {
  355. ret |= IVibrator::CAP_EXTERNAL_CONTROL;
  356. } else {
  357. ALOGE("No haptics ALSA device");
  358. }
  359. if (mHwApi->hasOwtFreeSpace()) {
  360. ret |= IVibrator::CAP_COMPOSE_EFFECTS;
  361. if (mIsChirpEnabled) {
  362. ret |= IVibrator::CAP_FREQUENCY_CONTROL | IVibrator::CAP_COMPOSE_PWLE_EFFECTS;
  363. }
  364. }
  365. *_aidl_return = ret;
  366. return ndk::ScopedAStatus::ok();
  367. }
  368. ndk::ScopedAStatus Vibrator::off() {
  369. ATRACE_NAME("Vibrator::off");
  370. bool ret{true};
  371. const std::scoped_lock<std::mutex> lock(mActiveId_mutex);
  372. if (mActiveId >= 0) {
  373. /* Stop the active effect. */
  374. if (!mHwApi->setFFPlay(mInputFd, mActiveId, false)) {
  375. ALOGE("Failed to stop effect %d (%d): %s", mActiveId, errno, strerror(errno));
  376. ret = false;
  377. }
  378. if ((mActiveId >= WAVEFORM_MAX_PHYSICAL_INDEX) &&
  379. (!mHwApi->eraseOwtEffect(mInputFd, mActiveId, &mFfEffects))) {
  380. ALOGE("Failed to clean up the composed effect %d", mActiveId);
  381. ret = false;
  382. }
  383. } else {
  384. ALOGV("Vibrator is already off");
  385. }
  386. mActiveId = -1;
  387. setGlobalAmplitude(false);
  388. if (mF0Offset) {
  389. mHwApi->setF0Offset(0);
  390. }
  391. if (ret) {
  392. return ndk::ScopedAStatus::ok();
  393. } else {
  394. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
  395. }
  396. }
  397. ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs,
  398. const std::shared_ptr<IVibratorCallback> &callback) {
  399. ATRACE_NAME("Vibrator::on");
  400. if (timeoutMs > MAX_TIME_MS) {
  401. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  402. }
  403. const uint16_t index = (timeoutMs < WAVEFORM_LONG_VIBRATION_THRESHOLD_MS)
  404. ? WAVEFORM_SHORT_VIBRATION_EFFECT_INDEX
  405. : WAVEFORM_LONG_VIBRATION_EFFECT_INDEX;
  406. if (MAX_COLD_START_LATENCY_MS <= MAX_TIME_MS - timeoutMs) {
  407. timeoutMs += MAX_COLD_START_LATENCY_MS;
  408. }
  409. setGlobalAmplitude(true);
  410. if (mF0Offset) {
  411. mHwApi->setF0Offset(mF0Offset);
  412. }
  413. return on(timeoutMs, index, nullptr /*ignored*/, callback);
  414. }
  415. ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength,
  416. const std::shared_ptr<IVibratorCallback> &callback,
  417. int32_t *_aidl_return) {
  418. ATRACE_NAME("Vibrator::perform");
  419. return performEffect(effect, strength, callback, _aidl_return);
  420. }
  421. ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect> *_aidl_return) {
  422. *_aidl_return = {Effect::TEXTURE_TICK, Effect::TICK, Effect::CLICK, Effect::HEAVY_CLICK,
  423. Effect::DOUBLE_CLICK};
  424. return ndk::ScopedAStatus::ok();
  425. }
  426. ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) {
  427. ATRACE_NAME("Vibrator::setAmplitude");
  428. if (amplitude <= 0.0f || amplitude > 1.0f) {
  429. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  430. }
  431. mLongEffectScale = amplitude;
  432. if (!isUnderExternalControl()) {
  433. return setGlobalAmplitude(true);
  434. } else {
  435. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  436. }
  437. }
  438. ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled) {
  439. ATRACE_NAME("Vibrator::setExternalControl");
  440. setGlobalAmplitude(enabled);
  441. if (mHasHapticAlsaDevice || mConfigHapticAlsaDeviceDone || hasHapticAlsaDevice()) {
  442. if (!mHwApi->setHapticPcmAmp(&mHapticPcm, enabled, mCard, mDevice)) {
  443. ALOGE("Failed to %s haptic pcm device: %d", (enabled ? "enable" : "disable"), mDevice);
  444. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
  445. }
  446. } else {
  447. ALOGE("No haptics ALSA device");
  448. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
  449. }
  450. mIsUnderExternalControl = enabled;
  451. return ndk::ScopedAStatus::ok();
  452. }
  453. ndk::ScopedAStatus Vibrator::getCompositionDelayMax(int32_t *maxDelayMs) {
  454. ATRACE_NAME("Vibrator::getCompositionDelayMax");
  455. *maxDelayMs = COMPOSE_DELAY_MAX_MS;
  456. return ndk::ScopedAStatus::ok();
  457. }
  458. ndk::ScopedAStatus Vibrator::getCompositionSizeMax(int32_t *maxSize) {
  459. ATRACE_NAME("Vibrator::getCompositionSizeMax");
  460. *maxSize = COMPOSE_SIZE_MAX;
  461. return ndk::ScopedAStatus::ok();
  462. }
  463. ndk::ScopedAStatus Vibrator::getSupportedPrimitives(std::vector<CompositePrimitive> *supported) {
  464. *supported = mSupportedPrimitives;
  465. return ndk::ScopedAStatus::ok();
  466. }
  467. ndk::ScopedAStatus Vibrator::getPrimitiveDuration(CompositePrimitive primitive,
  468. int32_t *durationMs) {
  469. ndk::ScopedAStatus status;
  470. uint32_t effectIndex;
  471. if (primitive != CompositePrimitive::NOOP) {
  472. status = getPrimitiveDetails(primitive, &effectIndex);
  473. if (!status.isOk()) {
  474. return status;
  475. }
  476. *durationMs = mEffectDurations[effectIndex];
  477. } else {
  478. *durationMs = 0;
  479. }
  480. return ndk::ScopedAStatus::ok();
  481. }
  482. ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect> &composite,
  483. const std::shared_ptr<IVibratorCallback> &callback) {
  484. ATRACE_NAME("Vibrator::compose");
  485. uint16_t size;
  486. uint16_t nextEffectDelay;
  487. auto ch = dspmem_chunk_create(new uint8_t[FF_CUSTOM_DATA_LEN_MAX_COMP]{0x00},
  488. FF_CUSTOM_DATA_LEN_MAX_COMP);
  489. if (composite.size() > COMPOSE_SIZE_MAX || composite.empty()) {
  490. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  491. }
  492. /* Check if there is a wait before the first effect. */
  493. nextEffectDelay = composite.front().delayMs;
  494. if (nextEffectDelay > COMPOSE_DELAY_MAX_MS || nextEffectDelay < 0) {
  495. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  496. } else if (nextEffectDelay > 0) {
  497. size = composite.size() + 1;
  498. } else {
  499. size = composite.size();
  500. }
  501. dspmem_chunk_write(ch, 8, 0); /* Padding */
  502. dspmem_chunk_write(ch, 8, (uint8_t)(0xFF & size)); /* nsections */
  503. dspmem_chunk_write(ch, 8, 0); /* repeat */
  504. uint8_t header_count = dspmem_chunk_bytes(ch);
  505. /* Insert 1 section for a wait before the first effect. */
  506. if (nextEffectDelay) {
  507. dspmem_chunk_write(ch, 32, 0); /* amplitude, index, repeat & flags */
  508. dspmem_chunk_write(ch, 16, (uint16_t)(0xFFFF & nextEffectDelay)); /* delay */
  509. }
  510. for (uint32_t i_curr = 0, i_next = 1; i_curr < composite.size(); i_curr++, i_next++) {
  511. auto &e_curr = composite[i_curr];
  512. uint32_t effectIndex = 0;
  513. uint32_t effectVolLevel = 0;
  514. if (e_curr.scale < 0.0f || e_curr.scale > 1.0f) {
  515. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  516. }
  517. if (e_curr.primitive != CompositePrimitive::NOOP) {
  518. ndk::ScopedAStatus status;
  519. status = getPrimitiveDetails(e_curr.primitive, &effectIndex);
  520. if (!status.isOk()) {
  521. return status;
  522. }
  523. effectVolLevel = intensityToVolLevel(e_curr.scale, effectIndex);
  524. }
  525. /* Fetch the next composite effect delay and fill into the current section */
  526. nextEffectDelay = 0;
  527. if (i_next < composite.size()) {
  528. auto &e_next = composite[i_next];
  529. int32_t delay = e_next.delayMs;
  530. if (delay > COMPOSE_DELAY_MAX_MS || delay < 0) {
  531. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  532. }
  533. nextEffectDelay = delay;
  534. }
  535. if (effectIndex == 0 && nextEffectDelay == 0) {
  536. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  537. }
  538. dspmem_chunk_write(ch, 8, (uint8_t)(0xFF & effectVolLevel)); /* amplitude */
  539. dspmem_chunk_write(ch, 8, (uint8_t)(0xFF & effectIndex)); /* index */
  540. dspmem_chunk_write(ch, 8, 0); /* repeat */
  541. dspmem_chunk_write(ch, 8, 0); /* flags */
  542. dspmem_chunk_write(ch, 16, (uint16_t)(0xFFFF & nextEffectDelay)); /* delay */
  543. }
  544. dspmem_chunk_flush(ch);
  545. if (header_count == dspmem_chunk_bytes(ch)) {
  546. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  547. } else {
  548. return performEffect(WAVEFORM_MAX_INDEX /*ignored*/, VOLTAGE_SCALE_MAX /*ignored*/, ch,
  549. callback);
  550. }
  551. }
  552. ndk::ScopedAStatus Vibrator::on(uint32_t timeoutMs, uint32_t effectIndex, dspmem_chunk *ch,
  553. const std::shared_ptr<IVibratorCallback> &callback) {
  554. ndk::ScopedAStatus status = ndk::ScopedAStatus::ok();
  555. if (effectIndex >= FF_MAX_EFFECTS) {
  556. ALOGE("Invalid waveform index %d", effectIndex);
  557. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  558. }
  559. if (mAsyncHandle.wait_for(ASYNC_COMPLETION_TIMEOUT) != std::future_status::ready) {
  560. ALOGE("Previous vibration pending: prev: %d, curr: %d", mActiveId, effectIndex);
  561. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
  562. }
  563. if (ch) {
  564. /* Upload OWT effect. */
  565. if (ch->head == nullptr) {
  566. ALOGE("Invalid OWT bank");
  567. delete ch;
  568. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  569. }
  570. bool isPwle = (*reinterpret_cast<uint16_t *>(ch->head) != 0x0000);
  571. effectIndex = isPwle ? WAVEFORM_PWLE : WAVEFORM_COMPOSE;
  572. uint32_t freeBytes;
  573. mHwApi->getOwtFreeSpace(&freeBytes);
  574. if (dspmem_chunk_bytes(ch) > freeBytes) {
  575. ALOGE("Invalid OWT length: Effect %d: %d > %d!", effectIndex, dspmem_chunk_bytes(ch),
  576. freeBytes);
  577. delete ch;
  578. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  579. }
  580. int errorStatus;
  581. if (!mHwApi->uploadOwtEffect(mInputFd, ch->head, dspmem_chunk_bytes(ch),
  582. &mFfEffects[effectIndex], &effectIndex, &errorStatus)) {
  583. delete ch;
  584. ALOGE("Invalid uploadOwtEffect");
  585. return ndk::ScopedAStatus::fromExceptionCode(errorStatus);
  586. }
  587. delete ch;
  588. } else if (effectIndex == WAVEFORM_SHORT_VIBRATION_EFFECT_INDEX ||
  589. effectIndex == WAVEFORM_LONG_VIBRATION_EFFECT_INDEX) {
  590. /* Update duration for long/short vibration. */
  591. mFfEffects[effectIndex].replay.length = static_cast<uint16_t>(timeoutMs);
  592. if (!mHwApi->setFFEffect(mInputFd, &mFfEffects[effectIndex],
  593. static_cast<uint16_t>(timeoutMs))) {
  594. ALOGE("Failed to edit effect %d (%d): %s", effectIndex, errno, strerror(errno));
  595. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
  596. }
  597. }
  598. const std::scoped_lock<std::mutex> lock(mActiveId_mutex);
  599. mActiveId = effectIndex;
  600. /* Play the event now. */
  601. if (!mHwApi->setFFPlay(mInputFd, effectIndex, true)) {
  602. ALOGE("Failed to play effect %d (%d): %s", effectIndex, errno, strerror(errno));
  603. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
  604. }
  605. mAsyncHandle = std::async(&Vibrator::waitForComplete, this, callback);
  606. return ndk::ScopedAStatus::ok();
  607. }
  608. uint16_t Vibrator::amplitudeToScale(float amplitude, float maximum, bool scalable) {
  609. float ratio = 100; /* Unit: % */
  610. if (maximum != 0)
  611. ratio = amplitude / maximum * 100;
  612. if (maximum == 0 || ratio > 100)
  613. ratio = 100;
  614. if (scalable && mContextEnable & mAdaptiveHapticsEnable) {
  615. uint32_t now = getCurrentTimeInMs();
  616. uint32_t last_played = mLastEffectPlayedTime;
  617. float context_scale = 1.0;
  618. bool device_face_up = getDeviceState() == capo::PositionType::ON_TABLE_FACE_UP;
  619. float pre_scaled_ratio = ratio;
  620. mLastEffectPlayedTime = now;
  621. ALOGD("Vibrator Now: %u, Last: %u, ScaleTime: %u, Since? %d", now, mLastFaceUpEvent, mScaleTime, (now < mLastFaceUpEvent + mScaleTime));
  622. /* If the device is face-up or within the fade scaling range, find new scaling factor */
  623. if (device_face_up || now < mLastFaceUpEvent + mScaleTime) {
  624. /* Device is face-up, so we will scale it down. Start with highest scaling factor */
  625. context_scale = mScalingFactor <= 100 ? static_cast<float>(mScalingFactor)/100 : 1.0;
  626. if (mFadeEnable && mScaleTime > 0 && (context_scale < 1.0) && (now < mLastFaceUpEvent + mScaleTime) && !device_face_up) {
  627. float fade_scale = static_cast<float>(now - mLastFaceUpEvent)/static_cast<float>(mScaleTime);
  628. context_scale += ((1.0 - context_scale)*fade_scale);
  629. ALOGD("Vibrator fade scale applied: %f", fade_scale);
  630. }
  631. ratio *= context_scale;
  632. ALOGD("Vibrator adjusting for face-up: pre: %f, post: %f",
  633. std::round(pre_scaled_ratio), std::round(ratio));
  634. }
  635. /* If we haven't played an effect within the cooldown time, save the scaling factor */
  636. if ((now - last_played) > mScaleCooldown) {
  637. ALOGD("Vibrator updating lastplayed scale, old: %f, new: %f", mLastPlayedScale, context_scale);
  638. mLastPlayedScale = context_scale;
  639. }
  640. else {
  641. /* Override the scale to match previously played scale */
  642. ratio = mLastPlayedScale * pre_scaled_ratio;
  643. ALOGD("Vibrator repeating last scale: %f, new ratio: %f, duration since last: %u", mLastPlayedScale, ratio, (now - last_played));
  644. }
  645. }
  646. return std::round(ratio);
  647. }
  648. void Vibrator::updateContext() {
  649. mContextEnable = mHwApi->getContextEnable();
  650. mFadeEnable = mHwApi->getContextFadeEnable();
  651. mScalingFactor = mHwApi->getContextScale();
  652. mScaleTime = mHwApi->getContextSettlingTime();
  653. mScaleCooldown = mHwApi->getContextCooldownTime();
  654. }
  655. ndk::ScopedAStatus Vibrator::setEffectAmplitude(float amplitude, float maximum, bool scalable) {
  656. uint16_t scale;
  657. if (mAdaptiveHapticsEnable && scalable) {
  658. updateContext();
  659. }
  660. scale = amplitudeToScale(amplitude, maximum, scalable);
  661. if (!mHwApi->setFFGain(mInputFd, scale)) {
  662. ALOGE("Failed to set the gain to %u (%d): %s", scale, errno, strerror(errno));
  663. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
  664. }
  665. return ndk::ScopedAStatus::ok();
  666. }
  667. ndk::ScopedAStatus Vibrator::setGlobalAmplitude(bool set) {
  668. uint8_t amplitude = set ? roundf(mLongEffectScale * mLongEffectVol[1]) : VOLTAGE_SCALE_MAX;
  669. if (!set) {
  670. mLongEffectScale = 1.0; // Reset the scale for the later new effect.
  671. }
  672. return setEffectAmplitude(amplitude, VOLTAGE_SCALE_MAX, true);
  673. }
  674. ndk::ScopedAStatus Vibrator::getSupportedAlwaysOnEffects(std::vector<Effect> * /*_aidl_return*/) {
  675. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  676. }
  677. ndk::ScopedAStatus Vibrator::alwaysOnEnable(int32_t /*id*/, Effect /*effect*/,
  678. EffectStrength /*strength*/) {
  679. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  680. }
  681. ndk::ScopedAStatus Vibrator::alwaysOnDisable(int32_t /*id*/) {
  682. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  683. }
  684. ndk::ScopedAStatus Vibrator::getResonantFrequency(float *resonantFreqHz) {
  685. std::string caldata{8, '0'};
  686. if (!mHwCal->getF0(&caldata)) {
  687. ALOGE("Failed to get resonant frequency (%d): %s", errno, strerror(errno));
  688. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
  689. }
  690. *resonantFreqHz = static_cast<float>(std::stoul(caldata, nullptr, 16)) / (1 << Q14_BIT_SHIFT);
  691. return ndk::ScopedAStatus::ok();
  692. }
  693. ndk::ScopedAStatus Vibrator::getQFactor(float *qFactor) {
  694. std::string caldata{8, '0'};
  695. if (!mHwCal->getQ(&caldata)) {
  696. ALOGE("Failed to get q factor (%d): %s", errno, strerror(errno));
  697. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
  698. }
  699. *qFactor = static_cast<float>(std::stoul(caldata, nullptr, 16)) / (1 << Q16_BIT_SHIFT);
  700. return ndk::ScopedAStatus::ok();
  701. }
  702. ndk::ScopedAStatus Vibrator::getFrequencyResolution(float *freqResolutionHz) {
  703. int32_t capabilities;
  704. Vibrator::getCapabilities(&capabilities);
  705. if (capabilities & IVibrator::CAP_FREQUENCY_CONTROL) {
  706. *freqResolutionHz = PWLE_FREQUENCY_RESOLUTION_HZ;
  707. return ndk::ScopedAStatus::ok();
  708. } else {
  709. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  710. }
  711. }
  712. ndk::ScopedAStatus Vibrator::getFrequencyMinimum(float *freqMinimumHz) {
  713. int32_t capabilities;
  714. Vibrator::getCapabilities(&capabilities);
  715. if (capabilities & IVibrator::CAP_FREQUENCY_CONTROL) {
  716. *freqMinimumHz = PWLE_FREQUENCY_MIN_HZ;
  717. return ndk::ScopedAStatus::ok();
  718. } else {
  719. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  720. }
  721. }
  722. ndk::ScopedAStatus Vibrator::getBandwidthAmplitudeMap(std::vector<float> *_aidl_return) {
  723. // TODO(b/170919640): complete implementation
  724. int32_t capabilities;
  725. Vibrator::getCapabilities(&capabilities);
  726. if (capabilities & IVibrator::CAP_FREQUENCY_CONTROL) {
  727. std::vector<float> bandwidthAmplitudeMap(PWLE_BW_MAP_SIZE, 1.0);
  728. *_aidl_return = bandwidthAmplitudeMap;
  729. return ndk::ScopedAStatus::ok();
  730. } else {
  731. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  732. }
  733. }
  734. ndk::ScopedAStatus Vibrator::getPwlePrimitiveDurationMax(int32_t *durationMs) {
  735. int32_t capabilities;
  736. Vibrator::getCapabilities(&capabilities);
  737. if (capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS) {
  738. *durationMs = COMPOSE_PWLE_PRIMITIVE_DURATION_MAX_MS;
  739. return ndk::ScopedAStatus::ok();
  740. } else {
  741. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  742. }
  743. }
  744. ndk::ScopedAStatus Vibrator::getPwleCompositionSizeMax(int32_t *maxSize) {
  745. int32_t capabilities;
  746. Vibrator::getCapabilities(&capabilities);
  747. if (capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS) {
  748. *maxSize = COMPOSE_PWLE_SIZE_MAX_DEFAULT;
  749. return ndk::ScopedAStatus::ok();
  750. } else {
  751. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  752. }
  753. }
  754. ndk::ScopedAStatus Vibrator::getSupportedBraking(std::vector<Braking> *supported) {
  755. int32_t capabilities;
  756. Vibrator::getCapabilities(&capabilities);
  757. if (capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS) {
  758. *supported = {
  759. Braking::NONE,
  760. };
  761. return ndk::ScopedAStatus::ok();
  762. } else {
  763. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  764. }
  765. }
  766. static void resetPreviousEndAmplitudeEndFrequency(float *prevEndAmplitude,
  767. float *prevEndFrequency) {
  768. const float reset = -1.0;
  769. *prevEndAmplitude = reset;
  770. *prevEndFrequency = reset;
  771. }
  772. static void incrementIndex(int *index) {
  773. *index += 1;
  774. }
  775. static void constructPwleSegment(dspmem_chunk *ch, uint16_t delay, uint16_t amplitude,
  776. uint16_t frequency, uint8_t flags, uint32_t vbemfTarget = 0) {
  777. dspmem_chunk_write(ch, 16, delay);
  778. dspmem_chunk_write(ch, 12, amplitude);
  779. dspmem_chunk_write(ch, 12, frequency);
  780. /* feature flags to control the chirp, CLAB braking, back EMF amplitude regulation */
  781. dspmem_chunk_write(ch, 8, (flags | 1) << 4);
  782. if (flags & PWLE_AMP_REG_BIT) {
  783. dspmem_chunk_write(ch, 24, vbemfTarget); /* target back EMF voltage */
  784. }
  785. }
  786. static int constructActiveSegment(dspmem_chunk *ch, int duration, float amplitude, float frequency,
  787. bool chirp) {
  788. uint16_t delay = 0;
  789. uint16_t amp = 0;
  790. uint16_t freq = 0;
  791. uint8_t flags = 0x0;
  792. if ((floatToUint16(duration, &delay, 4, 0.0f, COMPOSE_PWLE_PRIMITIVE_DURATION_MAX_MS) < 0) ||
  793. (floatToUint16(amplitude, &amp, 2048, CS40L26_PWLE_LEVEL_MIX, CS40L26_PWLE_LEVEL_MAX) <
  794. 0) ||
  795. (floatToUint16(frequency, &freq, 4, PWLE_FREQUENCY_MIN_HZ, PWLE_FREQUENCY_MAX_HZ) < 0)) {
  796. ALOGE("Invalid argument: %d, %f, %f", duration, amplitude, frequency);
  797. return -ERANGE;
  798. }
  799. if (chirp) {
  800. flags |= PWLE_CHIRP_BIT;
  801. }
  802. constructPwleSegment(ch, delay, amp, freq, flags, 0 /*ignored*/);
  803. return 0;
  804. }
  805. static int constructBrakingSegment(dspmem_chunk *ch, int duration, Braking brakingType) {
  806. uint16_t delay = 0;
  807. uint16_t freq = 0;
  808. uint8_t flags = 0x00;
  809. if (floatToUint16(duration, &delay, 4, 0.0f, COMPOSE_PWLE_PRIMITIVE_DURATION_MAX_MS) < 0) {
  810. ALOGE("Invalid argument: %d", duration);
  811. return -ERANGE;
  812. }
  813. floatToUint16(PWLE_FREQUENCY_MIN_HZ, &freq, 4, PWLE_FREQUENCY_MIN_HZ, PWLE_FREQUENCY_MAX_HZ);
  814. if (static_cast<std::underlying_type<Braking>::type>(brakingType)) {
  815. flags |= PWLE_BRAKE_BIT;
  816. }
  817. constructPwleSegment(ch, delay, 0 /*ignored*/, freq, flags, 0 /*ignored*/);
  818. return 0;
  819. }
  820. static void updateWLength(dspmem_chunk *ch, uint32_t totalDuration) {
  821. totalDuration *= 8; /* Unit: 0.125 ms (since wlength played @ 8kHz). */
  822. totalDuration |= WT_LEN_CALCD; /* Bit 23 is for WT_LEN_CALCD; Bit 22 is for WT_INDEFINITE. */
  823. *(ch->head + 0) = (totalDuration >> 24) & 0xFF;
  824. *(ch->head + 1) = (totalDuration >> 16) & 0xFF;
  825. *(ch->head + 2) = (totalDuration >> 8) & 0xFF;
  826. *(ch->head + 3) = totalDuration & 0xFF;
  827. }
  828. static void updateNSection(dspmem_chunk *ch, int segmentIdx) {
  829. *(ch->head + 7) |= (0xF0 & segmentIdx) >> 4; /* Bit 4 to 7 */
  830. *(ch->head + 9) |= (0x0F & segmentIdx) << 4; /* Bit 3 to 0 */
  831. }
  832. ndk::ScopedAStatus Vibrator::composePwle(const std::vector<PrimitivePwle> &composite,
  833. const std::shared_ptr<IVibratorCallback> &callback) {
  834. ATRACE_NAME("Vibrator::composePwle");
  835. int32_t capabilities;
  836. Vibrator::getCapabilities(&capabilities);
  837. if ((capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS) == 0) {
  838. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  839. }
  840. if (composite.empty() || composite.size() > COMPOSE_PWLE_SIZE_MAX_DEFAULT) {
  841. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  842. }
  843. std::vector<Braking> supported;
  844. Vibrator::getSupportedBraking(&supported);
  845. bool isClabSupported =
  846. std::find(supported.begin(), supported.end(), Braking::CLAB) != supported.end();
  847. int segmentIdx = 0;
  848. uint32_t totalDuration = 0;
  849. float prevEndAmplitude;
  850. float prevEndFrequency;
  851. resetPreviousEndAmplitudeEndFrequency(&prevEndAmplitude, &prevEndFrequency);
  852. auto ch = dspmem_chunk_create(new uint8_t[FF_CUSTOM_DATA_LEN_MAX_PWLE]{0x00},
  853. FF_CUSTOM_DATA_LEN_MAX_PWLE);
  854. bool chirp = false;
  855. dspmem_chunk_write(ch, 24, 0x000000); /* Waveform length placeholder */
  856. dspmem_chunk_write(ch, 8, 0); /* Repeat */
  857. dspmem_chunk_write(ch, 12, 0); /* Wait time between repeats */
  858. dspmem_chunk_write(ch, 8, 0x00); /* nsections placeholder */
  859. for (auto &e : composite) {
  860. switch (e.getTag()) {
  861. case PrimitivePwle::active: {
  862. auto active = e.get<PrimitivePwle::active>();
  863. if (active.duration < 0 ||
  864. active.duration > COMPOSE_PWLE_PRIMITIVE_DURATION_MAX_MS) {
  865. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  866. }
  867. if (active.startAmplitude < PWLE_LEVEL_MIN ||
  868. active.startAmplitude > PWLE_LEVEL_MAX ||
  869. active.endAmplitude < PWLE_LEVEL_MIN || active.endAmplitude > PWLE_LEVEL_MAX) {
  870. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  871. }
  872. if (active.startAmplitude > CS40L26_PWLE_LEVEL_MAX) {
  873. active.startAmplitude = CS40L26_PWLE_LEVEL_MAX;
  874. }
  875. if (active.endAmplitude > CS40L26_PWLE_LEVEL_MAX) {
  876. active.endAmplitude = CS40L26_PWLE_LEVEL_MAX;
  877. }
  878. if (active.startFrequency < PWLE_FREQUENCY_MIN_HZ ||
  879. active.startFrequency > PWLE_FREQUENCY_MAX_HZ ||
  880. active.endFrequency < PWLE_FREQUENCY_MIN_HZ ||
  881. active.endFrequency > PWLE_FREQUENCY_MAX_HZ) {
  882. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  883. }
  884. if (!((active.startAmplitude == prevEndAmplitude) &&
  885. (active.startFrequency == prevEndFrequency))) {
  886. if (constructActiveSegment(ch, 0, active.startAmplitude, active.startFrequency,
  887. false) < 0) {
  888. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  889. }
  890. incrementIndex(&segmentIdx);
  891. }
  892. if (active.startFrequency != active.endFrequency) {
  893. chirp = true;
  894. }
  895. if (constructActiveSegment(ch, active.duration, active.endAmplitude,
  896. active.endFrequency, chirp) < 0) {
  897. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  898. }
  899. incrementIndex(&segmentIdx);
  900. prevEndAmplitude = active.endAmplitude;
  901. prevEndFrequency = active.endFrequency;
  902. totalDuration += active.duration;
  903. chirp = false;
  904. break;
  905. }
  906. case PrimitivePwle::braking: {
  907. auto braking = e.get<PrimitivePwle::braking>();
  908. if (braking.braking > Braking::CLAB) {
  909. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  910. } else if (!isClabSupported && (braking.braking == Braking::CLAB)) {
  911. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  912. }
  913. if (braking.duration > COMPOSE_PWLE_PRIMITIVE_DURATION_MAX_MS) {
  914. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  915. }
  916. if (constructBrakingSegment(ch, 0, braking.braking) < 0) {
  917. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  918. }
  919. incrementIndex(&segmentIdx);
  920. if (constructBrakingSegment(ch, braking.duration, braking.braking) < 0) {
  921. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  922. }
  923. incrementIndex(&segmentIdx);
  924. resetPreviousEndAmplitudeEndFrequency(&prevEndAmplitude, &prevEndFrequency);
  925. totalDuration += braking.duration;
  926. break;
  927. }
  928. }
  929. if (segmentIdx > COMPOSE_PWLE_SIZE_MAX_DEFAULT) {
  930. ALOGE("Too many PrimitivePwle section!");
  931. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  932. }
  933. }
  934. dspmem_chunk_flush(ch);
  935. /* Update wlength */
  936. totalDuration += MAX_COLD_START_LATENCY_MS;
  937. if (totalDuration > 0x7FFFF) {
  938. ALOGE("Total duration is too long (%d)!", totalDuration);
  939. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  940. }
  941. updateWLength(ch, totalDuration);
  942. /* Update nsections */
  943. updateNSection(ch, segmentIdx);
  944. return performEffect(WAVEFORM_MAX_INDEX /*ignored*/, VOLTAGE_SCALE_MAX /*ignored*/, ch,
  945. callback);
  946. }
  947. bool Vibrator::isUnderExternalControl() {
  948. return mIsUnderExternalControl;
  949. }
  950. binder_status_t Vibrator::dump(int fd, const char **args, uint32_t numArgs) {
  951. if (fd < 0) {
  952. ALOGE("Called debug() with invalid fd.");
  953. return STATUS_OK;
  954. }
  955. (void)args;
  956. (void)numArgs;
  957. dprintf(fd, "AIDL:\n");
  958. dprintf(fd, " F0 Offset: %" PRIu32 "\n", mF0Offset);
  959. dprintf(fd, " Voltage Levels:\n");
  960. dprintf(fd, " Tick Effect Min: %" PRIu32 " Max: %" PRIu32 "\n", mTickEffectVol[0],
  961. mTickEffectVol[1]);
  962. dprintf(fd, " Click Effect Min: %" PRIu32 " Max: %" PRIu32 "\n", mClickEffectVol[0],
  963. mClickEffectVol[1]);
  964. dprintf(fd, " Long Effect Min: %" PRIu32 " Max: %" PRIu32 "\n", mLongEffectVol[0],
  965. mLongEffectVol[1]);
  966. dprintf(fd, " FF effect:\n");
  967. dprintf(fd, " Physical waveform:\n");
  968. dprintf(fd, "\tId\tIndex\tt ->\tt'\n");
  969. for (uint8_t effectId = 0; effectId < WAVEFORM_MAX_PHYSICAL_INDEX; effectId++) {
  970. dprintf(fd, "\t%d\t%d\t%d\t%d\n", mFfEffects[effectId].id,
  971. mFfEffects[effectId].u.periodic.custom_data[1], mEffectDurations[effectId],
  972. mFfEffects[effectId].replay.length);
  973. }
  974. dprintf(fd, " OWT waveform:\n");
  975. dprintf(fd, "\tId\tBytes\tData\n");
  976. for (uint8_t effectId = WAVEFORM_MAX_PHYSICAL_INDEX; effectId < WAVEFORM_MAX_INDEX;
  977. effectId++) {
  978. uint32_t numBytes = mFfEffects[effectId].u.periodic.custom_len * 2;
  979. std::stringstream ss;
  980. ss << " ";
  981. for (int i = 0; i < numBytes; i++) {
  982. ss << std::uppercase << std::setfill('0') << std::setw(2) << std::hex
  983. << (uint16_t)(*(
  984. reinterpret_cast<uint8_t *>(mFfEffects[effectId].u.periodic.custom_data) +
  985. i))
  986. << " ";
  987. }
  988. dprintf(fd, "\t%d\t%d\t{%s}\n", mFfEffects[effectId].id, numBytes, ss.str().c_str());
  989. }
  990. dprintf(fd, "\n");
  991. dprintf(fd, "\n");
  992. mHwApi->debug(fd);
  993. dprintf(fd, "\n");
  994. mHwCal->debug(fd);
  995. dprintf(fd, "Capo Info\n");
  996. if (vibeContextListener) {
  997. dprintf(fd, "Capo ID: 0x%x\n", (uint32_t)(vibeContextListener->getNanoppAppId()));
  998. dprintf(fd, "Capo State: %d DetectedState: %d\n", vibeContextListener->getCarriedPosition(),
  999. getDeviceState());
  1000. } else {
  1001. dprintf(fd, "Capo ID: 0x%x\n", (uint32_t)(0xdeadbeef));
  1002. dprintf(fd, "Capo State: %d DetectedState: %d\n", (uint32_t)0x454545, getDeviceState());
  1003. }
  1004. fsync(fd);
  1005. return STATUS_OK;
  1006. }
  1007. bool Vibrator::hasHapticAlsaDevice() {
  1008. // We need to call findHapticAlsaDevice once only. Calling in the
  1009. // constructor is too early in the boot process and the pcm file contents
  1010. // are empty. Hence we make the call here once only right before we need to.
  1011. if (!mConfigHapticAlsaDeviceDone) {
  1012. if (mHwApi->getHapticAlsaDevice(&mCard, &mDevice)) {
  1013. mHasHapticAlsaDevice = true;
  1014. mConfigHapticAlsaDeviceDone = true;
  1015. } else {
  1016. ALOGE("Haptic ALSA device not supported");
  1017. }
  1018. } else {
  1019. ALOGD("Haptic ALSA device configuration done.");
  1020. }
  1021. return mHasHapticAlsaDevice;
  1022. }
  1023. ndk::ScopedAStatus Vibrator::getSimpleDetails(Effect effect, EffectStrength strength,
  1024. uint32_t *outEffectIndex, uint32_t *outTimeMs,
  1025. uint32_t *outVolLevel) {
  1026. uint32_t effectIndex;
  1027. uint32_t timeMs;
  1028. float intensity;
  1029. uint32_t volLevel;
  1030. switch (strength) {
  1031. case EffectStrength::LIGHT:
  1032. intensity = 0.5f;
  1033. break;
  1034. case EffectStrength::MEDIUM:
  1035. intensity = 0.7f;
  1036. break;
  1037. case EffectStrength::STRONG:
  1038. intensity = 1.0f;
  1039. break;
  1040. default:
  1041. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  1042. }
  1043. switch (effect) {
  1044. case Effect::TEXTURE_TICK:
  1045. effectIndex = WAVEFORM_LIGHT_TICK_INDEX;
  1046. intensity *= 0.5f;
  1047. break;
  1048. case Effect::TICK:
  1049. effectIndex = WAVEFORM_CLICK_INDEX;
  1050. intensity *= 0.5f;
  1051. break;
  1052. case Effect::CLICK:
  1053. effectIndex = WAVEFORM_CLICK_INDEX;
  1054. intensity *= 0.7f;
  1055. break;
  1056. case Effect::HEAVY_CLICK:
  1057. effectIndex = WAVEFORM_CLICK_INDEX;
  1058. intensity *= 1.0f;
  1059. break;
  1060. default:
  1061. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  1062. }
  1063. volLevel = intensityToVolLevel(intensity, effectIndex);
  1064. timeMs = mEffectDurations[effectIndex] + MAX_COLD_START_LATENCY_MS;
  1065. *outEffectIndex = effectIndex;
  1066. *outTimeMs = timeMs;
  1067. *outVolLevel = volLevel;
  1068. return ndk::ScopedAStatus::ok();
  1069. }
  1070. ndk::ScopedAStatus Vibrator::getCompoundDetails(Effect effect, EffectStrength strength,
  1071. uint32_t *outTimeMs, dspmem_chunk *outCh) {
  1072. ndk::ScopedAStatus status;
  1073. uint32_t timeMs = 0;
  1074. uint32_t thisEffectIndex;
  1075. uint32_t thisTimeMs;
  1076. uint32_t thisVolLevel;
  1077. switch (effect) {
  1078. case Effect::DOUBLE_CLICK:
  1079. dspmem_chunk_write(outCh, 8, 0); /* Padding */
  1080. dspmem_chunk_write(outCh, 8, 2); /* nsections */
  1081. dspmem_chunk_write(outCh, 8, 0); /* repeat */
  1082. status = getSimpleDetails(Effect::CLICK, strength, &thisEffectIndex, &thisTimeMs,
  1083. &thisVolLevel);
  1084. if (!status.isOk()) {
  1085. return status;
  1086. }
  1087. timeMs += thisTimeMs;
  1088. dspmem_chunk_write(outCh, 8, (uint8_t)(0xFF & thisVolLevel)); /* amplitude */
  1089. dspmem_chunk_write(outCh, 8, (uint8_t)(0xFF & thisEffectIndex)); /* index */
  1090. dspmem_chunk_write(outCh, 8, 0); /* repeat */
  1091. dspmem_chunk_write(outCh, 8, 0); /* flags */
  1092. dspmem_chunk_write(outCh, 16,
  1093. (uint16_t)(0xFFFF & WAVEFORM_DOUBLE_CLICK_SILENCE_MS)); /* delay */
  1094. timeMs += WAVEFORM_DOUBLE_CLICK_SILENCE_MS + MAX_PAUSE_TIMING_ERROR_MS;
  1095. status = getSimpleDetails(Effect::HEAVY_CLICK, strength, &thisEffectIndex, &thisTimeMs,
  1096. &thisVolLevel);
  1097. if (!status.isOk()) {
  1098. return status;
  1099. }
  1100. timeMs += thisTimeMs;
  1101. dspmem_chunk_write(outCh, 8, (uint8_t)(0xFF & thisVolLevel)); /* amplitude */
  1102. dspmem_chunk_write(outCh, 8, (uint8_t)(0xFF & thisEffectIndex)); /* index */
  1103. dspmem_chunk_write(outCh, 8, 0); /* repeat */
  1104. dspmem_chunk_write(outCh, 8, 0); /* flags */
  1105. dspmem_chunk_write(outCh, 16, 0); /* delay */
  1106. dspmem_chunk_flush(outCh);
  1107. break;
  1108. default:
  1109. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  1110. }
  1111. *outTimeMs = timeMs;
  1112. return ndk::ScopedAStatus::ok();
  1113. }
  1114. ndk::ScopedAStatus Vibrator::getPrimitiveDetails(CompositePrimitive primitive,
  1115. uint32_t *outEffectIndex) {
  1116. uint32_t effectIndex;
  1117. uint32_t primitiveBit = 1 << int32_t(primitive);
  1118. if ((primitiveBit & mSupportedPrimitivesBits) == 0x0) {
  1119. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  1120. }
  1121. switch (primitive) {
  1122. case CompositePrimitive::NOOP:
  1123. return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
  1124. case CompositePrimitive::CLICK:
  1125. effectIndex = WAVEFORM_CLICK_INDEX;
  1126. break;
  1127. case CompositePrimitive::THUD:
  1128. effectIndex = WAVEFORM_THUD_INDEX;
  1129. break;
  1130. case CompositePrimitive::SPIN:
  1131. effectIndex = WAVEFORM_SPIN_INDEX;
  1132. break;
  1133. case CompositePrimitive::QUICK_RISE:
  1134. effectIndex = WAVEFORM_QUICK_RISE_INDEX;
  1135. break;
  1136. case CompositePrimitive::SLOW_RISE:
  1137. effectIndex = WAVEFORM_SLOW_RISE_INDEX;
  1138. break;
  1139. case CompositePrimitive::QUICK_FALL:
  1140. effectIndex = WAVEFORM_QUICK_FALL_INDEX;
  1141. break;
  1142. case CompositePrimitive::LIGHT_TICK:
  1143. effectIndex = WAVEFORM_LIGHT_TICK_INDEX;
  1144. break;
  1145. case CompositePrimitive::LOW_TICK:
  1146. effectIndex = WAVEFORM_LOW_TICK_INDEX;
  1147. break;
  1148. default:
  1149. return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  1150. }
  1151. *outEffectIndex = effectIndex;
  1152. return ndk::ScopedAStatus::ok();
  1153. }
  1154. ndk::ScopedAStatus Vibrator::performEffect(Effect effect, EffectStrength strength,
  1155. const std::shared_ptr<IVibratorCallback> &callback,
  1156. int32_t *outTimeMs) {
  1157. ndk::ScopedAStatus status;
  1158. uint32_t effectIndex;
  1159. uint32_t timeMs = 0;
  1160. uint32_t volLevel;
  1161. dspmem_chunk *ch = nullptr;
  1162. switch (effect) {
  1163. case Effect::TEXTURE_TICK:
  1164. // fall-through
  1165. case Effect::TICK:
  1166. // fall-through
  1167. case Effect::CLICK:
  1168. // fall-through
  1169. case Effect::HEAVY_CLICK:
  1170. status = getSimpleDetails(effect, strength, &effectIndex, &timeMs, &volLevel);
  1171. break;
  1172. case Effect::DOUBLE_CLICK:
  1173. ch = dspmem_chunk_create(new uint8_t[FF_CUSTOM_DATA_LEN_MAX_COMP]{0x00},
  1174. FF_CUSTOM_DATA_LEN_MAX_COMP);
  1175. status = getCompoundDetails(effect, strength, &timeMs, ch);
  1176. volLevel = VOLTAGE_SCALE_MAX;
  1177. break;
  1178. default:
  1179. status = ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
  1180. break;
  1181. }
  1182. if (!status.isOk()) {
  1183. goto exit;
  1184. }
  1185. status = performEffect(effectIndex, volLevel, ch, callback);
  1186. exit:
  1187. *outTimeMs = timeMs;
  1188. return status;
  1189. }
  1190. ndk::ScopedAStatus Vibrator::performEffect(uint32_t effectIndex, uint32_t volLevel,
  1191. dspmem_chunk *ch,
  1192. const std::shared_ptr<IVibratorCallback> &callback) {
  1193. setEffectAmplitude(volLevel, VOLTAGE_SCALE_MAX, false);
  1194. return on(MAX_TIME_MS, effectIndex, ch, callback);
  1195. }
  1196. void Vibrator::waitForComplete(std::shared_ptr<IVibratorCallback> &&callback) {
  1197. if (!mHwApi->pollVibeState(VIBE_STATE_HAPTIC, POLLING_TIMEOUT)) {
  1198. ALOGW("Failed to get state \"Haptic\"");
  1199. }
  1200. mHwApi->pollVibeState(VIBE_STATE_STOPPED);
  1201. const std::scoped_lock<std::mutex> lock(mActiveId_mutex);
  1202. if ((mActiveId >= WAVEFORM_MAX_PHYSICAL_INDEX) &&
  1203. (!mHwApi->eraseOwtEffect(mInputFd, mActiveId, &mFfEffects))) {
  1204. ALOGE("Failed to clean up the composed effect %d", mActiveId);
  1205. }
  1206. mActiveId = -1;
  1207. if (callback) {
  1208. auto ret = callback->onComplete();
  1209. if (!ret.isOk()) {
  1210. ALOGE("Failed completion callback: %d", ret.getExceptionCode());
  1211. }
  1212. }
  1213. }
  1214. uint32_t Vibrator::intensityToVolLevel(float intensity, uint32_t effectIndex) {
  1215. uint32_t volLevel;
  1216. auto calc = [](float intst, std::array<uint32_t, 2> v) -> uint32_t {
  1217. return std::lround(intst * (v[1] - v[0])) + v[0];
  1218. };
  1219. switch (effectIndex) {
  1220. case WAVEFORM_LIGHT_TICK_INDEX:
  1221. volLevel = calc(intensity, mTickEffectVol);
  1222. break;
  1223. case WAVEFORM_QUICK_RISE_INDEX:
  1224. // fall-through
  1225. case WAVEFORM_QUICK_FALL_INDEX:
  1226. volLevel = calc(intensity, mLongEffectVol);
  1227. break;
  1228. case WAVEFORM_CLICK_INDEX:
  1229. // fall-through
  1230. case WAVEFORM_THUD_INDEX:
  1231. // fall-through
  1232. case WAVEFORM_SPIN_INDEX:
  1233. // fall-through
  1234. case WAVEFORM_SLOW_RISE_INDEX:
  1235. // fall-through
  1236. default:
  1237. volLevel = calc(intensity, mClickEffectVol);
  1238. break;
  1239. }
  1240. return volLevel;
  1241. }
  1242. } // namespace vibrator
  1243. } // namespace hardware
  1244. } // namespace android
  1245. } // namespace aidl