Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Send the telemetry status ping if it's an update and telemetry was off
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Oct 16, 2019
1 parent 84547c1 commit db2a1eb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
private final static long CRASH_RESTART_DELTA = 2000;
public final static boolean AUTOPLAY_ENABLED = false;
public final static boolean DEBUG_LOGGING_DEFAULT = false;
public final static boolean TELEMETRY_STATUS_UPDATE_SENT_DEFAULT = false;

// Enable telemetry by default (opt-out).
public final static boolean CRASH_REPORTING_DEFAULT = false;
Expand Down Expand Up @@ -130,6 +131,23 @@ public void setTelemetryEnabled(boolean isEnabled) {
if (isEnabled) {
TelemetryWrapper.telemetryStatus(true);
}

// Update the status sent flag
setTelemetryPingUpdateSent(true);
}

public boolean telemetryStatusSaved() {
return mPrefs.contains(mContext.getString(R.string.settings_key_telemetry));
}

public boolean isTelemetryPingUpdateSent() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_telemetry_status_update_sent), TELEMETRY_STATUS_UPDATE_SENT_DEFAULT);
}

public void setTelemetryPingUpdateSent(boolean isSent) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_telemetry_status_update_sent), isSent);
editor.commit();
}

public void setGeolocationData(String aGeolocationData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import android.os.SystemClock;
import android.util.Log;

import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient;
import androidx.annotation.NonNull;
import androidx.annotation.UiThread;

import org.mozilla.telemetry.Telemetry;
import org.mozilla.telemetry.TelemetryHolder;
import org.mozilla.telemetry.config.TelemetryConfiguration;
Expand All @@ -15,7 +17,6 @@
import org.mozilla.telemetry.net.TelemetryClient;
import org.mozilla.telemetry.ping.TelemetryCorePingBuilder;
import org.mozilla.telemetry.ping.TelemetryMobileEventPingBuilder;
import org.mozilla.telemetry.ping.TelemetryPingBuilder;
import org.mozilla.telemetry.schedule.TelemetryScheduler;
import org.mozilla.telemetry.schedule.jobscheduler.JobSchedulerTelemetryScheduler;
import org.mozilla.telemetry.serialize.JSONPingSerializer;
Expand All @@ -33,11 +34,11 @@
import java.util.HashSet;
import java.util.Map;

import androidx.annotation.NonNull;
import androidx.annotation.UiThread;
import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient;

import static java.lang.Math.toIntExact;
import static org.mozilla.vrbrowser.ui.widgets.Windows.*;
import static org.mozilla.vrbrowser.ui.widgets.Windows.MAX_WINDOWS;
import static org.mozilla.vrbrowser.ui.widgets.Windows.WindowPlacement;


public class TelemetryWrapper {
Expand Down Expand Up @@ -171,6 +172,19 @@ public static void init(Context aContext) {
TelemetryHolder.set(new Telemetry(configuration, storage, client, scheduler)
.addPingBuilder(new TelemetryCorePingBuilder(configuration))
.addPingBuilder(new TelemetryMobileEventPingBuilder(configuration)));

// Check if the Telemetry status has ever been saved (enabled/disabled)
boolean saved = SettingsStore.getInstance(aContext).telemetryStatusSaved();
// Check if we have already sent the previous status event
boolean sent = SettingsStore.getInstance(aContext).isTelemetryPingUpdateSent();
// If the Telemetry status has been changed but that ping has not been sent, we send it now
// This should only been true for versions of the app prior to implementing the Telemetry status ping
// We only send the status ping if it was disabled
if (saved && !sent && !telemetryEnabled) {
telemetryStatus(false);
SettingsStore.getInstance(aContext).setTelemetryPingUpdateSent(true);
}

} finally {
StrictMode.setThreadPolicy(threadPolicy);
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/non_L10n.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<string name="settings_key_debug_logging" translatable="false">settings_key_debug_logging</string>
<string name="settings_key_autoplay" translatable="false">settings_key_autoplay</string>
<string name="settings_key_pid" translatable="false">settings_key_pid</string>
<string name="settings_key_telemetry_status_update_sent" translatable="false">settings_key_telemetry_status_update_sent</string>
<string name="environment_override_help_url" translatable="false">https://github.com/MozillaReality/FirefoxReality/wiki/Environments</string>
<string name="private_policy_url" translatable="false">https://www.mozilla.org/privacy/firefox/</string>
<string name="private_report_url" translatable="false">https://mixedreality.mozilla.org/fxr/report?src=browser-fxr&amp;label=browser-firefox-reality&amp;url=%1$s</string>
Expand Down

0 comments on commit db2a1eb

Please sign in to comment.