[IOT-2745][Java][1.3.1-RC1] Static Analysis fix. 27/22627/2
authorSenthil Kumar G S <senthil.gs@samsung.com>
Wed, 27 Sep 2017 14:54:34 +0000 (20:24 +0530)
committerUze Choi <uzchoi@samsung.com>
Thu, 28 Sep 2017 08:47:36 +0000 (08:47 +0000)
Java static analysis fix for easy-setup module.
1. Removed unused imports.
2. Updated log to include error info.
3. Avoided multiple statements in single line.
4. Removed unused methods/code.
5. Proper order of java modifiers, etc.

Change-Id: Ida08e2084246aca7c5f1528bb2efe4c57682c85c
Signed-off-by: Senthil Kumar G S <senthil.gs@samsung.com>
14 files changed:
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProp.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudPropProvisioningCallback.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/DeviceProp.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESConstants.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetup.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeConf.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeStatus.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/SecurityProvisioningStatus.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ESCloudProvState.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ESErrorCode.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ESResult.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ProvStatus.java
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/EasysetupActivity.java
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/LoginActivity.java

index 22a2acb..044221b 100755 (executable)
@@ -63,7 +63,7 @@ public class CloudProp {
             mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHPROVIDER, authProvider);
             mRep.setValue(ESConstants.OC_RSRVD_ES_CISERVER, ciServer);
         } catch (OcException e) {
-            Log.e(TAG, "setCloudProp is failed.");
+            Log.e(TAG, "setCloudProp is failed: " + e.toString());
         }
     }
 
@@ -88,7 +88,7 @@ public class CloudProp {
             mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHPROVIDER, authProvider);
             mRep.setValue(ESConstants.OC_RSRVD_ES_CISERVER, ciServer);
         } catch (OcException e) {
-            Log.e(TAG, "setCloudPropWithAccessToken is failed.");
+            Log.e(TAG, "setCloudPropWithAccessToken is failed: "  + e.toString());
         }
     }
 
@@ -119,7 +119,7 @@ public class CloudProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getAuthCode is failed.");
+            Log.e(TAG, "getAuthCode is failed: "  + e.toString());
         }
         return null;
     }
@@ -142,7 +142,7 @@ public class CloudProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getAuthProvider is failed.");
+            Log.e(TAG, "getAuthProvider is failed: "  + e.toString());
         }
         return null;
     }
@@ -165,7 +165,7 @@ public class CloudProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getCiServer is failed.");
+            Log.e(TAG, "getCiServer is failed: "  + e.toString());
         }
         return null;
     }
@@ -206,7 +206,7 @@ public class CloudProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getAccessToken is failed.");
+            Log.e(TAG, "getAccessToken is failed: "  + e.toString());
         }
         return null;
     }
@@ -229,7 +229,7 @@ public class CloudProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getAccessTokenType is failed.");
+            Log.e(TAG, "getAccessTokenType is failed: "  + e.toString());
         }
         return OAUTH_TOKENTYPE.NONE_OAUTH_TOKENTYPE;
     }
index f0583d1..36cedce 100755 (executable)
@@ -37,6 +37,6 @@ public abstract class CloudPropProvisioningCallback {
      *          a result of cloud property provisioning
      *          a state of cloud property provisioning
      */
-       public abstract void onProgress(CloudPropProvisioningStatus status);
+    public abstract void onProgress(CloudPropProvisioningStatus status);
 }
 
index 2cff252..12e6052 100755 (executable)
@@ -59,7 +59,7 @@ public class DeviceProp {
             mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHTYPE, authtype.getValue());
             mRep.setValue(ESConstants.OC_RSRVD_ES_ENCTYPE, enctype.getValue());
         } catch (OcException e) {
-            Log.e(TAG, "setWiFiProp is failed.");
+            Log.e(TAG, "setWiFiProp is failed: " + e.toString());
         }
     }
 
@@ -82,7 +82,7 @@ public class DeviceProp {
             mRep.setValue(ESConstants.OC_RSRVD_ES_COUNTRY, country);
             mRep.setValue(ESConstants.OC_RSRVD_ES_LOCATION, location);
         } catch (OcException e) {
-            Log.e(TAG, "setDevConfProp is failed.");
+            Log.e(TAG, "setDevConfProp is failed: " + e.toString());
         }
     }
 
