From 557329f76160c6e8a03094235d227b00d67bc611 Mon Sep 17 00:00:00 2001 From: Chris Boyle Date: Sun, 9 Nov 2014 16:42:52 +0000 Subject: [PATCH] Cope with null intent/action in NFC. And a couple of speculative defenses for #228. Bump version. --- app/build.gradle | 2 +- .../main/java/name/boyle/chris/sgtpuzzles/GamePlay.java | 5 +++-- app/src/main/jni/android.c | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 46293de0a..a7d768847 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,7 +38,7 @@ android { defaultConfig { applicationId "name.boyle.chris.sgtpuzzles" - versionCode 96 + versionCode 97 versionName "${timestamp()}-${idForSimon()}" if (file(ndkDir.absolutePath + '/platforms/android-15').exists()) { // the last without PIE diff --git a/app/src/main/java/name/boyle/chris/sgtpuzzles/GamePlay.java b/app/src/main/java/name/boyle/chris/sgtpuzzles/GamePlay.java index 44e0682f4..f6f265c74 100644 --- a/app/src/main/java/name/boyle/chris/sgtpuzzles/GamePlay.java +++ b/app/src/main/java/name/boyle/chris/sgtpuzzles/GamePlay.java @@ -414,7 +414,7 @@ protected void onNewIntent(Intent intent) @TargetApi(Build.VERSION_CODES.GINGERBREAD) private boolean handleNFC(Intent intent) { - if (!intent.getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) return false; + if (intent == null || !NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) return false; Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if (rawMsgs.length == 0) return false; NdefMessage msg = (NdefMessage) rawMsgs[0]; @@ -742,7 +742,7 @@ private void startGame(final GameLaunch launch) } @UsedByJNI - private void clearForNewGame(final String startingBackend, final float[] colours) { + private void clearForNewGame(final String startingBackend, final float[] colours, final boolean canUndo, final boolean canRedo) { runOnUiThread(new Runnable() { public void run() { gameView.colours = new int[colours.length / 3]; @@ -772,6 +772,7 @@ public void run() { gameTypes.clear(); gameView.keysHandled = 0; everCompleted = false; + changedState(canUndo, canRedo); } }); } diff --git a/app/src/main/jni/android.c b/app/src/main/jni/android.c index b04d411b8..c21558104 100644 --- a/app/src/main/jni/android.c +++ b/app/src/main/jni/android.c @@ -731,8 +731,7 @@ void notifyClearForNewGame(jstring whichBackend) jfloatArray jColours = (*env)->NewFloatArray(env, n*3); if (jColours == NULL) return; (*env)->SetFloatArrayRegion(env, jColours, 0, n*3, colours); - (*env)->CallVoidMethod(env, obj, clearForNewGame, whichBackend, jColours); - android_changed_state(NULL, midend_can_undo(fe->me), midend_can_redo(fe->me)); + (*env)->CallVoidMethod(env, obj, clearForNewGame, whichBackend, jColours, midend_can_undo(fe->me), midend_can_redo(fe->me)); } void populatePresets() @@ -790,8 +789,10 @@ void startPlayingInt(JNIEnv *env, jobject _obj, jobject _gameView, jstring backe midend_size(fe->me, &x, &y, FALSE); notifyClearForNewGame(whichBackend); + if ((*env)->ExceptionCheck(env)) return; populatePresets(); + if ((*env)->ExceptionCheck(env)) return; fe->ox = -1; @@ -834,7 +835,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) blitterLoad = (*env)->GetMethodID(env, vcls, "blitterLoad", "(III)V"); blitterSave = (*env)->GetMethodID(env, vcls, "blitterSave", "(III)V"); changedState = (*env)->GetMethodID(env, cls, "changedState", "(ZZ)V"); - clearForNewGame = (*env)->GetMethodID(env, cls, "clearForNewGame", "(Ljava/lang/String;[F)V"); + clearForNewGame = (*env)->GetMethodID(env, cls, "clearForNewGame", "(Ljava/lang/String;[FZZ)V"); clipRect = (*env)->GetMethodID(env, vcls, "clipRect", "(IIII)V"); dialogAdd = (*env)->GetMethodID(env, cls, "dialogAdd", "(IILjava/lang/String;Ljava/lang/String;I)V"); dialogInit = (*env)->GetMethodID(env, cls, "dialogInit", "(ILjava/lang/String;)V");