Skip to content

Commit

Permalink
Moved exception logging to AppEvent generator for diagnosis purposes.
Browse files Browse the repository at this point in the history
* Logging cleanup.
  • Loading branch information
audaciouscode committed May 18, 2017
1 parent 48ea849 commit f79153b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 46 deletions.
Expand Up @@ -46,7 +46,7 @@ protected void onCreate(Bundle savedInstanceState) {
try {
this.mGeneratorClass = (Class<? extends Generator>) Class.forName(this.getIntent().getStringExtra(DataDisclosureDetailActivity.GENERATOR_CLASS_NAME));
} catch (ClassNotFoundException e) {
e.printStackTrace();
// e.printStackTrace();
}

if (this.mGeneratorClass != null) {
Expand Down
Expand Up @@ -36,7 +36,6 @@ public DataPointViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

return new DataPointViewHolder(view);
} catch (Exception e) {
e.printStackTrace();
try {
generatorClass = Generator.class;

Expand Down Expand Up @@ -76,7 +75,6 @@ public void onBindViewHolder(final DataPointViewHolder holder, int position) {
Method bindViewHolder = generatorClass.getDeclaredMethod("bindViewHolder", DataPointViewHolder.class);
bindViewHolder.invoke(null, holder);
} catch (Exception e) {
e.printStackTrace();
try {
generatorClass = Generator.class;

Expand Down Expand Up @@ -122,11 +120,11 @@ public int compare(Class<? extends Generator> one, Class<? extends Generator> tw

oneUpdated = (long) oneGenerated.invoke(null, context);
} catch (NoSuchMethodException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
// e.printStackTrace();
}

long twoUpdated = 0;
Expand All @@ -136,11 +134,11 @@ public int compare(Class<? extends Generator> one, Class<? extends Generator> tw

twoUpdated = (long) twoGenerated.invoke(null, context);
} catch (NoSuchMethodException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
// e.printStackTrace();
}

if (oneUpdated < twoUpdated) {
Expand Down
Expand Up @@ -7,7 +7,6 @@
import android.os.Bundle;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.util.Log;
import android.util.SparseArray;

import com.audacious_software.passive_data_kit.Logger;
Expand Down Expand Up @@ -55,33 +54,25 @@ public void start() {
for (String className : this.mGenerators)
{
try {
Log.e("PDK", "TRYING " + className);

Class<Generator> probeClass = (Class<Generator>) Class.forName(className);

Method isEnabled = probeClass.getDeclaredMethod("isEnabled", Context.class);

Boolean enabled = (Boolean) isEnabled.invoke(null, this.mContext);

Log.e("PDK", "GENERATOR ENABLED? " + probeClass + " ==> " + enabled);

if (enabled) {
this.startGenerator(className);
}
else {
this.stopGenerator(className);
}
} catch (ClassNotFoundException e) {
Log.e("PDK", "ClassNotFoundException " + className);
Logger.getInstance(this.mContext).logThrowable(e);
} catch (NoSuchMethodException e) {
Log.e("PDK", "NoSuchMethodException " + className);
Logger.getInstance(this.mContext).logThrowable(e);
} catch (InvocationTargetException e) {
Log.e("PDK", "InvocationTargetException " + className);
Logger.getInstance(this.mContext).logThrowable(e);
} catch (IllegalAccessException e) {
Log.e("PDK", "IllegalAccessException " + className);
Logger.getInstance(this.mContext).logThrowable(e);
}
}
Expand All @@ -103,8 +94,6 @@ private void startGenerator(String className) throws ClassNotFoundException, NoS
else {
Method start = generatorClass.getDeclaredMethod("start", Context.class);

Log.e("PDK", "GOT START METHOD: " + className + " -> " + start);

start.invoke(null, this.mContext);

this.mActiveGenerators.add(className);
Expand Down Expand Up @@ -142,13 +131,13 @@ public ArrayList<DiagnosticAction> diagnostics() {

actions.addAll(generatorActions);
} catch (ClassNotFoundException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
// e.printStackTrace();
}
}

Expand Down Expand Up @@ -185,8 +174,6 @@ public void registerCustomViewClass(String identifier, Class<? extends Generator
public Class<? extends Generator> fetchCustomViewClass(String identifier) {
Class<? extends Generator> generatorClass = this.mGeneratorMap.get(identifier);

Log.e("PDK", "FETCH VIEW: " + identifier + " => " + generatorClass);

if (generatorClass == null)
generatorClass = Generator.class;

Expand All @@ -203,26 +190,20 @@ public Class<? extends Generator> fetchCustomViewClass(int viewType) {
}

public Generator getGenerator(String className) {
Log.e("BB", "GENERATOR FIND START");
for (String name : this.mActiveGenerators) {
Log.e("BB", "GENERATOR NAME: " + name);
}
Log.e("BB", "GENERATOR FIND END");

if (this.mActiveGenerators.contains(className)) {
try {
Class<Generator> probeClass = (Class<Generator>) Class.forName(className);

Method getInstance = probeClass.getDeclaredMethod("getInstance", Context.class);
return (Generator) getInstance.invoke(null, this.mContext);
} catch (ClassNotFoundException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
// e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
// e.printStackTrace();
}
}

Expand All @@ -236,7 +217,7 @@ public List<Class<? extends Generator>> activeGenerators() {
try {
active.add((Class<? extends Generator>) Class.forName(className));
} catch (ClassNotFoundException e) {
e.printStackTrace();
// e.printStackTrace();
}
}

Expand Down
Expand Up @@ -121,6 +121,10 @@ private void startGenerator() {
this.mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, Intent intent) {
if (me.mDatabase == null) {
return;
}

ContentValues values = new ContentValues();
values.put(Battery.HISTORY_OBSERVED, now);

Expand Down Expand Up @@ -235,10 +239,6 @@ public void onReceive(final Context context, Intent intent) {
}
};

IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);

this.mContext.registerReceiver(this.mReceiver, filter);

Generators.getInstance(this.mContext).registerCustomViewClass(Battery.GENERATOR_IDENTIFIER, Battery.class);

File path = PassiveDataKit.getGeneratorsStorage(this.mContext);
Expand All @@ -255,6 +255,9 @@ public void onReceive(final Context context, Intent intent) {
}

this.setDatabaseVersion(this.mDatabase, Battery.DATABASE_VERSION);

IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
this.mContext.registerReceiver(this.mReceiver, filter);
}

public static boolean isEnabled(Context context) {
Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.audacious_software.passive_data_kit.diagnostics.DiagnosticAction;
import com.audacious_software.passive_data_kit.generators.Generator;
import com.audacious_software.passive_data_kit.generators.Generators;
import com.audacious_software.passive_data_kit.generators.diagnostics.AppEvent;
import com.audacious_software.pdk.passivedatakit.R;
import com.rvalerio.fgchecker.AppChecker;

Expand Down Expand Up @@ -111,8 +112,6 @@ public void onForeground(String process) {
}
}

Log.e("PDK", "PROCESS: " + process + " -- " + screenActive);

ContentValues values = new ContentValues();
values.put(ForegroundApplication.HISTORY_OBSERVED, now);
values.put(ForegroundApplication.HISTORY_APPLICATION, process);
Expand Down Expand Up @@ -362,7 +361,7 @@ public int compare(HashMap<String, Double> mapOne, HashMap<String, Double> mapTw
Drawable icon = packageManager.getApplicationIcon(appPackage);
appIcon.setImageDrawable(icon);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
AppEvent.getInstance(context).logThrowable(e);
}

TextView appWhen = (TextView) row.findViewById(R.id.app_last_used);
Expand Down
Expand Up @@ -48,6 +48,7 @@
import com.audacious_software.passive_data_kit.diagnostics.DiagnosticAction;
import com.audacious_software.passive_data_kit.generators.Generator;
import com.audacious_software.passive_data_kit.generators.Generators;
import com.audacious_software.passive_data_kit.generators.diagnostics.AppEvent;
import com.audacious_software.pdk.passivedatakit.R;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
Expand Down Expand Up @@ -739,7 +740,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
me.onCheckedChanged(compoundButton, checked);
}
} catch (IOException e1) {
e1.printStackTrace();
AppEvent.getInstance(context).logThrowable(e1);
}

e.putInt(Location.ACCURACY_MODE, option);
Expand Down
Expand Up @@ -28,7 +28,10 @@
import org.json.JSONObject;

import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -49,6 +52,11 @@ public class AppEvent extends Generator{
private static final int CARD_PAGE_SIZE = 8;
private static final int CARD_MAX_PAGES = 8;

private static final String DETAILS_THROWABLE_STACKTRACE = "stacktrace";
private static final String DETAILS_THROWABLE_MESSAGE = "message";
private static final String EVENT_LOG_THROWABLE = "log_throwable";


private static AppEvent sInstance = null;

private SQLiteDatabase mDatabase = null;
Expand Down Expand Up @@ -371,7 +379,19 @@ public boolean logEvent(String eventName, Map<String, ? extends Object> eventDet
}

public void logThrowable(Throwable t) {
t.printStackTrace();

StringWriter out = new StringWriter();
PrintWriter writer = new PrintWriter(out);

t.printStackTrace(writer);
writer.flush();

HashMap<String, String> details = new HashMap<>();
details.put(AppEvent.DETAILS_THROWABLE_STACKTRACE, out.toString());
details.put(AppEvent.DETAILS_THROWABLE_MESSAGE, t.getMessage());

this.logEvent(AppEvent.EVENT_LOG_THROWABLE, details);
}

public static List<DataDisclosureDetailActivity.Action> getDisclosureActions(final Context context) {
Expand Down
Expand Up @@ -803,7 +803,7 @@ private void fetchIntradayActivities() {
}
}
} catch (JSONException e) {
e.printStackTrace();
AppEvent.getInstance(this.mContext).logThrowable(e);
}
}
}
Expand Down

0 comments on commit f79153b

Please sign in to comment.