6
6
import android .os .SystemClock ;
7
7
import android .util .Log ;
8
8
9
- import mozilla .components .lib .fetch .httpurlconnection .HttpURLConnectionClient ;
9
+ import androidx .annotation .NonNull ;
10
+ import androidx .annotation .UiThread ;
11
+
10
12
import org .mozilla .telemetry .Telemetry ;
11
13
import org .mozilla .telemetry .TelemetryHolder ;
12
14
import org .mozilla .telemetry .config .TelemetryConfiguration ;
32
34
import java .util .HashSet ;
33
35
import java .util .Map ;
34
36
35
- import androidx .annotation .NonNull ;
36
- import androidx .annotation .UiThread ;
37
+ import mozilla .components .lib .fetch .httpurlconnection .HttpURLConnectionClient ;
37
38
38
39
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 ;
40
42
41
43
42
44
public class TelemetryWrapper {
@@ -87,6 +89,7 @@ private class Method {
87
89
// TODO: Support "select_query" after providing search suggestion.
88
90
private static final String VOICE_QUERY = "voice_query" ;
89
91
private static final String IMMERSIVE_MODE = "immersive_mode" ;
92
+ private static final String TELEMETRY_STATUS = "status" ;
90
93
91
94
// How many max-windows dialogs happen / what percentage
92
95
private static final String MAX_WINDOWS_DIALOG = "max_windows_dialog" ;
@@ -132,6 +135,7 @@ private class Extra {
132
135
private static final String THREE_OPEN_WINDOWS_TIME_PCT = "three_windows_open_time_pct" ;
133
136
private static final String WINDOWS_OPEN_W_MEAN = "window_open_w_mean" ;
134
137
private static final String WINDOWS_PRIVATE_OPEN_W_MEAN = "window_open_private_w_mean" ;
138
+ private static final String TELEMETRY_STATUS = "telemetry_status" ;
135
139
}
136
140
137
141
// We should call this at the application initial stage. Instead,
@@ -151,6 +155,8 @@ public static void init(Context aContext) {
151
155
.setPreferencesImportantForTelemetry (resources .getString (R .string .settings_key_locale ))
152
156
.setCollectionEnabled (telemetryEnabled )
153
157
.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 )
154
160
.setBuildId (String .valueOf (BuildConfig .VERSION_CODE ));
155
161
156
162
final JSONPingSerializer serializer = new JSONPingSerializer ();
@@ -166,6 +172,19 @@ public static void init(Context aContext) {
166
172
TelemetryHolder .set (new Telemetry (configuration , storage , client , scheduler )
167
173
.addPingBuilder (new TelemetryCorePingBuilder (configuration ))
168
174
.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
+
169
188
} finally {
170
189
StrictMode .setThreadPolicy (threadPolicy );
171
190
}
@@ -656,4 +675,17 @@ private static void queueOpenWindowsPctEvent() {
656
675
}
657
676
}
658
677
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
+
659
691
}
0 commit comments