@@ -105,7 +105,7 @@ public class DeviceProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getSsid is failed.");
+            Log.e(TAG, "getSsid is failed: " + e.toString());
         }
         return null;
     }
@@ -129,7 +129,7 @@ public class DeviceProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getPassword is failed.");
+            Log.e(TAG, "getPassword is failed: " + e.toString());
         }
         return null;
     }
@@ -154,7 +154,7 @@ public class DeviceProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getAuthType is failed.");
+            Log.e(TAG, "getAuthType is failed: " + e.toString());
         }
         return WIFI_AUTHTYPE.NONE_AUTH;
     }
@@ -179,7 +179,7 @@ public class DeviceProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getEncType is failed.");
+            Log.e(TAG, "getEncType is failed: " + e.toString());
         }
         return WIFI_ENCTYPE.NONE_ENC;
     }
@@ -203,7 +203,7 @@ public class DeviceProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getLanguage is failed.");
+            Log.e(TAG, "getLanguage is failed: " + e.toString());
         }
         return null;
     }
@@ -227,7 +227,7 @@ public class DeviceProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getCountry is failed.");
+            Log.e(TAG, "getCountry is failed: " + e.toString());
         }
         return null;
     }
@@ -251,7 +251,7 @@ public class DeviceProp {
         }
         catch (OcException e)
         {
-            Log.e(TAG, "getLocation is failed.");
+            Log.e(TAG, "getLocation is failed: " + e.toString());
         }
         return null;
     }
index e18281d..f0088d6 100755 (executable)
@@ -22,6 +22,8 @@ package org.iotivity.service.easysetup.mediator;
 
 public class ESConstants {
 
+    private ESConstants() {}
+
     public static final String OC_RSRVD_REPRESENTATION = "rep";
 
     public static final String OC_RSRVD_ES_PROVSTATUS = "ps";
@@ -46,7 +48,7 @@ public class ESConstants {
     public static final String OC_RSRVD_ES_LOCATION = "loc";
 
 /**
-* Easysetup defined resoruce types and uris
+* Easysetup defined resource types and uris
 */
     public static final String OC_RSRVD_ES_RES_TYPE_EASYSETUP = "oic.r.easysetup";
     public static final String OC_RSRVD_ES_URI_EASYSETUP = "/EasySetupResURI";
index b89c8d7..aa68134 100755 (executable)
@@ -25,13 +25,10 @@ package org.iotivity.service.easysetup.mediator;
 import android.content.Context;
 import android.util.Log;
 
-import org.iotivity.base.OcConnectivityType;
 import org.iotivity.base.OcResource;
 import org.iotivity.base.OcPlatform;
 
 import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.List;
 
 /**
  * This provides an API to instanciate a new RemoteEnrollee object correspondent to Enrollee
@@ -56,7 +53,7 @@ public class EasySetup {
         {
             System.loadLibrary("ocprovision");
         } catch (UnsatisfiedLinkError e) {
-            Log.i(TAG, "ocprovision library does not exist. (Unsecure mode)");
+            Log.i(TAG, "ocprovision library does not exist (Unsecure mode): " + e.toString());
         }
 
         System.loadLibrary("ocstack-jni");
@@ -74,7 +71,7 @@ public class EasySetup {
      * @param context android context
      * @return a initialized singleton instance of EasySetup
      */
-    public synchronized static EasySetup getInstance(Context context) {
+    public static synchronized EasySetup getInstance(Context context) {
         if (sInstance == null) {
             sInstance = new EasySetup();
             mContext = context;
index 51e439c..9925112 100755 (executable)
@@ -29,7 +29,6 @@ import org.iotivity.service.easysetup.mediator.enums.WIFI_FREQ;
 import org.iotivity.service.easysetup.mediator.enums.WIFI_MODE;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -93,7 +92,7 @@ public class EnrolleeConf
                         return (String) rep.getValue(ESConstants.OC_RSRVD_ES_DEVNAME);
                     }
                 } catch (OcException e) {
-                    Log.e(TAG, "getWiFiModes is failed.");
+                    Log.e(TAG, "getWiFiModes is failed: " + e.toString());
                 }
             }
         }
@@ -133,7 +132,7 @@ public class EnrolleeConf
                         return (String) rep.getValue(ESConstants.OC_RSRVD_ES_MODELNUMBER);
                     }
                 } catch (OcException e) {
-                    Log.e(TAG, "getModelNumber is failed.");
+                    Log.e(TAG, "getModelNumber is failed: " + e.toString());
                 }
             }
         }
