diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module')
14 files changed, 0 insertions, 1327 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/http/HttpRequestImpl.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/http/HttpRequestImpl.java deleted file mode 100644 index 24cb353d24..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/http/HttpRequestImpl.java +++ /dev/null @@ -1,196 +0,0 @@ -package com.mapbox.mapboxsdk.module.http; - -import android.os.Build; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; -import android.text.TextUtils; -import android.util.Log; -import com.mapbox.mapboxsdk.BuildConfig; -import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.mapbox.mapboxsdk.http.HttpIdentifier; -import com.mapbox.mapboxsdk.http.HttpLogger; -import com.mapbox.mapboxsdk.http.HttpRequest; -import com.mapbox.mapboxsdk.http.HttpRequestUrl; -import com.mapbox.mapboxsdk.http.HttpResponder; -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.Dispatcher; -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.ResponseBody; - -import javax.net.ssl.SSLException; -import java.io.IOException; -import java.io.InterruptedIOException; -import java.net.NoRouteToHostException; -import java.net.ProtocolException; -import java.net.SocketException; -import java.net.UnknownHostException; - -import static com.mapbox.mapboxsdk.module.http.HttpRequestUtil.toHumanReadableAscii; - -public class HttpRequestImpl implements HttpRequest { - - private static final String userAgentString = toHumanReadableAscii( - String.format("%s %s (%s) Android/%s (%s)", - HttpIdentifier.getIdentifier(), - BuildConfig.MAPBOX_VERSION_STRING, - BuildConfig.GIT_REVISION_SHORT, - Build.VERSION.SDK_INT, - Build.CPU_ABI) - ); - - @VisibleForTesting - static final OkHttpClient DEFAULT_CLIENT = new OkHttpClient.Builder().dispatcher(getDispatcher()).build(); - - @VisibleForTesting - static OkHttpClient client = DEFAULT_CLIENT; - - private Call call; - - @Override - public void executeRequest(HttpResponder httpRequest, long nativePtr, @NonNull String resourceUrl, - @NonNull String etag, @NonNull String modified, boolean offlineUsage) { - OkHttpCallback callback = new OkHttpCallback(httpRequest); - try { - HttpUrl httpUrl = HttpUrl.parse(resourceUrl); - if (httpUrl == null) { - HttpLogger.log(Log.ERROR, String.format("[HTTP] Unable to parse resourceUrl %s", resourceUrl)); - return; - } - - final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE); - resourceUrl = HttpRequestUrl.buildResourceUrl(host, resourceUrl, httpUrl.querySize(), offlineUsage); - - final Request.Builder builder = new Request.Builder() - .url(resourceUrl) - .tag(resourceUrl.toLowerCase(MapboxConstants.MAPBOX_LOCALE)) - .addHeader("User-Agent", userAgentString); - if (etag.length() > 0) { - builder.addHeader("If-None-Match", etag); - } else if (modified.length() > 0) { - builder.addHeader("If-Modified-Since", modified); - } - - final Request request = builder.build(); - call = client.newCall(request); - call.enqueue(callback); - } catch (Exception exception) { - callback.handleFailure(call, exception); - } - } - - @Override - public void cancelRequest() { - // call can be null if the constructor gets aborted (e.g, under a NoRouteToHostException). - if (call != null) { - call.cancel(); - } - } - - public static void enablePrintRequestUrlOnFailure(boolean enabled) { - HttpLogger.logRequestUrl = enabled; - } - - public static void enableLog(boolean enabled) { - HttpLogger.logEnabled = enabled; - } - - public static void setOkHttpClient(@Nullable OkHttpClient okHttpClient) { - if (okHttpClient != null) { - HttpRequestImpl.client = okHttpClient; - } else { - HttpRequestImpl.client = DEFAULT_CLIENT; - } - } - - private static class OkHttpCallback implements Callback { - - private HttpResponder httpRequest; - - OkHttpCallback(HttpResponder httpRequest) { - this.httpRequest = httpRequest; - } - - @Override - public void onFailure(@NonNull Call call, @NonNull IOException e) { - handleFailure(call, e); - } - - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - HttpLogger.log(Log.VERBOSE, String.format("[HTTP] Request was successful (code = %s).", response.code())); - } else { - // We don't want to call this unsuccessful because a 304 isn't really an error - String message = !TextUtils.isEmpty(response.message()) ? response.message() : "No additional information"; - HttpLogger.log(Log.DEBUG, String.format("[HTTP] Request with response = %s: %s", response.code(), message)); - } - - ResponseBody responseBody = response.body(); - if (responseBody == null) { - HttpLogger.log(Log.ERROR, "[HTTP] Received empty response body"); - return; - } - - byte[] body; - try { - body = responseBody.bytes(); - } catch (IOException ioException) { - onFailure(call, ioException); - // throw ioException; - return; - } finally { - response.close(); - } - - httpRequest.onResponse(response.code(), - response.header("ETag"), - response.header("Last-Modified"), - response.header("Cache-Control"), - response.header("Expires"), - response.header("Retry-After"), - response.header("x-rate-limit-reset"), - body); - } - - private void handleFailure(@Nullable Call call, Exception e) { - String errorMessage = e.getMessage() != null ? e.getMessage() : "Error processing the request"; - int type = getFailureType(e); - - if (HttpLogger.logEnabled && call != null && call.request() != null) { - String requestUrl = call.request().url().toString(); - HttpLogger.logFailure(type, errorMessage, requestUrl); - } - httpRequest.handleFailure(type, errorMessage); - } - - private int getFailureType(Exception e) { - if ((e instanceof NoRouteToHostException) || (e instanceof UnknownHostException) || (e instanceof SocketException) - || (e instanceof ProtocolException) || (e instanceof SSLException)) { - return CONNECTION_ERROR; - } else if ((e instanceof InterruptedIOException)) { - return TEMPORARY_ERROR; - } - return PERMANENT_ERROR; - } - } - - @NonNull - private static Dispatcher getDispatcher() { - Dispatcher dispatcher = new Dispatcher(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - // Matches core limit set on - // https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/src/http_file_source.cpp#L192 - dispatcher.setMaxRequestsPerHost(20); - } else { - // Limiting concurrent request on Android 4.4, to limit impact of SSL handshake platform library crash - // https://github.com/mapbox/mapbox-gl-native/issues/14910 - dispatcher.setMaxRequestsPerHost(10); - } - return dispatcher; - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/http/HttpRequestUtil.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/http/HttpRequestUtil.java deleted file mode 100644 index 5d8dafbdf2..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/http/HttpRequestUtil.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.mapbox.mapboxsdk.module.http; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import okhttp3.OkHttpClient; -import okio.Buffer; - -/** - * Utility class for setting OkHttpRequest configurations - */ -public class HttpRequestUtil { - - /** - * Set the log state of OkHttpRequest. Default value is true. - * <p> - * This configuration will outlast the lifecycle of the Map. - * </p> - * - * @param enabled True will enable logging, false will disable - */ - public static void setLogEnabled(boolean enabled) { - HttpRequestImpl.enableLog(enabled); - } - - /** - * Enable printing of the request url when an error occurred. Default value is false. - * <p> - * Requires {@link #setLogEnabled(boolean)} to be activated. - * </p> - * <p> - * This configuration will outlast the lifecycle of the Map. - * </p> - * - * @param enabled True will print urls, false will disable - */ - public static void setPrintRequestUrlOnFailure(boolean enabled) { - HttpRequestImpl.enablePrintRequestUrlOnFailure(enabled); - } - - /** - * Set the OkHttpClient used for requesting map resources. - * <p> - * This configuration survives across mapView instances. - * Reset the OkHttpClient to the default by passing null as parameter. - * </p> - * - * @param client the OkHttpClient - */ - public static void setOkHttpClient(@Nullable OkHttpClient client) { - HttpRequestImpl.setOkHttpClient(client); - } - - @NonNull - static String toHumanReadableAscii(String s) { - for (int i = 0, length = s.length(), c; i < length; i += Character.charCount(c)) { - c = s.codePointAt(i); - if (c > '\u001f' && c < '\u007f') { - continue; - } - - Buffer buffer = new Buffer(); - buffer.writeUtf8(s, 0, i); - for (int j = i; j < length; j += Character.charCount(c)) { - c = s.codePointAt(j); - buffer.writeUtf8CodePoint(c > '\u001f' && c < '\u007f' ? c : '?'); - } - return buffer.readUtf8(); - } - return s; - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/http/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/http/package-info.java deleted file mode 100644 index d2f42025d8..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/http/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Contains the Mapbox Maps Android Modular Http API classes. - */ -package com.mapbox.mapboxsdk.module.http; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/loader/LibraryLoaderProviderImpl.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/loader/LibraryLoaderProviderImpl.java deleted file mode 100644 index 9e5e72d409..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/loader/LibraryLoaderProviderImpl.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.mapbox.mapboxsdk.module.loader; - -import com.mapbox.mapboxsdk.LibraryLoader; -import com.mapbox.mapboxsdk.LibraryLoaderProvider; -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException; -import com.mapbox.mapboxsdk.log.Logger; - -import static com.facebook.soloader.SoLoader.init; -import static com.facebook.soloader.SoLoader.loadLibrary; - -/** - * Concrete implementation of a native library loader. - * <p> - * Uses ReLinker from https://github.com/KeepSafe/ReLinker. - * </p> - */ -public class LibraryLoaderProviderImpl implements LibraryLoaderProvider { - - /** - * Creates and returns a the default Library Loader. - * - * @return the default library loader - */ - @Override - public LibraryLoader getDefaultLibraryLoader() { - return new SoLibraryLoader(); - } - - /** - * Concrete implementation of a LibraryLoader using ReLinker. - */ - private static class SoLibraryLoader extends LibraryLoader { - - private static final String TAG = "SoLibraryLoader"; - - @Override - public void load(String name) { - try { - // nativeExopackage = false, https://buck.build/article/exopackage.html - init(Mapbox.getApplicationContext(), false); - loadLibrary(name); - } catch (MapboxConfigurationException exception) { - Logger.e(TAG, "Couldn't load so file with relinker, application context missing, " - + "call Mapbox.getInstance(Context context, String accessToken) first"); - } - } - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/loader/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/loader/package-info.java deleted file mode 100644 index e296baeffe..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/loader/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Contains the Mapbox Maps Android Modular Library Loader API classes. - */ -package com.mapbox.mapboxsdk.module.loader; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapBaseEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapBaseEvent.java deleted file mode 100644 index 130217fea7..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapBaseEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.mapbox.mapboxsdk.module.telemetry; - -import android.annotation.SuppressLint; -import android.os.Parcel; - -import com.mapbox.android.telemetry.Event; - -/** - * Base event class for telemetry events. - */ -@SuppressLint("ParcelCreator") -abstract class MapBaseEvent extends Event { - private final String event; - private final String created; - - MapBaseEvent(PhoneState phoneState) { - this.event = getEventName(); - this.created = phoneState.getCreated(); - } - - abstract String getEventName(); - - String getEvent() { - return event; - } - - String getCreated() { - return created; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactory.java deleted file mode 100644 index 14b5c6231f..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.mapbox.mapboxsdk.module.telemetry; - -import android.os.Bundle; -import android.support.annotation.FloatRange; -import android.support.annotation.NonNull; - -import com.mapbox.android.telemetry.TelemetryUtils; -import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.mapbox.mapboxsdk.offline.OfflineRegion; - -class MapEventFactory { - - static MapLoadEvent buildMapLoadEvent(@NonNull PhoneState phoneState) { - String userId = TelemetryUtils.retrieveVendorId(); - return new MapLoadEvent(userId, phoneState); - } - - static OfflineDownloadStartEvent buildOfflineDownloadStartEvent(PhoneState phoneState, - String shapeForOfflineRegion, - @FloatRange(from = MapboxConstants.MINIMUM_ZOOM, - to = MapboxConstants.MAXIMUM_ZOOM) Double minZoom, - @FloatRange(from = MapboxConstants.MINIMUM_ZOOM, - to = MapboxConstants.MAXIMUM_ZOOM) Double maxZoom, - String styleURL) { - - OfflineDownloadStartEvent offlineEvent = - new OfflineDownloadStartEvent(phoneState, shapeForOfflineRegion, minZoom, maxZoom); - offlineEvent.setStyleURL(styleURL); - return offlineEvent; - } - - static OfflineDownloadEndEvent buildOfflineDownloadCompleteEvent(PhoneState phoneState, - String shapeForOfflineRegion, - @FloatRange(from = MapboxConstants.MINIMUM_ZOOM, - to = MapboxConstants.MAXIMUM_ZOOM) Double minZoom, - @FloatRange(from = MapboxConstants.MINIMUM_ZOOM, - to = MapboxConstants.MAXIMUM_ZOOM) Double maxZoom, - String styleURL, - long sizeOfResourcesCompleted, - long numberOfTilesCompleted, - @OfflineRegion.DownloadState int state) { - - OfflineDownloadEndEvent offlineEvent = - new OfflineDownloadEndEvent(phoneState, shapeForOfflineRegion, minZoom, maxZoom); - offlineEvent.setStyleURL(styleURL); - offlineEvent.setSizeOfResourcesCompleted(sizeOfResourcesCompleted); - offlineEvent.setNumberOfTilesCompleted(numberOfTilesCompleted); - offlineEvent.setState(state); - return offlineEvent; - } - - static PerformanceEvent buildPerformanceEvent(@NonNull PhoneState phoneState, @NonNull String sessionId, - @NonNull Bundle data) { - return new PerformanceEvent(phoneState, sessionId, data); - } - -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java deleted file mode 100644 index b12a10b8c4..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.mapbox.mapboxsdk.module.telemetry; - -import android.annotation.SuppressLint; -import android.os.Build; - -import com.mapbox.mapboxsdk.BuildConfig; - -/** - * Event will be sent while map is loaded. - */ -@SuppressLint("ParcelCreator") -class MapLoadEvent extends MapBaseEvent { - private static final String EVENT_NAME = "map.load"; - private final String operatingSystem = "Android - " + Build.VERSION.RELEASE; - private final String sdkIdentifier = BuildConfig.MAPBOX_SDK_IDENTIFIER; - private final String sdkVersion = BuildConfig.MAPBOX_SDK_VERSION; - private final String model = Build.MODEL; - private final String userId; - private final String carrier; - private final String cellularNetworkType; - private final String orientation; - private final float resolution; - private final float accessibilityFontScale; - private final int batteryLevel; - private final boolean pluggedIn; - private final boolean wifi; - - MapLoadEvent(String userId, PhoneState phoneState) { - super(phoneState); - this.userId = userId; - this.batteryLevel = phoneState.getBatteryLevel(); - this.pluggedIn = phoneState.isPluggedIn(); - this.cellularNetworkType = phoneState.getCellularNetworkType(); - this.carrier = phoneState.getCarrier(); - this.resolution = phoneState.getResolution(); - this.accessibilityFontScale = phoneState.getAccessibilityFontScale(); - this.wifi = phoneState.isWifi(); - this.orientation = phoneState.getOrientation(); - } - - @Override - String getEventName() { - return EVENT_NAME; - } - - String getOperatingSystem() { - return operatingSystem; - } - - String getSdkIdentifier() { - return sdkIdentifier; - } - - String getSdkVersion() { - return sdkVersion; - } - - String getModel() { - return model; - } - - String getUserId() { - return userId; - } - - String getCarrier() { - return carrier; - } - - String getCellularNetworkType() { - return cellularNetworkType; - } - - String getOrientation() { - return orientation; - } - - float getResolution() { - return resolution; - } - - float getAccessibilityFontScale() { - return accessibilityFontScale; - } - - int getBatteryLevel() { - return batteryLevel; - } - - boolean isPluggedIn() { - return pluggedIn; - } - - boolean isWifi() { - return wifi; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - MapLoadEvent that = (MapLoadEvent) o; - - if (Float.compare(that.resolution, resolution) != 0) { - return false; - } - if (Float.compare(that.accessibilityFontScale, accessibilityFontScale) != 0) { - return false; - } - if (batteryLevel != that.batteryLevel) { - return false; - } - if (pluggedIn != that.pluggedIn) { - return false; - } - if (wifi != that.wifi) { - return false; - } - if (!operatingSystem.equals(that.operatingSystem)) { - return false; - } - if (model != null ? !model.equals(that.model) : that.model != null) { - return false; - } - if (userId != null ? !userId.equals(that.userId) : that.userId != null) { - return false; - } - if (carrier != null ? !carrier.equals(that.carrier) : that.carrier != null) { - return false; - } - if (cellularNetworkType != null ? !cellularNetworkType.equals(that.cellularNetworkType) : - that.cellularNetworkType != null) { - return false; - } - return orientation != null ? orientation.equals(that.orientation) : that.orientation == null; - } - - @Override - public int hashCode() { - int result = operatingSystem != null ? operatingSystem.hashCode() : 0; - result = 31 * result + sdkIdentifier.hashCode(); - result = 31 * result + sdkVersion.hashCode(); - result = 31 * result + (model != null ? model.hashCode() : 0); - result = 31 * result + (userId != null ? userId.hashCode() : 0); - result = 31 * result + (carrier != null ? carrier.hashCode() : 0); - result = 31 * result + (cellularNetworkType != null ? cellularNetworkType.hashCode() : 0); - result = 31 * result + (orientation != null ? orientation.hashCode() : 0); - result = 31 * result + (resolution != +0.0f ? Float.floatToIntBits(resolution) : 0); - result = 31 * result + (accessibilityFontScale != +0.0f ? Float.floatToIntBits(accessibilityFontScale) : 0); - result = 31 * result + batteryLevel; - result = 31 * result + (pluggedIn ? 1 : 0); - result = 31 * result + (wifi ? 1 : 0); - return result; - } - - @Override - public String toString() { - return "MapLoadEvent{" - + ", operatingSystem='" + operatingSystem + '\'' - + ", sdkIdentifier='" + sdkIdentifier + '\'' - + ", sdkVersion='" + sdkVersion + '\'' - + ", model='" + model + '\'' - + ", userId='" + userId + '\'' - + ", carrier='" + carrier + '\'' - + ", cellularNetworkType='" + cellularNetworkType + '\'' - + ", orientation='" + orientation + '\'' - + ", resolution=" + resolution - + ", accessibilityFontScale=" + accessibilityFontScale - + ", batteryLevel=" + batteryLevel - + ", pluggedIn=" + pluggedIn - + ", wifi=" + wifi - + '}'; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java deleted file mode 100644 index 9f1b053a88..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.mapbox.mapboxsdk.module.telemetry; - -import android.annotation.SuppressLint; -import android.support.annotation.FloatRange; - -import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.mapbox.mapboxsdk.offline.OfflineRegion; - -/** - * Event will be sent while offline download end. - */ -@SuppressLint("ParcelCreator") -public class OfflineDownloadEndEvent extends MapBaseEvent { - private static final String EVENT_NAME = "map.offlineDownload.end"; - private final Double minZoom; - private final Double maxZoom; - private final String shapeForOfflineRegion; - private String styleURL; - private String state; - private long sizeOfResourcesCompleted; - private long numberOfTilesCompleted; - - OfflineDownloadEndEvent(PhoneState phoneState, String shapeForOfflineRegion, - @FloatRange(from = MapboxConstants.MINIMUM_ZOOM, - to = MapboxConstants.MAXIMUM_ZOOM) Double minZoom, - @FloatRange(from = MapboxConstants.MINIMUM_ZOOM, - to = MapboxConstants.MAXIMUM_ZOOM) Double maxZoom) { - super(phoneState); - this.shapeForOfflineRegion = shapeForOfflineRegion; - this.minZoom = minZoom; - this.maxZoom = maxZoom; - } - - @Override - String getEventName() { - return EVENT_NAME; - } - - Double getMinZoom() { - return minZoom; - } - - Double getMaxZoom() { - return maxZoom; - } - - String getShapeForOfflineRegion() { - return shapeForOfflineRegion; - } - - String getStyleURL() { - return styleURL; - } - - void setStyleURL(String styleURL) { - this.styleURL = styleURL; - } - - long getSizeOfResourcesCompleted() { - return sizeOfResourcesCompleted; - } - - void setSizeOfResourcesCompleted(long sizeOfResourcesCompleted) { - this.sizeOfResourcesCompleted = sizeOfResourcesCompleted; - } - - long getNumberOfTilesCompleted() { - return numberOfTilesCompleted; - } - - void setNumberOfTilesCompleted(long numberOfTilesCompleted) { - this.numberOfTilesCompleted = numberOfTilesCompleted; - } - - String getState() { - return state; - } - - void setState(@OfflineRegion.DownloadState int state) { - this.state = String.valueOf(state); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - OfflineDownloadEndEvent that = (OfflineDownloadEndEvent) o; - - if (sizeOfResourcesCompleted != that.sizeOfResourcesCompleted) { - return false; - } - if (numberOfTilesCompleted != that.numberOfTilesCompleted) { - return false; - } - if (minZoom != null ? !minZoom.equals(that.minZoom) : that.minZoom != null) { - return false; - } - if (maxZoom != null ? !maxZoom.equals(that.maxZoom) : that.maxZoom != null) { - return false; - } - if (shapeForOfflineRegion != null ? !shapeForOfflineRegion.equals(that.shapeForOfflineRegion) - : that.shapeForOfflineRegion != null) { - return false; - } - if (styleURL != null ? !styleURL.equals(that.styleURL) : that.styleURL != null) { - return false; - } - return state != null ? state.equals(that.state) : that.state == null; - } - - @Override - public int hashCode() { - int result = minZoom != null ? minZoom.hashCode() : 0; - result = 31 * result + (maxZoom != null ? maxZoom.hashCode() : 0); - result = 31 * result + (shapeForOfflineRegion != null ? shapeForOfflineRegion.hashCode() : 0); - result = 31 * result + (styleURL != null ? styleURL.hashCode() : 0); - result = 31 * result + (state != null ? state.hashCode() : 0); - result = 31 * result + (int) (sizeOfResourcesCompleted ^ (sizeOfResourcesCompleted >>> 32)); - result = 31 * result + (int) (numberOfTilesCompleted ^ (numberOfTilesCompleted >>> 32)); - return result; - } - - @Override - public String toString() { - return "OfflineDownloadEndEvent{" - + ", minZoom=" + minZoom - + ", maxZoom=" + maxZoom - + ", shapeForOfflineRegion='" + shapeForOfflineRegion + '\'' - + ", styleURL='" + styleURL + '\'' - + ", sizeOfResourcesCompleted=" + sizeOfResourcesCompleted - + ", numberOfTilesCompleted=" + numberOfTilesCompleted - + ", state=" + state - + '}'; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java deleted file mode 100644 index 497c7e6588..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.mapbox.mapboxsdk.module.telemetry; - -import android.annotation.SuppressLint; -import android.support.annotation.FloatRange; - -import com.mapbox.mapboxsdk.constants.MapboxConstants; - -/** - * Event will be sent while offline download start. - */ -@SuppressLint("ParcelCreator") -public class OfflineDownloadStartEvent extends MapBaseEvent { - private static final String EVENT_NAME = "map.offlineDownload.start"; - private final Double minZoom; - private final Double maxZoom; - private final String shapeForOfflineRegion; - private String styleURL; - - OfflineDownloadStartEvent(PhoneState phoneState, String shapeForOfflineRegion, - @FloatRange(from = MapboxConstants.MINIMUM_ZOOM, - to = MapboxConstants.MAXIMUM_ZOOM) Double minZoom, - @FloatRange(from = MapboxConstants.MINIMUM_ZOOM, - to = MapboxConstants.MAXIMUM_ZOOM) Double maxZoom) { - super(phoneState); - this.shapeForOfflineRegion = shapeForOfflineRegion; - this.minZoom = minZoom; - this.maxZoom = maxZoom; - } - - @Override - String getEventName() { - return EVENT_NAME; - } - - Double getMinZoom() { - return minZoom; - } - - Double getMaxZoom() { - return maxZoom; - } - - String getShapeForOfflineRegion() { - return shapeForOfflineRegion; - } - - String getStyleURL() { - return styleURL; - } - - void setStyleURL(String styleURL) { - this.styleURL = styleURL; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - OfflineDownloadStartEvent that = (OfflineDownloadStartEvent) o; - - if (minZoom != null ? !minZoom.equals(that.minZoom) : that.minZoom != null) { - return false; - } - if (maxZoom != null ? !maxZoom.equals(that.maxZoom) : that.maxZoom != null) { - return false; - } - if (shapeForOfflineRegion != null ? !shapeForOfflineRegion.equals(that.shapeForOfflineRegion) : - that.shapeForOfflineRegion != null) { - return false; - } - return styleURL != null ? styleURL.equals(that.styleURL) : that.styleURL == null; - } - - @Override - public int hashCode() { - int result = minZoom != null ? minZoom.hashCode() : 0; - result = 31 * result + (maxZoom != null ? maxZoom.hashCode() : 0); - result = 31 * result + (shapeForOfflineRegion != null ? shapeForOfflineRegion.hashCode() : 0); - result = 31 * result + (styleURL != null ? styleURL.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "OfflineDownloadStartEvent{" - + ", minZoom=" + minZoom - + ", maxZoom=" + maxZoom - + ", shapeForOfflineRegion='" + shapeForOfflineRegion + '\'' - + ", styleURL='" + styleURL + '\'' - + '}'; - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PerformanceEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PerformanceEvent.java deleted file mode 100644 index 81079c2d97..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PerformanceEvent.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.mapbox.mapboxsdk.module.telemetry; - -import android.annotation.SuppressLint; -import android.os.Bundle; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; - -import java.util.ArrayList; -import java.util.List; - -/** - * Generic Performance Event that can be used for performance measurements. - * Customer measurements can be added to the bundle. - * <p> - * Bundle is expected to have following properties: - * "attributes", "counters", and "metadata" with String values. - * </p> - * <p> - * Attributes: a string representing an array of name/string value pair objects. - * Counters: a string representing an array of name/number value pair objects. - * Metadata is a string representation of a JsonObject with string values. - * </p> - * <p> - * Here is an example of a Performance event bundle data: - * </p> - * <p> - * "attributes": [{ "name": "style_id", "value": "mapbox://styles/mapbox/streets-v10"}] - * </p> - * <p> - * "counters": [{"name": "fps_average", "value": 90.7655486547093}, - * {"name": "fps_deviation", "value": 29.301809631465574}] - * “metadata”: { - * “version”: “9”, - * “screenSize”: “1080x1794”, - * “country”: “US”, - * “device”: “Pixel 2”, - * “abi”: “arm64-v8a”, - * “brand”: “google”, - * “ram”: “3834167296”, - * “os”: “android”, - * “gpu”: “Qualcomm, Adreno (TM) 540, OpenGL ES 3.2 V@313.0 (GIT@7bf2852, Ie32bfa6f6f)“, - * “manufacturer”: “Google” - * } - * </p> - */ -@SuppressLint("ParcelCreator") -class PerformanceEvent extends MapBaseEvent { - private static final String PERFORMANCE_TRACE = "mobile.performance_trace"; - private final String sessionId; - private final List<PerformanceAttribute<String>> attributes; - private final List<PerformanceAttribute<Double>> counters; - private final JsonObject metadata; - - PerformanceEvent(PhoneState phoneState, String sessionId, Bundle bundle) { - super(phoneState); - this.sessionId = sessionId; - this.attributes = initList(bundle.getString("attributes"), - new TypeToken<ArrayList<PerformanceAttribute<String>>>() { - }); - this.counters = initList(bundle.getString("counters"), - new TypeToken<ArrayList<PerformanceAttribute<Double>>>() { - }); - this.metadata = initMetaData(bundle.getString("metadata")); - } - - private <T> ArrayList<PerformanceAttribute<T>> initList(String fromString, TypeToken typeToken) { - if (fromString == null || fromString.isEmpty()) { - return new ArrayList<>(); - } - return new Gson().fromJson(fromString, typeToken.getType()); - } - - private JsonObject initMetaData(String fromString) { - if (fromString == null) { - return new JsonObject(); - } else { - return new Gson().fromJson(fromString, JsonObject.class); - } - } - - @Override - String getEventName() { - return PERFORMANCE_TRACE; - } - - String getSessionId() { - return sessionId; - } - - List<PerformanceAttribute<String>> getAttributes() { - return attributes; - } - - List<PerformanceAttribute<Double>> getCounters() { - return counters; - } - - JsonObject getMetadata() { - return metadata; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - PerformanceEvent that = (PerformanceEvent) o; - - if (sessionId != null ? !sessionId.equals(that.sessionId) : that.sessionId != null) { - return false; - } - if (attributes != null ? !attributes.equals(that.attributes) : that.attributes != null) { - return false; - } - if (counters != null ? !counters.equals(that.counters) : that.counters != null) { - return false; - } - return metadata != null ? metadata.equals(that.metadata) : that.metadata == null; - } - - @Override - public int hashCode() { - int result = sessionId != null ? sessionId.hashCode() : 0; - result = 31 * result + (attributes != null ? attributes.hashCode() : 0); - result = 31 * result + (counters != null ? counters.hashCode() : 0); - result = 31 * result + (metadata != null ? metadata.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "PerformanceEvent{" - + "sessionId='" + sessionId + '\'' - + ", attributes=" + attributes - + ", counters=" + counters - + ", metadata=" + metadata - + '}'; - } - - static class PerformanceAttribute<T> { - private final String name; - private final T value; - - PerformanceAttribute(String name, T value) { - this.name = name; - this.value = value; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - PerformanceAttribute<?> that = (PerformanceAttribute<?>) o; - - if (name != null ? !name.equals(that.name) : that.name != null) { - return false; - } - return value != null ? value.equals(that.value) : that.value == null; - } - - @Override - public int hashCode() { - int result = name != null ? name.hashCode() : 0; - result = 31 * result + (value != null ? value.hashCode() : 0); - return result; - } - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java deleted file mode 100644 index a7f574bf40..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.mapbox.mapboxsdk.module.telemetry; - -import android.content.Context; -import android.content.res.Configuration; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; -import android.support.annotation.NonNull; -import android.telephony.TelephonyManager; -import android.text.TextUtils; -import android.util.DisplayMetrics; -import android.view.WindowManager; - -import com.mapbox.android.telemetry.TelemetryUtils; - -/** - * Class that holds kinds of states of the current phone. - */ -class PhoneState { - private static final String NO_CARRIER = "EMPTY_CARRIER"; - private static final int NO_NETWORK = -1; - private String created; - private String cellularNetworkType; - private Orientation orientation; - private String carrier; - private int batteryLevel; - private boolean pluggedIn; - private boolean wifi; - private float accessibilityFontScale; - private float resolution; - - PhoneState() { - - } - - PhoneState(@NonNull Context context) { - this.created = TelemetryUtils.obtainCurrentDate(); - this.batteryLevel = TelemetryUtils.obtainBatteryLevel(context); - this.pluggedIn = TelemetryUtils.isPluggedIn(context); - this.cellularNetworkType = TelemetryUtils.obtainCellularNetworkType(context); - this.orientation = Orientation.getOrientation(context.getResources().getConfiguration().orientation); - this.accessibilityFontScale = context.getResources().getConfiguration().fontScale; - this.carrier = obtainCellularCarrier(context); - this.resolution = obtainDisplayDensity(context); - this.wifi = isConnectedToWifi(context); - } - - private String obtainCellularCarrier(@NonNull Context context) { - TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - if (manager == null) { - return NO_CARRIER; - } - String carrierName = manager.getNetworkOperatorName(); - if (TextUtils.isEmpty(carrierName)) { - return NO_CARRIER; - } - return carrierName; - } - - private float obtainDisplayDensity(@NonNull Context context) { - DisplayMetrics displayMetrics = new DisplayMetrics(); - ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics); - return displayMetrics.density; - } - - private boolean isConnectedToWifi(@NonNull Context context) { - try { - WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); - if (wifiMgr == null) { - return false; - } - //noinspection MissingPermission - WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); - return wifiMgr.isWifiEnabled() && wifiInfo.getNetworkId() != NO_NETWORK; - } catch (Exception exception) { - return false; - } - } - - String getCreated() { - return created; - } - - void setCreated(String created) { - this.created = created; - } - - int getBatteryLevel() { - return batteryLevel; - } - - void setBatteryLevel(int batteryLevel) { - this.batteryLevel = batteryLevel; - } - - boolean isPluggedIn() { - return pluggedIn; - } - - void setPluggedIn(boolean pluggedIn) { - this.pluggedIn = pluggedIn; - } - - String getCellularNetworkType() { - return cellularNetworkType; - } - - void setCellularNetworkType(String cellularNetworkType) { - this.cellularNetworkType = cellularNetworkType; - } - - String getOrientation() { - return orientation.getOrientation(); - } - - void setOrientation(Orientation orientation) { - this.orientation = orientation; - } - - String getCarrier() { - return carrier; - } - - void setCarrier(String carrier) { - this.carrier = carrier; - } - - boolean isWifi() { - return wifi; - } - - void setWifi(boolean wifi) { - this.wifi = wifi; - } - - float getAccessibilityFontScale() { - return accessibilityFontScale; - } - - void setAccessibilityFontScale(float accessibilityFontScale) { - this.accessibilityFontScale = accessibilityFontScale; - } - - float getResolution() { - return resolution; - } - - void setResolution(float resolution) { - this.resolution = resolution; - } - - enum Orientation { - ORIENTATION_PORTRAIT("Portrait"), - ORIENTATION_LANDSCAPE("Landscape"); - private String orientation; - - Orientation(String orientation) { - this.orientation = orientation; - } - - public static Orientation getOrientation(int index) { - if (Configuration.ORIENTATION_PORTRAIT == index) { - return ORIENTATION_PORTRAIT; - } - return ORIENTATION_LANDSCAPE; - } - - public String getOrientation() { - return orientation; - } - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java deleted file mode 100644 index e33fb7c1b5..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.mapbox.mapboxsdk.module.telemetry; - -import android.content.Context; -import android.os.Bundle; -import android.support.annotation.FloatRange; -import android.support.annotation.NonNull; - -import com.mapbox.android.accounts.v1.MapboxAccounts; -import com.mapbox.android.telemetry.AppUserTurnstile; -import com.mapbox.android.telemetry.MapboxTelemetry; -import com.mapbox.android.telemetry.SessionInterval; -import com.mapbox.android.telemetry.TelemetryEnabler; -import com.mapbox.mapboxsdk.BuildConfig; -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.mapbox.mapboxsdk.maps.TelemetryDefinition; -import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition; -import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition; - -import java.util.UUID; - -public class TelemetryImpl implements TelemetryDefinition { - - private final MapboxTelemetry telemetry; - private final Context appContext; - - public TelemetryImpl() { - appContext = Mapbox.getApplicationContext(); - String accessToken = Mapbox.getAccessToken(); - telemetry = new MapboxTelemetry(appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT); - TelemetryEnabler.State telemetryState = TelemetryEnabler.retrieveTelemetryStateFromPreferences(); - if (TelemetryEnabler.State.ENABLED.equals(telemetryState)) { - telemetry.enable(); - } - } - - /** - * Register the app user turnstile event - */ - @Override - public void onAppUserTurnstileEvent() { - AppUserTurnstile turnstileEvent = new AppUserTurnstile(BuildConfig.MAPBOX_SDK_IDENTIFIER, - BuildConfig.MAPBOX_SDK_VERSION); - turnstileEvent.setSkuId(MapboxAccounts.SKU_ID_MAPS_MAUS); - telemetry.push(turnstileEvent); - telemetry.push(MapEventFactory.buildMapLoadEvent(new PhoneState(appContext))); - } - - /** - * Register an end-user gesture interaction event. - * - * @param eventType type of gesture event occurred - * @param latitude the latitude value of the gesture focal point - * @param longitude the longitude value of the gesture focal point - * @param zoom current zoom of the map - * @deprecated since 7.5.0, this event is no longer supported - */ - @Deprecated - @Override - public void onGestureInteraction(String eventType, double latitude, double longitude, - @FloatRange(from = MapboxConstants.MINIMUM_ZOOM, - to = MapboxConstants.MAXIMUM_ZOOM) double zoom) { - //no-op - } - - /** - * Set the end-user selected state to participate or opt-out in telemetry collection. - * - * @param enabledTelemetry true if enabled, false otherwise - */ - @Override - public void setUserTelemetryRequestState(boolean enabledTelemetry) { - if (enabledTelemetry) { - TelemetryEnabler.updateTelemetryState(TelemetryEnabler.State.ENABLED); - telemetry.enable(); - } else { - telemetry.disable(); - TelemetryEnabler.updateTelemetryState(TelemetryEnabler.State.DISABLED); - } - } - - @Override - public void disableTelemetrySession() { - telemetry.disable(); - } - - /** - * Set the debug logging state of telemetry. - * - * @param debugLoggingEnabled true to enable logging - */ - @Override - public void setDebugLoggingEnabled(boolean debugLoggingEnabled) { - telemetry.updateDebugLoggingEnabled(debugLoggingEnabled); - } - - /** - * Set the telemetry rotation session id interval - * - * @param interval the selected session interval - * @return true if rotation session id was updated - */ - @Override - public boolean setSessionIdRotationInterval(int interval) { - return telemetry.updateSessionIdRotationInterval(new SessionInterval(interval)); - } - - /** - * Register an offline region creation event. - * - * @param offlineDefinition the offline region definition - */ - @Override - public void onCreateOfflineRegion(@NonNull OfflineRegionDefinition offlineDefinition) { - telemetry.push(MapEventFactory.buildOfflineDownloadStartEvent(new PhoneState(appContext), - offlineDefinition instanceof OfflineTilePyramidRegionDefinition ? "tileregion" : "shaperegion", - offlineDefinition.getMinZoom(), - offlineDefinition.getMaxZoom(), - offlineDefinition.getStyleURL()) - ); - } - - /** - * Register a performance event - * - * @param data performance event data - */ - @Override - public void onPerformanceEvent(Bundle data) { - if (data == null) { - data = new Bundle(); - } - telemetry.push(MapEventFactory.buildPerformanceEvent(new PhoneState(appContext), - UUID.randomUUID().toString(), data)); - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/package-info.java deleted file mode 100644 index c77612bed4..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Contains the Mapbox Maps Android Modular Telemetry API classes. - */ -package com.mapbox.mapboxsdk.module.telemetry; |