Skip to content

Commit

Permalink
Add HWWallet disconnection callback when GDK explicitly closed, so any
Browse files Browse the repository at this point in the history
hw-specific disconnect/cleanup code can be executed immediately.
  • Loading branch information
JamieDriver committed Jan 14, 2021
1 parent 9a8c3fe commit 9449310
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/src/main/java/com/greenaddress/greenapi/HWWallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public abstract class HWWallet {
protected NetworkData mNetwork;
protected HWDeviceData mHWDeviceData;

// For any explicit disconnection the hw may want to do
public abstract void disconnect();

// Return the base58check encoded xpubs for each path in paths
public abstract List<String> getXpubs(final GaActivity parent, final List<List<Integer>> paths);

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/greenaddress/greenapi/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ public void connectWithProxy(final String network, final String proxyAsString, f

public void disconnect() throws Exception {
super.disconnect();

if (mHWWallet != null) {
mHWWallet.disconnect();
mHWWallet = null;
}
mWatchOnlyUsername = null;
mHWWallet = null;
mSettings = null;
mTwoFAReset = false;
pinJustSaved = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ else if (msg.contains("6985"))
});
}

@Override
public void disconnect() {
// No-op
}

public List<String> getXpubs(final GaActivity parent, final List<List<Integer>> paths) {
final List<String> xpubs = new ArrayList<>(paths.size());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public JadeHWWallet(final Context ctx, final JadeAPI jade, final NetworkData net
this.jade = jade;
}

@Override
public void disconnect() {
this.jade.disconnect();
}

public void authenticate() throws Exception {
final VersionInfo verInfo = this.jade.getVersionInfo();
if (!verInfo.getHasPin()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public TrezorHWWallet(final Trezor t, final NetworkData network, final HWDeviceD
mHWDeviceData = hwDeviceData;
}

@Override
public void disconnect() {
// No-op
}

@Override
public List<String> getXpubs(final GaActivity parent, final List<List<Integer>> paths) {
final List<String> xpubs = new ArrayList<>(paths.size());
Expand Down

0 comments on commit 9449310

Please sign in to comment.