@@ -190,7 +189,7 @@ public class EnrolleeConf
                         }
                     }
                 } catch (OcException e) {
-                    Log.e(TAG, "getWiFiModes is failed.");
+                    Log.e(TAG, "getWiFiModes is failed: " + e.toString());
                 }
             }
         }
@@ -239,7 +238,7 @@ public class EnrolleeConf
                         }
                     }
                 } catch (OcException e) {
-                    Log.e(TAG, "getWiFiFreq is failed.");
+                    Log.e(TAG, "getWiFiFreq is failed: " + e.toString());
                 }
             }
         }
index 3421c40..425ced8 100755 (executable)
@@ -60,7 +60,7 @@ public class EnrolleeStatus
                 return ProvStatus.fromInt(provStatus);
             }
         } catch (OcException e) {
-            Log.e(TAG, "getProvStatus is failed.");
+            Log.e(TAG, "getProvStatus is failed: " + e.toString());
         }
         return ProvStatus.fromInt(0);
     }
@@ -79,7 +79,7 @@ public class EnrolleeStatus
                 return ESErrorCode.fromInt(errCode);
             }
         } catch (OcException e) {
-            Log.e(TAG, "getLastErrCode is failed.");
+            Log.e(TAG, "getLastErrCode is failed: " + e.toString());
         }
         return ESErrorCode.fromInt(0);
     }
