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

use java.net.URL instead of URI

This commit is contained in:
Loic Blot 2017-10-30 09:17:02 +01:00
parent 5c0eb4ca14
commit c08e0fbd51
No known key found for this signature in database
GPG Key ID: EFAA458E8C153987
3 changed files with 33 additions and 20 deletions

View File

@ -24,7 +24,6 @@ import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
@ -47,6 +46,8 @@ import com.dd.processbutton.iml.ActionProcessButton;
import org.apache.commons.httpclient.methods.GetMethod;
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.defines.DefaultPrefs;
@ -57,6 +58,9 @@ import fr.unix_experience.owncloud_sms.engine.OCHttpClient;
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
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.
*/
@ -192,8 +196,12 @@ public class LoginActivity extends AppCompatActivity {
_signInButton.setProgress(25);
showProgress(true);
String serverURL = protocol + serverAddr;
try {
mAuthTask = new UserLoginTask(serverURL, login, password);
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> {
UserLoginTask(String serverURI, String login, String password) {
Log.i(TAG, "_serverURI = " + serverURI);
_serverURI = Uri.parse(serverURI);
UserLoginTask(String serverURL, String login, String password) throws MalformedURLException {
_serverURL = new URL(serverURL);
Log.i(TAG, "_serverURL = " + serverURL);
_login = login;
_password = password;
}
@ -259,7 +267,7 @@ public class LoginActivity extends AppCompatActivity {
@Override
protected Boolean doInBackground(Void... params) {
_returnCode = 0;
OCHttpClient http = new OCHttpClient(getBaseContext(), _serverURI, _login, _password);
OCHttpClient http = new OCHttpClient(getBaseContext(), _serverURL, _login, _password);
GetMethod testMethod = null;
try {
testMethod = http.getVersion();
@ -292,13 +300,13 @@ public class LoginActivity extends AppCompatActivity {
}
// Generate a label
String accountLabel = _login + "@" + _serverURI.getHost();
String accountLabel = _login + "@" + _serverURL.getHost();
// We create the account
Account account = new Account(accountLabel, accountType);
Bundle accountBundle = new Bundle();
accountBundle.putString("ocLogin", _login);
accountBundle.putString("ocURI", _serverURI.toString());
accountBundle.putString("ocURI", _serverURL.toString());
// And we push it to Android
AccountManager accMgr = AccountManager.get(getApplicationContext());
@ -365,7 +373,7 @@ public class LoginActivity extends AppCompatActivity {
showProgress(false);
}
private final Uri _serverURI;
private final URL _serverURL;
private final String _login;
private final String _password;
private int _returnCode;

View File

@ -18,7 +18,6 @@ package fr.unix_experience.owncloud_sms.engine;
*/
import android.content.Context;
import android.net.Uri;
import android.util.Base64;
import android.util.Log;
@ -41,6 +40,7 @@ import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import java.io.IOException;
import java.net.URL;
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 PARAM_PROTOCOL_VERSION = "http.protocol.version";
private final Uri _serverURI;
private final URL _serverURI;
private final String _username;
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_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());
Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", easyhttps);
_serverURI = serverURI;
_serverURI = serverURL;
_username = accountName;
_password = accountPassword;
getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);

View File

@ -20,7 +20,6 @@ package fr.unix_experience.owncloud_sms.engine;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import org.apache.commons.httpclient.HttpException;
@ -34,6 +33,8 @@ import org.json.JSONObject;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
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.enums.OCSyncErrorType;
@ -56,11 +57,15 @@ public class OCSMSOwnCloudClient {
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,
serverURI, accountManager.getUserData(account, "ocLogin"),
serverURL, accountManager.getUserData(account, "ocLogin"),
accountManager.getPassword(account));
_connectivityMonitor = new ConnectivityMonitor(_context);
} catch (MalformedURLException e) {
throw new IllegalStateException(context.getString(R.string.err_sync_account_unparsable));
}
}
public Integer getServerAPIVersion() throws OCSyncException {