1 /* 2 * Copyright (C) 2020 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_OS_PARCELDURATION_H 18 #define ANDROID_OS_PARCELDURATION_H 19 20 #include <binder/Parcelable.h> 21 #include <math.h> 22 #include <utils/RefBase.h> 23 24 namespace android::os { 25 26 /** 27 * Parcelable version of {@link java.time.Duration} that can be used in binder calls. 28 * This file needs to be kept in sync with 29 * frameworks/base/core/java/android/os/ParcelDuration.java 30 */ 31 struct ParcelDuration : public android::Parcelable { mSecondsParcelDuration32 ParcelDuration(int64_t seconds = 0, int32_t nanos = 0) : mSeconds(seconds), mNanos(nanos) {} 33 34 status_t readFromParcel(const android::Parcel* parcel) override; 35 status_t writeToParcel(android::Parcel* parcel) const override; 36 bool operator==(const ParcelDuration& pd) const { 37 return mSeconds == pd.mSeconds && mNanos == pd.mNanos; 38 } 39 40 private: 41 int64_t mSeconds; 42 int32_t mNanos; 43 }; 44 45 } // namespace android::os 46 47 #endif /* ANDROID_OS_PARCELDURATION_H */ 48