index dc98dd0..ced1d4b 100644 (file)
@@ -57,7 +57,9 @@ public enum ESCloudProvState {
 
     public static ESCloudProvState fromInt(int i) {
         for (ESCloudProvState b : ESCloudProvState.values()) {
-            if (b.getValue() == i) { return b; }
+            if (b.getValue() == i) {
+                return b;
+            }
         }
         return null;
     }
index d94edf2..264410d 100755 (executable)
@@ -55,7 +55,7 @@ public enum ESErrorCode {
      */
     ES_ERRCODE_TIMEOUT(5),
 
-       /**
+    /**
      * Error Code that cloud server is not reachable due to wrong URL of cloud server, for example.
      */
     ES_ERRCODE_FAILED_TO_ACCESS_CLOUD_SERVER(6),
@@ -113,7 +113,9 @@ public enum ESErrorCode {
 
     public static ESErrorCode fromInt(int i) {
         for (ESErrorCode b : ESErrorCode.values()) {
-            if (b.getValue() == i) { return b; }
+            if (b.getValue() == i) {
+                return b;
+            }
         }
         return null;
     }
index fce3537..9495cb0 100755 (executable)
@@ -41,13 +41,15 @@ public enum ESResult {
         this.value = value;
     }
 
-       public int getValue() {
+    public int getValue() {
         return value;
     }
 
-       public static ESResult fromInt(int i) {
+    public static ESResult fromInt(int i) {
         for (ESResult b : ESResult.values()) {
-            if (b.getValue() == i) { return b; }
+            if (b.getValue() == i) {
+                return b;
+            }
         }
         return null;
     }
index aa52174..c6e6776 100755 (executable)
@@ -92,7 +92,9 @@ public enum ProvStatus {
 
     public static ProvStatus fromInt(int i) {
         for (ProvStatus b : ProvStatus.values()) {
-            if (b.getValue() == i) { return b; }
+            if (b.getValue() == i) {
+                return b;
+            }
         }
         return null;
     }
index cc369d9..3b5d2e6 100755 (executable)
@@ -43,10 +43,10 @@ import android.widget.ToggleButton;
 
 import org.iotivity.base.ErrorCode;
 import org.iotivity.base.ModeType;
+import org.iotivity.base.OcAccountManager;
 import org.iotivity.base.OcConnectivityType;
 import org.iotivity.base.OcException;
 import org.iotivity.base.OcHeaderOption;
-import org.iotivity.base.ObserveType;
 import org.iotivity.base.OcPlatform;
 import org.iotivity.base.OcPresenceStatus;
 import org.iotivity.base.OcProvisioning;
@@ -55,14 +55,13 @@ import org.iotivity.base.OcResource;
 import org.iotivity.base.PlatformConfig;
 import org.iotivity.base.QualityOfService;
 import org.iotivity.base.ServiceType;
-import org.iotivity.base.OcAccountManager;
-import org.iotivity.service.easysetup.mediator.ESConstants;
 import org.iotivity.service.easysetup.mediator.CloudProp;
 import org.iotivity.service.easysetup.mediator.CloudPropProvisioningCallback;
 import org.iotivity.service.easysetup.mediator.CloudPropProvisioningStatus;
 import org.iotivity.service.easysetup.mediator.DeviceProp;
 import org.iotivity.service.easysetup.mediator.DevicePropProvisioningCallback;
 import org.iotivity.service.easysetup.mediator.DevicePropProvisioningStatus;
+import org.iotivity.service.easysetup.mediator.ESConstants;
 import org.iotivity.service.easysetup.mediator.ESException;
 import org.iotivity.service.easysetup.mediator.EasySetup;
 import org.iotivity.service.easysetup.mediator.EnrolleeConf;
@@ -71,7 +70,6 @@ import org.iotivity.service.easysetup.mediator.GetConfigurationStatus;
 import org.iotivity.service.easysetup.mediator.RemoteEnrollee;
 import org.iotivity.service.easysetup.mediator.SecurityProvisioningCallback;
 import org.iotivity.service.easysetup.mediator.SecurityProvisioningStatus;
-import org.iotivity.service.easysetup.mediator.enums.ESCloudProvState;
 import org.iotivity.service.easysetup.mediator.enums.ESResult;
 import org.iotivity.service.easysetup.mediator.enums.WIFI_AUTHTYPE;
 import org.iotivity.service.easysetup.mediator.enums.WIFI_ENCTYPE;
@@ -95,13 +93,16 @@ public class EasysetupActivity extends Activity
                                 implements OcPlatform.OnPresenceListener,
                                            OcResource.OnObserveListener{
     private static final String TAG = "Easysetup Mediator: ";
+    private static final String SUCCESS = "Success";
+    private static final String FAILED = "Failed";
+    private static final String ACCESSTOKEN = "accesstoken";
+    private static final String REFRESHTOKEN = "refreshtoken";
+    private static final String COMMUNICATION_ERROR = "Communication Error";
+    private static final String deviceID = "9E09F4FE-978A-4BC3-B356-1F93BCA37829";
+    private static final String CIServer = "coap+tcp://13.124.29.169:5683";
     PlatformConfig cfg;
     OcAccountManager m_accountManager = null;
-    final String deviceID = "9E09F4FE-978A-4BC3-B356-1F93BCA37829";
-    final String CIServer = "coap+tcp://13.124.29.169:5683";
-
     private static final int BUFFER_SIZE = 1024;
-
     private String filePath = "";
     public static final String OIC_CLIENT_JSON_DB_FILE =  "oic_svr_db_client.dat";
     public static final String OIC_SQL_DB_FILE =  "PDM.db";
@@ -253,11 +254,15 @@ public class EasysetupActivity extends Activity
                         startActivityForResult(intent, 2);
                         mProvisionCloudPropInfo.setVisibility(View.VISIBLE);
                         break;
+
+                    default:
+                        break;
                 }
             }
         });
 
-        ArrayAdapter<CharSequence> adAuthType, adEnctype;
+        ArrayAdapter<CharSequence> adAuthType;
+        ArrayAdapter<CharSequence> adEnctype;
 
         adAuthType = ArrayAdapter.createFromResource(this, R.array.auth_type,
                 android.R.layout.simple_spinner_item);
@@ -301,8 +306,8 @@ public class EasysetupActivity extends Activity
         }
         SharedPreferences settings =
                                 getApplicationContext().getSharedPreferences("IoTivityCloud", 0);
-        mAccessToken = settings.getString("accesstoken", null);
-        mRefreshtoken = settings.getString("refreshtoken", null);
+        mAccessToken = settings.getString(ACCESSTOKEN, null);
+        mRefreshtoken = settings.getString(REFRESHTOKEN, null);
         mUserID = settings.getString("uid", null);
 
         if(mRefreshtoken == null)
@@ -365,12 +370,10 @@ public class EasysetupActivity extends Activity
             }
             Log.d(TAG, "Sql db directory exists at " + sqlDbPath);
 
-            //SQLiteDatabase.openOrCreateDatabase(sqlDbPath+ OIC_SQL_DB_FILE, null);
             OcProvisioning.provisionInit(sqlDbPath + OIC_SQL_DB_FILE);
             mSecurityMode.setChecked(true);
         } catch (OcException e) {
-            logMessage(TAG + "provisionInit error: " + e.getMessage());
-            Log.e(TAG, e.getMessage());
+            Log.e(TAG, "provisionInit error: " + e.getMessage());
             Toast.makeText(this,"provisionInit error: " + e.getMessage(),
                     Toast.LENGTH_LONG).show();
             mSecurityMode.setChecked(false);
@@ -395,9 +398,37 @@ public class EasysetupActivity extends Activity
              */
             OcProvisioning.provisionClose();
         } catch (OcException e) {
-            logMessage(TAG + "provisionClose error: " + e.getMessage());
-            Log.e(TAG, e.getMessage());
+            Log.e(TAG, "provisionClose error: " + e.getMessage());
+        }
+    }
+
+    private String getSecureUDPEndpoint(OcResource ocResource) {
+        if(null == ocResource) {
+            return null;
+        }
+
+        String udpEndpoint = null;
+        List<String> endpoints = ocResource.getAllHosts();
+        if(null != endpoints && !endpoints.isEmpty())
+        {
+            Log.d(TAG, "Endpoints of the resource: " + endpoints);
+            Iterator<String> itr = endpoints.iterator();
+            while(itr.hasNext())
+            {
+                String endpoint = itr.next();
+                if(null != endpoint && endpoint.contains("coaps://"))
+                {
+                    udpEndpoint = endpoint;
+                    Log.d(TAG, "Found coaps endpoint: setHost() returned " + udpEndpoint);
+                    break;
+                }
+            }
         }
+        else
+        {
+            Log.d(TAG, "No endpoints found");
+        }
+        return udpEndpoint;
     }
 
     OcPlatform.OnResourceFoundListener listener =
