Skip to content

Commit 2eafc08

Browse files
authored
Merge pull request #22 from getsentry/feature/android-native-client
Native Android Support, Internal fixes and more ...
2 parents 637dc55 + 447e341 commit 2eafc08

38 files changed

+1233
-645
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
assets
22
examples
33
docs
4+
.idea

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
copy-to-source:
2+
@echo "--> Copy'in stuff from node_modules to local"
3+
cp -r examples/ReactNativeExample/node_modules/react-native-sentry/* .

android/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
33

44
android {
55
compileSdkVersion 23
6-
buildToolsVersion "23.0.1"
6+
buildToolsVersion '25.0.0'
77

88
defaultConfig {
99
minSdkVersion 16
@@ -21,5 +21,5 @@ android {
2121

2222
dependencies {
2323
compile 'com.facebook.react:react-native:+'
24-
}
25-
24+
compile 'io.sentry:sentry-android:1.0.0-beta'
25+
}

android/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="io.sentry">
3+
<uses-permission android:name="android.permission.INTERNET" />
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
35
</manifest>
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package io.sentry;
2+
3+
import com.facebook.react.bridge.Arguments;
4+
import com.facebook.react.bridge.ReadableArray;
5+
import com.facebook.react.bridge.ReadableType;
6+
import com.facebook.react.bridge.WritableArray;
7+
8+
import java.util.Map;
9+
10+
import org.json.JSONArray;
11+
import org.json.JSONObject;
12+
import org.json.JSONException;
13+
14+
public class ArrayUtil {
15+
16+
public static JSONArray toJSONArray(ReadableArray readableArray) throws JSONException {
17+
JSONArray jsonArray = new JSONArray();
18+
19+
for (int i = 0; i < readableArray.size(); i++) {
20+
ReadableType type = readableArray.getType(i);
21+
22+
switch (type) {
23+
case Null:
24+
jsonArray.put(i, null);
25+
break;
26+
case Boolean:
27+
jsonArray.put(i, readableArray.getBoolean(i));
28+
break;
29+
case Number:
30+
jsonArray.put(i, readableArray.getDouble(i));
31+
break;
32+
case String:
33+
jsonArray.put(i, readableArray.getString(i));
34+
break;
35+
case Map:
36+
jsonArray.put(i, MapUtil.toJSONObject(readableArray.getMap(i)));
37+
break;
38+
case Array:
39+
jsonArray.put(i, ArrayUtil.toJSONArray(readableArray.getArray(i)));
40+
break;
41+
}
42+
}
43+
44+
return jsonArray;
45+
}
46+
47+
public static Object[] toArray(JSONArray jsonArray) throws JSONException {
48+
Object[] array = new Object[jsonArray.length()];
49+
50+
for (int i = 0; i < jsonArray.length(); i++) {
51+
Object value = jsonArray.get(i);
52+
53+
if (value instanceof JSONObject) {
54+
value = MapUtil.toMap((JSONObject) value);
55+
}
56+
if (value instanceof JSONArray) {
57+
value = ArrayUtil.toArray((JSONArray) value);
58+
}
59+
60+
array[i] = value;
61+
}
62+
63+
return array;
64+
}
65+
66+
public static Object[] toArray(ReadableArray readableArray) {
67+
Object[] array = new Object[readableArray.size()];
68+
69+
for (int i = 0; i < readableArray.size(); i++) {
70+
ReadableType type = readableArray.getType(i);
71+
72+
switch (type) {
73+
case Null:
74+
array[i] = null;
75+
break;
76+
case Boolean:
77+
array[i] = readableArray.getBoolean(i);
78+
break;
79+
case Number:
80+
array[i] = readableArray.getDouble(i);
81+
break;
82+
case String:
83+
array[i] = readableArray.getString(i);
84+
break;
85+
case Map:
86+
array[i] = MapUtil.toMap(readableArray.getMap(i));
87+
break;
88+
case Array:
89+
array[i] = ArrayUtil.toArray(readableArray.getArray(i));
90+
break;
91+
}
92+
}
93+
94+
return array;
95+
}
96+
97+
public static WritableArray toWritableArray(Object[] array) {
98+
WritableArray writableArray = Arguments.createArray();
99+
100+
for (int i = 0; i < array.length; i++) {
101+
Object value = array[i];
102+
103+
if (value == null) {
104+
writableArray.pushNull();
105+
}
106+
if (value instanceof Boolean) {
107+
writableArray.pushBoolean((Boolean) value);
108+
}
109+
if (value instanceof Double) {
110+
writableArray.pushDouble((Double) value);
111+
}
112+
if (value instanceof Integer) {
113+
writableArray.pushInt((Integer) value);
114+
}
115+
if (value instanceof String) {
116+
writableArray.pushString((String) value);
117+
}
118+
if (value instanceof Map) {
119+
writableArray.pushMap(MapUtil.toWritableMap((Map<String, Object>) value));
120+
}
121+
if (value.getClass().isArray()) {
122+
writableArray.pushArray(ArrayUtil.toWritableArray((Object[]) value));
123+
}
124+
}
125+
126+
return writableArray;
127+
}
128+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.sentry;
2+
3+
import com.facebook.react.bridge.ReadableArray;
4+
5+
public interface ExceptionsManagerModuleInterface {
6+
7+
String MODULE_NAME = "RKExceptionsManager";
8+
9+
void reportFatalException(String title, ReadableArray details, int exceptionId);
10+
11+
void reportSoftException(String title, ReadableArray details, int exceptionId);
12+
13+
void updateExceptionMessage(String title, ReadableArray details, int exceptionId);
14+
15+
void dismissRedbox();
16+
17+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package io.sentry;
2+
3+
import com.facebook.react.bridge.Arguments;
4+
import com.facebook.react.bridge.ReadableMap;
5+
import com.facebook.react.bridge.ReadableMapKeySetIterator;
6+
import com.facebook.react.bridge.ReadableType;
7+
import com.facebook.react.bridge.WritableMap;
8+
9+
import java.util.Map;
10+
import java.util.HashMap;
11+
import java.util.Iterator;
12+
13+
import org.json.JSONArray;
14+
import org.json.JSONObject;
15+
import org.json.JSONException;
16+
17+
public class MapUtil {
18+
19+
public static JSONObject toJSONObject(ReadableMap readableMap) throws JSONException {
20+
JSONObject jsonObject = new JSONObject();
21+
22+
ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
23+
24+
while (iterator.hasNextKey()) {
25+
String key = iterator.nextKey();
26+
ReadableType type = readableMap.getType(key);
27+
28+
switch (type) {
29+
case Null:
30+
jsonObject.put(key, null);
31+
break;
32+
case Boolean:
33+
jsonObject.put(key, readableMap.getBoolean(key));
34+
break;
35+
case Number:
36+
jsonObject.put(key, readableMap.getDouble(key));
37+
break;
38+
case String:
39+
jsonObject.put(key, readableMap.getString(key));
40+
break;
41+
case Map:
42+
jsonObject.put(key, MapUtil.toJSONObject(readableMap.getMap(key)));
43+
break;
44+
case Array:
45+
jsonObject.put(key, ArrayUtil.toJSONArray(readableMap.getArray(key)));
46+
break;
47+
}
48+
}
49+
50+
return jsonObject;
51+
}
52+
53+
public static Map<String, Object> toMap(JSONObject jsonObject) throws JSONException {
54+
Map<String, Object> map = new HashMap<>();
55+
Iterator<String> iterator = jsonObject.keys();
56+
57+
while (iterator.hasNext()) {
58+
String key = iterator.next();
59+
Object value = jsonObject.get(key);
60+
61+
if (value instanceof JSONObject) {
62+
value = MapUtil.toMap((JSONObject) value);
63+
}
64+
if (value instanceof JSONArray) {
65+
value = ArrayUtil.toArray((JSONArray) value);
66+
}
67+
68+
map.put(key, value);
69+
}
70+
71+
return map;
72+
}
73+
74+
public static Map<String, Object> toMap(ReadableMap readableMap) {
75+
Map<String, Object> map = new HashMap<>();
76+
ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
77+
78+
while (iterator.hasNextKey()) {
79+
String key = iterator.nextKey();
80+
ReadableType type = readableMap.getType(key);
81+
82+
switch (type) {
83+
case Null:
84+
map.put(key, null);
85+
break;
86+
case Boolean:
87+
map.put(key, readableMap.getBoolean(key));
88+
break;
89+
case Number:
90+
map.put(key, readableMap.getDouble(key));
91+
break;
92+
case String:
93+
map.put(key, readableMap.getString(key));
94+
break;
95+
case Map:
96+
map.put(key, MapUtil.toMap(readableMap.getMap(key)));
97+
break;
98+
case Array:
99+
map.put(key, ArrayUtil.toArray(readableMap.getArray(key)));
100+
break;
101+
}
102+
}
103+
104+
return map;
105+
}
106+
107+
public static WritableMap toWritableMap(Map<String, Object> map) {
108+
WritableMap writableMap = Arguments.createMap();
109+
Iterator iterator = map.entrySet().iterator();
110+
111+
while (iterator.hasNext()) {
112+
Map.Entry pair = (Map.Entry)iterator.next();
113+
Object value = pair.getValue();
114+
115+
if (value == null) {
116+
writableMap.putNull((String) pair.getKey());
117+
} else if (value instanceof Boolean) {
118+
writableMap.putBoolean((String) pair.getKey(), (Boolean) value);
119+
} else if (value instanceof Double) {
120+
writableMap.putDouble((String) pair.getKey(), (Double) value);
121+
} else if (value instanceof Integer) {
122+
writableMap.putInt((String) pair.getKey(), (Integer) value);
123+
} else if (value instanceof String) {
124+
writableMap.putString((String) pair.getKey(), (String) value);
125+
} else if (value instanceof Map) {
126+
writableMap.putMap((String) pair.getKey(), MapUtil.toWritableMap((Map<String, Object>) value));
127+
} else if (value.getClass() != null && value.getClass().isArray()) {
128+
writableMap.putArray((String) pair.getKey(), ArrayUtil.toWritableArray((Object[]) value));
129+
}
130+
131+
iterator.remove();
132+
}
133+
134+
return writableMap;
135+
}
136+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.sentry;
2+
3+
import com.facebook.react.bridge.ReactApplicationContext;
4+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
5+
import com.facebook.react.bridge.WritableMap;
6+
import com.facebook.react.modules.core.DeviceEventManagerModule;
7+
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
11+
public class RNSentryEventEmitter extends ReactContextBaseJavaModule {
12+
13+
public static final String SENTRY_EVENT_SENT_SUCCESSFULLY = "Sentry/eventSentSuccessfully";
14+
15+
public RNSentryEventEmitter(ReactApplicationContext reactContext) {
16+
super(reactContext);
17+
}
18+
19+
@Override
20+
public String getName() {
21+
return "RNSentryEventEmitter";
22+
}
23+
24+
@Override
25+
public Map<String, Object> getConstants() {
26+
final Map<String, Object> constants = new HashMap<>();
27+
constants.put("EVENT_SENT_SUCCESSFULLY", SENTRY_EVENT_SENT_SUCCESSFULLY);
28+
return constants;
29+
}
30+
31+
public static void sendEvent(ReactApplicationContext reactContext, String eventName, WritableMap params) {
32+
reactContext
33+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
34+
.emit(eventName, params);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)