mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2026-08-20 12:52:59 +00:00
Update tools versions & prepare JNI work to reduce memory & CPU usage
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package fr.unix_experience.owncloud_sms.activities;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014-2015, Loic Blot <loic.blot@unix-experience.fr>
|
||||
* Copyright (c) 2014-2017, Loic Blot <loic.blot@unix-experience.fr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import fr.unix_experience.owncloud_sms.enums.MailboxID;
|
||||
import fr.unix_experience.owncloud_sms.jni.SmsBuffer;
|
||||
import fr.unix_experience.owncloud_sms.providers.SmsDataProvider;
|
||||
|
||||
public class AndroidSmsFetcher {
|
||||
@@ -56,6 +57,9 @@ public class AndroidSmsFetcher {
|
||||
// Mailbox ID is required by server
|
||||
entry.put("mbox", mbID.ordinal());
|
||||
result.put(entry);
|
||||
SmsBuffer buf = new SmsBuffer();
|
||||
buf.push(mbID.ordinal());
|
||||
buf.print();
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.e(AndroidSmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e);
|
||||
|
||||
@@ -27,24 +27,32 @@ import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpMethod;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.HttpVersion;
|
||||
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
|
||||
import org.apache.commons.httpclient.URI;
|
||||
import org.apache.commons.httpclient.URIException;
|
||||
import org.apache.commons.httpclient.cookie.CookiePolicy;
|
||||
import org.apache.commons.httpclient.params.HttpClientParams;
|
||||
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
|
||||
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
|
||||
import org.apache.commons.httpclient.cookie.CookiePolicy;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
import org.apache.commons.httpclient.params.HttpClientParams;
|
||||
import org.apache.commons.httpclient.params.HttpMethodParams;
|
||||
import org.apache.commons.httpclient.protocol.Protocol;
|
||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||
import org.apache.commons.httpclient.params.HttpMethodParams;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import fr.unix_experience.owncloud_sms.providers.AndroidVersionProvider;
|
||||
|
||||
public class OCHttpClient extends HttpClient {
|
||||
static {
|
||||
System.loadLibrary("nativesms");
|
||||
}
|
||||
|
||||
public static native String getAllSmsIdsCall();
|
||||
public static native String getLastMsgTimestamp();
|
||||
public static native String getPushRoute();
|
||||
public static native String getVersionCall();
|
||||
|
||||
private static final String TAG = OCHttpClient.class.getCanonicalName();
|
||||
private static final String PARAM_PROTOCOL_VERSION = "http.protocol.version";
|
||||
@@ -52,12 +60,6 @@ public class OCHttpClient extends HttpClient {
|
||||
private final String _username;
|
||||
private final String _password;
|
||||
|
||||
// API v1 calls
|
||||
private static final String OC_GET_VERSION = "/index.php/apps/ocsms/get/apiversion?format=json";
|
||||
private static final String OC_GET_ALL_SMS_IDS = "/index.php/apps/ocsms/get/smsidlist?format=json";
|
||||
private static final String OC_GET_LAST_MSG_TIMESTAMP = "/index.php/apps/ocsms/get/lastmsgtime?format=json";
|
||||
private static final String OC_PUSH_ROUTE = "/index.php/apps/ocsms/push?format=json";
|
||||
|
||||
// API v2 calls
|
||||
private static final String OC_V2_GET_PHONELIST = "/index.php/apps/ocsms/api/v2/phones/list?format=json";
|
||||
private static final String OC_V2_GET_MESSAGES ="/index.php/apps/ocsms/api/v2/messages/[START]/[LIMIT]?format=json";
|
||||
@@ -72,7 +74,7 @@ public class OCHttpClient extends HttpClient {
|
||||
_username = accountName;
|
||||
_password = accountPassword;
|
||||
getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
|
||||
getParams().setParameter(PARAM_PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
|
||||
getParams().setParameter(OCHttpClient.PARAM_PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
|
||||
getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
|
||||
getParams().setParameter(HttpMethodParams.USER_AGENT,
|
||||
"nextcloud-phonesync (" + new AndroidVersionProvider(context).getVersionCode() + ")");
|
||||
@@ -84,15 +86,15 @@ public class OCHttpClient extends HttpClient {
|
||||
}
|
||||
|
||||
GetMethod getAllSmsIds() {
|
||||
return get(OCHttpClient.OC_GET_ALL_SMS_IDS);
|
||||
return get(OCHttpClient.getAllSmsIdsCall());
|
||||
}
|
||||
|
||||
public GetMethod getVersion() {
|
||||
return get(OCHttpClient.OC_GET_VERSION);
|
||||
return get(OCHttpClient.getVersionCall());
|
||||
}
|
||||
|
||||
PostMethod pushSms(StringRequestEntity ent) {
|
||||
PostMethod post = new PostMethod(_serverURI.toString() + OCHttpClient.OC_PUSH_ROUTE);
|
||||
PostMethod post = new PostMethod(_serverURI.toString() + OCHttpClient.getPushRoute());
|
||||
post.setRequestEntity(ent);
|
||||
return post;
|
||||
}
|
||||
@@ -109,24 +111,24 @@ public class OCHttpClient extends HttpClient {
|
||||
private int followRedirections(HttpMethod httpMethod) throws IOException {
|
||||
int redirectionsCount = 0;
|
||||
int status = httpMethod.getStatusCode();
|
||||
while (redirectionsCount < 3 &&
|
||||
(status == HttpStatus.SC_MOVED_PERMANENTLY ||
|
||||
status == HttpStatus.SC_MOVED_TEMPORARILY ||
|
||||
status == HttpStatus.SC_TEMPORARY_REDIRECT)
|
||||
while ((redirectionsCount < 3) &&
|
||||
((status == HttpStatus.SC_MOVED_PERMANENTLY) ||
|
||||
(status == HttpStatus.SC_MOVED_TEMPORARILY) ||
|
||||
(status == HttpStatus.SC_TEMPORARY_REDIRECT))
|
||||
) {
|
||||
Header location = httpMethod.getResponseHeader("Location");
|
||||
if (location == null) {
|
||||
location = httpMethod.getResponseHeader("location");
|
||||
}
|
||||
if (location == null) {
|
||||
Log.e(TAG, "No valid location header found when redirecting.");
|
||||
Log.e(OCHttpClient.TAG, "No valid location header found when redirecting.");
|
||||
return 500;
|
||||
}
|
||||
|
||||
try {
|
||||
httpMethod.setURI(new URI(location.getValue()));
|
||||
} catch (URIException e) {
|
||||
Log.e(TAG, "Invalid URI in 302 FOUND response");
|
||||
Log.e(OCHttpClient.TAG, "Invalid URI in 302 FOUND response");
|
||||
return 500;
|
||||
}
|
||||
|
||||
@@ -134,10 +136,10 @@ public class OCHttpClient extends HttpClient {
|
||||
redirectionsCount++;
|
||||
}
|
||||
|
||||
if (redirectionsCount >= 3 && status == HttpStatus.SC_MOVED_PERMANENTLY ||
|
||||
status == HttpStatus.SC_MOVED_TEMPORARILY ||
|
||||
status == HttpStatus.SC_TEMPORARY_REDIRECT) {
|
||||
Log.e(TAG, "Too many redirection done. Aborting, please ensure your server is " +
|
||||
if (((redirectionsCount >= 3) && (status == HttpStatus.SC_MOVED_PERMANENTLY)) ||
|
||||
(status == HttpStatus.SC_MOVED_TEMPORARILY) ||
|
||||
(status == HttpStatus.SC_TEMPORARY_REDIRECT)) {
|
||||
Log.e(OCHttpClient.TAG, "Too many redirection done. Aborting, please ensure your server is " +
|
||||
"correctly configured");
|
||||
return 400;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package fr.unix_experience.owncloud_sms.jni;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2014-2017, Loic Blot <loic.blot@unix-experience.fr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public class SmsBuffer {
|
||||
static {
|
||||
System.loadLibrary("nativesms");
|
||||
}
|
||||
|
||||
private long mHandle;
|
||||
|
||||
public SmsBuffer() {
|
||||
mHandle = SmsBuffer.createNativeObject();
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
SmsBuffer.deleteNativeObject(mHandle);
|
||||
mHandle = 0;
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
private static native long createNativeObject();
|
||||
private static native void deleteNativeObject(long handle);
|
||||
|
||||
public static native void push(long handle, int mbid);
|
||||
public void push(int mbid) {
|
||||
SmsBuffer.push(mHandle, mbid);
|
||||
}
|
||||
|
||||
public static native void print(long handle);
|
||||
public void print() {
|
||||
SmsBuffer.print(mHandle);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,22 @@
|
||||
package fr.unix_experience.owncloud_sms.notifications;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014-2017, Loic Blot <loic.blot@unix-experience.fr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
|
||||
Reference in New Issue
Block a user