1 /* 2 * Copyright (C) 2017 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.lowpan; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 import java.util.Objects; 24 25 /** 26 * Describes the information needed to describe a network 27 * 28 * @hide 29 */ 30 // @SystemApi 31 public class LowpanProvision implements Parcelable { 32 33 // Builder 34 35 /** @hide */ 36 // @SystemApi 37 public static class Builder { 38 private final LowpanProvision provision = new LowpanProvision(); 39 setLowpanIdentity(@onNull LowpanIdentity identity)40 public Builder setLowpanIdentity(@NonNull LowpanIdentity identity) { 41 provision.mIdentity = identity; 42 return this; 43 } 44 setLowpanCredential(@onNull LowpanCredential credential)45 public Builder setLowpanCredential(@NonNull LowpanCredential credential) { 46 provision.mCredential = credential; 47 return this; 48 } 49 build()50 public LowpanProvision build() { 51 return provision; 52 } 53 } 54 LowpanProvision()55 private LowpanProvision() {} 56 57 // Instance Variables 58 59 private LowpanIdentity mIdentity = new LowpanIdentity(); 60 private LowpanCredential mCredential = null; 61 62 // Public Getters and Setters 63 64 @NonNull getLowpanIdentity()65 public LowpanIdentity getLowpanIdentity() { 66 return mIdentity; 67 } 68 69 @Nullable getLowpanCredential()70 public LowpanCredential getLowpanCredential() { 71 return mCredential; 72 } 73 74 @Override toString()75 public String toString() { 76 StringBuffer sb = new StringBuffer(); 77 78 sb.append("LowpanProvision { identity => ").append(mIdentity.toString()); 79 80 if (mCredential != null) { 81 sb.append(", credential => ").append(mCredential.toString()); 82 } 83 84 sb.append("}"); 85 86 return sb.toString(); 87 } 88 89 @Override hashCode()90 public int hashCode() { 91 return Objects.hash(mIdentity, mCredential); 92 } 93 94 @Override equals(Object obj)95 public boolean equals(Object obj) { 96 if (!(obj instanceof LowpanProvision)) { 97 return false; 98 } 99 LowpanProvision rhs = (LowpanProvision) obj; 100 101 if (!mIdentity.equals(rhs.mIdentity)) { 102 return false; 103 } 104 105 if (!Objects.equals(mCredential, rhs.mCredential)) { 106 return false; 107 } 108 109 return true; 110 } 111 112 /** Implement the Parcelable interface. */ 113 @Override describeContents()114 public int describeContents() { 115 return 0; 116 } 117 118 /** Implement the Parcelable interface. */ 119 @Override writeToParcel(Parcel dest, int flags)120 public void writeToParcel(Parcel dest, int flags) { 121 mIdentity.writeToParcel(dest, flags); 122 if (mCredential == null) { 123 dest.writeBoolean(false); 124 } else { 125 dest.writeBoolean(true); 126 mCredential.writeToParcel(dest, flags); 127 } 128 } 129 130 /** Implement the Parcelable interface. */ 131 public static final Creator<LowpanProvision> CREATOR = 132 new Creator<LowpanProvision>() { 133 public LowpanProvision createFromParcel(Parcel in) { 134 Builder builder = new Builder(); 135 136 builder.setLowpanIdentity(LowpanIdentity.CREATOR.createFromParcel(in)); 137 138 if (in.readBoolean()) { 139 builder.setLowpanCredential(LowpanCredential.CREATOR.createFromParcel(in)); 140 } 141 142 return builder.build(); 143 } 144 145 public LowpanProvision[] newArray(int size) { 146 return new LowpanProvision[size]; 147 } 148 }; 149 }; 150