From d9aea648e22ca5a5fd50e791c1f228f46784400c Mon Sep 17 00:00:00 2001 From: Kerry Washington Date: Thu, 10 Oct 2024 16:32:49 +0100 Subject: [PATCH 1/2] Tech debt/add af sdk (#248) - AF working - Changed requiredActivity - Added analytics error report - test this.Activity is null or not - Bugfix - Phrase Reminder crash - added an exception handler for UserNotAuthenticatedException. - note: this should allow for the system to display the native authorization UI when needed - fixes issue - https://console.firebase.google.com/u/0/project/litewallet-beta/crashlytics/app/android:com.loafwallet/issues/09dac17241309f0e823ef597a9a82cd4 - Added dev note - remove calls to BREventManager - removed BREventManager - renamed error message - fixed Firebase Analytics event error Signed-off-by: kcw-grunt --- app/build.gradle | 4 +- .../fragments/FragmentBalanceSeedReminder.kt | 21 +++- .../fragments/FragmentFingerprint.java | 2 +- .../presenter/history/HistoryFragment.kt | 42 +++++-- .../tools/animation/BRAnimator.java | 5 +- .../tools/manager/BREventManager.java | 116 ------------------ .../tools/manager/BRSharedPrefs.java | 2 +- .../tools/manager/InternetManager.java | 2 - .../breadwallet/tools/manager/TxManager.java | 7 +- .../tools/security/BitcoinUrlHandler.java | 13 -- .../breadwallet/tools/util/BRConstants.java | 2 +- .../com/breadwallet/tools/util/Utils.java | 2 +- 12 files changed, 62 insertions(+), 156 deletions(-) delete mode 100644 app/src/main/java/com/breadwallet/tools/manager/BREventManager.java diff --git a/app/build.gradle b/app/build.gradle index 3152eea20..ce04b6796 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,8 +63,8 @@ android { applicationId = 'com.loafwallet' minSdkVersion 31 targetSdkVersion 34 - versionCode 20241007 - versionName "v2.11.1" + versionCode 20241016 + versionName "v2.11.4" multiDexEnabled true archivesBaseName = "${versionName}(${versionCode})" diff --git a/app/src/main/java/com/breadwallet/presenter/fragments/FragmentBalanceSeedReminder.kt b/app/src/main/java/com/breadwallet/presenter/fragments/FragmentBalanceSeedReminder.kt index fc523031e..5634e0e39 100644 --- a/app/src/main/java/com/breadwallet/presenter/fragments/FragmentBalanceSeedReminder.kt +++ b/app/src/main/java/com/breadwallet/presenter/fragments/FragmentBalanceSeedReminder.kt @@ -10,7 +10,11 @@ import android.widget.* import androidx.fragment.app.Fragment import com.breadwallet.R import com.breadwallet.tools.animation.BRAnimator +import com.breadwallet.tools.manager.AnalyticsManager +import com.breadwallet.tools.manager.TxManager import com.breadwallet.tools.security.BRKeyStore +import com.breadwallet.tools.util.BRConstants +import timber.log.Timber import java.util.* class FragmentBalanceSeedReminder : Fragment() { @@ -66,14 +70,21 @@ class FragmentBalanceSeedReminder : Fragment() { setListeners() fetchSeedPhrase() } - + private fun registerAnalyticsError(errorString: String) { + Timber.d("Fragment Balance Seed: RegisterError : %s", errorString) + val params = Bundle() + params.putString("lwa_error_message", errorString); + AnalyticsManager.logCustomEventWithParams(BRConstants._20200112_ERR, params) + } fun fetchSeedPhrase() { - try { - seedPhraseTextView.text = String(BRKeyStore.getPhrase(context, 0)) - } catch (_: UserNotAuthenticatedException) { + seedPhraseTextView.text = "NO_PHRASE" + if (this.activity == null) { + registerAnalyticsError("null_in_fragment_balance_fetch_seed") + } + else { + seedPhraseTextView.text = String(BRKeyStore.getPhrase(this.activity, 0)) ?: "NO_PHRASE" } } - private fun animateClose() { BRAnimator.animateBackgroundDim(backgroundLayout, true) BRAnimator.animateSignalSlide(signalLayout, true) { close() } diff --git a/app/src/main/java/com/breadwallet/presenter/fragments/FragmentFingerprint.java b/app/src/main/java/com/breadwallet/presenter/fragments/FragmentFingerprint.java index f731ee1d4..975bf5f64 100644 --- a/app/src/main/java/com/breadwallet/presenter/fragments/FragmentFingerprint.java +++ b/app/src/main/java/com/breadwallet/presenter/fragments/FragmentFingerprint.java @@ -174,7 +174,7 @@ public void setCompletion(BRAuthCompletion completion) { public void onError() { String authError = "auth_prompt_failed"; Bundle params = new Bundle(); - params.putString("error_message",authError); + params.putString("lwa_error_message",authError); AnalyticsManager.logCustomEventWithParams(BRConstants._20200112_ERR, params); } diff --git a/app/src/main/java/com/breadwallet/presenter/history/HistoryFragment.kt b/app/src/main/java/com/breadwallet/presenter/history/HistoryFragment.kt index 8aa05d0b5..f65b1dbc7 100644 --- a/app/src/main/java/com/breadwallet/presenter/history/HistoryFragment.kt +++ b/app/src/main/java/com/breadwallet/presenter/history/HistoryFragment.kt @@ -7,15 +7,18 @@ import android.view.ViewGroup import com.breadwallet.databinding.FragmentHistoryBinding import com.breadwallet.presenter.activities.BreadActivity import com.breadwallet.presenter.base.BaseFragment +import com.breadwallet.tools.manager.AnalyticsManager import com.breadwallet.tools.manager.BRSharedPrefs import com.breadwallet.tools.manager.BRSharedPrefs.OnIsoChangedListener import com.breadwallet.tools.manager.TxManager import com.breadwallet.tools.sqlite.TransactionDataSource.OnTxAddedListener import com.breadwallet.tools.threads.BRExecutor +import com.breadwallet.tools.util.BRConstants import com.breadwallet.wallet.BRPeerManager import com.breadwallet.wallet.BRPeerManager.OnTxStatusUpdate import com.breadwallet.wallet.BRWalletManager import com.breadwallet.wallet.BRWalletManager.OnBalanceChanged +import timber.log.Timber /** Litewallet * Created by Mohamed Barry on 6/1/20 @@ -56,11 +59,22 @@ class HistoryFragment : BRPeerManager.getInstance().removeListener(this) BRSharedPrefs.removeListener(this) } - + private fun registerAnalyticsError(errorString: String) { + val params = Bundle() + params.putString("lwa_error_message", errorString); + AnalyticsManager.logCustomEventWithParams(BRConstants._20200112_ERR, params) + Timber.d("History Fragment: RegisterError : %s", errorString) + } override fun onResume() { super.onResume() addObservers() - TxManager.getInstance().onResume(requireActivity() as BreadActivity) + + if (this.activity == null) { + registerAnalyticsError("null_in_history_fragment_on_resume") + } + else { + TxManager.getInstance().onResume(this.activity) + } } override fun onPause() { @@ -74,7 +88,12 @@ class HistoryFragment : override fun onStatusUpdate() { BRExecutor.getInstance().forBackgroundTasks().execute { - TxManager.getInstance().updateTxList(requireActivity() as BreadActivity) + if (this.activity == null) { + registerAnalyticsError("null_in_history_fragment_on_status_update") + } + else { + TxManager.getInstance().updateTxList(this.activity) + } } } @@ -84,14 +103,23 @@ class HistoryFragment : override fun onTxAdded() { BRExecutor.getInstance().forBackgroundTasks().execute { - TxManager.getInstance().updateTxList(requireActivity() as BreadActivity) + if (this.activity == null) { + registerAnalyticsError("null_in_history_fragment_on_tx_added") + } + else { + TxManager.getInstance().updateTxList(this.activity) + } } } - private fun updateUI() { BRExecutor.getInstance().forLightWeightBackgroundTasks().execute { - Thread.currentThread().name = Thread.currentThread().name + "HistoryFragment:updateUI" - TxManager.getInstance().updateTxList(requireActivity() as BreadActivity) + if (this.activity == null) { + registerAnalyticsError("null_in_history_fragment_update_ui") + } + else { + Thread.currentThread().name = Thread.currentThread().name + "HistoryFragment:updateUI" + TxManager.getInstance().updateTxList(this.activity) + } } } diff --git a/app/src/main/java/com/breadwallet/tools/animation/BRAnimator.java b/app/src/main/java/com/breadwallet/tools/animation/BRAnimator.java index 5c9a3cffe..f5b55df58 100644 --- a/app/src/main/java/com/breadwallet/tools/animation/BRAnimator.java +++ b/app/src/main/java/com/breadwallet/tools/animation/BRAnimator.java @@ -11,6 +11,7 @@ import android.app.Activity; import android.app.FragmentManager; import android.app.FragmentTransaction; + import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; @@ -18,7 +19,6 @@ import android.view.ViewGroup; import android.view.animation.DecelerateInterpolator; import android.view.animation.OvershootInterpolator; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -29,7 +29,6 @@ import com.breadwallet.R; import com.breadwallet.presenter.activities.BreadActivity; import com.breadwallet.presenter.activities.LoginActivity; -import com.breadwallet.presenter.activities.camera.CameraActivity; import com.breadwallet.presenter.activities.camera.ScanQRActivity; import com.breadwallet.presenter.customviews.BRDialogView; import com.breadwallet.presenter.entities.TxItem; @@ -43,6 +42,7 @@ import com.breadwallet.presenter.fragments.FragmentSend; import com.breadwallet.presenter.fragments.FragmentSignal; import com.breadwallet.presenter.fragments.FragmentTransactionDetails; + import com.breadwallet.presenter.interfaces.BROnSignalCompletion; import com.breadwallet.tools.threads.BRExecutor; import com.breadwallet.tools.util.BRConstants; @@ -325,6 +325,7 @@ public void run() { } public static void killAllFragments(Activity app) { + //DEV: Needs refactor if (app != null && !app.isDestroyed()) app.getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); } diff --git a/app/src/main/java/com/breadwallet/tools/manager/BREventManager.java b/app/src/main/java/com/breadwallet/tools/manager/BREventManager.java deleted file mode 100644 index a337aa117..000000000 --- a/app/src/main/java/com/breadwallet/tools/manager/BREventManager.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.breadwallet.tools.manager; - -import android.content.Context; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; - -import com.breadwallet.BreadApp; -import com.breadwallet.tools.util.BRConstants; -import com.breadwallet.tools.util.Utils; -import com.platform.APIClient; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import okhttp3.MediaType; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import timber.log.Timber; - -import static com.platform.APIClient.BASE_URL; - -public class BREventManager implements BreadApp.OnAppBackgrounded { - private static BREventManager instance; - private String sessionId; - private List events = new ArrayList<>(); - - private BREventManager() { - sessionId = UUID.randomUUID().toString(); - BreadApp.addOnBackgroundedListener(this); - } - - public static BREventManager getInstance() { - if (instance == null) instance = new BREventManager(); - return instance; - } - - public void pushEvent(String eventName, Map attributes) { - Timber.d("timber: pushEvent: %s", eventName); - Event event = new Event(sessionId, System.currentTimeMillis() * 1000, eventName, attributes); - events.add(event); - } - - public void pushEvent(String eventName) { - Timber.d("timber: pushEvent: %s", eventName); - Event event = new Event(sessionId, System.currentTimeMillis() * 1000, eventName, null); - events.add(event); - } - - @Override - public void onBackgrounded() { - Timber.d("timber: onBackgrounded: "); - } - - //returns the list of JSONArray which consist of Event arrays - private static List getEventsFromDisk(Context context) { - List result = new ArrayList<>(); - File dir = new File(context.getFilesDir().getAbsolutePath() + "/events/"); - if (dir.listFiles() == null) return result; - for (File f : dir.listFiles()) { - if (f.isFile()) { - String name = f.getName(); - Timber.d("timber: getEventsFromDisk: name:%s", name); - try { - JSONArray arr = new JSONArray(readFile(name)); - result.add(arr); - } catch (JSONException e) { - Timber.e(e); - } - } else { - Timber.i("timber: getEventsFromDisk: Unexpected directory where file is expected: %s", f.getName()); - } - } - return result; - } - - private static String readFile(String fileName) { - try { - File f = new File(fileName); - //check whether file exists - FileInputStream is = new FileInputStream(f); - int size = is.available(); - byte[] buffer = new byte[size]; - is.read(buffer); - is.close(); - return new String(buffer); - } catch (IOException e) { - Timber.e(e, "timber:Error in Reading"); - return null; - } - } - - public class Event { - public String sessionId; - public long time; - public String eventName; - public Map attributes; - - public Event(String sessionId, long time, String eventName, Map attributes) { - this.sessionId = sessionId; - this.time = time; - this.eventName = eventName; - this.attributes = attributes; - } - } -} diff --git a/app/src/main/java/com/breadwallet/tools/manager/BRSharedPrefs.java b/app/src/main/java/com/breadwallet/tools/manager/BRSharedPrefs.java index 6832c9320..3472a10cd 100644 --- a/app/src/main/java/com/breadwallet/tools/manager/BRSharedPrefs.java +++ b/app/src/main/java/com/breadwallet/tools/manager/BRSharedPrefs.java @@ -288,7 +288,7 @@ public static void putGeoPermissionsRequested(Context activity, boolean requeste public static int getStartHeight(Context context) { SharedPreferences settingsToGet = context.getSharedPreferences(BRConstants.PREFS_NAME, 0); - return settingsToGet.getInt(BRConstants.START_HEIGHT, 0); + return settingsToGet.getInt(BRConstants.START_HEIGHT, 0); } public static void putStartHeight(Context context, int startHeight) { diff --git a/app/src/main/java/com/breadwallet/tools/manager/InternetManager.java b/app/src/main/java/com/breadwallet/tools/manager/InternetManager.java index 6598d7356..9955a4622 100644 --- a/app/src/main/java/com/breadwallet/tools/manager/InternetManager.java +++ b/app/src/main/java/com/breadwallet/tools/manager/InternetManager.java @@ -34,7 +34,6 @@ public static void addConnectionListener(ConnectionReceiverListener listener) { if (!connectionReceiverListeners.contains(listener)) connectionReceiverListeners.add(listener); } - @Override public void onReceive(final Context context, final Intent intent) { boolean connected = false; @@ -48,7 +47,6 @@ public void onReceive(final Context context, final Intent intent) { connected = false; } - BREventManager.getInstance().pushEvent(connected ? "reachability.isReachble" : "reachability.isNotReachable"); for (ConnectionReceiverListener listener : connectionReceiverListeners) { listener.onConnectionChanged(connected); } diff --git a/app/src/main/java/com/breadwallet/tools/manager/TxManager.java b/app/src/main/java/com/breadwallet/tools/manager/TxManager.java index ebf2fcfd8..37e5db4a8 100644 --- a/app/src/main/java/com/breadwallet/tools/manager/TxManager.java +++ b/app/src/main/java/com/breadwallet/tools/manager/TxManager.java @@ -4,6 +4,7 @@ import android.animation.AnimatorListenerAdapter; import android.app.Activity; import android.content.Context; +import android.os.Bundle; import android.os.Looper; import android.util.AttributeSet; import android.view.View; @@ -20,6 +21,7 @@ import com.breadwallet.tools.animation.BRAnimator; import com.breadwallet.tools.listeners.RecyclerItemClickListener; import com.breadwallet.tools.threads.BRExecutor; +import com.breadwallet.tools.util.BRConstants; import com.breadwallet.wallet.BRPeerManager; import com.breadwallet.wallet.BRWalletManager; @@ -64,7 +66,6 @@ public void onAnimationEnd(Animator animation) { }); } else { //clicked on the prompt - BREventManager.getInstance().pushEvent("prompt." + PromptManager.getInstance().getPromptName(currentPrompt) + ".trigger"); if (currentPrompt != PromptManager.PromptItem.SYNCING) { PromptManager.PromptInfo info = PromptManager.getInstance().promptInfo(app, currentPrompt); if (info != null) @@ -114,7 +115,6 @@ public void run() { void showPrompt(Activity app, PromptManager.PromptItem item) { crashIfNotMain(); if (item == null) throw new RuntimeException("can't be null"); - BREventManager.getInstance().pushEvent("prompt." + PromptManager.getInstance().getPromptName(item) + ".displayed"); if (currentPrompt != PromptManager.PromptItem.SYNCING) { currentPrompt = item; } @@ -132,9 +132,6 @@ void hidePrompt(final Activity app, final PromptManager.PromptItem item) { if (item == PromptManager.PromptItem.SYNCING) { showNextPrompt(app); updateCard(app); - } else { - if (item != null) - BREventManager.getInstance().pushEvent("prompt." + PromptManager.getInstance().getPromptName(item) + ".dismissed"); } } diff --git a/app/src/main/java/com/breadwallet/tools/security/BitcoinUrlHandler.java b/app/src/main/java/com/breadwallet/tools/security/BitcoinUrlHandler.java index 597daee07..b4ce90008 100644 --- a/app/src/main/java/com/breadwallet/tools/security/BitcoinUrlHandler.java +++ b/app/src/main/java/com/breadwallet/tools/security/BitcoinUrlHandler.java @@ -10,7 +10,6 @@ import com.breadwallet.presenter.entities.RequestObject; import com.breadwallet.tools.animation.BRAnimator; import com.breadwallet.tools.animation.BRDialog; -import com.breadwallet.tools.manager.BREventManager; import com.breadwallet.tools.threads.PaymentProtocolTask; import com.breadwallet.tools.util.Utils; import com.breadwallet.wallet.BRWalletManager; @@ -35,18 +34,6 @@ public static synchronized boolean processRequest(FragmentActivity app, String u return false; } - Map attr = new HashMap<>(); - URI uri = null; - try { - uri = new URI(url); - } catch (URISyntaxException e) { - Timber.e(e); - } - attr.put("scheme", uri == null ? "null" : uri.getScheme()); - attr.put("host", uri == null ? "null" : uri.getHost()); - attr.put("path", uri == null ? "null" : uri.getPath()); - BREventManager.getInstance().pushEvent("send.handleURL", attr); - RequestObject requestObject = getRequestFromString(url); if (BRWalletManager.getInstance().confirmSweep(app, url)) { return true; diff --git a/app/src/main/java/com/breadwallet/tools/util/BRConstants.java b/app/src/main/java/com/breadwallet/tools/util/BRConstants.java index a931d1da6..091f20942 100644 --- a/app/src/main/java/com/breadwallet/tools/util/BRConstants.java +++ b/app/src/main/java/com/breadwallet/tools/util/BRConstants.java @@ -125,7 +125,7 @@ private BRConstants() { public static final String _20200111_WNI = "wallet_not_initialized"; public static final String _20200111_PNI = "phrase_not_initialized"; public static final String _20200111_UTST = "unable_to_sign_transaction"; - public static final String _20200112_ERR = "error"; + public static final String _20200112_ERR = "lwa_error"; public static final String _20200112_DSR = "did_start_resync"; public static final String _20200125_DSRR = "did_show_review_request"; public static final String _20201118_DTGS = "did_tap_get_support"; diff --git a/app/src/main/java/com/breadwallet/tools/util/Utils.java b/app/src/main/java/com/breadwallet/tools/util/Utils.java index ab5e75ca4..b149ccbec 100644 --- a/app/src/main/java/com/breadwallet/tools/util/Utils.java +++ b/app/src/main/java/com/breadwallet/tools/util/Utils.java @@ -294,7 +294,7 @@ else if (name == PartnerNames.PUSHERSTAGING) { e.printStackTrace(); } Bundle params = new Bundle(); - params.putString("error_message: %s Key not found", name.toString()); + params.putString("lwa_error_message: %s Key not found", name.toString()); AnalyticsManager.logCustomEventWithParams(BRConstants._20200112_ERR,params); return ""; } From 4dae39fda4167afc3a5de88b8fbbc21c245531fa Mon Sep 17 00:00:00 2001 From: kcw-grunt Date: Wed, 23 Oct 2024 12:30:41 +0100 Subject: [PATCH 2/2] version bump update gitignore Signed-off-by: kcw-grunt --- .gitignore | 1 + .idea/androidTestResultsUserPreferences.xml | 66 --------------------- app/build.gradle | 4 +- 3 files changed, 3 insertions(+), 68 deletions(-) delete mode 100644 .idea/androidTestResultsUserPreferences.xml diff --git a/.gitignore b/.gitignore index 8830a3e22..4430b926c 100644 --- a/.gitignore +++ b/.gitignore @@ -101,3 +101,4 @@ app/src/litewalletDebug/google-services.json /app/release/google-services.json /app/debug/google-services.json /.idea/dictionaries/grunt.xml +androidTestResultsUserPreferences.xml diff --git a/.idea/androidTestResultsUserPreferences.xml b/.idea/androidTestResultsUserPreferences.xml deleted file mode 100644 index 33c7e7b32..000000000 --- a/.idea/androidTestResultsUserPreferences.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index ce04b6796..c21e02a8b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,8 +63,8 @@ android { applicationId = 'com.loafwallet' minSdkVersion 31 targetSdkVersion 34 - versionCode 20241016 - versionName "v2.11.4" + versionCode 20241023 + versionName "v2.12.0" multiDexEnabled true archivesBaseName = "${versionName}(${versionCode})"