1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2025-06-08 16:36:10 +00:00

Don't let Java choose when cleaning SmsBuffer, do it ourself

This commit is contained in:
Loic Blot 2017-08-23 22:59:43 +02:00 committed by Loïc Blot
parent 5e6a1fc28e
commit 11bbed02b8
5 changed files with 21 additions and 6 deletions

View File

@ -20,8 +20,8 @@ android {
defaultConfig { defaultConfig {
applicationId "fr.unix_experience.owncloud_sms" applicationId "fr.unix_experience.owncloud_sms"
versionCode 51 versionCode 54
versionName "1.1.1" versionName "1.2.0"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 26 targetSdkVersion 26
maxSdkVersion 26 maxSdkVersion 26
@ -29,7 +29,7 @@ android {
// Specifies the ABI configurations of your native // Specifies the ABI configurations of your native
// libraries Gradle should build and package with your APK. // libraries Gradle should build and package with your APK.
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a',
'arm64-v8a' 'arm64-v8a', 'mips', 'mips64'
} }
externalNativeBuild { externalNativeBuild {
cmake { cmake {

View File

@ -51,7 +51,7 @@ jlong SmsBuffer::createNativeObject(JNIEnv *env, jobject self)
void SmsBuffer::deleteNativeObject(JNIEnv *env, jobject self, jlong ptr) void SmsBuffer::deleteNativeObject(JNIEnv *env, jobject self, jlong ptr)
{ {
__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "deleteSmsBuffer"); __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "deleteNativeObject 0x%li", ptr);
delete reinterpret_cast<SmsBuffer *>(ptr); delete reinterpret_cast<SmsBuffer *>(ptr);
} }

View File

@ -60,6 +60,7 @@ public interface ASyncSMSSync {
} }
} }
OCSMSNotificationUI.cancel(_context); OCSMSNotificationUI.cancel(_context);
_smsBuffer.clear();
Log.i(ASyncSMSSync.TAG, "Stopping background sync"); Log.i(ASyncSMSSync.TAG, "Stopping background sync");
return null; return null;
} }

View File

@ -175,6 +175,7 @@ public class OCSMSOwnCloudClient {
} }
doHttpRequest(post); doHttpRequest(post);
if (_jsonQueryBuffer == null) { if (_jsonQueryBuffer == null) {
Log.e(OCSMSOwnCloudClient.TAG,"Request failed. It doesn't return a valid JSON Object"); Log.e(OCSMSOwnCloudClient.TAG,"Request failed. It doesn't return a valid JSON Object");
throw new OCSyncException(R.string.err_sync_push_request, OCSyncErrorType.IO); throw new OCSyncException(R.string.err_sync_push_request, OCSyncErrorType.IO);

View File

@ -24,13 +24,14 @@ public class SmsBuffer {
private long mHandle; private long mHandle;
String TAG = SmsBuffer.class.getSimpleName();
public SmsBuffer() { public SmsBuffer() {
mHandle = SmsBuffer.createNativeObject(); mHandle = SmsBuffer.createNativeObject();
} }
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
SmsBuffer.deleteNativeObject(mHandle); clear();
mHandle = 0;
super.finalize(); super.finalize();
} }
@ -45,9 +46,21 @@ public class SmsBuffer {
public void push(int id, int mbid, int type, long date, String address, String body, public void push(int id, int mbid, int type, long date, String address, String body,
String read, String seen) { String read, String seen) {
if (mHandle == 0) {
throw new IllegalAccessError("Pushing data to empty native handler, aborting");
}
SmsBuffer.push(mHandle, id, mbid, type, date, address, body, read, seen); SmsBuffer.push(mHandle, id, mbid, type, date, address, body, read, seen);
} }
public void clear() {
if (mHandle == 0) {
return;
}
SmsBuffer.deleteNativeObject(mHandle);
mHandle = 0;
}
/* /*
JNI: Eepty method JNI: Eepty method
*/ */