Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] send logs to error-reports@status.im #8122

Merged
merged 1 commit into from May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions android/app/build.gradle
Expand Up @@ -271,6 +271,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.8_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.8_status":
version "3.0.7"
resolved "git+https://github.com/status-im/react-native-mail.git#5dd2d4e92fa696a9dd0efebdc530df22772326fe"

"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
2 changes: 1 addition & 1 deletion modules/react-native-status/desktop/rctstatus.cpp
Expand Up @@ -201,7 +201,7 @@ void showFileInGraphicalShell(QWidget *parent, const QFileInfo &fileInfo)
#endif
}

void RCTStatus::sendLogs(QString dbJSON) {
void RCTStatus::sendLogs(QString dbJSON, double callbackId) {
Q_D(RCTStatus);

qCDebug(RCTSTATUS) << "::sendLogs call - logFilePath:" << getLogFilePath()
Expand Down
2 changes: 1 addition & 1 deletion modules/react-native-status/desktop/rctstatus.h
Expand Up @@ -39,7 +39,7 @@ class RCTStatus : public QObject, public ModuleInterface {
Q_INVOKABLE void stopNode();
Q_INVOKABLE void createAccount(QString password, double callbackId);
Q_INVOKABLE void sendDataNotification(QString dataPayloadJSON, QString tokensJSON, double callbackId);
Q_INVOKABLE void sendLogs(QString dbJSON);
Q_INVOKABLE void sendLogs(QString dbJSON, double callbackId);
Q_INVOKABLE void addPeer(QString enode, double callbackId);
Q_INVOKABLE void recoverAccount(QString passphrase, QString password, double callbackId);
Q_INVOKABLE void login(QString address, QString password, double callbackId);
Expand Down
Expand Up @@ -33,3 +33,4 @@
(def snoopy-buffer #js {})
(def background-timer #js {:setTimeout (fn [cb ms] (js/setTimeout cb ms))})
(def react-navigation (js/require "react-navigation"))
(def react-native-mail #js {:mail (fn [])})
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
2 changes: 2 additions & 0 deletions scripts/prepare-for-platform.sh
Expand Up @@ -61,6 +61,8 @@ if [ ! -f .babelrc ] || [ $(readlink .babelrc) != "${PLATFORM_FOLDER}/.babelrc"
ln -sf ${PLATFORM_FOLDER}/metro.config.js metro.config.js
fi

rm -rf /home/jenkins/.cache/yarn/v4/.tmp/6ec8ff0e65cf4f48c50d7472fa1f10ca
rm -rf /Users/jenkins/Library/Caches/Yarn/v4/.tmp/6ec8ff0e65cf4f48c50d7472fa1f10ca
yarn install --frozen-lockfile

case $1 in
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 []))))