1 /* 2 * Copyright (C) 2022 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 package android.adservices.common; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 import java.util.Objects; 24 25 /** 26 * A class to hold the metadata of an IPC call. 27 * 28 * @hide 29 */ 30 public class CallerMetadata implements Parcelable { 31 private @NonNull long mBinderElapsedTimestamp; 32 CallerMetadata(@onNull long binderElapsedTimestamp)33 private CallerMetadata(@NonNull long binderElapsedTimestamp) { 34 mBinderElapsedTimestamp = binderElapsedTimestamp; 35 } 36 CallerMetadata(@onNull Parcel in)37 private CallerMetadata(@NonNull Parcel in) { 38 mBinderElapsedTimestamp = in.readLong(); 39 } 40 41 @NonNull 42 public static final Parcelable.Creator<CallerMetadata> CREATOR = 43 new Parcelable.Creator<CallerMetadata>() { 44 @Override 45 public CallerMetadata createFromParcel(@NonNull Parcel in) { 46 Objects.requireNonNull(in); 47 return new CallerMetadata(in); 48 } 49 50 @Override 51 public CallerMetadata[] newArray(int size) { 52 return new CallerMetadata[size]; 53 } 54 }; 55 56 @Override describeContents()57 public int describeContents() { 58 return 0; 59 } 60 61 @Override writeToParcel(@onNull Parcel out, int flags)62 public void writeToParcel(@NonNull Parcel out, int flags) { 63 out.writeLong(mBinderElapsedTimestamp); 64 } 65 66 /** Get the binder elapsed timestamp. */ getBinderElapsedTimestamp()67 public long getBinderElapsedTimestamp() { 68 return mBinderElapsedTimestamp; 69 } 70 71 /** Builder for {@link CallerMetadata} objects. */ 72 public static final class Builder { 73 private long mBinderElapsedTimestamp; 74 Builder()75 public Builder() { 76 } 77 78 /** Set the binder elapsed timestamp. */ setBinderElapsedTimestamp( @onNull long binderElapsedTimestamp)79 public @NonNull CallerMetadata.Builder setBinderElapsedTimestamp( 80 @NonNull long binderElapsedTimestamp) { 81 mBinderElapsedTimestamp = binderElapsedTimestamp; 82 return this; 83 } 84 85 /** Builds a {@link CallerMetadata} instance. */ build()86 public @NonNull CallerMetadata build() { 87 return new CallerMetadata(mBinderElapsedTimestamp); 88 } 89 } 90 } 91