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

Commit 51a797f

Browse files
keianhzoMortimerGoro
authored andcommitted
Added support for a telemetry enabled/disabled ping (#1936)
* Added support for a telemetry enabled/disabled ping Changed the telemetry status key name Revert "Changed the telemetry status key name" This reverts commit 6a632dc542ce40b6890e4b6c50c1c33a648d813c. * Send the telemetry status ping if it's an update and telemetry was off * Shorten the telemetry status string length
1 parent ef0066d commit 51a797f

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
7474
public final static boolean AUTOPLAY_ENABLED = false;
7575
public final static boolean DEBUG_LOGGING_DEFAULT = false;
7676
public final static boolean POP_UPS_BLOCKING_DEFAULT = true;
77+
public final static boolean TELEMETRY_STATUS_UPDATE_SENT_DEFAULT = false;
7778

7879
// Enable telemetry by default (opt-out).
7980
public final static boolean CRASH_REPORTING_DEFAULT = false;
@@ -112,6 +113,11 @@ public void setTelemetryEnabled(boolean isEnabled) {
112113
editor.putBoolean(mContext.getString(R.string.settings_key_telemetry), isEnabled);
113114
editor.commit();
114115

116+
// We send before disabling in case of opting-out
117+
if (!isEnabled) {
118+
TelemetryWrapper.telemetryStatus(false);
119+
}
120+
115121
// If the state of Telemetry is not the same, we reinitialize it.
116122
final boolean hasEnabled = isTelemetryEnabled();
117123
if (hasEnabled != isEnabled) {
@@ -120,6 +126,28 @@ public void setTelemetryEnabled(boolean isEnabled) {
120126

121127
TelemetryHolder.get().getConfiguration().setUploadEnabled(isEnabled);
122128
TelemetryHolder.get().getConfiguration().setCollectionEnabled(isEnabled);
129+
130+
// We send after enabling in case of opting-in
131+
if (isEnabled) {
132+
TelemetryWrapper.telemetryStatus(true);
133+
}
134+
135+
// Update the status sent flag
136+
setTelemetryPingUpdateSent(true);
137+
}
138+
139+
public boolean telemetryStatusSaved() {
140+
return mPrefs.contains(mContext.getString(R.string.settings_key_telemetry));
141+
}
142+
143+
public boolean isTelemetryPingUpdateSent() {
144+
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_telemetry_status_update_sent), TELEMETRY_STATUS_UPDATE_SENT_DEFAULT);
145+
}
146+
147+
public void setTelemetryPingUpdateSent(boolean isSent) {
148+
SharedPreferences.Editor editor = mPrefs.edit();
149+
editor.putBoolean(mContext.getString(R.string.settings_key_telemetry_status_update_sent), isSent);
150+
editor.commit();
123151
}
124152

125153
public void setGeolocationData(String aGeolocationData) {

app/src/common/shared/org/mozilla/vrbrowser/telemetry/TelemetryWrapper.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import android.os.SystemClock;
77
import android.util.Log;
88

9-
import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient;
9+
import androidx.annotation.NonNull;
10+
import androidx.annotation.UiThread;
11+
1012
import org.mozilla.telemetry.Telemetry;
1113
import org.mozilla.telemetry.TelemetryHolder;
1214
import org.mozilla.telemetry.config.TelemetryConfiguration;
@@ -32,11 +34,11 @@
3234
import java.util.HashSet;
3335
import java.util.Map;
3436

35-
import androidx.annotation.NonNull;
36-
import androidx.annotation.UiThread;
37+
import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient;
3738

3839
import static java.lang.Math.toIntExact;
39-
import static org.mozilla.vrbrowser.ui.widgets.Windows.*;
40+
import static org.mozilla.vrbrowser.ui.widgets.Windows.MAX_WINDOWS;
41+
import static org.mozilla.vrbrowser.ui.widgets.Windows.WindowPlacement;
4042

4143

4244
public class TelemetryWrapper {
@@ -87,6 +89,7 @@ private class Method {
8789
// TODO: Support "select_query" after providing search suggestion.
8890
private static final String VOICE_QUERY = "voice_query";
8991
private static final String IMMERSIVE_MODE = "immersive_mode";
92+
private static final String TELEMETRY_STATUS = "status";
9093

9194
// How many max-windows dialogs happen / what percentage
9295
private static final String MAX_WINDOWS_DIALOG = "max_windows_dialog";
@@ -132,6 +135,7 @@ private class Extra {
132135
private static final String THREE_OPEN_WINDOWS_TIME_PCT = "three_windows_open_time_pct";
133136
private static final String WINDOWS_OPEN_W_MEAN = "window_open_w_mean";
134137
private static final String WINDOWS_PRIVATE_OPEN_W_MEAN = "window_open_private_w_mean";
138+
private static final String TELEMETRY_STATUS = "telemetry_status";
135139
}
136140

137141
// We should call this at the application initial stage. Instead,
@@ -151,6 +155,8 @@ public static void init(Context aContext) {
151155
.setPreferencesImportantForTelemetry(resources.getString(R.string.settings_key_locale))
152156
.setCollectionEnabled(telemetryEnabled)
153157
.setUploadEnabled(telemetryEnabled)
158+
// We need to set this to 1 as we want the telemetry opt-in/out ping always to be sent and the minimum is 3 by default.
159+
.setMinimumEventsForUpload(1)
154160
.setBuildId(String.valueOf(BuildConfig.VERSION_CODE));
155161

156162
final JSONPingSerializer serializer = new JSONPingSerializer();
@@ -166,6 +172,19 @@ public static void init(Context aContext) {
166172
TelemetryHolder.set(new Telemetry(configuration, storage, client, scheduler)
167173
.addPingBuilder(new TelemetryCorePingBuilder(configuration))
168174
.addPingBuilder(new TelemetryMobileEventPingBuilder(configuration)));
175+
176+
// Check if the Telemetry status has ever been saved (enabled/disabled)
177+
boolean saved = SettingsStore.getInstance(aContext).telemetryStatusSaved();
178+
// Check if we have already sent the previous status event
179+
boolean sent = SettingsStore.getInstance(aContext).isTelemetryPingUpdateSent();
180+
// If the Telemetry status has been changed but that ping has not been sent, we send it now
181+
// This should only been true for versions of the app prior to implementing the Telemetry status ping
182+
// We only send the status ping if it was disabled
183+
if (saved && !sent && !telemetryEnabled) {
184+
telemetryStatus(false);
185+
SettingsStore.getInstance(aContext).setTelemetryPingUpdateSent(true);
186+
}
187+
169188
} finally {
170189
StrictMode.setThreadPolicy(threadPolicy);
171190
}
@@ -656,4 +675,17 @@ private static void queueOpenWindowsPctEvent() {
656675
}
657676
}
658677

678+
public static void telemetryStatus(boolean status) {
679+
TelemetryEvent event = TelemetryEvent.create(Category.ACTION, Method.TELEMETRY_STATUS, Object.APP);
680+
event.extra(Extra.TELEMETRY_STATUS, String.valueOf(status));
681+
event.queue();
682+
683+
// We flush immediately as the Telemetry is going to be turned off in case of opting-out
684+
// and we want to make sure that this ping is delivered.
685+
TelemetryHolder.get()
686+
.queuePing(TelemetryCorePingBuilder.TYPE)
687+
.queuePing(TelemetryMobileEventPingBuilder.TYPE)
688+
.scheduleUpload();
689+
}
690+
659691
}

app/src/main/res/values/non_L10n.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<string name="settings_key_autoplay" translatable="false">settings_key_autoplay</string>
4545
<string name="settings_key_pid" translatable="false">settings_key_pid</string>
4646
<string name="settings_key_pop_up_blocking" translatable="false">settings_key_pop_up_blocking</string>
47+
<string name="settings_key_telemetry_status_update_sent" translatable="false">settings_key_telemetry_status_update_sent</string>
4748
<string name="environment_override_help_url" translatable="false">https://github.com/MozillaReality/FirefoxReality/wiki/Environments</string>
4849
<string name="private_policy_url" translatable="false">https://www.mozilla.org/privacy/firefox/</string>
4950
<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>

0 commit comments

Comments
 (0)