1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
package org.robolectric.shadows;
import static android.os.Build.VERSION_CODES.TIRAMISU;
import android.companion.AssociationInfo;
import android.net.MacAddress;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
import org.robolectric.util.ReflectionHelpers.ClassParameter;
/** Builder for {@link AssociationInfo}. */
public class AssociationInfoBuilder {
private int id;
private int userId;
private String packageName;
private String deviceMacAddress;
private CharSequence displayName;
private String deviceProfile;
private boolean selfManaged;
private boolean notifyOnDeviceNearby;
private long approvedMs;
private long lastTimeConnectedMs;
private AssociationInfoBuilder() {}
public static AssociationInfoBuilder newBuilder() {
return new AssociationInfoBuilder();
}
public AssociationInfoBuilder setId(int id) {
this.id = id;
return this;
}
public AssociationInfoBuilder setUserId(int userId) {
this.userId = userId;
return this;
}
public AssociationInfoBuilder setPackageName(String packageName) {
this.packageName = packageName;
return this;
}
public AssociationInfoBuilder setDeviceMacAddress(String deviceMacAddress) {
this.deviceMacAddress = deviceMacAddress;
return this;
}
public AssociationInfoBuilder setDisplayName(CharSequence displayName) {
this.displayName = displayName;
return this;
}
public AssociationInfoBuilder setDeviceProfile(String deviceProfile) {
this.deviceProfile = deviceProfile;
return this;
}
public AssociationInfoBuilder setSelfManaged(boolean selfManaged) {
this.selfManaged = selfManaged;
return this;
}
public AssociationInfoBuilder setNotifyOnDeviceNearby(boolean notifyOnDeviceNearby) {
this.notifyOnDeviceNearby = notifyOnDeviceNearby;
return this;
}
public AssociationInfoBuilder setApprovedMs(long approvedMs) {
this.approvedMs = approvedMs;
return this;
}
public AssociationInfoBuilder setLastTimeConnectedMs(long lastTimeConnectedMs) {
this.lastTimeConnectedMs = lastTimeConnectedMs;
return this;
}
public AssociationInfo build() {
try {
if (RuntimeEnvironment.getApiLevel() <= TIRAMISU) {
return ReflectionHelpers.callConstructor(
AssociationInfo.class,
ClassParameter.from(int.class, id),
ClassParameter.from(int.class, userId),
ClassParameter.from(String.class, packageName),
ClassParameter.from(MacAddress.class, MacAddress.fromString(deviceMacAddress)),
ClassParameter.from(CharSequence.class, displayName),
ClassParameter.from(String.class, deviceProfile),
ClassParameter.from(boolean.class, selfManaged),
ClassParameter.from(boolean.class, notifyOnDeviceNearby),
ClassParameter.from(boolean.class, false /*revoked*/),
ClassParameter.from(long.class, approvedMs),
ClassParameter.from(long.class, lastTimeConnectedMs));
} else {
return ReflectionHelpers.callConstructor(
AssociationInfo.class,
ClassParameter.from(int.class, id),
ClassParameter.from(int.class, userId),
ClassParameter.from(String.class, packageName),
ClassParameter.from(MacAddress.class, MacAddress.fromString(deviceMacAddress)),
ClassParameter.from(CharSequence.class, displayName),
ClassParameter.from(String.class, deviceProfile),
ClassParameter.from(Class.forName("android.companion.AssociatedDevice"), null),
ClassParameter.from(boolean.class, selfManaged),
ClassParameter.from(boolean.class, notifyOnDeviceNearby),
ClassParameter.from(boolean.class, false /*revoked*/),
ClassParameter.from(long.class, approvedMs),
ClassParameter.from(long.class, lastTimeConnectedMs),
ClassParameter.from(int.class, 0 /*systemDataSyncFlags*/));
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
|