Skip to content

Commit

Permalink
Apply commits in #443 #444 #445 #457 as a patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsha Sura committed Mar 16, 2020
1 parent c120f28 commit 99ba4e9
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ android {
release {
minifyEnabled true
}
debug {
minifyEnabled true
}
}

flavorDimensions "version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ public void onClick(View v) {
}
}
});

Button sendTurnstile = findViewById(R.id.turnstile);

sendTurnstile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapboxTelemetry.push(new AppUserTurnstile("fooSdk", "1.0.0"));
}
});
}

@SuppressLint("MissingPermission")
Expand Down Expand Up @@ -175,6 +184,9 @@ public void run() {
});
}
Log.i(LOG_TAG, message);
if (!successful) {
throw new AssertionError("Failed to POST Event: " + code);
}
}

@Override
Expand All @@ -189,6 +201,7 @@ public void run() {
});
}
Log.e(LOG_TAG, "Failure: " + message);
throw new AssertionError("Failed to POST Event");
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@
app:layout_constraintTop_toTopOf="parent" android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintVertical_bias="0.076"/>

<Button
android:text="Send Turnstile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/turnstile"
android:layout_marginTop="20dp"
android:padding="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/fill_queue"/>

</android.support.constraint.ConstraintLayout>
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ext {

pluginVersion = [
checkstyle : '8.4',
gradle : '3.4.1',
gradle : '3.5.3',
dependencyGraph : '0.5.0',
mapboxSdkVersions: '1.0.1'
]
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jun 06 12:04:38 PDT 2019
#Fri Dec 06 11:54:00 PST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import android.annotation.SuppressLint;
import android.os.Parcel;
import android.support.annotation.Keep;
import android.text.TextUtils;


import com.google.gson.annotations.SerializedName;

/**
* This class is temporary and exists only
* to comply with legacy telemetry interface,
Expand All @@ -12,20 +16,34 @@
* back and forth json serialization overhead.
*/
@SuppressLint("ParcelCreator")
@Keep
public class CrashEvent extends Event {
@SerializedName("event")
private final String event;
@SerializedName("created")
private final String created;

@SerializedName("sdkIdentifier")
private String sdkIdentifier;
@SerializedName("sdkVersion")
private String sdkVersion;
@SerializedName("osVersion")
private String osVersion;
@SerializedName("model")
private String model;
@SerializedName("device")
private String device;
@SerializedName("isSilent")
private String isSilent;
@SerializedName("stackTraceHash")
private String stackTraceHash;
@SerializedName("stackTrace")
private String stackTrace;
@SerializedName("threadDetails")
private String threadDetails;
@SerializedName("appId")
private String appId;
@SerializedName("appVersion")
private String appVersion;

public CrashEvent(String event, String created) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.support.v4.content.LocalBroadcastManager;

import android.util.Log;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
Expand Down Expand Up @@ -225,8 +226,16 @@ private boolean isUserAgentValid(String userAgent) {

private void initializeTelemetryClient() {
if (configurationClient == null) {
this.configurationClient = new ConfigurationClient(applicationContext,
TelemetryUtils.createFullUserAgent(userAgent, applicationContext), sAccessToken.get(), new OkHttpClient());
if (BuildConfig.DEBUG) {
// Strict mode work around : https://github.com/square/okhttp/issues/3537
this.configurationClient = new ConfigurationClient(applicationContext,
TelemetryUtils.createFullUserAgent(userAgent, applicationContext), sAccessToken.get(),
TelemetryUtils.createOkHttpClientWithStrictModeWorkAround());
} else {
this.configurationClient = new ConfigurationClient(applicationContext,
TelemetryUtils.createFullUserAgent(userAgent, applicationContext), sAccessToken.get(),
new OkHttpClient());
}
}

if (certificateBlacklist == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,40 @@
import android.os.Parcel;
import android.os.Parcelable;

import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.google.gson.annotations.SerializedName;

import static com.mapbox.android.telemetry.TelemetryEnabler.TELEMETRY_STATES;

@Keep
public class AppUserTurnstile extends Event implements Parcelable {
private static final String APP_USER_TURNSTILE = "appUserTurnstile";
private static final String OPERATING_SYSTEM = "Android - " + Build.VERSION.RELEASE;
private static final String APPLICATION_CONTEXT_CANT_BE_NULL = "Create a MapboxTelemetry instance before calling "
+ "this method.";

@SerializedName("event")
private final String event;
@SerializedName("created")
private final String created;
@SerializedName("userId")
private final String userId;
@SerializedName("enabled.telemetry")
private final boolean enabledTelemetry;
@SerializedName("device")
private final String device;
@SerializedName("sdkIdentifier")
private final String sdkIdentifier;
@SerializedName("sdkVersion")
private final String sdkVersion;
@SerializedName("model")
private final String model;
@SerializedName("operatingSystem")
private final String operatingSystem;
@SerializedName("skuId")
private String skuId;

public AppUserTurnstile(String sdkIdentifier, String sdkVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Keep;


import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

@Keep
public class Attachment extends Event implements Parcelable {
private static final String VIS_ATTACHMENT = "vis.attachment";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Keep;

import com.google.gson.annotations.SerializedName;

@Keep
public class LocationEvent extends Event implements Parcelable {
private static final String LOCATION = "location";
private static final String SOURCE_MAPBOX = "mapbox";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.TrafficStats;
import android.os.BatteryManager;
import android.os.Build;
import android.support.annotation.Nullable;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -26,6 +31,9 @@

import com.mapbox.android.core.MapboxSdkInfoForUserAgentGenerator;

import javax.net.SocketFactory;

import okhttp3.OkHttpClient;
import okio.Buffer;

import static com.mapbox.android.telemetry.MapboxTelemetryConstants.MAPBOX_SHARED_PREFERENCES;
Expand Down Expand Up @@ -292,4 +300,39 @@ static boolean adjustWakeUpMode(Context context) {
}
return false;
}

static OkHttpClient createOkHttpClientWithStrictModeWorkAround() {
return new OkHttpClient().newBuilder()
.socketFactory(new SocketFactory() {
SocketFactory socketFactory = SocketFactory.getDefault();
private static final int THREAD_ID = 10000;

@Override
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
TrafficStats.setThreadStatsTag(THREAD_ID);
return socketFactory.createSocket(host, port);
}

@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws
IOException, UnknownHostException {
TrafficStats.setThreadStatsTag(THREAD_ID);
return socketFactory.createSocket(host, port, localHost, localPort);
}

@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
TrafficStats.setThreadStatsTag(THREAD_ID);
return socketFactory.createSocket(host, port);
}

@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws
IOException {
TrafficStats.setThreadStatsTag(THREAD_ID);
return socketFactory.createSocket(address, port, localAddress, localPort);
}
})
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Keep;


import com.google.gson.annotations.SerializedName;

import java.util.HashMap;

public class VisionEvent extends Event implements Parcelable {
@Keep
public class VisionEvent extends Event implements Parcelable {
private static final String VIS_GENERAL = "vision.general";

@SerializedName("event")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Keep;

import com.google.gson.annotations.SerializedName;

/**
* Vision object detection event v2.
*/

@Keep
public class VisionObjectDetectionEvent extends Event implements Parcelable {
static final String VIS_OBJECT_DETECTION = "vision.objectDetection";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public class SchemaTest {
private static final String LOCATION = "location";
private static ArrayList<JsonObject> schemaArray;

/**
* Properties in Location Schema that are added in backend
* but not incorporated into the Android SDK yet.
**/
private String[] additionalLocationProperties =
{"speed", "course", "floor", "speedAccuracy", "courseAccuracy", "verticalAccuracy"};

@BeforeClass
public static void downloadSchema() throws Exception {
unpackSchemas();
Expand All @@ -56,6 +63,12 @@ public void checkAppUserTurnstileEventFields() throws Exception {
@Test
public void checkLocationEventSize() throws Exception {
JsonObject schema = grabSchema(LOCATION);
if (schema != null) {
// Ignore the location properties that are not incorporated into the android sdk yet.
for (String string : additionalLocationProperties) {
schema.remove(string);
}
}
List<Field> fields = grabClassFields(LocationEvent.class);

assertEquals(schema.size(), fields.size());
Expand All @@ -70,7 +83,6 @@ public void checkLocationEventFields() throws Exception {
}



@Test
public void validateVisionEventFormat() {
JsonObject schema = grabSchema(VisionObjectDetectionEvent.VIS_OBJECT_DETECTION);
Expand Down Expand Up @@ -175,7 +187,7 @@ private static void unpackSchemas() throws IOException {
}

private JsonObject grabSchema(String eventName) {
for (JsonObject thisSchema: schemaArray) {
for (JsonObject thisSchema : schemaArray) {
String name = thisSchema.get("name").getAsString();

if (name.equalsIgnoreCase(eventName)) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapbox/mapbox-events-android",
"version": "4.0.0",
"version": "4.7.1",
"description": "Telemetry and Location Services",
"keywords": [
"mapbox",
Expand All @@ -20,7 +20,7 @@
"pretty-bytes": "^5.1.0"
},
"engines": {
"node": ">=6"
"node": ">=10"
},
"dependencies": {
"@mapbox/cloudfriend": "^2.5.0"
Expand Down

0 comments on commit 99ba4e9

Please sign in to comment.