Home | History | Annotate | Download | only in vibrator
      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>
     18 
     19 #include <binder/Parcel.h>
     20 #include <log/log.h>
     21 #include <utils/Errors.h>
     22 
     23 void writeAudioAttributes(const audio_attributes_t& attrs, android::Parcel* out) {
     24     out->writeInt32(attrs.usage);
     25     out->writeInt32(attrs.content_type);
     26     out->writeInt32(attrs.source);
     27     out->writeInt32(attrs.flags);
     28 }
     29 
     30 void readAudioAttributes(audio_attributes_t* attrs, const android::Parcel* in) {
     31     attrs->usage = static_cast<audio_usage_t>(in->readInt32());
     32     attrs->content_type = static_cast<audio_content_type_t>(in->readInt32());
     33     attrs->source = static_cast<audio_source_t>(in->readInt32());
     34     attrs->flags = static_cast<audio_flags_mask_t>(in->readInt32());
     35 }
     36 
     37 namespace android {
     38 namespace os {
     39 
     40 ExternalVibration::ExternalVibration(int32_t uid, std::string pkg, const audio_attributes_t& attrs,
     41             sp<IExternalVibrationController> controller) :
     42     mUid(uid), mPkg(pkg), mAttrs(attrs), mController(controller) { }
     43 
     44 status_t ExternalVibration::writeToParcel(Parcel* parcel) const {
     45     parcel->writeInt32(mUid);
     46     parcel->writeString16(String16(mPkg.c_str()));
     47     writeAudioAttributes(mAttrs, parcel);
     48     parcel->writeStrongBinder(IInterface::asBinder(mController));
     49     parcel->writeStrongBinder(mToken);
     50     return OK;
     51 }
     52 status_t ExternalVibration::readFromParcel(const Parcel* parcel) {
     53     mUid = parcel->readInt32();
     54     String8 pkgStr8 = String8(parcel->readString16());
     55     mPkg = pkgStr8.c_str();
     56     readAudioAttributes(&mAttrs, parcel);
     57     mController = IExternalVibrationController::asInterface(parcel->readStrongBinder());
     58     mToken = parcel->readStrongBinder();
     59     return OK;
     60 }
     61 
     62 inline bool ExternalVibration::operator==(const ExternalVibration& rhs) const {
     63     return mToken == rhs.mToken;
     64 }
     65 
     66 } // namespace os
     67 } // namespace android
     68