Skip to content

Commit

Permalink
Added some log messages to understand why application is not working …
Browse files Browse the repository at this point in the history
…well
  • Loading branch information
ThibaudM committed Dec 3, 2017
1 parent a2e7a64 commit e5a7a1e
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 3 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/thibaudperso/sonycamera/sdk/CameraWS.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.thibaudperso.sonycamera.timelapse.control.Logger;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -86,18 +87,23 @@ void sendRequest(final String method, final JSONArray params, final Listener lis
throw new RequestNotWellFormatedException(e);
}

Logger.v(getClass().getSimpleName() + ": sendRequest: url: " + mWSUrl + ", json: " + inputJsonObject.toString());

JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST,
mWSUrl, inputJsonObject, new Response.Listener<JSONObject>() {

@Override
public void onResponse(final JSONObject response) {

Logger.v(getClass().getSimpleName() + ": result: " + response.toString());

if (listener == null) return;

try {

if (response.has("result")) {
listener.cameraResponse(ResponseCode.OK, response.getJSONArray("result"));
Logger.v(getClass().getSimpleName() + ": result-parsed: OK");

} else if (response.has("error")) {
//if no "results" element is present, there has probably an error occured
Expand All @@ -106,14 +112,17 @@ public void onResponse(final JSONObject response) {
ResponseCode errorCode = ResponseCode.find(arr.getInt(0));
String errorMessage = arr.getString(1);
listener.cameraResponse(errorCode, errorMessage);
Logger.v(getClass().getSimpleName() + ": result-parsed: Failed1: " + errorMessage);
} else {
listener.cameraResponse(ResponseCode.RESPONSE_NOT_WELL_FORMATED,
response);
Logger.v(getClass().getSimpleName() + ": result-parsed: Failed2: Not well formated");
}

} catch (JSONException e) {
e.printStackTrace();
listener.cameraResponse(ResponseCode.RESPONSE_NOT_WELL_FORMATED, response);
Logger.v(getClass().getSimpleName() + ": result-parsed: Failed3: " + e.toString());

}
}
Expand All @@ -124,6 +133,7 @@ public void onErrorResponse(VolleyError error) {
if (listener == null) return;
error.printStackTrace();
listener.cameraResponse(ResponseCode.WS_UNREACHABLE, null);
Logger.v(getClass().getSimpleName() + ": result-parsed: Failed4: Web service unreachable");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public String toString() {
return mModel;
}

public String toLongString() {
return "model: " + mModel + ", id: " + mId + ", webService: " + mWebService;
}

public static Comparator<Device> COMPARE_BY_DEVICEMODEL = new Comparator<Device>() {
public int compare(Device one, Device other) {
return one.mModel.compareTo(other.mModel);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.thibaudperso.sonycamera.timelapse.control;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.thibaudperso.sonycamera.timelapse.TimelapseApplication;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

/**
* Created by thibaud on 11/09/2017.
*/

public class Logger {

private final static SimpleDateFormat DATE_FORMAT =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US);

private static String logs = "";

public static void v(String message) {
m("DEBUG - " + message);
}

public static void e(String message) {
m("ERROR - " + message);
}

private static void m(String message) {

logs += DATE_FORMAT.format(Calendar.getInstance().getTime()) + " (" +
android.os.Process.myPid() + ") - " + message + "\n";

}

private static String getLogsString(Context context) {
DeviceManager dm = ((TimelapseApplication) context.getApplicationContext()).getDeviceManager();

return dm.getSelectedDevice().toLongString()+"\n\n"+logs;

}

public static void printDebug(Context context) {
Log.v("DEBUG", getLogsString(context));
}

public static void sendEmail(Context context) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "[Timelapse Sony] Troubleshooting");
i.putExtra(Intent.EXTRA_TEXT, getLogsString(context));
try {
context.startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(context, "There are no email clients installed.",
Toast.LENGTH_SHORT).show();
}
}


public static String intentToString(Intent intent) {
if (intent == null)
return "";

StringBuilder stringBuilder = new StringBuilder("action: ")
.append(intent.getAction())
.append(" data: ")
.append(intent.getDataString())
.append(" extras: ")
;
for (String key : intent.getExtras().keySet())
stringBuilder.append(key).append("=").append(intent.getExtras().get(key)).append(" ");

return stringBuilder.toString();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.thibaudperso.sonycamera.sdk.CameraAPI;
import com.thibaudperso.sonycamera.sdk.model.Device;
import com.thibaudperso.sonycamera.timelapse.TimelapseApplication;
import com.thibaudperso.sonycamera.timelapse.control.Logger;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void start() {
mCameraAPI.addDeviceChangedListener(mDeviceChangedListener);

WifiManager wifiManager = (WifiManager) mApplication.getSystemService(Context.WIFI_SERVICE);
if(Build.VERSION.SDK_INT > 12) {
if (Build.VERSION.SDK_INT > 12) {
mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "WifiLock2");
mWifiLock.acquire();
}
Expand Down Expand Up @@ -485,8 +486,12 @@ public void onNewDevice(Device device) {

private void setCurrentState(State newState) {

if (BuildConfig.DEBUG && !Arrays.asList(newState.previousPossibleStates()).contains(mCurrentState)) {
throw new RuntimeException("Current State: " + mCurrentState + ", new State: " + newState);
if (!Arrays.asList(newState.previousPossibleStates()).contains(mCurrentState)) {
Logger.e(getClass().getSimpleName() + ": - Current State: " + mCurrentState + ", new State: " + newState);

if (BuildConfig.DEBUG) {
throw new RuntimeException("Current State: " + mCurrentState + ", new State: " + newState);
}
}

Log.d(LOG_TAG, "State: " + mCurrentState + " ---> " + newState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import android.net.wifi.WifiManager;
import android.support.v4.content.ContextCompat;

import com.thibaudperso.sonycamera.timelapse.control.Logger;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -35,6 +37,7 @@ WifiInfo getConnectedWifi() {
}

void connectToNetworkId(int netId) {
Logger.e(getClass().getSimpleName() + ": - connectToNetworkId: " + netId);

if(mWifiManager == null) {
return;
Expand All @@ -53,6 +56,7 @@ void connectToNetworkId(int netId) {
}
if (!netIdFound) return;

Logger.e(getClass().getSimpleName() + ": - mWifiManager.enableNetwork(" + netId + ", true)");
mWifiManager.enableNetwork(netId, true);
}

Expand Down Expand Up @@ -138,6 +142,7 @@ public interface Listener {

@Override
public void onReceive(Context context, Intent intent) {
Logger.e(getClass().getSimpleName() + ": mBroadcastReceiver - " + Logger.intentToString(intent));

if (mListener == null) return;
if (isInitialStickyBroadcast()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.thibaudperso.sonycamera.sdk.model.Device;
import com.thibaudperso.sonycamera.timelapse.TimelapseApplication;
import com.thibaudperso.sonycamera.timelapse.control.DeviceManager;
import com.thibaudperso.sonycamera.timelapse.control.Logger;
import com.thibaudperso.sonycamera.timelapse.control.connection.NFCHandler;
import com.thibaudperso.sonycamera.timelapse.control.connection.StateMachineConnection;
import com.thibaudperso.sonycamera.timelapse.ui.adjustments.AdjustmentsActivity;
Expand Down Expand Up @@ -173,6 +174,14 @@ public void onDevicesListChanged(List<Device> devices) {
});


viewResult.findViewById(R.id.connection_troubleshooting).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Logger.printDebug(getContext());
Logger.sendEmail(getContext());
}
});

mConnectionAutomaticCheckbox = ((CheckBox) viewResult.findViewById(R.id.connection_automatic_checkbox));
mConnectionAutomaticCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/fragment_connection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@
ads:adUnitId="@string/ads_pub_id">
</com.google.android.gms.ads.AdView>

<Button
android:id="@+id/connection_troubleshooting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Troubleshooting"
android:layout_above="@id/adView"/>

</RelativeLayout>

Expand Down

0 comments on commit e5a7a1e

Please sign in to comment.