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 package android.companion;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 import android.annotation.UserIdInt;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import com.android.internal.util.DataClass;
25 
26 import java.util.Date;
27 import java.util.Objects;
28 
29 /**
30  * A record indicating that a device with a given address was confirmed by the user to be
31  * associated to a given companion app
32  *
33  * @hide
34  */
35 @DataClass(genEqualsHashCode = true, genToString = true, genHiddenConstructor = true)
36 public final class Association implements Parcelable {
37 
38     private final @UserIdInt int mUserId;
39     private final @NonNull String mDeviceMacAddress;
40     private final @NonNull String mPackageName;
41     private final @Nullable String mDeviceProfile;
42     private final boolean mNotifyOnDeviceNearby;
43     private final long mTimeApprovedMs;
44 
45     /** @hide */
getUserId()46     public int getUserId() {
47         return mUserId;
48     }
49 
timeApprovedMsToString()50     private String timeApprovedMsToString() {
51         return new Date(mTimeApprovedMs).toString();
52     }
53 
54 
55 
56 
57 
58     // Code below generated by codegen v1.0.22.
59     //
60     // DO NOT MODIFY!
61     // CHECKSTYLE:OFF Generated code
62     //
63     // To regenerate run:
64     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/companion/Association.java
65     //
66     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
67     //   Settings > Editor > Code Style > Formatter Control
68     //@formatter:off
69 
70 
71     /**
72      * Creates a new Association.
73      *
74      * @hide
75      */
76     @DataClass.Generated.Member
Association( @serIdInt int userId, @NonNull String deviceMacAddress, @NonNull String packageName, @Nullable String deviceProfile, boolean notifyOnDeviceNearby, long timeApprovedMs)77     public Association(
78             @UserIdInt int userId,
79             @NonNull String deviceMacAddress,
80             @NonNull String packageName,
81             @Nullable String deviceProfile,
82             boolean notifyOnDeviceNearby,
83             long timeApprovedMs) {
84         this.mUserId = userId;
85         com.android.internal.util.AnnotationValidations.validate(
86                 UserIdInt.class, null, mUserId);
87         this.mDeviceMacAddress = deviceMacAddress;
88         com.android.internal.util.AnnotationValidations.validate(
89                 NonNull.class, null, mDeviceMacAddress);
90         this.mPackageName = packageName;
91         com.android.internal.util.AnnotationValidations.validate(
92                 NonNull.class, null, mPackageName);
93         this.mDeviceProfile = deviceProfile;
94         this.mNotifyOnDeviceNearby = notifyOnDeviceNearby;
95         this.mTimeApprovedMs = timeApprovedMs;
96 
97         // onConstructed(); // You can define this method to get a callback
98     }
99 
100     @DataClass.Generated.Member
getDeviceMacAddress()101     public @NonNull String getDeviceMacAddress() {
102         return mDeviceMacAddress;
103     }
104 
105     @DataClass.Generated.Member
getPackageName()106     public @NonNull String getPackageName() {
107         return mPackageName;
108     }
109 
110     @DataClass.Generated.Member
getDeviceProfile()111     public @Nullable String getDeviceProfile() {
112         return mDeviceProfile;
113     }
114 
115     @DataClass.Generated.Member
isNotifyOnDeviceNearby()116     public boolean isNotifyOnDeviceNearby() {
117         return mNotifyOnDeviceNearby;
118     }
119 
120     @DataClass.Generated.Member
getTimeApprovedMs()121     public long getTimeApprovedMs() {
122         return mTimeApprovedMs;
123     }
124 
125     @Override
126     @DataClass.Generated.Member
toString()127     public String toString() {
128         // You can override field toString logic by defining methods like:
129         // String fieldNameToString() { ... }
130 
131         return "Association { " +
132                 "userId = " + mUserId + ", " +
133                 "deviceMacAddress = " + mDeviceMacAddress + ", " +
134                 "packageName = " + mPackageName + ", " +
135                 "deviceProfile = " + mDeviceProfile + ", " +
136                 "notifyOnDeviceNearby = " + mNotifyOnDeviceNearby + ", " +
137                 "timeApprovedMs = " + timeApprovedMsToString() +
138         " }";
139     }
140 
141     @Override
142     @DataClass.Generated.Member
equals(@ullable Object o)143     public boolean equals(@Nullable Object o) {
144         // You can override field equality logic by defining either of the methods like:
145         // boolean fieldNameEquals(Association other) { ... }
146         // boolean fieldNameEquals(FieldType otherValue) { ... }
147 
148         if (this == o) return true;
149         if (o == null || getClass() != o.getClass()) return false;
150         @SuppressWarnings("unchecked")
151         Association that = (Association) o;
152         //noinspection PointlessBooleanExpression
153         return true
154                 && mUserId == that.mUserId
155                 && Objects.equals(mDeviceMacAddress, that.mDeviceMacAddress)
156                 && Objects.equals(mPackageName, that.mPackageName)
157                 && Objects.equals(mDeviceProfile, that.mDeviceProfile)
158                 && mNotifyOnDeviceNearby == that.mNotifyOnDeviceNearby
159                 && mTimeApprovedMs == that.mTimeApprovedMs;
160     }
161 
162     @Override
163     @DataClass.Generated.Member
hashCode()164     public int hashCode() {
165         // You can override field hashCode logic by defining methods like:
166         // int fieldNameHashCode() { ... }
167 
168         int _hash = 1;
169         _hash = 31 * _hash + mUserId;
170         _hash = 31 * _hash + Objects.hashCode(mDeviceMacAddress);
171         _hash = 31 * _hash + Objects.hashCode(mPackageName);
172         _hash = 31 * _hash + Objects.hashCode(mDeviceProfile);
173         _hash = 31 * _hash + Boolean.hashCode(mNotifyOnDeviceNearby);
174         _hash = 31 * _hash + Long.hashCode(mTimeApprovedMs);
175         return _hash;
176     }
177 
178     @Override
179     @DataClass.Generated.Member
writeToParcel(@onNull Parcel dest, int flags)180     public void writeToParcel(@NonNull Parcel dest, int flags) {
181         // You can override field parcelling by defining methods like:
182         // void parcelFieldName(Parcel dest, int flags) { ... }
183 
184         byte flg = 0;
185         if (mNotifyOnDeviceNearby) flg |= 0x10;
186         if (mDeviceProfile != null) flg |= 0x8;
187         dest.writeByte(flg);
188         dest.writeInt(mUserId);
189         dest.writeString(mDeviceMacAddress);
190         dest.writeString(mPackageName);
191         if (mDeviceProfile != null) dest.writeString(mDeviceProfile);
192         dest.writeLong(mTimeApprovedMs);
193     }
194 
195     @Override
196     @DataClass.Generated.Member
describeContents()197     public int describeContents() { return 0; }
198 
199     /** @hide */
200     @SuppressWarnings({"unchecked", "RedundantCast"})
201     @DataClass.Generated.Member
Association(@onNull Parcel in)202     /* package-private */ Association(@NonNull Parcel in) {
203         // You can override field unparcelling by defining methods like:
204         // static FieldType unparcelFieldName(Parcel in) { ... }
205 
206         byte flg = in.readByte();
207         boolean notifyOnDeviceNearby = (flg & 0x10) != 0;
208         int userId = in.readInt();
209         String deviceMacAddress = in.readString();
210         String packageName = in.readString();
211         String deviceProfile = (flg & 0x8) == 0 ? null : in.readString();
212         long timeApprovedMs = in.readLong();
213 
214         this.mUserId = userId;
215         com.android.internal.util.AnnotationValidations.validate(
216                 UserIdInt.class, null, mUserId);
217         this.mDeviceMacAddress = deviceMacAddress;
218         com.android.internal.util.AnnotationValidations.validate(
219                 NonNull.class, null, mDeviceMacAddress);
220         this.mPackageName = packageName;
221         com.android.internal.util.AnnotationValidations.validate(
222                 NonNull.class, null, mPackageName);
223         this.mDeviceProfile = deviceProfile;
224         this.mNotifyOnDeviceNearby = notifyOnDeviceNearby;
225         this.mTimeApprovedMs = timeApprovedMs;
226 
227         // onConstructed(); // You can define this method to get a callback
228     }
229 
230     @DataClass.Generated.Member
231     public static final @NonNull Parcelable.Creator<Association> CREATOR
232             = new Parcelable.Creator<Association>() {
233         @Override
234         public Association[] newArray(int size) {
235             return new Association[size];
236         }
237 
238         @Override
239         public Association createFromParcel(@NonNull Parcel in) {
240             return new Association(in);
241         }
242     };
243 
244     @DataClass.Generated(
245             time = 1612832377589L,
246             codegenVersion = "1.0.22",
247             sourceFile = "frameworks/base/core/java/android/companion/Association.java",
248             inputSignatures = "private final @android.annotation.UserIdInt int mUserId\nprivate final @android.annotation.NonNull java.lang.String mDeviceMacAddress\nprivate final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.Nullable java.lang.String mDeviceProfile\nprivate final  boolean mNotifyOnDeviceNearby\nprivate final  long mTimeApprovedMs\npublic  int getUserId()\nprivate  java.lang.String timeApprovedMsToString()\nclass Association extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genHiddenConstructor=true)")
249     @Deprecated
__metadata()250     private void __metadata() {}
251 
252 
253     //@formatter:on
254     // End of generated code
255 
256 }
257