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