Skip to content

Commit

Permalink
Add emergency activity to be displayed in case of uncaught exception
Browse files Browse the repository at this point in the history
  • Loading branch information
btcontract committed Apr 2, 2017
1 parent 291ed3b commit 16493a4
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified app/app-release.apk
Binary file not shown.
16 changes: 5 additions & 11 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<afterSyncTasks>
Expand Down Expand Up @@ -46,39 +45,34 @@
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/scala" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/scala" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/scala" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/scala" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/scala" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/android-scala" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
Expand All @@ -92,7 +86,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/org.apmem.tools/layouts/1.10/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/mockable-android-23.jar" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-rules" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/release" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
Expand All @@ -101,21 +94,22 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
<excludeFolder url="jar://$MODULE_DIR$/build/intermediates/mockable-android-23.jar!/" />
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="wire-runtime-2.1.1" level="project" />
<orderEntry type="library" exported="" name="http-request-6.0" level="project" />
<orderEntry type="library" exported="" name="slf4j-api-1.7.20" level="project" />
<orderEntry type="library" exported="" name="okio-1.6.0" level="project" />
<orderEntry type="library" exported="" name="slf4j-api-1.7.20" level="project" />
<orderEntry type="library" exported="" name="rxscala_2.11-0.26.0" level="project" />
<orderEntry type="library" exported="" name="layouts-1.10" level="project" />
<orderEntry type="library" exported="" name="core-1.54.0.0" level="project" />
<orderEntry type="library" exported="" name="okhttp-2.7.2" level="project" />
<orderEntry type="library" exported="" name="core-3.2.1" level="project" />
<orderEntry type="library" exported="" name="quicklens_2.11-1.4.7" level="project" />
<orderEntry type="library" exported="" name="ndeftools-1.2.4" level="project" />
<orderEntry type="library" exported="" name="bitcoinj-core-0.14.4" level="project" />
<orderEntry type="library" exported="" name="ndeftools-1.2.4" level="project" />
<orderEntry type="library" exported="" name="quicklens_2.11-1.4.7" level="project" />
<orderEntry type="library" exported="" name="netcipher-1.2.1" level="project" />
<orderEntry type="library" exported="" name="spray-json_2.11-1.3.2" level="project" />
<orderEntry type="library" exported="" name="jsr305-2.0.1" level="project" />
Expand All @@ -127,9 +121,9 @@
<orderEntry type="library" exported="" name="pg-1.54.0.0" level="project" />
<orderEntry type="library" exported="" name="rxjava-1.1.0" level="project" />
<orderEntry type="library" exported="" name="prov-1.54.0.0" level="project" />
<orderEntry type="library" exported="" name="scrypt-1.4.0" level="project" />
<orderEntry type="library" exported="" name="pkix-1.54.0.0" level="project" />
<orderEntry type="library" exported="" name="protobuf-java-2.6.1" level="project" />
<orderEntry type="library" exported="" name="scrypt-1.4.0" level="project" />
<orderEntry type="library" exported="" name="scala-library-2.11.8" level="project" />
<orderEntry type="library" exported="" name="android-segmented-1.0.5" level="project" />
<orderEntry type="library" exported="" name="nv-websocket-client-1.27" level="project" />
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ android {

defaultConfig {
applicationId "com.btcontract.wallet"
versionName "1.074"
versionName "1.075"
minSdkVersion 15
versionCode 47
versionCode 48
}

buildTypes {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<activity android:launchMode="singleTask" android:name="TxsActivity"
android:screenOrientation="portrait" android:theme="@style/LiteBar"/>

<activity android:launchMode="singleTask" android:name="EmergencyActivity"
android:screenOrientation="portrait" android:theme="@style/LiteBar"/>

<activity android:launchMode="singleTask" android:name="ScanActivity"
android:screenOrientation="portrait" android:theme="@style/NoBar"/>

Expand Down
58 changes: 58 additions & 0 deletions app/src/main/java/com/btcontract/wallet/EmergencyActivity.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.btcontract.wallet

import java.io.FileInputStream

import R.string._
import com.btcontract.wallet.Utils._
import android.view.WindowManager.LayoutParams
import android.app.AlertDialog.Builder
import android.os.Bundle
import android.view.View
import org.bitcoinj.wallet.WalletProtobufSerializer

import concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.util.{Success, Try}


class EmergencyActivity extends AnimatorActivity { me =>
override def onCreate(savedInstanceState: Bundle) =
{
super.onCreate(savedInstanceState)
add(me getString emerge_subtitle, Informer.PEERS).ui.run
getActionBar.setTitle(me getString emerge_title)
setContentView(R.layout.activity_emergency)
prepareWallet
}

def emergeReport(v: View) = Try(getIntent getStringExtra "report") match {
case Success(report: String) => negBld(dialog_ok).setMessage(report).show
case _ => negBld(dialog_ok).setMessage(me getString err_general).show
}

def emergeMnemonic(v: View) = passPlus(none) { password =>
<(Mnemonic decrypt password, wrong) { walletSeed =>
getWindow.setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE)
val bld = new Builder(me) setCustomTitle getString(sets_noscreen)
bld.setMessage(Mnemonic text walletSeed).show
}
}

def wrong(err: Throwable) = {
negBld(dialog_ok).setMessage(err.getMessage).show
me toast password_wrong
}

def prepareWallet = Future {
app.kit = new app.WalletKit {
val stream = new FileInputStream(app.walletFile)
val proto = try WalletProtobufSerializer parseToProto stream finally stream.close
wallet = new WalletProtobufSerializer readWallet (app.params, null, proto)
store = null
blockChain = null
peerGroup = null

def startUp = none
}
}
}
24 changes: 24 additions & 0 deletions app/src/main/java/com/btcontract/wallet/UncaughtHandler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.btcontract.wallet

import java.io.{PrintWriter, StringWriter}
import java.lang.Thread.UncaughtExceptionHandler
import android.content.Intent
import android.app.Activity


class UncaughtHandler(ctxt: Activity)
extends UncaughtExceptionHandler { me =>

def uncaughtException(thread: Thread, exc: Throwable): Unit = {
val emerge: Class[EmergencyActivity] = classOf[EmergencyActivity]
val stackTrace: StringWriter = new StringWriter
val intent = new Intent(ctxt, emerge)

exc printStackTrace new PrintWriter(stackTrace)
intent.putExtra("report", stackTrace.toString)
ctxt startActivity intent

android.os.Process killProcess android.os.Process.myPid
System exit 10
}
}
6 changes: 6 additions & 0 deletions app/src/main/java/com/btcontract/wallet/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import ViewGroup.LayoutParams.WRAP_CONTENT
import InputMethodManager.HIDE_NOT_ALWAYS
import Transaction.MIN_NONDUST_OUTPUT
import Context.INPUT_METHOD_SERVICE
import android.os.Bundle
import android.view.WindowManager.LayoutParams


Expand Down Expand Up @@ -363,6 +364,11 @@ abstract class TimerActivity extends Activity { me =>
metrix
}

override def onCreate(savedInstanceState: Bundle): Unit = {
Thread setDefaultUncaughtExceptionHandler new UncaughtHandler(me)
super.onCreate(savedInstanceState)
}

// Timer utilities and toast
override def onDestroy = wrap(super.onDestroy)(timer.cancel)
implicit def anyToRunnable(process: => Unit): Runnable = new Runnable { def run = process }
Expand Down
11 changes: 5 additions & 6 deletions app/src/main/java/com/btcontract/wallet/WalletApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ package com.btcontract.wallet
import Utils._
import R.string._
import org.bitcoinj.core._

import org.bitcoinj.wallet.listeners._
import org.bitcoinj.core.listeners.TransactionConfidenceEventListener
import info.guardianproject.netcipher.proxy.OrbotHelper
import collection.JavaConverters.asScalaBufferConverter
import com.google.common.util.concurrent.Service.State
import org.bitcoinj.net.discovery.DnsDiscovery
import org.bitcoinj.wallet.KeyChain.KeyPurpose
import org.bitcoinj.wallet.Wallet.BalanceType
import org.bitcoinj.crypto.KeyCrypterScrypt
import com.google.protobuf.ByteString
import android.app.Application
import android.widget.Toast
import java.io.File

import org.bitcoinj.wallet.listeners.{WalletChangeEventListener, WalletCoinsSentEventListener, WalletCoinsReceivedEventListener}
import org.bitcoinj.uri.{BitcoinURIParseException, OptionalFieldValidationException}
import org.bitcoinj.uri.{RequiredFieldValidationException, BitcoinURI}
import org.bitcoinj.wallet.{DeterministicSeed, Wallet, Protos}
import org.bitcoinj.uri.{BitcoinURI, RequiredFieldValidationException}
import android.content.{ClipData, ClipboardManager, Context}
import org.bitcoinj.crypto.{ChildNumber, KeyCrypterScrypt}
import State.{STARTING, RUNNING}
import org.bitcoinj.wallet.{Protos, Wallet}
import State.{RUNNING, STARTING}

import java.util.concurrent.TimeUnit.MILLISECONDS
import Context.CLIPBOARD_SERVICE
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_emergency.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_height="fill_parent" android:layout_width="fill_parent">

<Button
style="@style/MarginInfo"
android:onClick="emergeReport"
android:layout_width="wrap_content"
android:text="@string/emerge_report"/>

<Button
style="@style/Info"
android:onClick="emergeMnemonic"
android:layout_width="wrap_content"
android:text="@string/sets_mnemonic"/>

</LinearLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<resources>
<string name="lang">rus</string>

<!-- emergency mode -->
<string name="emerge_report">Показать отчет об ошибке</string>
<string name="emerge_title">Что-то пошло не так</string>
<string name="emerge_subtitle">Аварийный режим</string>

<!-- app wide -->
<string name="or">или</string>
<string name="app_name">Bitcoin</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<resources>
<string name="lang">ukr</string>

<!-- emergency mode -->
<string name="emerge_report">Переглянути звіт про помилку</string>
<string name="emerge_title">Щось пішло не так</string>
<string name="emerge_subtitle">Аварійний режим</string>

<!-- app wide -->
<string name="or">або</string>
<string name="app_name">Bitcoin</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<resources>
<string name="lang">eng</string>

<!-- emergency mode -->
<string name="emerge_report">Show error report</string>
<string name="emerge_title">Something went wrong</string>
<string name="emerge_subtitle">Emergency mode</string>

<!-- app wide -->
<string name="or">or</string>
<string name="app_name">Bitcoin</string>
Expand Down

0 comments on commit 16493a4

Please sign in to comment.