1 /* 2 * Copyright (C) 2019 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.net.wifi.aware; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * A Parcelable {@link PeerHandle}. Can be constructed from a {@code PeerHandle} and then passed 25 * to any of the APIs which take a {@code PeerHandle} as inputs. 26 */ 27 public final class ParcelablePeerHandle extends PeerHandle implements Parcelable { 28 /** 29 * Construct a parcelable version of {@link PeerHandle}. 30 * 31 * @param peerHandle The {@link PeerHandle} to be made parcelable. 32 */ ParcelablePeerHandle(@onNull PeerHandle peerHandle)33 public ParcelablePeerHandle(@NonNull PeerHandle peerHandle) { 34 super(peerHandle.peerId); 35 } 36 37 @Override describeContents()38 public int describeContents() { 39 return 0; 40 } 41 42 @Override writeToParcel(Parcel dest, int flags)43 public void writeToParcel(Parcel dest, int flags) { 44 dest.writeInt(peerId); 45 } 46 47 public static final @android.annotation.NonNull Creator<ParcelablePeerHandle> CREATOR = 48 new Creator<ParcelablePeerHandle>() { 49 @Override 50 public ParcelablePeerHandle[] newArray(int size) { 51 return new ParcelablePeerHandle[size]; 52 } 53 54 @Override 55 public ParcelablePeerHandle createFromParcel(Parcel in) { 56 int peerHandle = in.readInt(); 57 return new ParcelablePeerHandle(new PeerHandle(peerHandle)); 58 } 59 }; 60 } 61