• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package autotest.moblab.rpc;
2 
3 /**
4  * The version information RPC entity.
5  */
6 import com.google.gwt.json.client.JSONObject;
7 
8 public class VersionInfo extends JsonRpcEntity {
9 
10   public enum UPDATE_STATUS {
11     IDLE,
12     CHECKING_FOR_UPDATE,
13     UPDATE_AVAILABLE,
14     DOWNLOADING,
15     UPDATED_NEED_REBOOT,
16     UNKNOWN
17   }
18 
19   private static final String NO_MILESTONE_FOUND = "NO MILESTONE FOUND";
20   private static final String NO_VERSION_FOUND = "NO VERSION FOUND";
21   private static final String NO_TRACK_FOUND = "NO TRACK FOUND";
22   private static final String NO_DESCRIPTION_FOUND = "NO DESCRIPTION FOUND";
23   private static final String NO_ID_FOUND = "NO ID FOUND";
24   private static final String NO_SERIAL_NUMBER_FOUND = "NO SERIAL NUMBER FOUND";
25   private static final String NO_UPDATE_VERSION_FOUND =
26       "NO UPDATE VERSION FOUND";
27 
28   private String milestoneInfo;
29   private String versionInfo;
30   private String releaseTrack;
31   private String releaseDescription;
32   private String moblabIdentification;
33   private String moblabSerialNumber;
34   private String moblabUpdateVersion;
35   private double moblabUpdateProgress;
36   private UPDATE_STATUS moblabUpdateStatus;
37 
VersionInfo()38   public VersionInfo() { reset(); }
39 
getVersion()40   public String getVersion() {
41     return new StringBuilder("R").append(milestoneInfo).append("-").append(versionInfo).toString();
42   }
getReleaseTrack()43   public String getReleaseTrack() { return releaseTrack; }
getReleaseDescription()44   public String getReleaseDescription() { return releaseDescription; }
getMoblabIdentification()45   public String getMoblabIdentification() { return moblabIdentification; }
getMoblabSerialNumber()46   public String getMoblabSerialNumber() { return moblabSerialNumber; }
getMoblabUpdateVersion()47   public String getMoblabUpdateVersion() { return moblabUpdateVersion; }
getMoblabUpdateProgress()48   public double getMoblabUpdateProgress() { return moblabUpdateProgress; }
getMoblabUpdateStatus()49   public UPDATE_STATUS getMoblabUpdateStatus() { return moblabUpdateStatus; }
50 
reset()51   private void reset() {
52     milestoneInfo = new String(NO_MILESTONE_FOUND);
53     versionInfo = new String(NO_VERSION_FOUND);
54     releaseTrack = new String(NO_TRACK_FOUND);
55     releaseDescription = new String(NO_DESCRIPTION_FOUND);
56     moblabIdentification = new String(NO_ID_FOUND);
57     moblabSerialNumber = new String(NO_SERIAL_NUMBER_FOUND);
58     moblabUpdateVersion = new String(NO_UPDATE_VERSION_FOUND);
59     moblabUpdateStatus = UPDATE_STATUS.UNKNOWN;
60     moblabUpdateProgress = 0.0;
61   }
62 
63   @Override
fromJson(JSONObject object)64   public void fromJson(JSONObject object) {
65     reset();
66     milestoneInfo = getStringFieldOrDefault(object, "CHROMEOS_RELEASE_CHROME_MILESTONE",
67         NO_MILESTONE_FOUND).trim();
68     versionInfo = getStringFieldOrDefault(object, "CHROMEOS_RELEASE_VERSION",
69         NO_VERSION_FOUND).trim();
70     releaseTrack = getStringFieldOrDefault(object, "CHROMEOS_RELEASE_TRACK",
71         NO_TRACK_FOUND).trim();
72     releaseDescription = getStringFieldOrDefault(object, "CHROMEOS_RELEASE_DESCRIPTION",
73         NO_DESCRIPTION_FOUND).trim();
74     moblabIdentification = getStringFieldOrDefault(object, "MOBLAB_ID",
75         NO_ID_FOUND).trim();
76     moblabSerialNumber = getStringFieldOrDefault(object, "MOBLAB_SERIAL_NUMBER",
77         NO_SERIAL_NUMBER_FOUND).trim();
78     moblabUpdateVersion = getStringFieldOrDefault(
79         object, "MOBLAB_UPDATE_VERSION", NO_UPDATE_VERSION_FOUND).trim();
80     moblabUpdateStatus = getUpdateStatus(object);
81 
82     String progressString = getStringFieldOrDefault(
83         object, "MOBLAB_UPDATE_PROGRESS", "0.0").trim();
84     try {
85       moblabUpdateProgress = Double.parseDouble(progressString);
86     }
87     catch (NumberFormatException e) {
88       moblabUpdateProgress = 0.0;
89     }
90   }
91 
getUpdateStatus(JSONObject object)92   private UPDATE_STATUS getUpdateStatus(JSONObject object) {
93     String status = getStringFieldOrDefault(
94         object, "MOBLAB_UPDATE_STATUS", "").trim();
95 
96     if(status.contains("IDLE")) {
97       return UPDATE_STATUS.IDLE;
98     }
99     else if(status.contains("CHECKING_FOR_UPDATE")) {
100       return UPDATE_STATUS.CHECKING_FOR_UPDATE;
101     }
102     else if(status.contains("UPDATE_AVAILABLE") || status.contains("VERIFYING")
103         || status.contains("FINALIZING")) {
104       return UPDATE_STATUS.UPDATE_AVAILABLE;
105     }
106     else if(status.contains("DOWNLOADING")) {
107       return UPDATE_STATUS.DOWNLOADING;
108     }
109     else if(status.contains("NEED_REBOOT")) {
110       return UPDATE_STATUS.UPDATED_NEED_REBOOT;
111     }
112     else {
113       return UPDATE_STATUS.UNKNOWN;
114     }
115   }
116 
getUpdateString()117   public String getUpdateString() {
118     switch(moblabUpdateStatus){
119       case CHECKING_FOR_UPDATE:
120         return "Checking for update..";
121       case UPDATE_AVAILABLE:
122         return "Version " + moblabUpdateVersion + " is available";
123       case DOWNLOADING:
124         int percent = (int)(moblabUpdateProgress * 100.0);
125         return "Downloading version " + moblabUpdateVersion
126             + " (" + percent + "%)";
127       case UPDATED_NEED_REBOOT:
128         return "Version " + moblabUpdateVersion
129             + " is available, reboot required";
130       case IDLE:
131       case UNKNOWN:
132       default:
133         return "No update found";
134     }
135   }
136 
getUpdateAction()137   public String getUpdateAction() {
138     switch(moblabUpdateStatus){
139       case CHECKING_FOR_UPDATE:
140       case UPDATE_AVAILABLE:
141       case DOWNLOADING:
142       case UPDATED_NEED_REBOOT:
143         return "Update Now";
144       case IDLE:
145       case UNKNOWN:
146       default:
147         return "Force Update";
148     }
149   }
150 
151   @Override
toJson()152   public JSONObject toJson() {
153     // Required override - but this is a read only UI so the write function does not need to be
154     // implemented.
155     return new JSONObject();
156   }
157 }
158