[android] - remove deprecated setAccessToken and getAccessToken from OfflineManager, make validating the access token a part of getAccessToken in Mapbox. (#7582)

This commit is contained in:
Tobrun
2017-01-04 12:15:26 +01:00
committed by GitHub
parent 654061c7d1
commit b387105419
4 changed files with 15 additions and 43 deletions

View File

@@ -39,9 +39,23 @@ public final class Mapbox {
* @return Mapbox Access Token
*/
public static String getAccessToken() {
validateAccessToken();
return INSTANCE.accessToken;
}
/**
* Runtime validation of Access Token.
*
* @throws InvalidAccessTokenException exception thrown when not using a valid accessToken
*/
private static void validateAccessToken() throws InvalidAccessTokenException {
String accessToken = INSTANCE.accessToken;
if (TextUtils.isEmpty(accessToken) || (!accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("pk.")
&& !accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("sk."))) {
throw new InvalidAccessTokenException();
}
}
/**
* Application context
*/
@@ -49,19 +63,6 @@ public final class Mapbox {
return INSTANCE.context;
}
/**
* Runtime validation of Access Token.
*
* @throws InvalidAccessTokenException the exception thrown
*/
public static void validateAccessToken() throws InvalidAccessTokenException {
String accessToken = INSTANCE.accessToken;
if (TextUtils.isEmpty(accessToken) || (!accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("pk.")
&& !accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("sk."))) {
throw new InvalidAccessTokenException();
}
}
/**
* Manually sets the connectivity state of the app. This is useful for apps that control their
* own connectivity state and want to bypass any checks to the ConnectivityManager.

View File

@@ -202,7 +202,6 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onCreate(@Nullable Bundle savedInstanceState) {
Mapbox.validateAccessToken();
nativeMapView.setAccessToken(Mapbox.getAccessToken());
if (savedInstanceState == null) {
@@ -411,7 +410,6 @@ public class MapView extends FrameLayout {
// stopgap for https://github.com/mapbox/mapbox-gl-native/issues/6242
if (TextUtils.isEmpty(nativeMapView.getAccessToken())) {
Mapbox.validateAccessToken();
nativeMapView.setAccessToken(Mapbox.getAccessToken());
}

View File

@@ -839,7 +839,6 @@ public final class MapboxMap {
if (!TextUtils.isEmpty(style)) {
// stopgap for https://github.com/mapbox/mapbox-gl-native/issues/6242
if (TextUtils.isEmpty(nativeMapView.getAccessToken())) {
Mapbox.validateAccessToken();
nativeMapView.setAccessToken(Mapbox.getAccessToken());
}
setStyleUrl(style);

View File

@@ -7,7 +7,6 @@ import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
@@ -97,10 +96,7 @@ public class OfflineManager {
String assetRoot = getDatabasePath(context);
String cachePath = assetRoot + File.separator + DATABASE_NAME;
mDefaultFileSourcePtr = createDefaultFileSource(cachePath, assetRoot, DEFAULT_MAX_CACHE_SIZE);
if (!TextUtils.isEmpty(Mapbox.getAccessToken())) {
setAccessToken(mDefaultFileSourcePtr, Mapbox.getAccessToken());
}
setAccessToken(mDefaultFileSourcePtr, Mapbox.getAccessToken());
// Delete any existing previous ambient cache database
deleteAmbientDatabase(context);
@@ -191,28 +187,6 @@ public class OfflineManager {
return instance;
}
/**
* Access token getter/setter
*
* @param accessToken the accessToken to be used by the offline manager.
* @deprecated As of release 4.1.0, replaced by {@link Mapbox#getInstance(Context, String)}}
*/
@Deprecated
public void setAccessToken(String accessToken) {
setAccessToken(mDefaultFileSourcePtr, accessToken);
}
/**
* Get Access Token
*
* @return Access Token
* @deprecated As of release 4.1.0, replaced by {@link Mapbox#getAccessToken()}
*/
@Deprecated
public String getAccessToken() {
return getAccessToken(mDefaultFileSourcePtr);
}
private Handler getHandler() {
if (handler == null) {
handler = new Handler(Looper.getMainLooper());