diff options
author | Brad Leege <bleege@gmail.com> | 2016-01-29 15:16:27 -0600 |
---|---|---|
committer | Brad Leege <bleege@gmail.com> | 2016-02-10 19:05:19 -0800 |
commit | 9ce4c8bafca4111c3209194936035d3304f1eb51 (patch) | |
tree | b03cf151933b2a22acc2ac53346fcb151b38f086 /platform | |
parent | cf107d85bf21f4c5d35b35159be959f60bf0744e (diff) | |
download | qtlocation-mapboxgl-9ce4c8bafca4111c3209194936035d3304f1eb51.tar.gz |
[android] #2421 - Checking for TelemetryService configuration in AndroidManifest.xml
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> |