Top Banner
Crashing in Crashing in Style Style
51

crashing in style

May 09, 2015

Download

Technology

Droidcon Berlin
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: crashing in style

Crashing in Crashing in StyleStyle

Page 2: crashing in style

About /me• Tam HANNA

– CEO, Tamoggemon Ltd.

– Director, Tamoggemon Holding k.s.

– Runs web sites about mobile computing

– Writes scientific books

Page 3: crashing in style

About /girly• Annette BOSBACH

– Clerk to the coordinating office, Tamoggemon Holding k.s.

– First GottaTxt fan

Page 4: crashing in style

Overview• The schedule

• Why track crashes

• Basic methods

• ACRA

Page 5: crashing in style

Source code• JAVA Source code is available

– Via Twitter

• Our IP: free to use– Too low to qualify for protection

– Plus, you have to listen to us so

Page 6: crashing in style

The schedule

Page 7: crashing in style

Crash first, Qt second

• 60% / 40%– More about Qt: at our booth

• Please tweet about us

Page 8: crashing in style

The @tamhanna show is cool

GottaTxt is the best app at #droidconnl

After listening to @tamhanna, my app doesn‘t

crash anymore!!!

@tamhanna threw chocolate on my head. Ouch! #droidconnl

Page 9: crashing in style

Why track Why track crashes?crashes?

Page 10: crashing in style

Market is crowded• Bad ratings kill an application

• BUT: responding to feedback helps– „The developer responds to ME!!!“

– I am important

– Ego issues => superhappy customer

Page 11: crashing in style

Why track crashes?• Isn‘t it better not to crash?

– Matthew A Brenner, UnME2

• Yes, but– Ever-increasing number of LOC– Fragmentation (to see /me mention that )– Margin pressure

• TU144 / Concorde problem

Page 12: crashing in style

Users are stupid• What OS version do you use?

– Common question for developers

– Perceived as denigration by some users

• Send me a file from the file system!– Common question for developers

– But for developer‘s wife or husband?

Page 13: crashing in style

Crash vs stat tracking

• Stat tracking– Which flows are used

– Entry/Exit path analysis

– e.g. Google Analytics

• Crash tracking– What causes crashes

– Where do users „die“

Page 14: crashing in style

And there‘s more• Track „points of pain“ for users

– Rejection of user input

– Games: user death

• Fix them in the next release– First 2min with application are critical

Page 15: crashing in style

Private debuggerPrivate debugger

Picture: Wikimedia Commons / fluteflute

Page 16: crashing in style

What‘s that• Special mode of operation

– Allows developer access to internals– ON the users phone

• Can be accessed via secret key– Must be easy to enter, difficult to guess– Prevent users from entering it by mistake

• Customer provides info to developer

Page 17: crashing in style

How to implement• By foot

• No ready made libraries available

Page 18: crashing in style

Example• GottaTxt

1. Open Thread

2. Enter „Secret Code“

3. Enter commands

4. Give response

Page 19: crashing in style

Try it at our booth

FREE VODKA FREE VODKA INCLUDED!!!INCLUDED!!!

Page 20: crashing in style

Basic crash Basic crash handlinghandling

Wikimedia Commons / David Monack

Page 21: crashing in style

Really easy way• Thread.setDefaultExceptionHandler()

• Write to file, then die

• Tell user to email file– Can usually be accomplished

Page 22: crashing in style

Problems• IO is buffered

• Thread terminates before data written

• Data lost

• !!!Occurs rarely!!!– Never saw it on Android

Page 23: crashing in style

Non-working solution

• StackOverflow user gupta

• Fire intent from exception handler

• Hope for it to arrive

Page 24: crashing in style

Non-working solution - II

• Doesn‘t work in practice

• Intent never arrives at application

Page 25: crashing in style

Workable solution• Completely override crash handling

– No Android Crash message shown

• Re-invoke application

• Example a360crash1

Page 26: crashing in style

public ExceptionTrap(Context _context, String _filePath)

{

myContext=_context;

myFilePath=_filePath;

myHandler=Thread.getDefaultUncaughtExceptionHandler();

}

Page 27: crashing in style

