• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

development


Commit MetaInfo

Revisión1f49fa9b7c6b2b603345fe74e6ec76969ba6f00d (tree)
Tiempo2009-08-20 08:14:18
AutorXavier Ducrohet <xav@andr...>
CommiterXavier Ducrohet

Log Message

Add OS version to ping service (win/mac only)

Cambiar Resumen

Diferencia incremental

--- a/tools/sdkstats/src/com/android/sdkstats/SdkStatsService.java
+++ b/tools/sdkstats/src/com/android/sdkstats/SdkStatsService.java
@@ -44,6 +44,8 @@ import java.net.HttpURLConnection;
4444 import java.net.URL;
4545 import java.net.URLEncoder;
4646 import java.util.Random;
47+import java.util.regex.Matcher;
48+import java.util.regex.Pattern;
4749
4850 /** Utility class to send "ping" usage reports to the server. */
4951 public class SdkStatsService {
@@ -93,14 +95,14 @@ public class SdkStatsService {
9395 "kfmclient openURL %URL%", // $NON-NLS-1$ Konqueror
9496 "opera -newwindow %URL%", // $NON-NLS-1$ Opera
9597 };
96-
98+
9799 public final static String PING_OPT_IN = "pingOptIn"; //$NON-NLS-1$
98100 public final static String PING_TIME = "pingTime"; //$NON-NLS-1$
99101 public final static String PING_ID = "pingId"; //$NON-NLS-1$
100102
101103
102104 private static PreferenceStore sPrefStore;
103-
105+
104106 /**
105107 * Send a "ping" to the Google toolbar server, if enough time has
106108 * elapsed since the last ping, and if the user has not opted out.
@@ -123,7 +125,7 @@ public class SdkStatsService {
123125 if (!prefs.contains(PING_ID)) {
124126 // First time: make up a new ID. TODO: Use something more random?
125127 prefs.setValue(PING_ID, new Random().nextLong());
126-
128+
127129 // Also give them a chance to opt out.
128130 prefs.setValue(PING_OPT_IN, getUserPermission(display));
129131 try {
@@ -132,13 +134,13 @@ public class SdkStatsService {
132134 catch (IOException ioe) {
133135 }
134136 }
135-
137+
136138 // If the user has not opted in, do nothing and quietly return.
137139 if (!prefs.getBoolean(PING_OPT_IN)) {
138140 // user opted out.
139141 return;
140142 }
141-
143+
142144 // If the last ping *for this app* was too recent, do nothing.
143145 String timePref = PING_TIME + "." + app; // $NON-NLS-1$
144146 long now = System.currentTimeMillis();
@@ -147,7 +149,7 @@ public class SdkStatsService {
147149 // too soon after a ping.
148150 return;
149151 }
150-
152+
151153 // Record the time of the attempt, whether or not it succeeds.
152154 prefs.setValue(timePref, now);
153155 try {
@@ -155,7 +157,7 @@ public class SdkStatsService {
155157 }
156158 catch (IOException ioe) {
157159 }
158-
160+
159161 // Send the ping itself in the background (don't block if the
160162 // network is down or slow or confused).
161163 final long id = prefs.getLong(PING_ID);
@@ -171,7 +173,7 @@ public class SdkStatsService {
171173 }.start();
172174 }
173175 }
174-
176+
175177 /**
176178 * Returns the DDMS {@link PreferenceStore}.
177179 */
@@ -187,7 +189,7 @@ public class SdkStatsService {
187189
188190 if (homeDir != null) {
189191 String rcFileName = homeDir + "ddms.cfg"; //$NON-NLS-1$
190-
192+
191193 // also look for an old pref file in the previous location
192194 String oldPrefPath = System.getProperty("user.home") //$NON-NLS-1$
193195 + File.separator + ".ddmsrc"; //$NON-NLS-1$
@@ -196,10 +198,10 @@ public class SdkStatsService {
196198 try {
197199 PreferenceStore oldStore = new PreferenceStore(oldPrefPath);
198200 oldStore.load();
199-
201+
200202 oldStore.save(new FileOutputStream(rcFileName), "");
201203 oldPrefFile.delete();
202-
204+
203205 PreferenceStore newStore = new PreferenceStore(rcFileName);
204206 newStore.load();
205207 sPrefStore = newStore;
@@ -220,10 +222,10 @@ public class SdkStatsService {
220222 sPrefStore = new PreferenceStore();
221223 }
222224 }
223-
225+
224226 return sPrefStore;
225227 }
226-
228+
227229 /**
228230 * Unconditionally send a "ping" request to the Google toolbar server.
229231 *
@@ -239,8 +241,16 @@ public class SdkStatsService {
239241 String os = System.getProperty("os.name"); // $NON-NLS-1$
240242 if (os.startsWith("Mac OS")) { // $NON-NLS-1$
241243 os = "mac"; // $NON-NLS-1$
244+ String osVers = getVersion();
245+ if (osVers != null) {
246+ os = os + "-" + osVers; // $NON-NLS-1$
247+ }
242248 } else if (os.startsWith("Windows")) { // $NON-NLS-1$
243249 os = "win"; // $NON-NLS-1$
250+ String osVers = getVersion();
251+ if (osVers != null) {
252+ os = os + "-" + osVers; // $NON-NLS-1$
253+ }
244254 } else if (os.startsWith("Linux")) { // $NON-NLS-1$
245255 os = "linux"; // $NON-NLS-1$
246256 } else {
@@ -272,6 +282,24 @@ public class SdkStatsService {
272282 }
273283
274284 /**
285+ * Returns the version of the os if it is defined as X.Y, or null otherwise.
286+ * <p/>
287+ * Example of returned versions can be found at http://lopica.sourceforge.net/os.html
288+ * <p/>
289+ * This method removes any exiting micro versions.
290+ */
291+ private static String getVersion() {
292+ Pattern p = Pattern.compile("(\\d+)\\.(\\d+).*"); // $NON-NLS-1$
293+ String osVers = System.getProperty("os.version"); // $NON-NLS-1$
294+ Matcher m = p.matcher(osVers);
295+ if (m.matches()) {
296+ return m.group(1) + "." + m.group(2); // $NON-NLS-1$
297+ }
298+
299+ return null;
300+ }
301+
302+ /**
275303 * Prompt the user for whether they want to opt out of reporting.
276304 * @return whether the user allows reporting (they do not opt out).
277305 */