From 640c391b1521005d99f54165ff20fd47a2a13d2d Mon Sep 17 00:00:00 2001 From: Simon Shields Date: Tue, 27 Dec 2016 21:36:39 +1100 Subject: Settings: cmstats: Stop sending stats to cyngn servers Change-Id: I30fa515f924f368b6cd7016ba03f366affaa6e5e --- res/values/config.xml | 5 +- .../android/settings/cmstats/ReportingService.java | 36 +++----- .../settings/cmstats/StatsUploadJobService.java | 100 +-------------------- 3 files changed, 15 insertions(+), 126 deletions(-) diff --git a/res/values/config.xml b/res/values/config.xml index aa97d3ca4..c93d6f399 100755 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -1,5 +1,6 @@ false - + https://stats.cyanogenmod.org/submit - https://shopvac.cyngn.com/community/heartbeat - https://account.cyngn.com/api/v1/community/heartbeat_token false diff --git a/src/com/android/settings/cmstats/ReportingService.java b/src/com/android/settings/cmstats/ReportingService.java index 841014335..5c876b907 100644 --- a/src/com/android/settings/cmstats/ReportingService.java +++ b/src/com/android/settings/cmstats/ReportingService.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2015 The CyanogenMod Project + * (C) 2017 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,39 +52,24 @@ public class ReportingService extends IntentService { String deviceCarrierId = Utilities.getCarrierId(getApplicationContext()); boolean optOut = intent.getBooleanExtra(EXTRA_OPTING_OUT, false); - final int cyanogenJobId = AnonymousStats.getNextJobId(getApplicationContext()); final int cmOrgJobId = AnonymousStats.getNextJobId(getApplicationContext()); - if (DEBUG) Log.d(TAG, "scheduling jobs id: " + cyanogenJobId + ", " + cmOrgJobId); + if (DEBUG) Log.d(TAG, "scheduling job id: " + cmOrgJobId); - PersistableBundle cyanogenBundle = new PersistableBundle(); - cyanogenBundle.putBoolean(StatsUploadJobService.KEY_OPT_OUT, optOut); - cyanogenBundle.putString(StatsUploadJobService.KEY_DEVICE_NAME, deviceName); - cyanogenBundle.putString(StatsUploadJobService.KEY_UNIQUE_ID, deviceId); - cyanogenBundle.putString(StatsUploadJobService.KEY_VERSION, deviceVersion); - cyanogenBundle.putString(StatsUploadJobService.KEY_COUNTRY, deviceCountry); - cyanogenBundle.putString(StatsUploadJobService.KEY_CARRIER, deviceCarrier); - cyanogenBundle.putString(StatsUploadJobService.KEY_CARRIER_ID, deviceCarrierId); - cyanogenBundle.putLong(StatsUploadJobService.KEY_TIMESTAMP, System.currentTimeMillis()); - - // get snapshot and persist it - PersistableBundle cmBundle = new PersistableBundle(cyanogenBundle); + PersistableBundle cmBundle = new PersistableBundle(); + cmBundle.putBoolean(StatsUploadJobService.KEY_OPT_OUT, optOut); + cmBundle.putString(StatsUploadJobService.KEY_DEVICE_NAME, deviceName); + cmBundle.putString(StatsUploadJobService.KEY_UNIQUE_ID, deviceId); + cmBundle.putString(StatsUploadJobService.KEY_VERSION, deviceVersion); + cmBundle.putString(StatsUploadJobService.KEY_COUNTRY, deviceCountry); + cmBundle.putString(StatsUploadJobService.KEY_CARRIER, deviceCarrier); + cmBundle.putString(StatsUploadJobService.KEY_CARRIER_ID, deviceCarrierId); + cmBundle.putLong(StatsUploadJobService.KEY_TIMESTAMP, System.currentTimeMillis()); // set job types - cyanogenBundle.putInt(StatsUploadJobService.KEY_JOB_TYPE, - StatsUploadJobService.JOB_TYPE_CYANOGEN); cmBundle.putInt(StatsUploadJobService.KEY_JOB_TYPE, StatsUploadJobService.JOB_TYPE_CMORG); - // schedule cyanogen stats upload - js.schedule(new JobInfo.Builder(cyanogenJobId, new ComponentName(getPackageName(), - StatsUploadJobService.class.getName())) - .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) - .setMinimumLatency(1000) - .setExtras(cyanogenBundle) - .setPersisted(true) - .build()); - // schedule cmorg stats upload js.schedule(new JobInfo.Builder(cmOrgJobId, new ComponentName(getPackageName(), StatsUploadJobService.class.getName())) diff --git a/src/com/android/settings/cmstats/StatsUploadJobService.java b/src/com/android/settings/cmstats/StatsUploadJobService.java index 580a20fdf..017198887 100644 --- a/src/com/android/settings/cmstats/StatsUploadJobService.java +++ b/src/com/android/settings/cmstats/StatsUploadJobService.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2015 The CyanogenMod Project + * (C) 2017 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,8 +47,7 @@ public class StatsUploadJobService extends JobService { private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); public static final String KEY_JOB_TYPE = "job_type"; - public static final int JOB_TYPE_CYANOGEN = 1; - public static final int JOB_TYPE_CMORG = 2; + public static final int JOB_TYPE_CMORG = 1; public static final String KEY_UNIQUE_ID = "uniqueId"; public static final String KEY_DEVICE_NAME = "deviceName"; @@ -114,25 +114,6 @@ public class StatsUploadJobService extends JobService { int jobType = extras.getInt(KEY_JOB_TYPE, -1); if (!isCancelled()) { switch (jobType) { - case JOB_TYPE_CYANOGEN: - try { - JSONObject json = new JSONObject(); - json.put("optOut", optOut); - json.put("uniqueId", deviceId); - json.put("deviceName", deviceName); - json.put("version", deviceVersion); - json.put("country", deviceCountry); - json.put("carrier", deviceCarrier); - json.put("carrierId", deviceCarrierId); - json.put("timestamp", timeStamp); - - success = uploadToCyanogen(json); - } catch (IOException | JSONException e) { - Log.e(TAG, "Could not upload stats checkin to cyanogen server", e); - success = false; - } - break; - case JOB_TYPE_CMORG: try { success = uploadToCM(deviceId, deviceName, deviceVersion, deviceCountry, @@ -192,83 +173,6 @@ public class StatsUploadJobService extends JobService { } - private boolean uploadToCyanogen(JSONObject json) - throws IOException, JSONException { - String authToken = getAuthToken(); - - if (authToken.isEmpty()) { - Log.w(TAG, "no auth token!"); - } - - URL url = new URL(getString(R.string.stats_cyanogen_url)); - HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); - try { - urlConnection.setInstanceFollowRedirects(true); - urlConnection.setDoInput(true); - urlConnection.setDoOutput(true); - - urlConnection.setRequestProperty("Accept-Encoding", "identity"); - urlConnection.setRequestProperty("Authorization", authToken); - urlConnection.setRequestProperty("Content-Type", "application/json"); - - OutputStream os = urlConnection.getOutputStream(); - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); - writer.write(json.toString()); - writer.flush(); - writer.close(); - os.close(); - - urlConnection.connect(); - - final int responseCode = urlConnection.getResponseCode(); - final boolean success = responseCode == HttpURLConnection.HTTP_OK; - - final String response = getResponse(urlConnection, !success); - if (DEBUG) - Log.d(TAG, "server responseCode: " + responseCode +", response=" + response); - - if (!success) { - Log.w(TAG, "failed sending, server returned: " + response); - } - return success; - } finally { - urlConnection.disconnect(); - } - } - - private String getAuthToken() { - HttpURLConnection urlConnection = null; - try { - URL url = new URL(getString(R.string.stats_cyanogen_token_url)); - urlConnection = (HttpURLConnection) url.openConnection(); - urlConnection.setInstanceFollowRedirects(true); - urlConnection.setDoInput(true); - - urlConnection.setRequestProperty("Accept-Encoding", "identity"); - urlConnection.setRequestProperty("Content-Type", "text/plain"); - - urlConnection.connect(); - - final int responseCode = urlConnection.getResponseCode(); - final boolean success = responseCode == HttpURLConnection.HTTP_OK; - if (DEBUG) Log.d(TAG, "server auth response code=" + responseCode); - final String response = getResponse(urlConnection, !success); - if (DEBUG) - Log.d(TAG, "server auth response=" + response); - - if (success) { - return response; - } - } catch (IOException e) { - Log.e(TAG, "error getting auth token", e); - } finally { - if (urlConnection != null) { - urlConnection.disconnect(); - } - } - return ""; - } - private String getResponse(HttpURLConnection httpUrlConnection, boolean errorStream) throws IOException { InputStream responseStream = new BufferedInputStream(errorStream -- cgit v1.2.3