Skip to content

Commit

Permalink
Do not use printStackTrace, at least one device has a crash with it.
Browse files Browse the repository at this point in the history
  • Loading branch information
lagerspetz committed Jan 9, 2018
1 parent 8b32814 commit 9d6034a
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 51 deletions.
4 changes: 2 additions & 2 deletions caratApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ android {
buildToolsVersion "25.0.2"

defaultConfig {
versionCode 130
versionName "2.17.16-debug"
versionCode 131
versionName "2.17.16"
applicationId "edu.berkeley.cs.amplab.carat.android"
minSdkVersion 10
//noinspection OldTargetApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ public static long getInstallationDate(){
date = pm.getPackageInfo(packageName, 0).firstInstallTime;
} catch(Throwable th){
if(Constants.DEBUG){
Logger.d(TAG, "Failed getting application installation date from package");
th.printStackTrace();
Logger.d(TAG, "Failed getting application installation date from package",th);
}
}
}
Expand Down Expand Up @@ -599,8 +598,7 @@ public void run() {
success = commManager.refreshAllReports();
} catch (Throwable th){
// Any sort of malformed response
Log.w(TAG, "Failed to refresh reports: " + th + Constants.MSG_TRY_AGAIN);
th.printStackTrace();
Log.w(TAG, "Failed to refresh reports: " + th + Constants.MSG_TRY_AGAIN, th);
}
main.runOnUiThread(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import edu.berkeley.cs.amplab.carat.android.utils.Logger;
import edu.berkeley.cs.amplab.carat.android.utils.NetworkingUtil;
import edu.berkeley.cs.amplab.carat.android.utils.PrefsManager;
import edu.berkeley.cs.amplab.carat.android.utils.Util;
import edu.berkeley.cs.amplab.carat.thrift.Answers;
import edu.berkeley.cs.amplab.carat.thrift.CaratService;
import edu.berkeley.cs.amplab.carat.thrift.Feature;
Expand Down Expand Up @@ -233,8 +234,7 @@ private void registerOnFirstRun(CaratService.Client instance) {
p.edit().putString(Constants.REGISTERED_OS, os).commit();
p.edit().putString(Constants.REGISTERED_MODEL, model).commit();
} catch (TException e) {
Logger.e("CommunicationManager", "Registration failed, will try again next time: " + e);
e.printStackTrace();
Logger.e("CommunicationManager", "Registration failed, will try again next time: " + e, e);
}
}
}
Expand Down Expand Up @@ -621,7 +621,7 @@ private boolean getQuestionnaires(String uuid){
return true;
} catch (Throwable th){
if(Constants.DEBUG){
th.printStackTrace();
Util.printStackTrace(TAG, th);
}
safeClose(instance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ private static boolean loadSSLProperties(Context c){
TRUSTSTORE_PASS = properties.getProperty("storePass");
return TRUSTSTORE_NAME != null && TRUSTSTORE_PASS != null;
} catch(Throwable th){
Logger.e(TAG, "Could not open truststore property file!");
th.printStackTrace();
Logger.e(TAG, "Could not open truststore property file!", th);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public static String getTimeBasedUuid(Context c, boolean includeTimestamp) {
String uuid = hexString.toString().substring(0, UUID_LENGTH);
return uuid;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
Util.printStackTrace(TAG, e);
return aID;
}
}
Expand Down Expand Up @@ -445,7 +445,7 @@ public static int[] readMeminfo() {
reader.close();
return new int[] { free, total, act, inact };
} catch (IOException ex) {
ex.printStackTrace();
Util.printStackTrace(TAG, ex);
}

return new int[] { 0, 0, 0, 0 };
Expand Down Expand Up @@ -540,7 +540,7 @@ public static long[] readUsagePoint() {
reader.close();
return new long[] { idle1, cpu1 };
} catch (IOException ex) {
ex.printStackTrace();
Util.printStackTrace(TAG, ex);
}

return null;
Expand Down Expand Up @@ -1391,14 +1391,14 @@ public static String getMemoryInfo() {

} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
Util.printStackTrace(TAG, e1);
}

try {
tmp = br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Util.printStackTrace(TAG, e);
}

StringBuilder sMemory = new StringBuilder();
Expand All @@ -1409,7 +1409,7 @@ public static String getMemoryInfo() {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Util.printStackTrace(TAG, e);
}

sMemory.append("\n").append(tmp).append("\n");
Expand All @@ -1433,7 +1433,7 @@ public static String getMemoryFree() {

} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
Util.printStackTrace(TAG, e1);
}

