Skip to content

Commit

Permalink
[android] send logs to error-reports@status.im
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed May 3, 2019
1 parent e6bd5c5 commit e48b976
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 33 deletions.
1 change: 1 addition & 0 deletions android/app/build.gradle
Expand Up @@ -269,6 +269,7 @@ dependencies {
implementation project(':react-native-webview')
implementation project(':react-native-config')
implementation project(':react-native-firebase')
implementation project(':RNMail')
compile ('com.google.android.gms:play-services-base:16.0.1') {
force = true
}
Expand Down
Expand Up @@ -35,6 +35,7 @@
import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;
import io.realm.react.RealmReactPackage;
import me.alwx.HttpServer.HttpServerReactPackage;
import com.chirag.RNMail.*;

public class MainApplication extends MultiDexApplication implements ReactApplication {

Expand All @@ -50,6 +51,7 @@ protected List<ReactPackage> getPackages() {
Function<String, String> callRPC = statusPackage.getCallRPC();
return Arrays.asList(
new MainReactPackage(),
new RNMail(),
new RNFirebasePackage(),
new RNFirebaseMessagingPackage(),
new RNFirebaseNotificationsPackage(),
Expand Down
2 changes: 2 additions & 0 deletions android/settings.gradle
Expand Up @@ -42,3 +42,5 @@ include ':react-native-config'
project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')
include ':react-native-android'
project(':react-native-android').projectDir = new File(rootProject.projectDir, '../node_modules/react-native/ReactAndroid')
include ':RNMail', ':app'
project(':RNMail').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mail/android')
3 changes: 2 additions & 1 deletion clj-rn.conf.edn
Expand Up @@ -43,7 +43,8 @@
"text-encoding"
"js-sha3"
"react-navigation"
"hi-base32"]
"hi-base32"
"react-native-mail"]

;; Desktop modules
:desktop-modules ["realm"
Expand Down
1 change: 1 addition & 0 deletions mobile_files/package.json.orig
Expand Up @@ -48,6 +48,7 @@
"react-native-invertible-scroll-view": "1.1.0",
"react-native-keychain": "git+https://github.com/status-im/react-native-keychain.git#v.3.0.0-status",
"react-native-languages": "^3.0.2",
"react-native-mail": "git+https://github.com/status-im/react-native-mail.git#v3.0.7_status",
"react-native-os": "git+https://github.com/status-im/react-native-os.git#v1.1.0-1-status",
"react-native-qrcode": "git+https://github.com/status-im/react-native-qrcode.git#v0.2.8",
"react-native-randombytes": "3.5.0",
Expand Down
4 changes: 4 additions & 0 deletions mobile_files/yarn.lock
Expand Up @@ -5527,6 +5527,10 @@ react-native-languages@^3.0.2:
resolved "https://registry.yarnpkg.com/react-native-languages/-/react-native-languages-3.0.2.tgz#c2c4c5050974fe4b50f7372051ca1f9824c1c778"
integrity sha512-LGsTfixFM6hXDhcFJI6mrtrNBsGPSvXT9RtZQ0tlqmGFKmMyZW6eQgJ7kLw8lISD2FIGl4jJwY06EAJpbMsNxg==

"react-native-mail@git+https://github.com/status-im/react-native-mail.git#v3.0.7_status":
version "3.0.7"
resolved "git+https://github.com/status-im/react-native-mail.git#9c002e9c178970786404f8ce34ba9b26c50ec6c0"

"react-native-os@git+https://github.com/status-im/react-native-os.git#v1.1.0-1-status":
version "1.1.0"
resolved "git+https://github.com/status-im/react-native-os.git#1a6d0835f919cb075793ad7c602f2724eee4702d"
Expand Down
Expand Up @@ -522,7 +522,7 @@ private Boolean zip(File[] _files, File zipFile, Stack<String> errorList) {
}

out.close();

return true;
} catch (Exception e) {
Log.e(TAG, e.getMessage());
Expand Down Expand Up @@ -557,9 +557,9 @@ public void onClick(final DialogInterface dialog, final int id) {
}
}).show();
}

