diff options
author | Simon Shields <keepcalm444@gmail.com> | 2016-12-29 11:00:19 +1100 |
---|---|---|
committer | Zhao Wei Liew <zhaoweiliew@gmail.com> | 2017-01-08 19:19:29 +0800 |
commit | 8535ca7c5b3eb96be20ef16c33d805ebe5bfbbf0 (patch) | |
tree | 27effea4a5f4811e97873c06c0522cdd5e81a12e | |
parent | ed584932ca159e2e49add95f766cb743bf84a960 (diff) | |
download | packages_apps_Settings-8535ca7c5b3eb96be20ef16c33d805ebe5bfbbf0.zip packages_apps_Settings-8535ca7c5b3eb96be20ef16c33d805ebe5bfbbf0.tar.gz packages_apps_Settings-8535ca7c5b3eb96be20ef16c33d805ebe5bfbbf0.tar.bz2 |
Settings: CMStats: use new server-side API
* version the API
* instead of sending a POST request with parameters,
POST a json blob.
Change-Id: I1e83f85ca833b823dfd23eacbc8309d9eeee72a9
-rwxr-xr-x | res/values/config.xml | 2 | ||||
-rw-r--r-- | src/com/android/settings/cmstats/StatsUploadJobService.java | 41 |
2 files changed, 26 insertions, 17 deletions
diff --git a/res/values/config.xml b/res/values/config.xml index c93d6f3..b7ccf9b 100755 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -52,7 +52,7 @@ <bool name="config_enable_duplicate_apn_checking">false</bool> <!-- Metrics server endpoint --> - <string name="stats_cm_url">https://stats.cyanogenmod.org/submit</string> + <string name="stats_cm_url">https://stats.lineageos.org/api/v1/stats</string> <!-- Display ro.product.name above Device model --> <bool name="config_displayDeviceName">false</bool> diff --git a/src/com/android/settings/cmstats/StatsUploadJobService.java b/src/com/android/settings/cmstats/StatsUploadJobService.java index 4533e28..c84e1a1 100644 --- a/src/com/android/settings/cmstats/StatsUploadJobService.java +++ b/src/com/android/settings/cmstats/StatsUploadJobService.java @@ -119,10 +119,11 @@ public class StatsUploadJobService extends JobService { switch (jobType) { case JOB_TYPE_CMORG: try { - success = uploadToCM(deviceId, deviceName, deviceVersion, deviceCountry, - deviceCarrier, deviceCarrierId); - } catch (IOException e) { - Log.e(TAG, "Could not upload stats checkin to commnity server", e); + JSONObject json = buildStatsRequest(deviceId, deviceName, + deviceVersion, deviceCountry, deviceCarrier, deviceCarrierId); + success = uploadToCM(json); + } catch (IOException | JSONException e) { + Log.e(TAG, "Could not upload stats checkin to community server", e); success = false; } break; @@ -141,24 +142,32 @@ public class StatsUploadJobService extends JobService { } } + private JSONObject buildStatsRequest(String deviceId, String deviceName, String deviceVersion, + String deviceCountry, String deviceCarrier, + String deviceCarrierId) throws JSONException { + JSONObject request = new JSONObject(); + request.put("device_hash", deviceId); + request.put("device_name", deviceName); + request.put("device_version", deviceVersion); + request.put("device_country", deviceCountry); + request.put("device_carrier", deviceCarrier); + request.put("device_carrier_id", deviceCarrierId); + return request; + } - private boolean uploadToCM(String deviceId, String deviceName, String deviceVersion, - String deviceCountry, String deviceCarrier, String deviceCarrierId) - throws IOException { - - final Uri uri = Uri.parse(getString(R.string.stats_cm_url)).buildUpon() - .appendQueryParameter("device_hash", deviceId) - .appendQueryParameter("device_name", deviceName) - .appendQueryParameter("device_version", deviceVersion) - .appendQueryParameter("device_country", deviceCountry) - .appendQueryParameter("device_carrier", deviceCarrier) - .appendQueryParameter("device_carrier_id", deviceCarrierId).build(); + private boolean uploadToCM(JSONObject json) throws IOException { + final Uri uri = Uri.parse(getString(R.string.stats_cm_url)); URL url = new URL(uri.toString()); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); try { urlConnection.setInstanceFollowRedirects(true); urlConnection.setDoOutput(true); - urlConnection.connect(); + urlConnection.setDoInput(true); + urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + + OutputStream os = urlConnection.getOutputStream(); + os.write(json.toString().getBytes("UTF-8")); + os.close(); final int responseCode = urlConnection.getResponseCode(); if (DEBUG) Log.d(TAG, "cm server response code=" + responseCode); |