Skip to content

Commit

Permalink
Bugfixes (#85)
Browse files Browse the repository at this point in the history
* android.view.WindowManager

* refactor

* lock_guard listener

* new version
  • Loading branch information
m2049r authored Sep 25, 2017
1 parent 6678222 commit a3db07c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.m2049r.xmrwallet"
minSdkVersion 21
targetSdkVersion 25
versionCode 17
versionName "0.8.0.4"
versionCode 18
versionName "0.8.0.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
Expand Down
19 changes: 15 additions & 4 deletions app/src/main/cpp/monerujo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static jclass class_WalletListener;
static jclass class_TransactionInfo;
static jclass class_Transfer;

std::mutex _listenerMutex;

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
cachedJVM = jvm;
LOGI("JNI_OnLoad");
Expand Down Expand Up @@ -101,6 +103,7 @@ struct MyWalletListener : Bitmonero::WalletListener {
};

void deleteGlobalJavaRef(JNIEnv *env) {
std::lock_guard<std::mutex> lock(_listenerMutex);
env->DeleteGlobalRef(jlistener);
jlistener = nullptr;
}
Expand All @@ -109,6 +112,7 @@ struct MyWalletListener : Bitmonero::WalletListener {
* @brief updated - generic callback, called when any event (sent/received/block reveived/etc) happened with the wallet;
*/
void updated() {
std::lock_guard<std::mutex> lock(_listenerMutex);
if (jlistener == nullptr) return;
LOGD("updated");
JNIEnv *jenv;
Expand All @@ -128,6 +132,7 @@ struct MyWalletListener : Bitmonero::WalletListener {
* @param amount - amount
*/
void moneySpent(const std::string &txId, uint64_t amount) {
std::lock_guard<std::mutex> lock(_listenerMutex);
if (jlistener == nullptr) return;
LOGD("moneySpent %"
PRIu64, amount);
Expand All @@ -139,6 +144,7 @@ struct MyWalletListener : Bitmonero::WalletListener {
* @param amount - amount
*/
void moneyReceived(const std::string &txId, uint64_t amount) {
std::lock_guard<std::mutex> lock(_listenerMutex);
if (jlistener == nullptr) return;
LOGD("moneyReceived %"
PRIu64, amount);
Expand All @@ -150,6 +156,7 @@ struct MyWalletListener : Bitmonero::WalletListener {
* @param amount - amount
*/
void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount) {
std::lock_guard<std::mutex> lock(_listenerMutex);
if (jlistener == nullptr) return;
LOGD("unconfirmedMoneyReceived %"
PRIu64, amount);
Expand All @@ -160,6 +167,7 @@ struct MyWalletListener : Bitmonero::WalletListener {
* @param height - block height
*/
void newBlock(uint64_t height) {
std::lock_guard<std::mutex> lock(_listenerMutex);
if (jlistener == nullptr) return;
//LOGD("newBlock");
JNIEnv *jenv;
Expand All @@ -178,6 +186,7 @@ struct MyWalletListener : Bitmonero::WalletListener {
* @brief refreshed - called when wallet refreshed by background thread or explicitly refreshed by calling "refresh" synchronously
*/
void refreshed() {
std::lock_guard<std::mutex> lock(_listenerMutex);
if (jlistener == nullptr) return;
LOGD("refreshed");
JNIEnv *jenv;
Expand Down Expand Up @@ -465,14 +474,15 @@ JNIEXPORT jboolean JNICALL
Java_com_m2049r_xmrwallet_model_WalletManager_closeJ(JNIEnv *env, jobject instance,
jobject walletInstance) {
Bitmonero::Wallet *wallet = getHandle<Bitmonero::Wallet>(env, walletInstance);
bool closeSuccess = Bitmonero::WalletManagerFactory::getWalletManager()->closeWallet(wallet, false);
bool closeSuccess = Bitmonero::WalletManagerFactory::getWalletManager()->closeWallet(wallet,
false);
if (closeSuccess) {
MyWalletListener *walletListener = getHandle<MyWalletListener>(env, walletInstance,
"listenerHandle");
if (walletListener != nullptr) {
walletListener->deleteGlobalJavaRef(env);
delete walletListener;
}
delete walletListener;
}
LOGD("wallet closed");
return closeSuccess;
Expand Down Expand Up @@ -601,7 +611,8 @@ Java_com_m2049r_xmrwallet_model_Wallet_initJ(JNIEnv *env, jobject instance,
const char *_daemon_username = env->GetStringUTFChars(daemon_username, JNI_FALSE);
const char *_daemon_password = env->GetStringUTFChars(daemon_password, JNI_FALSE);
Bitmonero::Wallet *wallet = getHandle<Bitmonero::Wallet>(env, instance);
bool status = wallet->init(_daemon_address, upper_transaction_size_limit, _daemon_username, _daemon_password);
bool status = wallet->init(_daemon_address, upper_transaction_size_limit, _daemon_username,
_daemon_password);
env->ReleaseStringUTFChars(daemon_address, _daemon_address);
env->ReleaseStringUTFChars(daemon_username, _daemon_username);
env->ReleaseStringUTFChars(daemon_password, _daemon_password);
Expand Down Expand Up @@ -919,7 +930,7 @@ jobject newTransferInstance(JNIEnv *env, uint64_t amount, const std::string &add

jobject newTransferList(JNIEnv *env, Bitmonero::TransactionInfo *info) {
const std::vector<Bitmonero::TransactionInfo::Transfer> &transfers = info->transfers();
if (transfers.size()==0) { // don't create empty Lists
if (transfers.size() == 0) { // don't create empty Lists
return nullptr;
}
// make new ArrayList
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void onClick(View v) {
etDaemonAddress.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
if (hasFocus && !getActivity().isFinishing()) {
etDaemonAddress.showDropDown();
Helper.showKeyboard(getActivity());
}
Expand Down

0 comments on commit a3db07c

Please sign in to comment.