Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

HttpClient configuration with modules #12449

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platform/android/MapboxGLAndroidModuleBase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
25 changes: 25 additions & 0 deletions platform/android/MapboxGLAndroidModuleBase/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion androidVersions.compileSdkVersion

defaultConfig {
minSdkVersion androidVersions.minSdkVersion
targetSdkVersion androidVersions.targetSdkVersion
buildConfigField "String", "MAPBOX_VERSION_STRING", String.format("\"Mapbox/%s\"", project.VERSION_NAME)
buildConfigField "String", "MAPBOX_SDK_IDENTIFIER", String.format("\"%s\"", "mapbox-maps-android")
buildConfigField "String", "MAPBOX_SDK_VERSION", String.format("\"%s\"", project.VERSION_NAME)
versionCode 1
versionName "1.0"
buildConfigField "String", "MAPBOX_EVENTS_USER_AGENT", String.format("\"MapboxEventsAndroid/%s\"", project.VERSION_NAME)
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

dependencies {
implementation dependenciesList.supportAnnotations
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="com.mapbox.mapboxsdk.module"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mapbox.mapboxsdk.constants;

public class TelemetryConstants {

public static final String TWO_FINGER_TAP = "TwoFingerTap";
public static final String DOUBLE_TAP = "DoubleTap";
public static final String SINGLE_TAP = "SingleTap";
public static final String PAN = "Pan";
public static final String PINCH = "Pinch";
public static final String ROTATION = "Rotation";
public static final String PITCH = "Pitch";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.mapbox.mapboxsdk.http;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.utils.MapboxConfigurationWrapper;

/**
* Base class for performing core http requests.
* <p>
* This abstraction allows to provide alternative implementations for the http interaction of this library.
* </p>
*/
public abstract class HttpRequest {

static final int CONNECTION_ERROR = 0;
static final int TEMPORARY_ERROR = 1;
static final int PERMANENT_ERROR = 2;

/**
* Executes the request.
*
* @param httpRequest callback to be invoked when we receive a response
* @param nativePtr the pointer associated to the request
* @param resourceUrl the resource url to download
* @param etag http header, identifier for a specific version of a resource
* @param modified http header, used to determine if a resource hasn't been modified since
*/
public abstract void executeRequest(HttpRequestResponder httpRequest, long nativePtr, String resourceUrl,
String etag, String modified);

/**
* Cancels the request.
*/
public abstract void cancelRequest();

//
// Utility methods
//

/**
* Returns the application identifier, consisting out the package name, version name and version code.
*
* @return the appliciation identifier
*/
static String getApplicationIdentifier() {
return getApplicationIdentifier(MapboxConfigurationWrapper.getContext());
}

/**
* Returns the application identifier, consisting out the package name, version name and version code.
*
* @param context the context used to retrieve the package manager from
* @return the appliciation identifier
*/
private static String getApplicationIdentifier(@NonNull Context context) {
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
return String.format("%s/%s (%s)", context.getPackageName(), packageInfo.versionName, packageInfo.versionCode);
} catch (Exception exception) {
return "";
}
}

/**
* Adapts a resource request url based on the host and query size.
*
* @param host the host used as endpoint
* @param resourceUrl the resource to download
* @param querySize the query size of the resource request
* @return the adapted resource url
*/
String buildResourceUrl(String host, String resourceUrl, int querySize) {
if (isValidMapboxEndpoint(host)) {
if (querySize == 0) {
resourceUrl = resourceUrl + "?";
} else {
resourceUrl = resourceUrl + "&";
}
resourceUrl = resourceUrl + "events=true";
}
return resourceUrl;
}

/**
* Validates if the host used as endpoint is a valid Mapbox endpoint.
*
* @param host the host used as endpoint
* @return true if a valid Mapbox endpoint
*/
private boolean isValidMapboxEndpoint(String host) {
return host.equals("mapbox.com") || host.endsWith(".mapbox.com") || host.equals("mapbox.cn")
|| host.endsWith(".mapbox.cn");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mapbox.mapboxsdk.http;

/**
* Interface definition for a callback to be invoked when either a response was returned for a requested resource or
* when an error occurred when requesting the resource.
*/
public interface HttpRequestResponder {

/**
* Invoked when a resource has finished.
*
* @param responseCode http response code
* @param eTag http header, identifier for a specific version of a resource
* @param lastModified http header, used to determine if a resource hasn't been modified since
* @param cacheControl http header, used to determine cache strategy of a resource
* @param expires http header, used to determine when a resource is stale
* @param retryAfter http header, used to indicate when the service is expected to be unavailable to the client
* @param xRateLimitReset http header, used to determine the remaining window before the rate limit resets
* @param body http response body, in an array of bytes representation
*/
void onResponse(int responseCode, String eTag, String lastModified, String cacheControl, String expires,
String retryAfter, String xRateLimitReset, byte[] body);

/**
* Invoked when a resource failed to be retrieved.
*
* @param type the error type, either one of {@link HttpRequest#CONNECTION_ERROR},
* {@link HttpRequest#TEMPORARY_ERROR} or {@link HttpRequest#PERMANENT_ERROR}
* @param errorMessage the error message associated with the failure
*/
void handleFailure(int type, String errorMessage);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package com.mapbox.mapboxsdk.log;

import android.util.Log;

public final class Logger {

private static final LoggerDefinition DEFAULT = new LoggerDefinition() {

@Override
public void v(String tag, String msg) {
Log.v(tag, msg);
}

@Override
public void v(String tag, String msg, Throwable tr) {
Log.v(tag, msg, tr);
}

@Override
public void d(String tag, String msg) {
Log.d(tag, msg);
}

@Override
public void d(String tag, String msg, Throwable tr) {
Log.d(tag, msg, tr);
}

@Override
public void i(String tag, String msg) {
Log.i(tag, msg);
}

@Override
public void i(String tag, String msg, Throwable tr) {
Log.i(tag, msg, tr);
}

@Override
public void w(String tag, String msg) {
Log.w(tag, msg);
}

@Override
public void w(String tag, String msg, Throwable tr) {
Log.w(tag, msg, tr);
}

@Override
public void w(String tag, Throwable tr) {
Log.w(tag, tr);
}

@Override
public void e(String tag, String msg) {
Log.e(tag, msg);
}

@Override
public void e(String tag, String msg, Throwable tr) {
Log.e(tag, msg, tr);
}
};

private static volatile LoggerDefinition logger = DEFAULT;

public static void setLoggerDefinition(LoggerDefinition loggerDefinition) {
logger = loggerDefinition;
}

public static void v(String tag, String msg) {
logger.v(tag, msg);
}

public static void v(String tag, String msg, Throwable tr) {
logger.v(tag, msg, tr);
}

public static void d(String tag, String msg) {
logger.d(tag, msg);
}

public static void d(String tag, String msg, Throwable tr) {
logger.d(tag, msg, tr);
}

public static void i(String tag, String msg) {
logger.i(tag, msg);
}

public static void i(String tag, String msg, Throwable tr) {
logger.i(tag, msg, tr);
}

public static void w(String tag, String msg) {
logger.w(tag, msg);
}

public static void w(String tag, String msg, Throwable tr) {
logger.w(tag, msg, tr);
}

public static void w(String tag, Throwable tr) {
logger.w(tag, tr);
}

public static void e(String tag, String msg) {
logger.e(tag, msg);
}

public static void e(String tag, String msg, Throwable tr) {
logger.e(tag, msg, tr);
}

public static void log(int severity, String tag, String message) {
LoggerDefinition.log(severity, tag, message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.mapbox.mapboxsdk.log;

import android.util.Log;

public interface LoggerDefinition {

void v(String tag, String msg);

void v(String tag, String msg, Throwable tr);

void d(String tag, String msg);

void d(String tag, String msg, Throwable tr);

void i(String tag, String msg);

void i(String tag, String msg, Throwable tr);

void w(String tag, String msg);

void w(String tag, String msg, Throwable tr);

void w(String tag, Throwable tr);

void e(String tag, String msg);

void e(String tag, String msg, Throwable tr);

static void log(int severity, String tag, String message) {
switch (severity) {
case Log.VERBOSE:
Logger.v(tag, message);
break;
case Log.DEBUG:
Logger.d(tag, message);
break;
case Log.INFO:
Logger.i(tag, message);
break;
case Log.WARN:
Logger.w(tag, message);
break;
case Log.ERROR:
Logger.e(tag, message);
break;
default:
throw new UnsupportedOperationException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mapbox.mapboxsdk.telemetry;

public interface TelemetryBase {

void onAppUserTurnstileEvent();
void onGestureInteraction(String eventType, double latitude, double longitude, double zoom);

void enableOnUserRequest();
void disableOnUserRequest();
void setDebugLoggingEnabled(boolean debugLoggingEnabled);
void setSessionIdRotationInterval(int interval);

}
Loading