Skip to content

Commit

Permalink
Merge pull request #7 from maptiler/mme-removal
Browse files Browse the repository at this point in the history
Mapbox mobile events and telemetry removal
  • Loading branch information
petr-pokorny-1 authored Jan 26, 2021
2 parents 6278642 + bd5df13 commit 01609cb
Show file tree
Hide file tree
Showing 378 changed files with 3,576 additions and 3,788 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
tags-ignore:
- '**'
paths-ignore:
- "parform/ios/**"
- "platform/ios/**"
- ".github/**"
- "README.md"
branches:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
/platform/android/x86_64
/.idea
/cmake-build-debug
/platform/android/.idea
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,9 @@
[submodule "platform/android/vendor/mapbox-gestures-android"]
path = platform/android/vendor/mapbox-gestures-android
url = https://github.com/mapbox/mapbox-gestures-android.git
[submodule "platform/ios/platform/ios/vendor/mapbox-events-ios"]
path = platform/ios/platform/ios/vendor/mapbox-events-ios
url = https://github.com/mapbox/mapbox-events-ios.git
[submodule "platform/ios/platform/darwin/docs/theme"]
path = platform/ios/platform/darwin/docs/theme
url = https://github.com/mapbox/jazzy-theme.git
[submodule "platform/android/vendor/mapbox-events-android"]
path = platform/android/vendor/mapbox-events-android
url = https://github.com/mapbox/mapbox-events-android.git
[submodule "maplibre-gl-js"]
path = maplibre-gl-js
url = https://github.com/maplibre/maplibre-gl-js.git
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package android.app;

import android.util.Log;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.Assert;
import org.junit.runner.RunWith;
import android.util.Log;

