-
Notifications
You must be signed in to change notification settings - Fork 207
/
SetWifiEnabledResponder.java
39 lines (30 loc) · 1.18 KB
/
SetWifiEnabledResponder.java
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
package jp.co.cyberagent.stf.query;
import android.content.Context;
import android.net.wifi.WifiManager;
import com.google.protobuf.GeneratedMessageLite;
import com.google.protobuf.InvalidProtocolBufferException;
import jp.co.cyberagent.stf.proto.Wire;
public class SetWifiEnabledResponder extends AbstractResponder {
public SetWifiEnabledResponder(Context context) {
super(context);
}
@Override
public GeneratedMessageLite respond(Wire.Envelope envelope) throws InvalidProtocolBufferException {
Wire.SetWifiEnabledRequest request =
Wire.SetWifiEnabledRequest.parseFrom(envelope.getMessage());
WifiManager wm = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
wm.setWifiEnabled(request.getEnabled());
return Wire.Envelope.newBuilder()
.setId(envelope.getId())
.setType(Wire.MessageType.SET_WIFI_ENABLED)
.setMessage(Wire.SetWifiEnabledResponse.newBuilder()
.setSuccess(true)
.build()
.toByteString())
.build();
}
@Override
public void cleanup() {
// No-op
}
}