1 package autotest.moblab.rpc;
2 
3 import com.google.gwt.json.client.JSONNull;
4 import com.google.gwt.json.client.JSONObject;
5 import com.google.gwt.json.client.JSONString;
6 
7 /**
8  * Wifi configuration RPC entity.
9  */
10 public class WifiInfo extends JsonRpcEntity {
11   public static final String JSON_FIELD_AP_NAME = "wifi_dut_ap_name";
12   public static final String JSON_FIELD_AP_PASS = "wifi_dut_ap_pass";
13 
14   /**
15    * The wifi AP name to connect to.
16    */
17   private String apName;
18 
19   /**
20    * The wifi AP password to use.
21    */
22   private String apPass;
23 
WifiInfo()24   public WifiInfo() {
25     reset();
26   }
27 
getApName()28   public String getApName() {
29     return apName;
30   }
31 
getApPass()32   public String getApPass() {
33     return apPass;
34   }
35 
setApName(String apName)36   public void setApName(String apName) {
37     if (apName != null && !apName.isEmpty()) {
38       this.apName = apName.trim();
39     } else {
40       this.apName = null;
41     }
42   }
43 
setApPass(String apPass)44   public void setApPass(String apPass) {
45     if (apPass != null && !apPass.isEmpty()) {
46       this.apPass = apPass.trim();
47     } else {
48       this.apPass = null;
49     }
50   }
51 
reset()52   private void reset() {
53     apName = null;
54     apPass = null;
55   }
56 
57   @Override
fromJson(JSONObject object)58   public void fromJson(JSONObject object) {
59     if (object != null) {
60       apName = getStringFieldOrDefault(object, JSON_FIELD_AP_NAME, null);
61       apPass = getStringFieldOrDefault(object, JSON_FIELD_AP_PASS, null);
62     }
63   }
64 
65   @Override
toJson()66   public JSONObject toJson() {
67     JSONObject object = new JSONObject();
68     if (apName != null) {
69       object.put(JSON_FIELD_AP_NAME, new JSONString(apName));
70     } else {
71       object.put(JSON_FIELD_AP_NAME, JSONNull.getInstance());
72     }
73     if (apPass != null) {
74       object.put(JSON_FIELD_AP_PASS, new JSONString(apPass));
75     } else {
76       object.put(JSON_FIELD_AP_PASS, JSONNull.getInstance());
77     }
78     return object;
79   }
80 }
81