1 /* 2 * Copyright (C) 2015 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 #ifndef ANDROID_EXTERNAL_VIBRATION_H 18 #define ANDROID_EXTERNAL_VIBRATION_H 19 20 #include <android/os/IExternalVibrationController.h> 21 #include <binder/Binder.h> 22 #include <binder/IBinder.h> 23 #include <binder/Parcelable.h> 24 #include <system/audio.h> 25 #include <utils/RefBase.h> 26 #include <vibrator/ExternalVibrationUtils.h> 27 28 namespace android { 29 namespace os { 30 31 class ExternalVibration : public Parcelable, public virtual RefBase { 32 public : 33 ExternalVibration() = default; 34 ExternalVibration(int32_t uid, std::string pkg, const audio_attributes_t& attrs, 35 sp<IExternalVibrationController> controller); 36 virtual ~ExternalVibration() = default; 37 38 bool operator==(const ExternalVibration&) const; 39 40 status_t writeToParcel(Parcel* parcel) const override; 41 status_t readFromParcel(const Parcel* parcel) override; 42 getUid()43 int32_t getUid() const { return mUid; } getPackage()44 std::string getPackage() const { return mPkg; } getAudioAttributes()45 audio_attributes_t getAudioAttributes() const { return mAttrs; } getController()46 sp<IExternalVibrationController> getController() { return mController; } 47 48 /* Converts the scale from non-public ExternalVibrationService into the HapticScale 49 * used by the utils. 50 */ 51 static os::HapticScale externalVibrationScaleToHapticScale(int externalVibrationScale); 52 53 private: 54 int32_t mUid; 55 std::string mPkg; 56 audio_attributes_t mAttrs; 57 sp<IExternalVibrationController> mController; 58 sp<IBinder> mToken = new BBinder(); 59 }; 60 61 } // namespace os 62 } // namespace android 63 64 #endif // ANDROID_EXTERNAL_VIBRATION_H 65