@@ -436,26 +467,10 @@ public class EasysetupActivity extends Activity
 
                             if(mSecurityMode.isChecked())
                             {
-                                // Change the host of the resource to secure endpoint.
-                                List<String> endpoints = ocResource.getAllHosts();
-                                if(null != endpoints || 0 == endpoints.size())
-                                {
-                                    Log.d(TAG, "Endpoints of the resource: " + endpoints);
-                                    Iterator<String> itr = endpoints.iterator();
-                                    while(itr.hasNext())
-                                    {
-                                        String endpoint = itr.next();
-                                        if(null != endpoint && endpoint.contains("coaps://"))
-                                        {
-                                            String retval = ocResource.setHost(endpoint);
-                                            Log.d(TAG, "Found coaps endpoint: setHost() returned " + retval);
-                                            break;
-                                        }
-                                    }
-                                }
-                                else
-                                {
-                                    Log.d(TAG, "No endpoints found");
+                                String endpoint = getSecureUDPEndpoint(ocResource);
+                                if(null != endpoint && !endpoint.isEmpty()) {
+                                    // Change the host of the resource to secure endpoint.
+                                    ocResource.setHost(endpoint);
                                 }
                             }
 
@@ -556,7 +571,7 @@ public class EasysetupActivity extends Activity
                                         runOnUiThread(new Runnable() {
                                             @Override
                                             public void run() {
-                                                mSecStateText.setText("Success");
+                                                mSecStateText.setText(SUCCESS);
                                                 mSecDevIDText.setText(securityProvisioningStatus.getDevUUID());
                                             }
                                         });
@@ -585,7 +600,7 @@ public class EasysetupActivity extends Activity
                                         runOnUiThread(new Runnable() {
                                             @Override
                                             public void run() {
-                                                mSecStateText.setText("Failed");
+                                                mSecStateText.setText(FAILED);
                                                 mStartConfigureSec.setEnabled(true);
                                             }
                                         });
@@ -633,7 +648,7 @@ public class EasysetupActivity extends Activity
                                         runOnUiThread(new Runnable() {
                                             @Override
                                             public void run() {
-                                                mGetconfigurationStateText.setText("Success");
+                                                mGetconfigurationStateText.setText(SUCCESS);
                                                 mDevNameText.setText(enrolleeConf.getDeviceName());
                                                 mModelNumberText.setText(enrolleeConf.getModelNumber());
                                                 setWifiModes(enrolleeConf.getWiFiModes());
@@ -653,7 +668,7 @@ public class EasysetupActivity extends Activity
                                         runOnUiThread(new Runnable() {
                                             @Override
                                             public void run() {
-                                                mGetconfigurationStateText.setText("Communication Error");
+                                                mGetconfigurationStateText.setText(COMMUNICATION_ERROR);
                                                 mStartGetConfiguration.setEnabled(true);
                                             }
                                         });
@@ -662,7 +677,7 @@ public class EasysetupActivity extends Activity
                                         runOnUiThread(new Runnable() {
                                             @Override
                                             public void run() {
-                                                mGetconfigurationStateText.setText("Failed");
+                                                mGetconfigurationStateText.setText(FAILED);
                                                 mStartGetConfiguration.setEnabled(true);
                                             }
                                         });
@@ -674,7 +689,7 @@ public class EasysetupActivity extends Activity
                             runOnUiThread(new Runnable() {
                                 @Override
                                 public void run() {
-                                    mGetconfigurationStateText.setText("Failed");
+                                    mGetconfigurationStateText.setText(FAILED);
                                     mStartGetConfiguration.setEnabled(true);
                                 }
                             });
@@ -725,13 +740,13 @@ public class EasysetupActivity extends Activity
                                         @Override
                                         public void run() {
                                             if(result.equals(ESResult.ES_OK)) {
-                                                mProvisionDevPropState.setText("Success");
+                                                mProvisionDevPropState.setText(SUCCESS);
                                             }
                                             else if(result.equals(ESResult.ES_ERROR)) {
-                                                mProvisionDevPropState.setText("Failed");
+                                                mProvisionDevPropState.setText(FAILED);
                                             }
                                             else if(result.equals(ESResult.ES_COMMUNICATION_ERROR)) {
-                                                mProvisionDevPropState.setText("Communication Error");
+                                                mProvisionDevPropState.setText(COMMUNICATION_ERROR);
                                             }
                                             mStartProvisionDevProp.setEnabled(true);
                                         }
@@ -743,7 +758,7 @@ public class EasysetupActivity extends Activity
                             runOnUiThread(new Runnable() {
                                 @Override
                                 public void run() {
-                                    mProvisionDevPropState.setText("Failed");
+                                    mProvisionDevPropState.setText(FAILED);
                                     mStartProvisionDevProp.setEnabled(true);
                                 }
                             });
@@ -801,7 +816,7 @@ public class EasysetupActivity extends Activity
                                                 mProvisionCloudPropState.setText("CERT-provisioning fails");
                                             }
                                             else if(result.equals(ESResult.ES_COMMUNICATION_ERROR)){
-                                                mProvisionCloudPropState.setText("Communication Error");
+                                                mProvisionCloudPropState.setText(COMMUNICATION_ERROR);
                                             }
                                             else {
                                                 mProvisionCloudPropState.setText("Cloud Provisioning fails");
@@ -815,7 +830,7 @@ public class EasysetupActivity extends Activity
                             runOnUiThread(new Runnable() {
                                 @Override
                                 public void run() {
-                                    mProvisionCloudPropState.setText("Failed");
+                                    mProvisionCloudPropState.setText(FAILED);
                                     mStartProvisionCloudProp.setEnabled(true);
                                 }
                             });
@@ -833,6 +848,7 @@ public class EasysetupActivity extends Activity
         OutputStream outputStream = null;
         int length;
         byte[] buffer = new byte[BUFFER_SIZE];
+        boolean retVal = true;
         try {
             inputStream = getAssets().open(OIC_CLIENT_JSON_DB_FILE);
             File file = new File(filePath);
@@ -845,24 +861,21 @@ public class EasysetupActivity extends Activity
                 outputStream.write(buffer, 0, length);
             }
         } catch (NullPointerException e) {
-            logMessage(TAG + "Null pointer exception " + e.getMessage());
-            Log.e(TAG, e.getMessage());
-            return false;
+            Log.e(TAG, "Null pointer exception: " + e.getMessage());
+            retVal = false;
         } catch (FileNotFoundException e) {
-            logMessage(TAG + "Json svr db file not found " + e.getMessage());
-            Log.e(TAG, e.getMessage());
-            return false;
+            Log.e(TAG, "Json svr db file not found: " + e.getMessage());
+            retVal = false;
         } catch (IOException e) {
-            logMessage(TAG + OIC_CLIENT_JSON_DB_FILE + " file copy failed");
-            Log.e(TAG, e.getMessage());
-            return false;
+            Log.e(TAG, OIC_CLIENT_JSON_DB_FILE + " file copy failed: " + e.getMessage());
+            retVal = false;
         } finally {
             if (inputStream != null) {
                 try {
                     inputStream.close();
                 } catch (IOException e) {
                     Log.e(TAG, e.getMessage());
-                    return false;
+                    retVal = false;
                 }
             }
             if (outputStream != null) {
@@ -870,15 +883,11 @@ public class EasysetupActivity extends Activity
                     outputStream.close();
                 } catch (IOException e) {
                     Log.e(TAG, e.getMessage());
-                    return false;
+                    retVal = false;
                 }
             }
         }
-        return true;
-    }
-
-    public void logMessage(String text) {
-
+        return retVal;
     }
 
     public void setWifiModes(ArrayList<WIFI_MODE> types) {
@@ -933,6 +942,7 @@ public class EasysetupActivity extends Activity
         Log.d(TAG, "Presence response: " + strStaus + " sequence: " + sequence + " host: " + host);
         runOnUiThread(new Runnable()
         {
+            @Override
             public void run() {
                 Toast.makeText(EasysetupActivity.this, "Easy-Setup completed", Toast.LENGTH_SHORT).show();
             }
@@ -967,8 +977,8 @@ public class EasysetupActivity extends Activity
         public void onPostCompleted(List<OcHeaderOption> list, OcRepresentation ocRepresentation) {
             Log.d(TAG, "onRefreshTokenPost..");
             try {
-                mAccessToken = ocRepresentation.getValue("accesstoken");
-                mRefreshtoken = ocRepresentation.getValue("refreshtoken");
+                mAccessToken = ocRepresentation.getValue(ACCESSTOKEN);
+                mRefreshtoken = ocRepresentation.getValue(REFRESHTOKEN);
 
                 saveCloudTokenAtSharedPreferences();
             }
@@ -995,6 +1005,7 @@ public class EasysetupActivity extends Activity
 
             runOnUiThread(new Runnable()
             {
+                @Override
                 public void run() {
                     Toast.makeText(EasysetupActivity.this, "RefreshToken in progress..", Toast.LENGTH_SHORT).show();
                 }
@@ -1002,7 +1013,7 @@ public class EasysetupActivity extends Activity
 
             rep.setValue("di", deviceID);
             rep.setValue("granttype", "refresh_token");
-            rep.setValue("refreshtoken", mRefreshtoken);
+            rep.setValue(REFRESHTOKEN, mRefreshtoken);
             rep.setValue("uid", mUserID);
             authResource.post(rep, new HashMap<String, String>(), onRefreshTokenPost);
         }
@@ -1018,11 +1029,11 @@ public class EasysetupActivity extends Activity
         Log.d(TAG, "accesstoken: " + mAccessToken);
         SharedPreferences settings = getApplicationContext().getSharedPreferences("IoTivityCloud", 0);
         SharedPreferences.Editor editor = settings.edit();
-        editor.putString("accesstoken", mAccessToken);
-        editor.putString("refreshtoken", mRefreshtoken);
+        editor.putString(ACCESSTOKEN, mAccessToken);
+        editor.putString(REFRESHTOKEN, mRefreshtoken);
         editor.putString("uid", mUserID);
 
-        if(editor.commit() == true)
+        if(editor.commit())
             Log.d(TAG, "accesstoken saved");
         else
             Log.d(TAG, "accesstoken not saved");
@@ -1035,12 +1046,13 @@ public class EasysetupActivity extends Activity
             try {
                 runOnUiThread(new Runnable()
                 {
+                    @Override
                     public void run() {
                         Toast.makeText(EasysetupActivity.this, "Sign-up completed", Toast.LENGTH_SHORT).show();
                     }
                 });
 
-                mAccessToken = ocRepresentation.getValue("accesstoken");
+                mAccessToken = ocRepresentation.getValue(ACCESSTOKEN);
                 mUserID = ocRepresentation.getValue("uid");
 
                 if(mAccessToken != null)
@@ -1068,6 +1080,7 @@ public class EasysetupActivity extends Activity
 
             runOnUiThread(new Runnable()
             {
+                @Override
                 public void run() {
                     Toast.makeText(EasysetupActivity.this, "SignUpDevice in progress..", Toast.LENGTH_SHORT).show();
                 }
@@ -1092,6 +1105,7 @@ public class EasysetupActivity extends Activity
 
             runOnUiThread(new Runnable()
             {
+                @Override
                 public void run() {
                     Toast.makeText(EasysetupActivity.this, "Sign-in completed", Toast.LENGTH_SHORT).show();
                 }
@@ -1117,6 +1131,7 @@ public class EasysetupActivity extends Activity
 
             runOnUiThread(new Runnable()
             {
+                @Override
                 public void run() {
                     Toast.makeText(EasysetupActivity.this, "SignInDevice in progress..", Toast.LENGTH_SHORT).show();
                 }
index ffb3bc8..8fbd744 100644 (file)
 package org.iotivity.service.easysetup;
 
 import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
 import android.content.Intent;
-import android.content.SharedPreferences;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
 import android.net.UrlQuerySanitizer;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiManager;
 import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.preference.PreferenceManager;
 import android.util.Log;
 import android.view.View;
-import android.view.View.OnClickListener;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.LinearLayout;
-import android.widget.ProgressBar;
-import android.widget.RadioButton;
-import android.widget.RelativeLayout;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import org.iotivity.base.ModeType;
-import org.iotivity.base.OcException;
-import org.iotivity.base.OcPlatform;
-import org.iotivity.base.OcProvisioning;
-import org.iotivity.base.PlatformConfig;
-import org.iotivity.base.QualityOfService;
-import org.iotivity.base.ServiceType;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
 
 public class LoginActivity extends Activity {
     private static final String TAG = "Easysetup Login: ";
@@ -82,17 +47,12 @@ public class LoginActivity extends Activity {
         mWebView.setVisibility(View.VISIBLE);
         mWebView.setInitialScale(200);
         mWebView.getSettings().setJavaScriptEnabled(true);
-        //mWebView.getSettings().setSupportZoom(true);
         mWebView.getSettings().setBuiltInZoomControls(true);
         mWebView.setWebViewClient(new WebViewClientClass());
 
         mWebView.loadUrl("https://github.com/login?return_to=%2Flogin%2Foauth%2Fauthorize%3Fclient_id%3Dea9c18f540323b0213d0%26redirect_uri%3Dhttp%253A%252F%252Fwww.example.com%252Foauth_callback%252F");
     }
 
-    public void onDestroy() {
-        super.onDestroy();
-    }
-
     private class WebViewClientClass extends WebViewClient {
 
         @Override
@@ -108,8 +68,7 @@ public class LoginActivity extends Activity {
                 sanitizer.setAllowUnregisteredParamaters(true);
                 sanitizer.parseUrl(url);
 
-                String mAuthCode = null;
-                mAuthCode = sanitizer.getValue("code");
+                String mAuthCode = sanitizer.getValue("code");
 
                 Intent intent = getIntent();
                 intent.putExtra("authCode", mAuthCode);