blob: 072a45b0ded466bd7dbda843a5b72e533a93515a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package com.mapbox.mapboxsdk.http;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.utils.ApplicationContextWrapper;
public abstract class HttpRequest {
static final int CONNECTION_ERROR = 0;
static final int TEMPORARY_ERROR = 1;
static final int PERMANENT_ERROR = 2;
public abstract void executeRequest(HttpRequestResponder httpRequest, long nativePtr, String resourceUrl,
String etag, String modified);
public abstract void cancelRequest();
//
// Utility methods
//
static String getApplicationIdentifier() {
ApplicationContextWrapper contextWrapper = ApplicationContextWrapper.getInstance(null);
Context context = contextWrapper.getBaseContext();
if(context == null){
throw new RuntimeException("Mapbox.java not correctly initialized");
}
return getApplicationIdentifier(context);
}
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 "";
}
}
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;
}
private boolean isValidMapboxEndpoint(String host) {
return host.equals("mapbox.com") || host.endsWith(".mapbox.com") || host.equals("mapbox.cn")
|| host.endsWith(".mapbox.cn");
}
}
|