@LargeTest
@RunWith(AndroidJUnit4.class)
Expand Down
6 changes: 0 additions & 6 deletions platform/android/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,6 @@ License: [BSD](https://opensource.org/licenses/BSD-2-Clause)

===========================================================================

Mapbox GL uses portions of Mapbox Android Telemetry Library.
URL: [https://github.com/mapbox/mapbox-events-android](https://github.com/mapbox/mapbox-events-android)
License: [The MIT License](https://opensource.org/licenses/MIT)

===========================================================================

Mapbox GL uses portions of Mapbox Java SDK.
URL: [https://github.com/mapbox/mapbox-java](https://github.com/mapbox/mapbox-java)
License: [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)
Expand Down
5 changes: 4 additions & 1 deletion platform/android/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ apply plugin: 'com.mapbox.android.sdk.versions'

dependencies {
lintChecks project(":MapboxGLAndroidSDKLint")
api dependenciesList.mapboxAndroidTelemetry
api dependenciesList.mapboxJavaGeoJSON
api dependenciesList.mapboxAndroidGestures
api dependenciesList.mapboxAndroidAccounts

implementation dependenciesList.mapboxJavaTurf
implementation dependenciesList.supportAnnotations
implementation dependenciesList.supportFragmentV4
implementation dependenciesList.okhttp3
implementation dependenciesList.gmsLocation

testImplementation dependenciesList.junit
testImplementation dependenciesList.mockito
testImplementation dependenciesList.mockk
testImplementation dependenciesList.robolectric
testImplementation dependenciesList.kotlinLib
testImplementation dependenciesList.commonsIO
testImplementation dependenciesList.assertjcore
}

android {
Expand Down
5 changes: 1 addition & 4 deletions platform/android/MapboxGLAndroidSDK/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-dontnote com.mapbox.mapboxsdk.maps.MapboxMap
-dontnote com.mapbox.mapboxsdk.maps.MapboxMapOptions
-dontnote com.mapbox.mapboxsdk.log.LoggerDefinition
-dontnote com.mapbox.android.core.location.LocationEnginePriority
-dontnote com.mapbox.mapboxsdk.location.engine.LocationEnginePriority

# config for okhttp 3.11.0, https://github.com/square/okhttp/pull/3354
-dontwarn javax.annotation.**
Expand All @@ -27,9 +27,6 @@
-keep class com.mapbox.geojson.** { *; }
-dontwarn com.google.auto.value.**

# config for telemetry events
-keep class com.mapbox.mapboxsdk.module.telemetry.** { *; }

# config for additional notes
-dontnote org.robolectric.Robolectric
-dontnote libcore.io.Memory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.text.format.DateUtils;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;

import com.mapbox.android.accounts.v1.MapboxAccounts;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.log.Logger;

import static com.mapbox.mapboxsdk.constants.MapboxConstants.KEY_PREFERENCE_SKU_TOKEN;

/**
* REMOVAL OR MODIFICATION OF THE FOLLOWING CODE VIOLATES THE MAPBOX TERMS
* OF SERVICE
Expand All @@ -39,45 +38,19 @@ class AccountsManager {

private SharedPreferences sharedPreferences;
private String userId;
private String skuToken;
private long timestamp;
private boolean isManaged;

AccountsManager() {
isManaged = isSkuTokenManaged();
initialize();
}

@VisibleForTesting
AccountsManager(SharedPreferences sharedPreferences, boolean isManaged) {
AccountsManager(SharedPreferences sharedPreferences) {
this.sharedPreferences = sharedPreferences;
this.isManaged = isManaged;
initialize();
}

private void initialize() {
retrieveSkuTokenAndTimestamp();
if (isManaged) {
validateRotation();
}
}

private boolean isSkuTokenManaged() {
boolean value = MapboxConstants.DEFAULT_MANAGE_SKU_TOKEN;
try {
// Try getting a custom value from the app Manifest
ApplicationInfo appInfo = retrieveApplicationInfo();
if (appInfo.metaData != null) {
value = appInfo.metaData.getBoolean(
MapboxConstants.KEY_META_DATA_MANAGE_SKU_TOKEN,
MapboxConstants.DEFAULT_MANAGE_SKU_TOKEN
);
}
} catch (Exception exception) {
Logger.e(TAG, "Failed to read the package metadata: ", exception);
}

return value;
}

private ApplicationInfo retrieveApplicationInfo() throws PackageManager.NameNotFoundException {
Expand All @@ -86,33 +59,6 @@ private ApplicationInfo retrieveApplicationInfo() throws PackageManager.NameNotF
PackageManager.GET_META_DATA);
}

private void retrieveSkuTokenAndTimestamp() {
SharedPreferences sharedPreferences = getSharedPreferences();
skuToken = sharedPreferences.getString(KEY_PREFERENCE_SKU_TOKEN, "");
timestamp = sharedPreferences.getLong(PREFERENCE_TIMESTAMP, 0L);
}

private void validateRotation() {
if (TextUtils.isEmpty(skuToken) || timestamp == 0L) {
skuToken = generateSkuToken(getUserId());
timestamp = persistRotation(skuToken);
}
}

String getSkuToken() {
if (isManaged) {
if (isExpired()) {
skuToken = generateSkuToken(getUserId());
timestamp = persistRotation(skuToken);
}
} else {
SharedPreferences sharedPreferences = getSharedPreferences();
String notManagedSkuToken = sharedPreferences.getString(KEY_PREFERENCE_SKU_TOKEN, "");
skuToken = notManagedSkuToken;
}
return skuToken;
}

private boolean isExpired() {
return isExpired(getNow(), timestamp);
}
Expand All @@ -121,15 +67,6 @@ static boolean isExpired(long now, long then) {
return ((now - then) > DateUtils.HOUR_IN_MILLIS);
}

private long persistRotation(String skuToken) {
long now = getNow();
SharedPreferences.Editor editor = getSharedPreferences().edit();
editor.putLong(PREFERENCE_TIMESTAMP, now);
editor.putString(KEY_PREFERENCE_SKU_TOKEN, skuToken);
editor.apply();
return now;
}

@NonNull
private SharedPreferences getSharedPreferences() {
if (sharedPreferences == null) {
Expand Down Expand Up @@ -167,9 +104,4 @@ private synchronized String getUserId() {
private String generateUserId() {
return MapboxAccounts.obtainEndUserId();
}

@NonNull
private String generateSkuToken(String userId) {
return MapboxAccounts.obtainMapsSkuUserToken(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.AssetManager;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;

import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
import com.mapbox.mapboxsdk.log.Logger;
import com.mapbox.mapboxsdk.maps.TelemetryDefinition;
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
import com.mapbox.mapboxsdk.storage.FileSource;
import com.mapbox.mapboxsdk.utils.ThreadUtils;
Expand All @@ -37,8 +36,6 @@ public final class Mapbox {
@Nullable
private String accessToken;
@Nullable
private TelemetryDefinition telemetry;
@Nullable
private AccountsManager accounts;

/**
Expand All @@ -61,7 +58,6 @@ public static synchronized Mapbox getInstance(@NonNull Context context, @Nullabl
FileSource.initializeFileDirsPaths(appContext);
INSTANCE = new Mapbox(appContext, accessToken);
if (isAccessTokenValid(accessToken)) {
initializeTelemetry();
INSTANCE.accounts = new AccountsManager();
}
ConnectivityReceiver.instance(appContext);
Expand Down Expand Up @@ -92,39 +88,15 @@ public static void setAccessToken(String accessToken) {
validateMapbox();
INSTANCE.accessToken = accessToken;

// cleanup telemetry which is dependent on an access token
if (INSTANCE.telemetry != null) {
INSTANCE.telemetry.disableTelemetrySession();
INSTANCE.telemetry = null;
}

// initialize components dependent on a token
if (isAccessTokenValid(accessToken)) {
initializeTelemetry();
INSTANCE.accounts = new AccountsManager();
} else {
INSTANCE.accounts = null;
}
FileSource.getInstance(getApplicationContext()).setAccessToken(accessToken);
}

/**
* Returns a SKU token, refreshed if necessary. This method is meant for internal SDK
* usage only.
*
* @return the SKU token
*/
public static String getSkuToken() {
if (!hasInstance() || INSTANCE.accounts == null) {
throw new MapboxConfigurationException(
"A valid access token parameter is required when using a Mapbox service."
+ "\nPlease see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one."
+ "\nMore information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens."
+ "Currently provided token is: " + INSTANCE.accessToken);
}
return INSTANCE.accounts.getSkuToken();
}

/**
* Application context
*
Expand Down Expand Up @@ -159,29 +131,6 @@ public static synchronized Boolean isConnected() {
return ConnectivityReceiver.instance(INSTANCE.context).isConnected();
}

/**
* Initializes telemetry
*/
private static void initializeTelemetry() {
try {
INSTANCE.telemetry = getModuleProvider().obtainTelemetry();
} catch (Exception exception) {
String message = "Error occurred while initializing telemetry";
Logger.e(TAG, message, exception);
MapStrictMode.strictModeViolation(message, exception);
}
}

/**
* Get an instance of Telemetry if initialised
*
* @return instance of telemetry
*/
@Nullable
public static TelemetryDefinition getTelemetry() {
return hasInstance() ? INSTANCE.telemetry : null;
}

/**
* Get the module provider
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.mapbox.mapboxsdk;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.mapbox.mapboxsdk.http.HttpRequest;
import com.mapbox.mapboxsdk.maps.TelemetryDefinition;

/**
* Injects concrete instances of configurable abstractions
Expand All @@ -18,15 +17,6 @@ public interface ModuleProvider {
@NonNull
HttpRequest createHttpRequest();

/**
* Get the concrete implementation of TelemetryDefinition
*
* @return a single instance of Telemetry
*/
@Nullable
TelemetryDefinition obtainTelemetry();


/**
* Get the concrete implementation of LibraryLoaderProvider
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.mapbox.mapboxsdk;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.mapbox.mapboxsdk.http.HttpRequest;
import com.mapbox.mapboxsdk.maps.TelemetryDefinition;
import com.mapbox.mapboxsdk.module.http.HttpRequestImpl;
import com.mapbox.mapboxsdk.module.loader.LibraryLoaderProviderImpl;
import com.mapbox.mapboxsdk.module.telemetry.TelemetryImpl;

public class ModuleProviderImpl implements ModuleProvider {

Expand All @@ -16,12 +14,6 @@ public HttpRequest createHttpRequest() {
return new HttpRequestImpl();
}

@Override
@Nullable
public TelemetryDefinition obtainTelemetry() {
return new TelemetryImpl();
}

@NonNull
@Override
public LibraryLoaderProvider createLibraryLoaderProvider() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.mapbox.mapboxsdk.annotations;

import androidx.annotation.NonNull;

import androidx.annotation.Nullable;

import com.mapbox.mapboxsdk.maps.MapView;
Expand Down
Loading

0 comments on commit 01609cb

Please sign in to comment.