mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-20 14:26:15 +00:00
use java.net.URL instead of URI
This commit is contained in:
parent
5c0eb4ca14
commit
c08e0fbd51
@ -24,7 +24,6 @@ import android.animation.AnimatorListenerAdapter;
|
|||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -47,6 +46,8 @@ import com.dd.processbutton.iml.ActionProcessButton;
|
|||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
import fr.unix_experience.owncloud_sms.R;
|
import fr.unix_experience.owncloud_sms.R;
|
||||||
import fr.unix_experience.owncloud_sms.defines.DefaultPrefs;
|
import fr.unix_experience.owncloud_sms.defines.DefaultPrefs;
|
||||||
@ -57,6 +58,9 @@ import fr.unix_experience.owncloud_sms.engine.OCHttpClient;
|
|||||||
*/
|
*/
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
public class LoginActivity extends AppCompatActivity {
|
public class LoginActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private static final String TAG = LoginActivity.class.getCanonicalName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep track of the login task to ensure we can cancel it if requested.
|
* Keep track of the login task to ensure we can cancel it if requested.
|
||||||
*/
|
*/
|
||||||
@ -192,8 +196,12 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
_signInButton.setProgress(25);
|
_signInButton.setProgress(25);
|
||||||
showProgress(true);
|
showProgress(true);
|
||||||
String serverURL = protocol + serverAddr;
|
String serverURL = protocol + serverAddr;
|
||||||
|
try {
|
||||||
mAuthTask = new UserLoginTask(serverURL, login, password);
|
mAuthTask = new UserLoginTask(serverURL, login, password);
|
||||||
mAuthTask.execute((Void) null);
|
mAuthTask.execute((Void) null);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
Log.e(TAG, "Invalid server URL " + serverURL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,9 +257,9 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
*/
|
*/
|
||||||
public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
|
public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
|
|
||||||
UserLoginTask(String serverURI, String login, String password) {
|
UserLoginTask(String serverURL, String login, String password) throws MalformedURLException {
|
||||||
Log.i(TAG, "_serverURI = " + serverURI);
|
_serverURL = new URL(serverURL);
|
||||||
_serverURI = Uri.parse(serverURI);
|
Log.i(TAG, "_serverURL = " + serverURL);
|
||||||
_login = login;
|
_login = login;
|
||||||
_password = password;
|
_password = password;
|
||||||
}
|
}
|
||||||
@ -259,7 +267,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Void... params) {
|
protected Boolean doInBackground(Void... params) {
|
||||||
_returnCode = 0;
|
_returnCode = 0;
|
||||||
OCHttpClient http = new OCHttpClient(getBaseContext(), _serverURI, _login, _password);
|
OCHttpClient http = new OCHttpClient(getBaseContext(), _serverURL, _login, _password);
|
||||||
GetMethod testMethod = null;
|
GetMethod testMethod = null;
|
||||||
try {
|
try {
|
||||||
testMethod = http.getVersion();
|
testMethod = http.getVersion();
|
||||||
@ -292,13 +300,13 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate a label
|
// Generate a label
|
||||||
String accountLabel = _login + "@" + _serverURI.getHost();
|
String accountLabel = _login + "@" + _serverURL.getHost();
|
||||||
|
|
||||||
// We create the account
|
// We create the account
|
||||||
Account account = new Account(accountLabel, accountType);
|
Account account = new Account(accountLabel, accountType);
|
||||||
Bundle accountBundle = new Bundle();
|
Bundle accountBundle = new Bundle();
|
||||||
accountBundle.putString("ocLogin", _login);
|
accountBundle.putString("ocLogin", _login);
|
||||||
accountBundle.putString("ocURI", _serverURI.toString());
|
accountBundle.putString("ocURI", _serverURL.toString());
|
||||||
|
|
||||||
// And we push it to Android
|
// And we push it to Android
|
||||||
AccountManager accMgr = AccountManager.get(getApplicationContext());
|
AccountManager accMgr = AccountManager.get(getApplicationContext());
|
||||||
@ -365,7 +373,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
showProgress(false);
|
showProgress(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Uri _serverURI;
|
private final URL _serverURL;
|
||||||
private final String _login;
|
private final String _login;
|
||||||
private final String _password;
|
private final String _password;
|
||||||
private int _returnCode;
|
private int _returnCode;
|
||||||
|
@ -18,7 +18,6 @@ package fr.unix_experience.owncloud_sms.engine;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -41,6 +40,7 @@ import org.apache.commons.httpclient.protocol.Protocol;
|
|||||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
import fr.unix_experience.owncloud_sms.providers.AndroidVersionProvider;
|
import fr.unix_experience.owncloud_sms.providers.AndroidVersionProvider;
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public class OCHttpClient extends HttpClient {
|
|||||||
|
|
||||||
private static final String TAG = OCHttpClient.class.getCanonicalName();
|
private static final String TAG = OCHttpClient.class.getCanonicalName();
|
||||||
private static final String PARAM_PROTOCOL_VERSION = "http.protocol.version";
|
private static final String PARAM_PROTOCOL_VERSION = "http.protocol.version";
|
||||||
private final Uri _serverURI;
|
private final URL _serverURI;
|
||||||
private final String _username;
|
private final String _username;
|
||||||
private final String _password;
|
private final String _password;
|
||||||
|
|
||||||
@ -66,11 +66,11 @@ public class OCHttpClient extends HttpClient {
|
|||||||
private static final String OC_V2_GET_MESSAGES_PHONE ="/index.php/apps/ocsms/api/v2/messages/[PHONENUMBER]/[START]/[LIMIT]?format=json";
|
private static final String OC_V2_GET_MESSAGES_PHONE ="/index.php/apps/ocsms/api/v2/messages/[PHONENUMBER]/[START]/[LIMIT]?format=json";
|
||||||
private static final String OC_V2_GET_MESSAGES_SENDQUEUE = "/index.php/apps/ocsms/api/v2/messages/sendqueue?format=json";
|
private static final String OC_V2_GET_MESSAGES_SENDQUEUE = "/index.php/apps/ocsms/api/v2/messages/sendqueue?format=json";
|
||||||
|
|
||||||
public OCHttpClient(Context context, Uri serverURI, String accountName, String accountPassword) {
|
public OCHttpClient(Context context, URL serverURL, String accountName, String accountPassword) {
|
||||||
super(new MultiThreadedHttpConnectionManager());
|
super(new MultiThreadedHttpConnectionManager());
|
||||||
Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
|
Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
|
||||||
Protocol.registerProtocol("https", easyhttps);
|
Protocol.registerProtocol("https", easyhttps);
|
||||||
_serverURI = serverURI;
|
_serverURI = serverURL;
|
||||||
_username = accountName;
|
_username = accountName;
|
||||||
_password = accountPassword;
|
_password = accountPassword;
|
||||||
getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
|
getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
|
||||||
|
@ -20,7 +20,6 @@ package fr.unix_experience.owncloud_sms.engine;
|
|||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
import org.apache.commons.httpclient.HttpException;
|
||||||
@ -34,6 +33,8 @@ import org.json.JSONObject;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
import fr.unix_experience.owncloud_sms.R;
|
import fr.unix_experience.owncloud_sms.R;
|
||||||
import fr.unix_experience.owncloud_sms.enums.OCSyncErrorType;
|
import fr.unix_experience.owncloud_sms.enums.OCSyncErrorType;
|
||||||
@ -56,11 +57,15 @@ public class OCSMSOwnCloudClient {
|
|||||||
throw new IllegalStateException(context.getString(R.string.err_sync_account_unparsable));
|
throw new IllegalStateException(context.getString(R.string.err_sync_account_unparsable));
|
||||||
}
|
}
|
||||||
|
|
||||||
Uri serverURI = Uri.parse(ocURI);
|
try {
|
||||||
|
URL serverURL = new URL(ocURI);
|
||||||
_http = new OCHttpClient(context,
|
_http = new OCHttpClient(context,
|
||||||
serverURI, accountManager.getUserData(account, "ocLogin"),
|
serverURL, accountManager.getUserData(account, "ocLogin"),
|
||||||
accountManager.getPassword(account));
|
accountManager.getPassword(account));
|
||||||
_connectivityMonitor = new ConnectivityMonitor(_context);
|
_connectivityMonitor = new ConnectivityMonitor(_context);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new IllegalStateException(context.getString(R.string.err_sync_account_unparsable));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getServerAPIVersion() throws OCSyncException {
|
public Integer getServerAPIVersion() throws OCSyncException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user