Conversation
HttpRequest request = httpService.newRequest(); | ||
request.post(config.getUri(), getMetricsData(context)); | ||
request.execute(); | ||
// TODO: response callback and response status logging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@secondsun I tried
final HttpResponse response = request.execute();
response.onComplete(new Runnable() {
@Override
public void run() {
Log.d(LOG_TAG, "status: " + response.getStatus());
}
});
but that results in a null pointer exception when it's trying to get the status code from the response. What's the recommended way to use the http module in such a case? It looks like it's already executing the http requests on the network thread, so no need to use AsyncTask?
|
||
public class MetricsService implements ServiceModule { | ||
public final static String LOG_TAG = "AEROGEAR/METRICS"; | ||
private final static String STORAGE_NAME = "aerogear-metrics"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would normally suggest using the full package name to avoid potential naming conflicts.
774f8d3
to
e0ffe89
Compare
build.gradle
Outdated
@@ -33,6 +33,14 @@ subprojects { | |||
} | |||
} | |||
|
|||
// We want to expose the SDK version and name to the metrics subproject | |||
project(':metrics') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be the core responsibility
metrics/build.gradle
Outdated
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
// Required for metrics, exposed by the parent project | ||
versionName project.ext.versionName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be the core responsibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Core for versioning on IOS
metrics/build.gradle
Outdated
|
||
dependencies { | ||
implementation project(path: ':core') | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be removed
metrics/build.gradle
Outdated
implementation 'com.android.support:appcompat-v7:26.1.0' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.1' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version is coming from the BOM and should be removed from here
metrics/src/main/AndroidManifest.xml
Outdated
@@ -0,0 +1,2 @@ | |||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |||
package="mobile.aerogear.org.metrics" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using a different kind of package (correctly or not) in the other modules org.aerogear.mobile.[module-name]
|
||
@Override | ||
public void configure(MobileCore core, ServiceConfiguration serviceConfiguration) { | ||
config = new MetricsConfig(serviceConfiguration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use ServiceConfiguration instead of creating a new one
|
||
@Override | ||
public void destroy() { | ||
// Not used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment is not necessarily, and it can be a empty method
} | ||
} | ||
|
||
private byte[] getMetricsData(final Context context) throws JSONException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a personal opinion it can be createMetricsData
or only metricsData
, but again it's only a personal thought
.getPackageManager() | ||
.getPackageInfo(context.getPackageName(), 0).versionName; | ||
} catch (PackageManager.NameNotFoundException e) { | ||
logger.error(LOG_TAG, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if's going to happen but I think we should raise an Exception instead of return null
|
||
public class MetricsService implements ServiceModule { | ||
private final static String MODULE_NAME = "metrics"; | ||
private final static String LOG_TAG = "AEROGEAR/METRICS"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/LOG_TAG/TAG
* @param context Android app context | ||
* @return String Client ID | ||
*/ | ||
private String getOrCreateClientId(final Context context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pb82 @wtrocki @danielpassos
First thing I noticed is private
methods/fields/etc.. I think we should better go with protected
as we are developing an SDK for our users and not an app. They might want to override stuff.
Just a general comment to keep in mind to make things extendable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice catch!!!
result.put("appVersion", getAppVersion(context)); | ||
result.put("sdkVersion", BuildConfig.VERSION_NAME); | ||
|
||
return result.toString().getBytes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar concern to make things extendable.
I would make this method protected
and make it return JSONObject. If a user wants to override metrics sent, they should be able to just call super
, get the JSONObject and then modify it.
toString
or getBytes()
conversion could very well happen in the caller of this method, if it is only called from one place.
* | ||
* @param context Android application context | ||
*/ | ||
public void init(final Context context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this depends on how we call this init
method. Perhaps we can still throw the exception and let the caller decide what to do with it.
Looked for callers, couldn't find any at the moment. How is this supposed to be called?
See also IOS SDK implementation: aerogear/aerogear-ios-sdk#13 |
@@ -103,7 +103,7 @@ afterEvaluate { project -> | |||
source = variant.javaCompile.source | |||
ext.androidJar = project.files(android.getBootClasspath().join(File.pathSeparator)) | |||
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) | |||
exclude '**/BuildConfig.java' | |||
exclude '**/BuildConfig' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason those exclusions don't work with .java
and gradle gives out warnings. That's why i've changed it, it seems to work as expected this way.
@@ -0,0 +1 @@ | |||
mock-maker-inline |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows Mockito to mock final classes and methods
import java.util.UUID; | ||
|
||
public class MetricsService implements ServiceModule { | ||
public final static String STORAGE_NAME = "mobile.aerogear.org.metrics"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/mobile.aerogear.org.metrics/org.aerogear.mobile.metrics
@pb82 Just need a very small fix and we are good to go. Awesome work here man. |
I haven't actually tried running the code, but looks good to me 👍 |
@danielpassos Changed the storage name to the actual package name |
Motivation
Initial version of the android metrics sdk.
JIRA: AGDROID-719
Description
Example Usage:
Progress