Repository navigation
Introduce abstract components - #12468
Conversation
d57b421 to
d9a24e1
Compare
|
To satisfy semver, I need to refactor telemetry module into an abstract class and add static methods |
| apply plugin: 'com.android.library' | ||
|
|
||
| android { | ||
| compileSdkVersion 28 |
There was a problem hiding this comment.
Can we use dependencies.gradle references here?
| if (context == null) { | ||
| throw new IllegalStateException("MapboxConfigurationWrapper isn't initialised correctly."); | ||
| } | ||
| return instance.getBaseContext(); |
There was a problem hiding this comment.
NIT: this can return the context variable.
| } | ||
|
|
||
| public static String getAccessToken() { | ||
| if (accessToken == null) { |
There was a problem hiding this comment.
This check and the exception that is thrown removes the possibility of passing a null access token.
There was a problem hiding this comment.
there are two places in code where this is referenced:
- Telemetry.java -> no issue there
- Mapbox.java -> indeed an issue
added try/catch and return null in those cases.
There was a problem hiding this comment.
Had to fixup Mapbox.java for unit tests, will look for a solution without the try catch
| @Override | ||
| public void onClick(DialogInterface dialog, int which) { | ||
| Telemetry.enableOnUserRequest(); | ||
| Mapbox.getTelemetry().enableOnUserRequest(); |
There was a problem hiding this comment.
This will throw an NPE if the access token is null.
| @Override | ||
| public void onClick(DialogInterface dialog, int which) { | ||
| Telemetry.disableOnUserRequest(); | ||
| Mapbox.getTelemetry().disableOnUserRequest(); |
There was a problem hiding this comment.
This will throw an NPE if the access token is null.
| private static final String OPENSTREETMAP = "OpenStreetMap"; | ||
| private static final String OPENSTREETMAP_ABBR = "OSM"; | ||
| static final String TELEMETRY = "Telemetry Settings"; | ||
| static final String TELEMETRY = "TelemetryBase Settings"; |
There was a problem hiding this comment.
I think this is an unnecessary result of the class name change?
There was a problem hiding this comment.
refactor issue, nice catch
| */ | ||
| public MapboxConfigurationException() { | ||
| super("\nUsing MapView requires calling Mapbox.getInstance(Context context, String accessToken) before " | ||
| super("\nUsing MapView requires calling Mapbox.initialize(Context context, String accessToken) before " |
There was a problem hiding this comment.
This should still point to Mapbox.getInstance.
There was a problem hiding this comment.
refactor issue, nice catch
| import android.text.TextUtils; | ||
| import com.mapbox.mapboxsdk.Mapbox; | ||
| import com.mapbox.mapboxsdk.maps.Telemetry; | ||
| import com.mapbox.mapboxsdk.telemetry.Telemetry; |
There was a problem hiding this comment.
As mentioned in #12468 (comment), this and all other Telemetry.java changes are semver major.
|
When it comes to logging, I feel like tagging all our logs with a unified tag, like |
|
|
||
| static void log(int type, String errorMessage) { | ||
| if (logEnabled) { | ||
| Timber.log(type, errorMessage); |
There was a problem hiding this comment.
Can we rely on the Logger here instead of Timber? A user might want to use our http module with a different LoggerDefinition.
There was a problem hiding this comment.
yes, timber also removed from build.gradle
5e8cec2 to
9606d09
Compare
A compromise between granularity and consistency could be to have all tags start with the same Mapbox-specific prefix (say |
Yes, this is already in place with https://github.com/mapbox/mapbox-gl-native/pull/12468/files#diff-8f41632c292f442353443b7ff4520ca1R16 @zugaldia @LukasPaczos, before re-reviewing, I will be working on removing the different modules. This is not a hard requirement. |
zugaldia
left a comment
There was a problem hiding this comment.
Small request to move all new implementations into the same package. Otherwise this is looking great, lots of moving pieces well taken care of.
There was a problem hiding this comment.
Could we move this file to a modules folder?
There was a problem hiding this comment.
Possible yes, but to completely exclude okhttp, the user would also have to exclude com.mapbox.mapboxsdk.http.HttpRequestUtil which we can't move due to semver. I'm suggesting postponing changing package names until next major release.
There was a problem hiding this comment.
Same as before, if this is the implementation, could we move this file to a modules folder?
There was a problem hiding this comment.
This is not possible due to semver
There was a problem hiding this comment.
Good point - could we move everything we can (new classes) and leave the rest for 7.x?
|
Looks good to me! I'm leaving the final word to @zugaldia. |
e13c993 to
4a182a7
Compare
|
@LukasPaczos @zugaldia another iteration on this PR, would love another round of 👀 |
jaegs
left a comment
There was a problem hiding this comment.
This changeset is massive which makes it a bit hard to review. Perhaps it could be broken up into smaller pieces.
Also any chance using git mv of git cp will preserve some of the blame?
| * @deprecated use {@link com.mapbox.mapboxsdk.module.http.HttpRequestUtil#setOkHttpClient(OkHttpClient)} instead. | ||
| */ | ||
| @Deprecated | ||
| public static void setOkHttpClient(OkHttpClient client) { |
There was a problem hiding this comment.
this method will require okhttp to build
There was a problem hiding this comment.
this is one of the files that would need to be excluded, due to semver we can't change this
| * @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, |
There was a problem hiding this comment.
"Favor composition over inheritance" is one of the rules from Effective Java
There was a problem hiding this comment.
composition is provided in the module file here. The HttpRequest class is the contract between the SDK and the alternate implementation. How would you enforce the availability of predefined methods, the sdk needs a predefined hook, either an interface or an abstract class?
There was a problem hiding this comment.
An interface is generally preferable since it doesn't lock the API user into single inheritance. I think an interface should work here unless I'm missing something.
There was a problem hiding this comment.
I went ahead with an interface for HttpRequest, other functionality besides executeRequest and cancel was extracted in separate classes. Looks a lot cleaner now, thank you for the clarification.
|
|
||
| @Override | ||
| public void v(String tag, String msg) { | ||
| Log.v(String.format(TAG_TEMPLATE, tag), msg); |
There was a problem hiding this comment.
this will perform string regex even if logging is off.
There was a problem hiding this comment.
wasn't aware of this, having this TAG_TEMPLATE formatting was only a nice to have, will remove it.
| httpRequest.handleFailure(type, errorMessage); | ||
| } | ||
|
|
||
| private void logFailure(int type, String errorMessage, String requestUrl) { |
There was a problem hiding this comment.
move it up to the base class, though will apply composition to it so it will be found in a separate helper class.
| if(severity == EventSeverity::Debug){ | ||
| auto method = _class.GetStaticMethod<Signature>(env, "d"); | ||
| _class.Call(env, method, tag, message); | ||
| }else if(severity == EventSeverity::Info){ |
802e0bf to
d0fbde0
Compare
e2c0fd8 to
b540403
Compare
LukasPaczos
left a comment
There was a problem hiding this comment.
I understand the concerns from #12468 (comment) but couldn't we add the Mbx- prefix to every TAG that is currently being created in all of the classes instead?
With the current setup and the TelemetryDefinition being returned in the public API, TelemetryImpl#onAppUserTurnstileEvent and TelemetryImpl#onGestureInteraction are not package-restricted and can be possibly used to pollute our telemetry data.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
How about moving this javadoc to the interface definition?
There was a problem hiding this comment.
NIT: since the javadoc in the interface is identical, we can remove this one.
There was a problem hiding this comment.
This method should get the TelemetryImpl reference using the Mapbox#getTelemetry and check for nullability to avoid crashing.
There was a problem hiding this comment.
This method should get the TelemetryImpl reference using the Mapbox#getTelemetry and check for nullability to avoid crashing.
There was a problem hiding this comment.
This method should get the TelemetryImpl reference using the Mapbox#getTelemetry and check for nullability to avoid crashing.
There was a problem hiding this comment.
What do you think about removing the null-check here, or crashing the app with a clearer exception, to catch start-up telemetry regressions during internal testing?
There was a problem hiding this comment.
added:
if (telemetry == null) {
throw new IllegalStateException("Telemetry was unavailable during test application start.");
}There was a problem hiding this comment.
This might not be impactful but breaks the semver. How about leaving an empty impl instead?
5fe8f97 to
123d2b4
Compare
There was a problem hiding this comment.
NIT: since the javadoc in the interface is identical, we can remove this one.
There was a problem hiding this comment.
NIT: since the javadoc in the interface is identical, we can remove this one.
4d4d8bd to
1a4697a
Compare
Follow up from #12449 and #12391.
This PR makes the following components configurable: