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_LOGIN_OPTIONS = "loginOptions";
public static final String KEY_ACCOUNT = "account";
private static final String NEXTCLOUD_SSO = "NextcloudSSO";
private static final String TAG = AccountAuthenticator.class.getSimpleName();
@ -158,7 +159,7 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
Account account, String authTokenType, Bundle options)
throws NetworkErrorException {
if(authTokenType.equals("NextcloudSSO")) {
if (NEXTCLOUD_SSO.equals(authTokenType)) {
AccountManager am = AccountManager.get(mContext);
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_TYPE, MainApp.getAccountType());
result.putString(AccountManager.KEY_AUTHTOKEN, "NextcloudSSO");
result.putString(AccountManager.KEY_AUTHTOKEN, NEXTCLOUD_SSO);
result.putString("username", username);
result.putString("password", am.getPassword(account));
result.putString("server_url", "https://" + server);

View file

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

View file

@ -17,7 +17,7 @@ import java.util.concurrent.Callable;
public class AsyncTaskHelper {
@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);
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) {
try {
return AsyncTaskHelper.ExecuteBlockingRequest(new Callable<InputStream>() {
return AsyncTaskHelper.executeBlockingRequest(new Callable<InputStream>() {
@Override
public InputStream call() throws Exception {
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 {
static final long serialVersionUID = 215521212534236L; //assign a long value
private static final long serialVersionUID = 215521212534236L; //assign a long value
public String method;
public Map<String, List<String>> header = new HashMap<>();

View file

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