Skip to content

Commit

Permalink
Merge 3495d23 into d5106da
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Apr 17, 2019
2 parents d5106da + 3495d23 commit 008faac
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
21 changes: 21 additions & 0 deletions features/runtime_versions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Runtime versions are included in all requests

Scenario: Runtime versions included in JVM exception
When I run "HandledExceptionScenario"
Then I should receive a request
And the request is valid for the error reporting API
And the payload field "events.0.device.runtimeVersions.androidApiLevel" is not null

Scenario: Runtime versions included in NDK error
When I run "CXXNullPointerScenario"
And I configure the app to run in the "non-crashy" state
And I relaunch the app
Then I should receive a request
And the request payload contains a completed native report
And the payload field "events.0.device.runtimeVersions.androidApiLevel" is not null

Scenario: Runtime versions included in session
When I run "ManualSessionScenario"
Then I should receive a request
And the request is valid for the session tracking API
And the payload field "device.runtimeVersions.androidApiLevel" is not null
23 changes: 21 additions & 2 deletions ndk/src/main/jni/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ int bsg_get_map_value_int(JNIEnv *env, bsg_jni_cache *jni_cache, jobject map,
return 0;
}

int bsg_populate_api_level_from_map(JNIEnv *env, bsg_jni_cache *jni_cache, jobject device_data) {
int value = -1;
jstring map_key = (*env)->NewStringUTF(env, "runtimeVersions");
jstring version_key = (*env)->NewStringUTF(env, "androidApiLevel");
jobject _map = (*env)->CallObjectMethod(env, device_data, jni_cache->hash_map_get, map_key);

if (_map != NULL) {
jobject _versions =
(*env)->CallObjectMethod(env, _map, jni_cache->hash_map_get, version_key);

if (_versions != NULL) {
value = (int)(*env)->CallIntMethod(env, _versions, jni_cache->integer_int_value);
(*env)->DeleteLocalRef(env, _versions);
}
(*env)->DeleteLocalRef(env, _map);
}
return value;
}

int bsg_populate_cpu_abi_from_map(JNIEnv *env, bsg_jni_cache *jni_cache,
jobject map, bsg_device_info *device) {
jstring key = (*env)->NewStringUTF(env, "cpuAbi");
Expand Down Expand Up @@ -291,15 +310,15 @@ void bsg_populate_device_data(JNIEnv *env, bsg_jni_cache *jni_cache,
bsg_get_map_value_bool(env, jni_cache, data, "emulator");
report->device.jailbroken =
bsg_get_map_value_bool(env, jni_cache, data, "jailbroken");
report->device.api_level =
bsg_get_map_value_int(env, jni_cache, data, "apiLevel");
report->device.total_memory =
bsg_get_map_value_long(env, jni_cache, data, "totalMemory");
report->device.dpi = bsg_get_map_value_int(env, jni_cache, data, "dpi");
report->device.screen_density =
bsg_get_map_value_float(env, jni_cache, data, "screenDensity");
bsg_populate_cpu_abi_from_map(env, jni_cache, data, &report->device);

report->device.api_level = bsg_populate_api_level_from_map(env, jni_cache, data);

(*env)->DeleteLocalRef(env, data);
}

Expand Down
4 changes: 2 additions & 2 deletions ndk/src/main/jni/utils/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ char *bsg_serialize_report_to_json_string(bugsnag_report *report) {
json_object_dotset_string(event, "device.model", report->device.model);
json_object_dotset_string(event, "device.orientation",
report->device.orientation);
json_object_dotset_number(event, "device.runtimeVersions.androidApiLevel",
report->device.api_level);

JSON_Value *abi_val = json_value_init_array();
JSON_Array *cpu_abis = json_value_get_array(abi_val);
Expand All @@ -250,8 +252,6 @@ char *bsg_serialize_report_to_json_string(bugsnag_report *report) {
report->device.os_build);
json_object_dotset_number(event, "device.totalMemory",
report->device.total_memory);
json_object_dotset_number(event, "metaData.device.apiLevel",
report->device.api_level);
json_object_dotset_string(event, "metaData.device.brand",
report->device.brand);
json_object_dotset_boolean(event, "metaData.device.emulator",
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/androidTest/java/com/bugsnag/android/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,13 @@ public void testPopulateDeviceMetadata() {
client = generateClient();
Map<String, Object> metaData = client.getDeviceData().getDeviceMetaData();

assertEquals(13, metaData.size());
assertEquals(12, metaData.size());
assertNotNull(metaData.get("batteryLevel"));
assertNotNull(metaData.get("charging"));
assertNotNull(metaData.get("locationStatus"));
assertNotNull(metaData.get("networkAccess"));
assertNotNull(metaData.get("time"));
assertNotNull(metaData.get("brand"));
assertNotNull(metaData.get("apiLevel"));
assertNotNull(metaData.get("osBuild"));
assertNotNull(metaData.get("locale"));
assertNotNull(metaData.get("screenDensity"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public void testJsonSerialisation() throws JSONException {
assertNotNull(deviceDataJson.getString("model"));
assertNotNull(deviceDataJson.get("cpuAbi"));
assertTrue(deviceDataJson.has("jailbroken"));

JSONObject versions = deviceDataJson.getJSONObject("runtimeVersions");
assertNotNull(versions.get("androidApiLevel"));
}

}
6 changes: 5 additions & 1 deletion sdk/src/main/java/com/bugsnag/android/DeviceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.util.DisplayMetrics;

import java.io.File;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
Expand Down Expand Up @@ -98,6 +99,10 @@ Map<String, Object> getDeviceDataSummary() {
map.put("osName", "android");
map.put("osVersion", Build.VERSION.RELEASE);
map.put("cpuAbi", cpuAbi);

Map<String, Object> versions = new HashMap<>();
versions.put("androidApiLevel", Build.VERSION.SDK_INT);
map.put("runtimeVersions", versions);
return map;
}

Expand All @@ -119,7 +124,6 @@ Map<String, Object> getDeviceMetaData() {
map.put("networkAccess", getNetworkAccess());
map.put("time", getTime());
map.put("brand", Build.BRAND);
map.put("apiLevel", Build.VERSION.SDK_INT);
map.put("osBuild", Build.DISPLAY);
map.put("locale", locale);
map.put("screenDensity", screenDensity);
Expand Down

0 comments on commit 008faac

Please sign in to comment.