diff options
Diffstat (limited to 'platform')
3 files changed, 48 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/TelemetryServiceNotConfiguredException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/TelemetryServiceNotConfiguredException.java new file mode 100644 index 0000000000..54908aa58b --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/TelemetryServiceNotConfiguredException.java @@ -0,0 +1,18 @@ +package com.mapbox.mapboxsdk.exceptions; + +import android.os.Bundle; +import com.mapbox.mapboxsdk.maps.MapView; + +/** + * A {@code TelemetryServiceNotConfiguredException} is thrown by {@link MapView} when it checks and finds that + * TelemetryService has not been configured in the app's AndroidManifest.xml {@link MapView#onCreate(Bundle)} + * + * @see MapView#onCreate(Bundle) + */ +public class TelemetryServiceNotConfiguredException extends RuntimeException { + + public TelemetryServiceNotConfiguredException() { + super("Using Mapbox Android SDK requires configuring TelemetryService. See the INSTALL.md"); + } + +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index bd0a010900..2a428947da 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -10,7 +10,9 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.pm.ServiceInfo; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -73,6 +75,7 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException; import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException; +import com.mapbox.mapboxsdk.exceptions.TelemetryServiceNotConfiguredException; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.layers.CustomLayer; @@ -366,6 +369,9 @@ public class MapView extends FrameLayout { // Force a check for an access token validateAccessToken(getAccessToken()); + // Force a check for Telemetry + validateTelemetryServiceConfigured(); + // Initialize EGL mNativeMapView.initializeDisplay(); mNativeMapView.initializeContext(); @@ -866,6 +872,28 @@ public class MapView extends FrameLayout { } } + // Checks that TelemetryService has been configured by developer + private void validateTelemetryServiceConfigured() { + + try { + // Check Implementing app's AndroidManifest.xml + PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), PackageManager.GET_SERVICES); + + if (packageInfo.services != null) { + + for (ServiceInfo service : packageInfo.services) { + if (TextUtils.equals("com.mapbox.mapboxsdk.telemetry.TelemetryService", service.name)) { + return; + } + } + } + + } catch (Exception e) { + Log.w(TAG, "Error checking for Telemetry Service Config: " + e); + } + throw new TelemetryServiceNotConfiguredException(); + } + /** * <p> * Sets the current Mapbox access token used to load map styles and tiles. diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index e331884224..c5106a4c79 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -88,6 +88,8 @@ <meta-data android:name="com.mapbox.AccessToken" android:value="" /> + + <service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService"/> </application> </manifest> |