فهرست منبع

Fix code quality issues

David Luhmer 6 سال پیش
والد
کامیت
07a9e8c55f

+ 8 - 5
src/main/java/com/nextcloud/android/sso/InputStreamBinder.java

@@ -15,6 +15,7 @@ import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.lib.common.OwnCloudAccount;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
+import com.owncloud.android.lib.common.utils.Log_OC;
 
 import org.apache.commons.httpclient.HttpMethodBase;
 import org.apache.commons.httpclient.NameValuePair;
@@ -33,6 +34,7 @@ import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -65,8 +67,9 @@ public class InputStreamBinder extends IInputStreamService.Stub {
     private Context context;
     private static final String CONTENT_TYPE_APPLICATION_JSON = "application/json";
     private static final String CHARSET_UTF8 = "UTF-8";
+    private static final int HTTP_STATUS_CODE_OK = 200;
 
-    private ArrayList<String> validPackages = new ArrayList<>(Arrays.asList(
+    private List<String> validPackages = new ArrayList<>(Arrays.asList(
             "de.luhmer.owncloudnewsreader"
     ));
 
@@ -100,7 +103,7 @@ public class InputStreamBinder extends IInputStreamService.Stub {
             NextcloudRequest request = deserializeObjectAndCloseStream(is);
             httpStream = processRequest(request);
         } catch (Exception e) {
-            e.printStackTrace();
+            Log_OC.e(TAG, e.getMessage());
             exception = e;
         }
 
@@ -110,7 +113,7 @@ public class InputStreamBinder extends IInputStreamService.Stub {
             InputStream resultStream = new java.io.SequenceInputStream(exceptionStream, httpStream);
             return ParcelFileDescriptorUtil.pipeFrom(resultStream, thread -> Log.d(TAG, "Done sending result"));
         } catch (IOException e) {
-            e.printStackTrace();
+            Log_OC.e(TAG, e.getMessage());
         }
         return null;
     }
@@ -147,7 +150,7 @@ public class InputStreamBinder extends IInputStreamService.Stub {
         }
 
         // Validate URL
-        if(!request.url.startsWith("/")) {
+        if(request.url.charAt(0) != '/') {
             throw new IllegalStateException("URL need to start with a /");
         }
 
@@ -194,7 +197,7 @@ public class InputStreamBinder extends IInputStreamService.Stub {
         method.addRequestHeader("OCS-APIREQUEST", "true");
 
         int status = client.executeMethod(method);
-        if (status == 200) {
+        if (status == HTTP_STATUS_CODE_OK) {
             return method.getResponseBodyAsStream();
         } else {
             throw new Exception("Request returned code: " + status);

+ 1 - 1
src/main/java/com/nextcloud/android/sso/aidl/NextcloudRequest.java

@@ -62,7 +62,7 @@ public class NextcloudRequest implements Serializable {
             return this;
         }
 
-        public Builder setParameter(HashMap<String, String> parameter) {
+        public Builder setParameter(Map<String, String> parameter) {
             ncr.parameter = parameter;
             return this;
         }

+ 6 - 3
src/main/java/com/nextcloud/android/sso/aidl/ParcelFileDescriptorUtil.java

@@ -3,6 +3,8 @@ package com.nextcloud.android.sso.aidl;
 import android.os.ParcelFileDescriptor;
 import android.util.Log;
 
+import com.owncloud.android.lib.common.utils.Log_OC;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -88,16 +90,17 @@ public final class ParcelFileDescriptorUtil {
                 try {
                     mIn.close();
                 } catch (IOException e) {
-                    Log.e(TAG, e.getMessage());
+                    Log_OC.e(TAG, e.getMessage());
                 }
                 try {
                     mOut.close();
                 } catch (IOException e) {
-                    Log.e(TAG, e.getMessage());
+                    Log_OC.e(TAG, e.getMessage());
                 }
             }
-            if (mListener != null)
+            if (mListener != null) {
                 mListener.onThreadFinished(this);
+            }
         }
     }
 }

+ 4 - 7
src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java

@@ -85,12 +85,12 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
                              String accountType, String authTokenType,
                              String[] requiredFeatures, Bundle options) {
         Log_OC.i(TAG, "Adding account with type " + accountType + " and auth token " + authTokenType);
-        
-        final Bundle bundle = new Bundle();
-        
+
         AccountManager accountManager = AccountManager.get(mContext);
         Account[] accounts = accountManager.getAccountsByType(MainApp.getAccountType(mContext));
-        
+
+        final Bundle bundle = new Bundle();
+
         if (mContext.getResources().getBoolean(R.bool.multiaccount_support) || accounts.length < 1) {
             try {
                 validateAccountType(accountType);
@@ -110,16 +110,13 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
             setIntentFlags(intent);
             
             bundle.putParcelable(AccountManager.KEY_INTENT, intent);
-        
         } else {
-
             // Return an error
             bundle.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION);
             final String message = String.format(mContext.getString(R.string.auth_unsupported_multiaccount), mContext.getString(R.string.app_name)); 
             bundle.putString(AccountManager.KEY_ERROR_MESSAGE, message);
            
             mHandler.post(() -> Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show());
-            
         }
         
         return bundle;

+ 0 - 62
src/main/java/com/owncloud/android/ui/asynctasks/AsyncTaskHelper.java

@@ -1,62 +0,0 @@
-package com.owncloud.android.ui.asynctasks;
-
-import android.os.AsyncTask;
-import android.os.Build;
-import android.support.annotation.RequiresApi;
-
-import java.util.concurrent.Callable;
-
-/**
- *  Nextcloud SingleSignOn
- *
- *  @author David Luhmer
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-public class AsyncTaskHelper {
-
-    @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
-    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();
-
-        if(at.exception != null) {
-            throw at.exception;
-        }
-
-        return result;
-    }
-
-    private static class GenericAsyncTaskWithCallable<T> extends AsyncTask<Void, Void, T> {
-
-        private Callable<T> callable;
-        private Exception exception;
-
-        GenericAsyncTaskWithCallable(Callable<T> callable) {
-            this.callable = callable;
-        }
-
-        @Override
-        protected T doInBackground(Void... params) {
-            try {
-                return callable.call();
-            } catch (Exception e) {
-                exception = e;
-                return null;
-            }
-        }
-    }
-}