From 88a10d99fa0df7f897eacfd60ff735046cc88acc Mon Sep 17 00:00:00 2001 From: JunZhang Date: Wed, 17 Jun 2020 15:04:37 +0800 Subject: [PATCH] handle se communication failed (#43) --- .../cobo/cold/selfcheck/SecurityCheck.java | 2 +- .../ui/fragment/AttackWarningFragment.java | 34 +++++++++++++++++-- app/src/main/res/values-zh-rCN/strings.xml | 4 +++ app/src/main/res/values/strings.xml | 4 +++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/cobo/cold/selfcheck/SecurityCheck.java b/app/src/main/java/com/cobo/cold/selfcheck/SecurityCheck.java index 434451f..e843dd9 100644 --- a/app/src/main/java/com/cobo/cold/selfcheck/SecurityCheck.java +++ b/app/src/main/java/com/cobo/cold/selfcheck/SecurityCheck.java @@ -48,7 +48,7 @@ public class SecurityCheck { private static final int CODE_SYS_OK = 0x00; private static final int CODE_SYS_ATTACKED = 0x01; private static final int CODE_FW_OK = 0x0000; - private static final int CODE_FW_GET_STATUS_FAILED = 0x0100; + public static final int CODE_FW_GET_STATUS_FAILED = 0x0100; private static final int CODE_FW_STATUS_NOT_FOUND = 0x0200; private static final int CODE_FW_STATUS_ATTACKED = 0x0300; private static final int CODE_FW_ERT_ATTACKED = 0x0400; diff --git a/app/src/main/java/com/cobo/cold/ui/fragment/AttackWarningFragment.java b/app/src/main/java/com/cobo/cold/ui/fragment/AttackWarningFragment.java index 8f9e394..6a29ee6 100644 --- a/app/src/main/java/com/cobo/cold/ui/fragment/AttackWarningFragment.java +++ b/app/src/main/java/com/cobo/cold/ui/fragment/AttackWarningFragment.java @@ -17,8 +17,12 @@ package com.cobo.cold.ui.fragment; +import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.os.IPowerManager; +import android.os.RemoteException; +import android.os.ServiceManager; import android.os.SystemProperties; import android.view.View; @@ -34,6 +38,7 @@ import java.util.Locale; import java.util.Objects; import java.util.concurrent.Executors; +import static com.cobo.cold.selfcheck.SecurityCheck.CODE_FW_GET_STATUS_FAILED; import static com.cobo.cold.selfcheck.SecurityCheck.CODE_FW_IN_BOOTMODE; import static com.cobo.cold.ui.fragment.setting.MainPreferenceFragment.removeAllFingerprint; @@ -59,16 +64,39 @@ public class AttackWarningFragment extends BaseFragment { if (firmware == CODE_FW_IN_BOOTMODE) { mBinding.text1.setText(R.string.update_failed); - mBinding.hint.setText(getString(R.string.contact_cobo_service,formatErrorCode(data))); + mBinding.hint.setText(getString(R.string.contact_cobo_service, formatErrorCode(data))); + } else if(firmware == CODE_FW_GET_STATUS_FAILED) { + mBinding.text1.setText(R.string.opration_failed); + mBinding.hint.setText(getString(R.string.reboot_hint,formatErrorCode(data))); } - mBinding.powerOff.setOnClickListener(v -> handleAttack(mActivity)); + if (firmware == CODE_FW_GET_STATUS_FAILED) { + mBinding.powerOff.setText(R.string.reboot); + mBinding.powerOff.setOnClickListener(v -> reboot()); + } else { + mBinding.powerOff.setText(R.string.clear_and_power_off); + mBinding.powerOff.setOnClickListener(v -> handleAttack(mActivity)); + } mBinding.serialno.setText(getString(R.string.serialno, SystemProperties.get("persist.sys.serialno"))); mBinding.icon.setOnClickListener(new AboutFragment.ExportLogHandler(mActivity, Executors.newSingleThreadExecutor())); } + private void reboot() { + new Thread("reboot") { + @Override + public void run() { + IPowerManager pm = IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE)); + try { + pm.reboot(false, null, false); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + }.start(); + } + - public void handleAttack(AppCompatActivity activity) { + private void handleAttack(AppCompatActivity activity) { ProgressModalDialog dialog = ProgressModalDialog.newInstance(); dialog.show(Objects.requireNonNull(activity.getSupportFragmentManager()), ""); Executors.newSingleThreadExecutor().execute(() -> { diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index f19debb..8ea8b29 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -453,5 +453,9 @@ 暂无签名记录 若扫描 BlueWallet 动态二维码困难,您可扫描分页二维码 Wasabi Wallet 暂不支持将交易导成二维码,您可将待签交易导出成文件 + 操作失败 + 请重新启动机器,多次重试未果请联系客服:support@cobo.com\n 状态码:%s + 重新启动 + 删除所有信息并关机 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9885559..3c2134d 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -492,5 +492,9 @@ No Signatures Difficulty scanning with BlueWallet? Try scanning these static QR codes instead of the single dynamic QR code. Wasabi Wallet does not support exporting transactions by QR code. Please export transactions using microSD. + Operation Failed + Please restart or contact us at support@cobo.com\n Status Code:%s + Restart + Erase all Information and Power off