| Michael Wright | 3fee95e | 2018-12-12 19:51:26 +0000 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2018 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 <vibrator/ExternalVibration.h> | 
| Jeongik Cha | e214e64 | 2022-09-26 23:08:56 +0900 | [diff] [blame] | 18 | #include <vibrator/ExternalVibrationUtils.h> | 
| Michael Wright | 3fee95e | 2018-12-12 19:51:26 +0000 | [diff] [blame] | 19 |  | 
| Jeongik Cha | e214e64 | 2022-09-26 23:08:56 +0900 | [diff] [blame] | 20 | #include <android/os/IExternalVibratorService.h> | 
| Michael Wright | 3fee95e | 2018-12-12 19:51:26 +0000 | [diff] [blame] | 21 | #include <binder/Parcel.h> | 
|  | 22 | #include <log/log.h> | 
|  | 23 | #include <utils/Errors.h> | 
|  | 24 |  | 
| Jeongik Cha | e214e64 | 2022-09-26 23:08:56 +0900 | [diff] [blame] | 25 |  | 
|  | 26 | // To guarantee if HapticScale enum has the same value as IExternalVibratorService | 
|  | 27 | static_assert(static_cast<int>(android::os::HapticScale::MUTE) == static_cast<int>(android::os::IExternalVibratorService::SCALE_MUTE)); | 
|  | 28 | static_assert(static_cast<int>(android::os::HapticScale::VERY_LOW) == static_cast<int>(android::os::IExternalVibratorService::SCALE_VERY_LOW)); | 
|  | 29 | static_assert(static_cast<int>(android::os::HapticScale::LOW) == static_cast<int>(android::os::IExternalVibratorService::SCALE_LOW)); | 
|  | 30 | static_assert(static_cast<int>(android::os::HapticScale::NONE) == static_cast<int>(android::os::IExternalVibratorService::SCALE_NONE)); | 
|  | 31 | static_assert(static_cast<int>(android::os::HapticScale::HIGH) == static_cast<int>(android::os::IExternalVibratorService::SCALE_HIGH)); | 
|  | 32 | static_assert(static_cast<int>(android::os::HapticScale::VERY_HIGH) == static_cast<int>(android::os::IExternalVibratorService::SCALE_VERY_HIGH)); | 
|  | 33 |  | 
| Michael Wright | 3fee95e | 2018-12-12 19:51:26 +0000 | [diff] [blame] | 34 | void writeAudioAttributes(const audio_attributes_t& attrs, android::Parcel* out) { | 
|  | 35 | out->writeInt32(attrs.usage); | 
|  | 36 | out->writeInt32(attrs.content_type); | 
|  | 37 | out->writeInt32(attrs.source); | 
|  | 38 | out->writeInt32(attrs.flags); | 
|  | 39 | } | 
|  | 40 |  | 
|  | 41 | void readAudioAttributes(audio_attributes_t* attrs, const android::Parcel* in) { | 
|  | 42 | attrs->usage = static_cast<audio_usage_t>(in->readInt32()); | 
|  | 43 | attrs->content_type = static_cast<audio_content_type_t>(in->readInt32()); | 
|  | 44 | attrs->source = static_cast<audio_source_t>(in->readInt32()); | 
|  | 45 | attrs->flags = static_cast<audio_flags_mask_t>(in->readInt32()); | 
|  | 46 | } | 
|  | 47 |  | 
|  | 48 | namespace android { | 
|  | 49 | namespace os { | 
|  | 50 |  | 
|  | 51 | ExternalVibration::ExternalVibration(int32_t uid, std::string pkg, const audio_attributes_t& attrs, | 
|  | 52 | sp<IExternalVibrationController> controller) : | 
|  | 53 | mUid(uid), mPkg(pkg), mAttrs(attrs), mController(controller) { } | 
|  | 54 |  | 
|  | 55 | status_t ExternalVibration::writeToParcel(Parcel* parcel) const { | 
|  | 56 | parcel->writeInt32(mUid); | 
|  | 57 | parcel->writeString16(String16(mPkg.c_str())); | 
|  | 58 | writeAudioAttributes(mAttrs, parcel); | 
|  | 59 | parcel->writeStrongBinder(IInterface::asBinder(mController)); | 
|  | 60 | parcel->writeStrongBinder(mToken); | 
|  | 61 | return OK; | 
|  | 62 | } | 
|  | 63 | status_t ExternalVibration::readFromParcel(const Parcel* parcel) { | 
|  | 64 | mUid = parcel->readInt32(); | 
|  | 65 | String8 pkgStr8 = String8(parcel->readString16()); | 
|  | 66 | mPkg = pkgStr8.c_str(); | 
|  | 67 | readAudioAttributes(&mAttrs, parcel); | 
|  | 68 | mController = IExternalVibrationController::asInterface(parcel->readStrongBinder()); | 
|  | 69 | mToken = parcel->readStrongBinder(); | 
|  | 70 | return OK; | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | inline bool ExternalVibration::operator==(const ExternalVibration& rhs) const { | 
|  | 74 | return mToken == rhs.mToken; | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | } // namespace os | 
|  | 78 | } // namespace android |