try {
Expand All @@ -1450,7 +1450,7 @@ public static String getMemoryFree() {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Util.printStackTrace(TAG, e);
}
return tmp;
}
Expand Down Expand Up @@ -1626,7 +1626,7 @@ public static boolean getBackgroundDataEnabled(Context context) {
}
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Util.printStackTrace(TAG, e);
}
// Log.v("BackgroundDataEnabled", "Background data enabled? " +
// bacDataEnabled);
Expand All @@ -1644,7 +1644,7 @@ public static int getScreenBrightness(Context context) {
screenBrightnessValue = android.provider.Settings.System.getInt(context.getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS);
} catch (SettingNotFoundException e) {
e.printStackTrace();
Util.printStackTrace(TAG, e);
}
return screenBrightnessValue;
}
Expand All @@ -1655,7 +1655,7 @@ public static boolean isAutoBrightness(Context context) {
autoBrightness = Settings.System.getInt(context.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
} catch (SettingNotFoundException e) {
e.printStackTrace();
Util.printStackTrace(TAG, e);
}
return autoBrightness;
}
Expand Down Expand Up @@ -1717,8 +1717,7 @@ public static String getCoarseLocation(Context context) {
return String.valueOf(latitude)+","+String.valueOf(longitude);
} catch (Throwable th){
if(Constants.DEBUG){
Logger.d("SamplingLibrary", "Failed getting coarse location!");
th.printStackTrace();
Logger.d("SamplingLibrary", "Failed getting coarse location!", th);
}
}
}
Expand Down Expand Up @@ -2109,7 +2108,7 @@ public static double getBatteryCapacity(Context context) {
getAveragePower.setAccessible(true);
return ((double) getAveragePower.invoke(mPowerProfile, "battery.capacity"));
} catch(Throwable th){
th.printStackTrace();
Util.printStackTrace(TAG, th);
return -1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ public void writeObject(Object o, String fname) {
dos.close();
} catch (IOException e) {
Logger.e(this.getClass().getName(), "Could not write object:" + o
+ "!");
e.printStackTrace();
+ "!", e);
} catch (Throwable th) {
Logger.e(this.getClass().getName(), "Problem writing object", th);
}
Expand All @@ -169,13 +168,11 @@ public Object readObject(String fname) {
return o;
} catch (IOException e) {
Logger.e(this.getClass().getName(), "Could not read object from "
+ fname + "!");
e.printStackTrace();
+ fname + "!", e);
} catch (ClassNotFoundException e) {
Logger.e(this.getClass().getName(),
"Could not find class: " + e.getMessage()
+ " reading from " + fname + "!");
e.printStackTrace();
+ " reading from " + fname + "!", e);
} catch (Throwable th) {
Logger.e(this.getClass().getName(), "Problem reading object", th);
}
Expand All @@ -192,8 +189,7 @@ public void writeText(String thing, String fname) {
dos.close();
} catch (IOException e) {
Logger.e(this.getClass().getName(), "Could not write text:" + thing
+ "!");
e.printStackTrace();
+ "!", e);
} catch (Throwable th) {
Logger.e(this.getClass().getName(), "Problem writing text in " + fname, th);
}
Expand All @@ -210,8 +206,7 @@ public String readText(String fname) {
return s;
} catch (IOException e) {
Logger.e(this.getClass().getName(), "Could not read text from "
+ fname + "!");
e.printStackTrace();
+ fname + "!", e);
} catch (Throwable th) {
Logger.e(this.getClass().getName(), "Problem reading text", th);
}
Expand All @@ -224,7 +219,6 @@ private FileInputStream getFin(String fname) {
} catch (FileNotFoundException e) {
Log.w(this.getClass().getName(), "File "
+ fname + " does not exist yet. Wait for reports.");
// e.printStackTrace();
return null;
} catch (Throwable th) {
Logger.e(this.getClass().getName(), "Problem opening file " + fname + " for input", th);
Expand All @@ -238,7 +232,6 @@ private FileOutputStream getFos(String fname) {
} catch (FileNotFoundException e) {
Log.w(this.getClass().getName(), "File "
+ fname + " does not exist yet. Wait for reports.");
// e.printStackTrace();
return null;
} catch (Throwable th) {
Logger.e(this.getClass().getName(), "Problem opening file " + fname + " for output", th);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import edu.berkeley.cs.amplab.carat.android.Constants;
import edu.berkeley.cs.amplab.carat.android.utils.Logger;
import edu.berkeley.cs.amplab.carat.android.utils.Util;
import edu.berkeley.cs.amplab.carat.thrift.Sample;

/**
Expand Down Expand Up @@ -299,7 +300,7 @@ private Sample fillSample(Cursor cursor) {
deserializer.deserialize(s, sampleB);
return s;
} catch (TException e) {
e.printStackTrace();
Util.printStackTrace(TAG, e);
}
}
return null;
Expand Down Expand Up @@ -407,7 +408,7 @@ private long addSample(Sample s) {
TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());
initialValues.put(COLUMN_SAMPLE, serializer.serialize(s));
} catch (Exception e) {
e.printStackTrace();
Util.printStackTrace(TAG, e);
}

return db.insert(SAMPLES_VIRTUAL_TABLE, null, initialValues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ private static File writeAssetToCache(Context context, String fileName){
}
} catch (Throwable th) {
if(Constants.DEBUG){
Logger.e(TAG, "Could not open asset file " + fileName + " for caching!");
th.printStackTrace();
Logger.e(TAG, "Could not open asset file " + fileName + " for caching!", th);
}
}
invalidate = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@


public class JsonParser {

private static String TAG = "CaratJSP";

public static String getJSONFromUrl(String url) {
String result = null;
Expand All @@ -34,13 +36,13 @@ public static String getJSONFromUrl(String url) {
in.close();
result = out.toString();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
Util.printStackTrace(TAG, e);
} catch (ProtocolException e) {
e.printStackTrace();
Util.printStackTrace(TAG, e);
} catch (MalformedURLException e) {
e.printStackTrace();
Util.printStackTrace(TAG, e);
} catch (IOException e) {
e.printStackTrace();
Util.printStackTrace(TAG, e);
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ private void parseJson(JSONObject data) {
} */
}
} catch (Throwable e) {
e.printStackTrace();

Util.printStackTrace(TAG, e);
}
}
}
Expand Down Expand Up @@ -173,7 +172,7 @@ private void saveAppValues(JSONArray jsonArray, int which) {
} catch (IllegalAccessException e) {
Logger.e(TAG, "IllegalAccessException in setFieldsFromJson()");
} catch (JSONException e) {
e.printStackTrace();
Util.printStackTrace(TAG, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,23 @@ public static void openStorePage(Context context, String packageName){
context.startActivity(playIntent);
}
}

public static void printStackTrace(String tag, Throwable th){
Logger.d(tag, getStackTrace(th));
}

public static String getStackTrace(Throwable th){
StringBuilder buf = new StringBuilder();
StackTraceElement[] trace = th.getStackTrace();
boolean first = true;
for (StackTraceElement elem: trace){
if (!first) {
buf.append("\t");

}else
first = false;
buf.append("in " + elem.getMethodName() + " in " + elem.getClassName() + "("+elem.getLineNumber()+")\n");
}
return buf.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ private void check(){
}
}
} catch (JSONException e) {
Logger.e(TAG, "Error parsing version gating JSON");
e.printStackTrace();
Logger.e(TAG, "Error parsing version gating JSON", e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.berkeley.cs.amplab.carat.android.Constants;
import edu.berkeley.cs.amplab.carat.android.R;
import edu.berkeley.cs.amplab.carat.android.utils.Logger;
import edu.berkeley.cs.amplab.carat.android.utils.Util;

import android.content.Context;
import android.util.AttributeSet;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void loadUrl(String url) {
}
}
} catch (IOException e) {
e.printStackTrace();
Util.printStackTrace(TAG, e);
}
// If all else fails:
super.loadUrl(url);
Expand Down

0 comments on commit 9d6034a

Please sign in to comment.