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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net.ip;
import android.annotation.Hide;
import android.annotation.NonNull;
import android.net.NattKeepalivePacketData;
import android.net.ProxyInfo;
import android.net.TcpKeepalivePacketData;
import android.net.TcpKeepalivePacketDataParcelable;
import android.net.shared.Layer2Information;
import android.net.shared.ProvisioningConfiguration;
import android.net.util.KeepalivePacketDataUtil;
import android.os.Binder;
import android.os.RemoteException;
import android.util.Log;
/**
* A convenience wrapper for IpClient.
*
* Wraps IIpClient calls, making them a bit more friendly to use. Currently handles:
* - Clearing calling identity
* - Ignoring RemoteExceptions
* - Converting to stable parcelables
*
* By design, all methods on IIpClient are asynchronous oneway IPCs and are thus void. All the
* wrapper methods in this class return a boolean that callers can use to determine whether
* RemoteException was thrown.
*/
@Hide
public class IpClientManager {
@NonNull private final IIpClient mIpClient;
@NonNull private final String mTag;
public IpClientManager(@NonNull IIpClient ipClient, @NonNull String tag) {
mIpClient = ipClient;
mTag = tag;
}
public IpClientManager(@NonNull IIpClient ipClient) {
this(ipClient, IpClientManager.class.getSimpleName());
}
private void log(String s, Throwable e) {
Log.e(mTag, s, e);
}
/**
* For clients using {@link ProvisioningConfiguration.Builder#withPreDhcpAction()}, must be
* called after {@link IIpClientCallbacks#onPreDhcpAction} to indicate that DHCP is clear to
* proceed.
*/
public boolean completedPreDhcpAction() {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.completedPreDhcpAction();
return true;
} catch (RemoteException e) {
log("Error completing PreDhcpAction", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Confirm the provisioning configuration.
*/
public boolean confirmConfiguration() {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.confirmConfiguration();
return true;
} catch (RemoteException e) {
log("Error confirming IpClient configuration", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Indicate that packet filter read is complete.
*/
public boolean readPacketFilterComplete(byte[] data) {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.readPacketFilterComplete(data);
return true;
} catch (RemoteException e) {
log("Error notifying IpClient of packet filter read", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Shut down this IpClient instance altogether.
*/
public boolean shutdown() {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.shutdown();
return true;
} catch (RemoteException e) {
log("Error shutting down IpClient", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Start provisioning with the provided parameters.
*/
public boolean startProvisioning(ProvisioningConfiguration prov) {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.startProvisioning(prov.toStableParcelable());
return true;
} catch (RemoteException e) {
log("Error starting IpClient provisioning", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Stop this IpClient.
*
* <p>This does not shut down the StateMachine itself, which is handled by {@link #shutdown()}.
*/
public boolean stop() {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.stop();
return true;
} catch (RemoteException e) {
log("Error stopping IpClient", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Set the TCP buffer sizes to use.
*
* This may be called, repeatedly, at any time before or after a call to
* #startProvisioning(). The setting is cleared upon calling #stop().
*/
public boolean setTcpBufferSizes(String tcpBufferSizes) {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.setTcpBufferSizes(tcpBufferSizes);
return true;
} catch (RemoteException e) {
log("Error setting IpClient TCP buffer sizes", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Set the HTTP Proxy configuration to use.
*
* This may be called, repeatedly, at any time before or after a call to
* #startProvisioning(). The setting is cleared upon calling #stop().
*/
public boolean setHttpProxy(ProxyInfo proxyInfo) {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.setHttpProxy(proxyInfo);
return true;
} catch (RemoteException e) {
log("Error setting IpClient proxy", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Enable or disable the multicast filter. Attempts to use APF to accomplish the filtering,
* if not, Callback.setFallbackMulticastFilter() is called.
*/
public boolean setMulticastFilter(boolean enabled) {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.setMulticastFilter(enabled);
return true;
} catch (RemoteException e) {
log("Error setting multicast filter", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Add a TCP keepalive packet filter before setting up keepalive offload.
*/
public boolean addKeepalivePacketFilter(int slot, TcpKeepalivePacketData pkt) {
return addKeepalivePacketFilter(slot, KeepalivePacketDataUtil.toStableParcelable(pkt));
}
/**
* Add a TCP keepalive packet filter before setting up keepalive offload.
* @deprecated This method is for use on pre-S platforms where TcpKeepalivePacketData is not
* system API. On newer platforms use
* addKeepalivePacketFilter(int, TcpKeepalivePacketData) instead.
*/
@Deprecated
public boolean addKeepalivePacketFilter(int slot, TcpKeepalivePacketDataParcelable pkt) {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.addKeepalivePacketFilter(slot, pkt);
return true;
} catch (RemoteException e) {
log("Error adding Keepalive Packet Filter ", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Add a NAT-T keepalive packet filter before setting up keepalive offload.
*/
public boolean addKeepalivePacketFilter(int slot, NattKeepalivePacketData pkt) {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.addNattKeepalivePacketFilter(
slot, KeepalivePacketDataUtil.toStableParcelable(pkt));
return true;
} catch (RemoteException e) {
log("Error adding NAT-T Keepalive Packet Filter ", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Remove a keepalive packet filter after stopping keepalive offload.
*/
public boolean removeKeepalivePacketFilter(int slot) {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.removeKeepalivePacketFilter(slot);
return true;
} catch (RemoteException e) {
log("Error removing Keepalive Packet Filter ", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Set the L2 key and group hint for storing info into the memory store.
*/
public boolean setL2KeyAndGroupHint(String l2Key, String groupHint) {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.setL2KeyAndGroupHint(l2Key, groupHint);
return true;
} catch (RemoteException e) {
log("Failed setL2KeyAndGroupHint", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Notify IpClient that preconnection is complete and that the link is ready for use.
* The success parameter indicates whether the packets passed in by 'onPreconnectionStart'
* were successfully sent to the network or not.
*/
public boolean notifyPreconnectionComplete(boolean success) {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.notifyPreconnectionComplete(success);
return true;
} catch (RemoteException e) {
log("Error notifying IpClient Preconnection completed", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Update the bssid, L2 key and group hint layer2 information.
*/
public boolean updateLayer2Information(Layer2Information info) {
final long token = Binder.clearCallingIdentity();
try {
mIpClient.updateLayer2Information(info.toStableParcelable());
return true;
} catch (RemoteException e) {
log("Error updating layer2 information", e);
return false;
} finally {
Binder.restoreCallingIdentity(token);
}
}
}
|