-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add emergency activity to be displayed in case of uncaught exception
- Loading branch information
btcontract
committed
Apr 2, 2017
1 parent
291ed3b
commit 16493a4
Showing
13 changed files
with
137 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/btcontract/wallet/EmergencyActivity.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
app/src/main/java/com/btcontract/wallet/UncaughtHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters