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

Download Brave Wallet component on demand on Android #19086

Merged
merged 8 commits into from
Aug 1, 2023

Conversation

AlexeyBarabash
Copy link
Contributor

@AlexeyBarabash AlexeyBarabash commented Jun 28, 2023

Resolves brave/brave-browser#31824

This PR does 3 things:

  1. Prevents automatic registration of Brave Wallet data files component for Android (wallet_data_files_installer.cc);
  2. Performs on demand registration of the component after user presses Get started/Restore button during Wallet onboarding (SetupWalletFragment.onViewCreated)
  3. Does display of the progress of the component download during onboarding screens (DownloadComponentProgressFragment.java)

The PR doesn't do anything with unregister component and cleanup downloaded/unpacked fiels.

Screenshots:

                                                             Description                                                              Screenshot
Secure your crypto screen 1-1
Backup your wallet screen 1-2
Your recovery phrase screen 1-3
Verify recovery phrase 1-4
Restore crypto account 2-1

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run lint, npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

I. Normal flow, unlimited fast internet connection

  1. Install Brave
  2. Open brave://components, ensure there is no Brave Wallet data files component
  3. Open Wallet => Get Started => ... you must not see or see for a moment the Download wallet data % label
  4. Open brave://components, ensure there is no Brave Wallet data files component is in list with Up-to-data status.

II. Create wallet flow on slow internet connection

  1. Configure internet speed of the device to be 256 kbit/s, it can be done through WiFi router settings
  2. Install Brave
  3. Open Wallet => Get Started. Expected to have Download wallet data file on Secure your crypto / Backup your wallet / Your recovery phrase / Verify recovery phrase screens

III. Recover wallet flow on slow internet connection

  1. Configure internet speed of the device to be 256 kbit/s, it can be done through WiFi router settings
  2. Install Brave
  3. Open Wallet => Restore. Expected to have Download wallet data file on Restore crypto account screen.

@AlexeyBarabash AlexeyBarabash added the CI/skip Do not run CI builds (except noplatform) label Jun 28, 2023
@AlexeyBarabash AlexeyBarabash self-assigned this Jun 28, 2023
@AlexeyBarabash AlexeyBarabash force-pushed the android_wallet_compo_on_demand branch 3 times, most recently from 5db0532 to 630023d Compare June 29, 2023 15:11
@AlexeyBarabash AlexeyBarabash force-pushed the android_wallet_compo_on_demand branch 4 times, most recently from fd29334 to 1f7de71 Compare July 17, 2023 13:50
@AlexeyBarabash AlexeyBarabash force-pushed the android_wallet_compo_on_demand branch 4 times, most recently from 236a13a to 6e0aaf4 Compare July 24, 2023 19:14
@AlexeyBarabash AlexeyBarabash changed the title WIP: download Brave Wallet component on demand on Android Download Brave Wallet component on demand on Android Jul 25, 2023
@AlexeyBarabash AlexeyBarabash marked this pull request as ready for review July 25, 2023 19:32
@AlexeyBarabash AlexeyBarabash requested review from a team as code owners July 25, 2023 19:32
@AlexeyBarabash AlexeyBarabash removed the CI/skip Do not run CI builds (except noplatform) label Jul 25, 2023
Copy link
Contributor

@iefremov iefremov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chromium_src lgtm

Copy link
Member

@SergeyZhukovsky SergeyZhukovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Copy link
Collaborator

@mkarolin mkarolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings++

*/
public interface ComponentUpdaterListener {
// Invoked when component update info has changed.
public void onComponentUpdateEvent(int event, String id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifier 'public' is redundant for interface methods and can be safely removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for such a thorough review @simoarpe. PR will be cleaner with your notices.

Fixed at 54818d8#diff-b0ad67a3cc1f46d4b3163f2b99f39d57f940215f0c4a0a327a02bea2cf99f35cR72

}

private final List<ComponentUpdaterListener> mComponentUpdaterListeners =
new CopyOnWriteArrayList<ComponentUpdaterListener>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit type argument ComponentUpdaterListener can be replaced with <>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* Class describing the progress of component download.
*/
public class CrxUpdateItem {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inner class CrxUpdateItem may be static -> public static class CrxUpdateItem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crxUpdateItem.mId = result.getString("id");
crxUpdateItem.mDownloadedBytes = (long) result.getDouble("downloaded_bytes");
crxUpdateItem.mTotalBytes = (long) result.getDouble("total_bytes");
crxUpdateItem.mState = (int) result.getInt("state");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting to int is redundant and can be safely removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crxUpdateItem.mTotalBytes = (long) result.getDouble("total_bytes");
crxUpdateItem.mState = (int) result.getInt("state");
} catch (JSONException e) {
Log.e(TAG, "getUpdateState JSONException error " + e);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not include the error in the error message. Better pass the entire stacktrace to the appropriate parameter:
Log.e(TAG, "getUpdateState JSONException error", e);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} catch (JSONException e) {
Log.e(TAG, "getUpdateState JSONException error " + e);
} catch (IllegalStateException e) {
Log.e(TAG, "getUpdateState IllegalStateException error " + e);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: Log.e(TAG, "getUpdateState IllegalStateException error", e);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* download. Used on all Brave Wallet Onboarding fragments.
*/
public class DownloadComponentProgressFragment extends Fragment {
private static final String TAG = "DCPF";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TAG is never used and can be safely removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WalletDataFilesInstaller.getWalletDataFilesComponentId());
showHideProgressByItem(updateItem);

mComponentUpdaterListener = new BraveComponentUpdater.ComponentUpdaterListener() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be replaced with lambda mComponentUpdaterListener = (event, id) -> {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private ElapsedRealtimeMillisTimer mGracePeriodNoDisplayTimer;
private static final long GRACE_NO_DISPLAY_MSEC = 1000;

public DownloadComponentProgressFragment() {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty constructor can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import org.chromium.base.annotations.CalledByNative;

/**
* Class that is used by wallet_data_files_installer.cc to determine, do we need to download
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Class that is used by wallet_data_files_installer.cc to determine, do we need to download
* Class that is used by wallet_data_files_installer.cc to determine if we need to download

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@simoarpe simoarpe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Android changes look good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Download Brave Wallet data files component on demand on Android
8 participants