@ReactMethod
public void sendLogs(final String dbJson) {
public void sendLogs(final String dbJson, final Callback callback) {
Log.d(TAG, "sendLogs");
if (!checkAvailability()) {
return;
Expand Down Expand Up @@ -594,33 +594,14 @@ public void sendLogs(final String dbJson) {
return;
}
}

dumpAdbLogsTo(new FileOutputStream(statusLogFile));

final Stack<String> errorList = new Stack<String>();
final Boolean zipped = zip(new File[] {dbFile, gethLogFile, statusLogFile}, zipFile, errorList);
if (zipped && zipFile.exists()) {
Log.d(TAG, "Sending " + zipFile.getAbsolutePath() + " file through share intent");

final String providerName = context.getPackageName() + ".provider";
final Activity activity = getCurrentActivity();
zipFile.setReadable(true, false);
final Uri dbJsonURI = FileProvider.getUriForFile(activity, providerName, zipFile);

Intent intentShareFile = new Intent(Intent.ACTION_SEND);

intentShareFile.setType("application/json");
intentShareFile.putExtra(Intent.EXTRA_STREAM, dbJsonURI);

SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormatGmt.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
intentShareFile.putExtra(Intent.EXTRA_SUBJECT, "Status.im logs");
intentShareFile.putExtra(Intent.EXTRA_TEXT,
String.format("Logs from %s GMT\n\nThese logs have been generated automatically by the user's request for debugging purposes.\n\n%s",
dateFormatGmt.format(new java.util.Date()),
errorList));

activity.startActivity(Intent.createChooser(intentShareFile, "Share Debug Logs"));
callback.invoke(zipFile.getAbsolutePath());
} else {
Log.d(TAG, "File " + zipFile.getAbsolutePath() + " does not exist");
}
Expand Down
Expand Up @@ -28,6 +28,7 @@
(def snoopy-buffer (js/require "rn-snoopy/stream/buffer"))
(def background-timer (.-default (js/require "react-native-background-timer")))
(def react-navigation (js/require "react-navigation"))
(def react-native-mail (.-default (js/require "react-native-mail")))
(def desktop-linking #js {:addEventListener (fn [])})
(def desktop-menu #js {:addEventListener (fn [])})
(def desktop-config #js {:addEventListener (fn [])})
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/native_module/core.cljs
Expand Up @@ -70,8 +70,8 @@
(defn send-data-notification [m callback]
(native-module/send-data-notification m callback))

(defn send-logs [dbJson]
(native-module/send-logs dbJson))
(defn send-logs [dbJson callback]
(native-module/send-logs dbJson callback))

(defn add-peer [enode callback]
(native-module/add-peer enode callback))
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/native_module/impl/module.cljs
Expand Up @@ -49,9 +49,9 @@
(when status
(.sendDataNotification status data-payload tokens on-result)))

(defn send-logs [dbJson]
(defn send-logs [dbJson callback]
(when status
(.sendLogs status dbJson)))
(.sendLogs status dbJson callback)))

(defn add-peer [enode on-result]
(when (and @node-started status)
Expand Down
16 changes: 16 additions & 0 deletions src/status_im/utils/email.cljs
@@ -0,0 +1,16 @@
(ns status-im.utils.email
(:require [re-frame.core :as re-frame]
[status-im.utils.fx :as fx]
[status-im.react-native.js-dependencies :as dependencies]))

(re-frame/reg-fx
:email/send
;; https://github.com/chirag04/react-native-mail#example
(fn [[opts callback]]
(.mail dependencies/react-native-mail
(clj->js opts)
callback)))

(fx/defn send-email
[_ opts callback]
{:email/send [opts callback]})
29 changes: 26 additions & 3 deletions src/status_im/utils/logging/core.cljs
Expand Up @@ -2,10 +2,21 @@
(:require [re-frame.core :as re-frame]
[status-im.native-module.core :as status]
[status-im.utils.fx :as fx]
[status-im.utils.types :as types]))
[status-im.utils.types :as types]
[status-im.utils.handlers :as handlers]
[status-im.utils.email :as mail]))

(def report-email "error-reports@status.im")

(re-frame/reg-fx
:logs/archive-logs
(fn [[db-json callback-handler]]
(status/send-logs
db-json
#(re-frame/dispatch [callback-handler %]))))

(fx/defn send-logs
[{:keys [db] :as cofx}]
[{:keys [db]}]
;; TODO: Add message explaining db export
(let [db-json (types/clj->json (select-keys db [:app-state
:current-chat-id
Expand All @@ -29,4 +40,16 @@
:dimensions/window
:my-profile/editing?
:node/status]))]
(status/send-logs db-json)))
{:logs/archive-logs [db-json ::send-email]}))

(handlers/register-handler-fx
::send-email
(fn [cofx [_ archive-path]]
(mail/send-email cofx
{:subject "Error report"
:recipients [report-email]
:body "logs attached"
:attachment {:path archive-path
:type "zip"
:name "status_logs.zip"}}
(fn []))))

0 comments on commit e48b976

Please sign in to comment.