changes according to codacy

This commit is contained in:
tobiasKaminsky 2017-10-26 08:20:30 +02:00 committed by AndyScherzinger
parent bdfabd70e9
commit f52eb08606
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
6 changed files with 83 additions and 88 deletions

View file

@ -57,6 +57,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
public static final String KEY_REQUIRED_FEATURES = "requiredFeatures"; public static final String KEY_REQUIRED_FEATURES = "requiredFeatures";
public static final String KEY_LOGIN_OPTIONS = "loginOptions"; public static final String KEY_LOGIN_OPTIONS = "loginOptions";
public static final String KEY_ACCOUNT = "account"; public static final String KEY_ACCOUNT = "account";
private static final String NEXTCLOUD_SSO = "NextcloudSSO";
private static final String TAG = AccountAuthenticator.class.getSimpleName(); private static final String TAG = AccountAuthenticator.class.getSimpleName();
@ -158,7 +159,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
Account account, String authTokenType, Bundle options) Account account, String authTokenType, Bundle options)
throws NetworkErrorException { throws NetworkErrorException {
if(authTokenType.equals("NextcloudSSO")) { if (NEXTCLOUD_SSO.equals(authTokenType)) {
AccountManager am = AccountManager.get(mContext); AccountManager am = AccountManager.get(mContext);
final Bundle result = new Bundle(); final Bundle result = new Bundle();
@ -167,7 +168,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
result.putString(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType()); result.putString(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType());
result.putString(AccountManager.KEY_AUTHTOKEN, "NextcloudSSO"); result.putString(AccountManager.KEY_AUTHTOKEN, NEXTCLOUD_SSO);
result.putString("username", username); result.putString("username", username);
result.putString("password", am.getPassword(account)); result.putString("password", am.getPassword(account));
result.putString("server_url", "https://" + server); result.putString("server_url", "https://" + server);

View file

@ -33,7 +33,6 @@ import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable;
import de.luhmer.owncloud.accountimporter.helper.InputStreamBinder; import de.luhmer.owncloud.accountimporter.helper.InputStreamBinder;
import de.luhmer.owncloud.accountimporter.helper.NextcloudRequest; import de.luhmer.owncloud.accountimporter.helper.NextcloudRequest;
@ -42,19 +41,17 @@ public class AccountManagerService extends Service {
private static final String TAG = AccountManagerService.class.getCanonicalName(); private static final String TAG = AccountManagerService.class.getCanonicalName();
public AccountManagerService() { }
@Override
public IBinder onBind(Intent intent) {
return (new InputStreamBinder(this));
}
/** Command to the service to display a message */ /** Command to the service to display a message */
private static final int MSG_CREATE_NEW_ACCOUNT = 3; private static final int MSG_CREATE_NEW_ACCOUNT = 3;
private static final int MSG_REQUEST_NETWORK_REQUEST = 4; private static final int MSG_REQUEST_NETWORK_REQUEST = 4;
private static final int MSG_RESPONSE_NETWORK_REQUEST = 5; private static final int MSG_RESPONSE_NETWORK_REQUEST = 5;
@Override
public IBinder onBind(Intent intent) {
return (new InputStreamBinder(this));
}
/** /**
* Handler of incoming messages from clients. * Handler of incoming messages from clients.
*/ */
@ -80,82 +77,79 @@ public class AccountManagerService extends Service {
Object result = null; Object result = null;
Exception exception = null; Exception exception = null;
try { try {
result = AsyncTaskHelper.ExecuteBlockingRequest(new Callable<Object>() { result = AsyncTaskHelper.executeBlockingRequest(() -> {
@Override Account account = AccountUtils.getOwnCloudAccountByName(AccountManagerService.this, accountName); // TODO handle case that account is not found!
public Object call() throws Exception { OwnCloudAccount ocAccount = new OwnCloudAccount(account, AccountManagerService.this);
Account account = AccountUtils.getOwnCloudAccountByName(AccountManagerService.this, accountName); // TODO handle case that account is not found! OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, AccountManagerService.this);
OwnCloudAccount ocAccount = new OwnCloudAccount(account, AccountManagerService.this);
OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, AccountManagerService.this);
//OwnCloudVersion version = AccountUtils.getServerVersion(account); //OwnCloudVersion version = AccountUtils.getServerVersion(account);
//client.setOwnCloudVersion(version); //client.setOwnCloudVersion(version);
// TODO do some checks if url is correct!! (prevent ../ in url etc.. // TODO do some checks if url is correct!! (prevent ../ in url etc..
request.url = client.getBaseUri() + request.url; request.url = client.getBaseUri() + request.url;
INetworkInterface network = (stream) ? new StreamingRequest(port) : new PlainRequest(); INetworkInterface network = (stream) ? new StreamingRequest(port) : new PlainRequest();
switch(request.method) { switch(request.method) {
case "GET": case "GET":
GetMethod get = new GetMethod(request.url); GetMethod get = new GetMethod(request.url);
get.setQueryString(convertMapToNVP(request.parameter)); get.setQueryString(convertMapToNVP(request.parameter));
get.addRequestHeader("OCS-APIREQUEST", "true"); get.addRequestHeader("OCS-APIREQUEST", "true");
int status = client.executeMethod(get); int status = client.executeMethod(get);
if(status == 200) { if(status == 200) {
return network.handleGetRequest(get); return network.handleGetRequest(get);
} else { } else {
throw new Exception("Network error!!"); throw new Exception("Network error!!");
} }
case "POST": case "POST":
PostMethod post = new PostMethod(request.url); PostMethod post = new PostMethod(request.url);
post.setQueryString(convertMapToNVP(request.parameter)); post.setQueryString(convertMapToNVP(request.parameter));
post.addRequestHeader("OCS-APIREQUEST", "true"); post.addRequestHeader("OCS-APIREQUEST", "true");
if(request.requestBody != null) { if(request.requestBody != null) {
StringRequestEntity requestEntity = new StringRequestEntity( StringRequestEntity requestEntity = new StringRequestEntity(
request.requestBody, request.requestBody,
"application/json", "application/json",
"UTF-8"); "UTF-8");
post.setRequestEntity(requestEntity); post.setRequestEntity(requestEntity);
} }
int status2 = client.executeMethod(post); int status2 = client.executeMethod(post);
if(status2 == 200) { if(status2 == 200) {
return network.handlePostRequest(post); return network.handlePostRequest(post);
} else { } else {
throw new Exception("Network error!!"); throw new Exception("Network error!!");
} }
case "PUT": case "PUT":
PutMethod put = new PutMethod(request.url); PutMethod put = new PutMethod(request.url);
put.setQueryString(convertMapToNVP(request.parameter)); put.setQueryString(convertMapToNVP(request.parameter));
put.addRequestHeader("OCS-APIREQUEST", "true"); put.addRequestHeader("OCS-APIREQUEST", "true");
if(request.requestBody != null) { if(request.requestBody != null) {
StringRequestEntity requestEntity = new StringRequestEntity( StringRequestEntity requestEntity = new StringRequestEntity(
request.requestBody, request.requestBody,
"application/json", "application/json",
"UTF-8"); "UTF-8");
put.setRequestEntity(requestEntity); put.setRequestEntity(requestEntity);
} }
int status4 = client.executeMethod(put); int status4 = client.executeMethod(put);
if(status4 == 200) { if(status4 == 200) {
return network.handlePutRequest(put); return network.handlePutRequest(put);
} else { } else {
throw new Exception("Network error!!"); throw new Exception("Network error!!");
} }
case "DELETE": case "DELETE":
DeleteMethod delete = new DeleteMethod(request.url); DeleteMethod delete = new DeleteMethod(request.url);
delete.setQueryString(convertMapToNVP(request.parameter)); delete.setQueryString(convertMapToNVP(request.parameter));
delete.addRequestHeader("OCS-APIREQUEST", "true"); delete.addRequestHeader("OCS-APIREQUEST", "true");
int status3 = client.executeMethod(delete); int status3 = client.executeMethod(delete);
if(status3 == 200) { if(status3 == 200) {
return true; return true;
} else { } else {
throw new Exception("Network error!!"); throw new Exception("Network error!!");
} }
default: default:
throw new Exception("Unexpected type!!"); throw new Exception("Unexpected type!!");
}
} }
}); });
} catch (Exception e) { } catch (Exception e) {
@ -225,7 +219,7 @@ public class AccountManagerService extends Service {
public class StreamingRequest implements INetworkInterface { public class StreamingRequest implements INetworkInterface {
int port; private int port;
public StreamingRequest(int port) { public StreamingRequest(int port) {
this.port = port; this.port = port;
@ -245,7 +239,7 @@ public class AccountManagerService extends Service {
InputStream in = get.getResponseBodyAsStream(); InputStream in = get.getResponseBodyAsStream();
OutputStream out = m_activity_socket.getOutputStream(); OutputStream out = m_activity_socket.getOutputStream();
// the header describes the frame data (type, width, height, length) // the header describes the frame data (type, width, height, length)
// frame width and heigth have been previously decoded // frame width and height have been previously decoded
//byte[] header = new byte[16]; //byte[] header = new byte[16];
//build_header( 1, width, height, frameData.length, header, 1 ); //build_header( 1, width, height, frameData.length, header, 1 );
//m_nos.write( header ); // message header //m_nos.write( header ); // message header

View file

@ -17,7 +17,7 @@ import java.util.concurrent.Callable;
public class AsyncTaskHelper { public class AsyncTaskHelper {
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB) @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public static <T> T ExecuteBlockingRequest(Callable<T> callable) throws Exception { public static <T> T executeBlockingRequest(Callable<T> callable) throws Exception {
GenericAsyncTaskWithCallable<T> at = new GenericAsyncTaskWithCallable<>(callable); GenericAsyncTaskWithCallable<T> at = new GenericAsyncTaskWithCallable<>(callable);
T result = at.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR).get(); T result = at.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR).get();

View file

@ -89,7 +89,7 @@ public class InputStreamBinder extends IInputStreamService.Stub {
private InputStream processRequest(final NextcloudRequest request) { private InputStream processRequest(final NextcloudRequest request) {
try { try {
return AsyncTaskHelper.ExecuteBlockingRequest(new Callable<InputStream>() { return AsyncTaskHelper.executeBlockingRequest(new Callable<InputStream>() {
@Override @Override
public InputStream call() throws Exception { public InputStream call() throws Exception {
Account account = AccountUtils.getOwnCloudAccountByName(context, request.accountName); // TODO handle case that account is not found! Account account = AccountUtils.getOwnCloudAccountByName(context, request.accountName); // TODO handle case that account is not found!

View file

@ -11,7 +11,7 @@ import java.util.Map;
public class NextcloudRequest implements Serializable { public class NextcloudRequest implements Serializable {
static final long serialVersionUID = 215521212534236L; //assign a long value private static final long serialVersionUID = 215521212534236L; //assign a long value
public String method; public String method;
public Map<String, List<String>> header = new HashMap<>(); public Map<String, List<String>> header = new HashMap<>();

View file

@ -37,10 +37,10 @@ public class ParcelFileDescriptorUtil {
return writeSide; return writeSide;
} }
static class TransferThread extends Thread { public static class TransferThread extends Thread {
final InputStream mIn; private final InputStream mIn;
final OutputStream mOut; private final OutputStream mOut;
final IThreadListener mListener; private final IThreadListener mListener;
TransferThread(InputStream in, OutputStream out, IThreadListener listener) { TransferThread(InputStream in, OutputStream out, IThreadListener listener) {
super("ParcelFileDescriptor Transfer Thread"); super("ParcelFileDescriptor Transfer Thread");