Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e4e7dac authored by Tim Schumacher's avatar Tim Schumacher Committed by Tim Schumacher
Browse files

CMStats: Use the new updater API

This now sends a JSON body instead of parameters

Change-Id: Ie13e1ac1675488903280b037ec1e2320e35b77bc
parent dd63b75c
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The CyanogenMod Project
 * Copyright (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.
@@ -30,12 +31,13 @@ import com.android.settings.Settings;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;

import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
@@ -103,19 +105,26 @@ public class ReportingService extends Service {

            // report to the cmstats service
            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost("https://stats.cyanogenmod.org/submit");
            HttpPost httpPost = new HttpPost("https://stats.lineageos.org/api/v1/stats");
            httpPost.setHeader("Content-Type", "application/json; charset=UTF-8");
            boolean success = false;

            JSONObject json = new JSONObject();

            try {
                json.put("device_hash", deviceId);
                json.put("device_name", deviceName);
                json.put("device_version", deviceVersion);
                json.put("device_country", deviceCountry);
                json.put("device_carrier", deviceCarrier);
                json.put("device_carrier_id", deviceCarrierId);
            } catch (JSONException e) {
                Log.e(TAG, "Could not encode JSON for stats", e);
                return success;
            }

            try {
                List<NameValuePair> kv = new ArrayList<NameValuePair>(5);
                kv.add(new BasicNameValuePair("device_hash", deviceId));
                kv.add(new BasicNameValuePair("device_name", deviceName));
                kv.add(new BasicNameValuePair("device_version", deviceVersion));
                kv.add(new BasicNameValuePair("device_country", deviceCountry));
                kv.add(new BasicNameValuePair("device_carrier", deviceCarrier));
                kv.add(new BasicNameValuePair("device_carrier_id", deviceCarrierId));

                httpPost.setEntity(new UrlEncodedFormEntity(kv));
                httpPost.setEntity(new StringEntity(json.toString()));
                httpClient.execute(httpPost);

                success = true;