@Overridepublic void uncaughtException(Thread _t, Throwable _a) {

try{StringWriter s=new StringWriter();_a.printStackTrace(new PrintWriter(s));

Intent launchIntent=new Intent(ErrorReporter.INTENTSTRING);launchIntent.putExtra("StackTrace", s.toString());launchIntent.putExtra("FilePath", myFilePath);

PendingIntent pIntent=PendingIntent.getService(myContext, 0, launchIntent, launchIntent.getFlags());AlarmManager mgr = (AlarmManager) myContext.getSystemService(Context.ALARM_SERVICE);mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, pIntent);

System.exit(2);

Page 28: crashing in style

public class ErrorReporter extends IntentService {

public static final String INTENTSTRING ="com.tamoggemon.a360crash1.intent.CALLERRORREPORTER";

public ErrorReporter() {super("TAG");}

@Override public void onCreate() { super.onCreate(); }

Page 29: crashing in style

protected void onHandleIntent(Intent intent) {//Newline, etc removed

try{boolean newFile=false;File writeFile=new File(intent.getStringExtra("FilePath"));if(writeFile.exists()==false){newFile=true;writeFile.createNewFile();} BufferedWriter buf = new BufferedWriter(new FileWriter(writeFile, true)); if(newFile) { buf.append(android.os.Build.MODEL); buf.append(android.os.Build.VERSION.RELEASE); } buf.append("-------------------CRASH-------------------") buf.append(intent.getStringExtra("StackTrace"));

Page 30: crashing in style

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myTrap=new ExceptionTrap(this, "/sdcard/A360Crash.log"); Thread.setDefaultUncaughtExceptionHandler(myTrap); setContentView(R.layout.main); findViewById(R.id.button1).setOnClickListener(this); }

@Overridepublic void onClick(View v) {

throw new RuntimeException("Fehler erfolgreich ausgelöst!");}

Page 31: crashing in style

<service android:name=".ErrorReporter">

<intent-filter >

<action android:name="com.tamoggemon.a360crash1.intent.CALLERRORREPORTER" />

</intent-filter>

</service>

Page 32: crashing in style

ACRAACRAWikimedia Commons / gerol

Page 33: crashing in style

What is ACRA• Android Crash Report for Android

• Very flexible library

• Can dump crash data to Google Docs

Page 34: crashing in style

Set up online• Google Account needed

• Create new form via SpreadSheet

• Export it to get FormKey

Page 35: crashing in style

Integrate into app@ReportsCrashes(formKey =

"dExKcElJWjVaUkpMem9WOWg3VE80SlE6MQ") public class MyApplication extends Application { @Override public void onCreate() { ACRA.init(this); super.onCreate(); }}

Page 36: crashing in style

Custom data• if(v==cmdStoreA)• {•

ErrorReporter.getInstance().putCustomData("myVariable", "A");

• }• if(v==cmdStoreB)• {•

ErrorReporter.getInstance().putCustomData("myVariable", "B");

• }

Page 37: crashing in style

Enable / Disable• if(v==cmdEnable)• {• SharedPreferences

aPrefs=ACRA.getACRASharedPreferences();• Editor anEditor=aPrefs.edit();• anEditor.putBoolean("acra.enable", true);• anEditor.commit();• }• if(v==cmdDisable)• {• SharedPreferences

aPrefs=ACRA.getACRASharedPreferences();• Editor anEditor=aPrefs.edit();• anEditor.putBoolean("acra.enable", false);• anEditor.commit();• }

Page 38: crashing in style

Further Options• ACRA does a LOT

– Interact with users

– Custom databases

• https://github.com/ACRA/acra/wiki/AdvancedUsage

Page 39: crashing in style

OOP FTW

Page 40: crashing in style

Problem of all solutions

• Integration requires manual work– Find all classes

– Integrate logging code

• Better solution: „stub objects“

Page 41: crashing in style
Page 42: crashing in style

How to implement it• By foot

• Loads of leeway for developers– Abstract actual logging?

Page 43: crashing in style

Examplepublic abstract class TMGNActivity extends Activity {

@Override public final void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState); logThis("Creating Activity"); logThis(getClass().getName()); tmgnOnCreate(savedInstanceState);

} public abstract void tmgnOnCreate(Bundle savedInstanceState);

Page 44: crashing in style

Other vendors

Page 45: crashing in style

Google Play Crash tracking

• Google Play provides crash tracking– Rudimentary, can‘t add own data

• Better than nothing– Check often

– Log-in freq. could (!!!) be used for ranking

Page 46: crashing in style

Crash Trackers• BugSense

– Specialized service

• Flurry– Afterthought for premium analytics

• Yours?– Tell us in Q&A

Page 47: crashing in style

ConclusionsConclusions

Page 48: crashing in style

Crashes will happen• Today‘s mobile apps are

– Highly complex

– Underfunded (thanks, Apple!)

• Even the OS crashes sometimes

• Users tolerate reasonable crashingUsers tolerate reasonable crashing

Page 49: crashing in style

Work-arounds are needed

• Paid users expect frequent updates– Let them generate their wishes themselves

• Monitoring is first step to improvement– See what users really think

Page 50: crashing in style

Olympic spirit• Important:

– TRACK CRASHES

– Perform PDCA cycle on data

• Not so important– How to track them

– Track 100% of them