Slide 1

Slide 1 text

HOW TO LOVE YOUR DEVELOPERS LIKE YOUR CUSTOMERS? Ishan Khanna Android @ Booking #droidkaigi @droidchef

Slide 2

Slide 2 text

OUTLINE 1. INSPIRATION FOR THE TALK 2. DEBUG FEATURES 3. COMMON SCENARIOS 4. LEVERAGING THE POWER OF OPEN SOURCE 5. A COOL DEBUGGING TRICK #droidkaigi @droidchef

Slide 3

Slide 3 text

INSPIRATION FOR THE TALK #droidkaigi @droidchef

Slide 4

Slide 4 text

“DEBUG FEATURES” WHAT ARE THEY? #droidkaigi @droidchef

Slide 5

Slide 5 text

WHO ARE THEY FOR? DEVELOPERS QUALITY ASSURANCE TESTERS PRODUCT OWNERS DESIGNERS

Slide 6

Slide 6 text

SCENARIO 1 THE SERVER URLs #droidkaigi @droidchef

Slide 7

Slide 7 text

PROD DEV-1 DEV-2 DEV-3 DEV-4 ANDROID APP

Slide 8

Slide 8 text

Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://dev-2.booking.com/") .build();

Slide 9

Slide 9 text

Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://dev-2.booking.com/") .build();

Slide 10

Slide 10 text

PROD DEV-1 DEV-2 DEV-3 DEV-4 ANDROID APP

Slide 11

Slide 11 text

Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://dev-3.booking.com/") .build();

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

SCENARIO 2 THE COPIES #droidkaigi @droidchef

Slide 14

Slide 14 text

SEARCH RESULTS IN ENGLISH

Slide 15

Slide 15 text

SEARCH RESULTS IN JAPANESE

Slide 16

Slide 16 text

SIDE BY SIDE COMPARISON

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

SCENARIO 3 NETWORK THROTTLING #droidkaigi @droidchef

Slide 19

Slide 19 text

public class NetworkThrottlingInterceptor implements Interceptor { private static final AtomicLong failRequestCount = new AtomicLong(Long.MAX_VALUE); private static boolean delayAllRequests = false; private static long minRequestDelay = 0; private static long maxRequestDelay = 0; private final Random random = new Random(4);

Slide 20

Slide 20 text

public Response intercept(Chain chain) throws IOException { long delay = minRequestDelay; if( minRequestDelay != maxRequestDelay ) { delay = (long) ((random.nextDouble() * (maxRequestDelay - minRequestDelay)) + minRequestDelay); } long end = System.currentTimeMillis() + delay; long now = System.currentTimeMillis(); while( now < end ) { try { Thread.sleep( end - now); } catch (InterruptedException e) { // Nothing to do here, timing controlled by outer loop. } now = System.currentTimeMillis(); } return chain.proceed(chain.request()); }

Slide 21

Slide 21 text

public static void delayAllRequests( long minRequestDelay, long maxRequestDelay ) { if( minRequestDelay == 0 && maxRequestDelay == 0 ) { delayAllRequests = false; } else { NetworkThrottlingInterceptor.minRequestDelay = minRequestDelay; NetworkThrottlingInterceptor.maxRequestDelay = maxRequestDelay; delayAllRequests = true; } }

Slide 22

Slide 22 text

public OkHttpClient configure(@NonNull OkHttpClient client) { client = super.configure(client); return client.newBuilder() .addNetworkInterceptor(new NetworkThrottlingInterceptor()) .addInterceptor(new SomeOtherInterceptor()) .build(); }

Slide 23

Slide 23 text

SCENARIO 4 UNAVAILABLE PLAY SERVICES #droidkaigi @droidchef

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

SCENARIO 5 DEBUG NOTIFICATIONS #droidkaigi @droidchef

Slide 27

Slide 27 text

APPLYING APP WIDE CHANGES ● USE A LIBRARY CALLED PROCESS PHEONIX ● WRITTEN BY JAKE WHARTON ● https://github.com/JakeWharton/ProcessPhoenix #droidkaigi @droidchef

Slide 28

Slide 28 text

START THE DEFAULT ACTIVITY IN A NEW PROCESS ProcessPhoenix.triggerRebirth(context);

Slide 29

Slide 29 text

OR, IF YOU WANT TO LAUNCH WITH AN INTENT Intent nextIntent = //... ProcessPhoenix.triggerRebirth(context, nextIntent);

Slide 30

Slide 30 text

TO CHECK IF YOUR APP IS IN PHEONIX PROCESS, TO SKIP INITIALIZATION IN onCreate if (ProcessPhoenix.isPhoenixProcess(this)) { return; }

Slide 31

Slide 31 text

DON’T REINVENT THE WHEEL #droidkaigi @droidchef

Slide 32

Slide 32 text

LEVERAGE EXISTING OPEN SOURCE SOLUTIONS #droidkaigi @droidchef

Slide 33

Slide 33 text

SOME MUST HAVE OPEN SOURCE LIBRARIES IN YOUR PROJECT #droidkaigi @droidchef

Slide 34

Slide 34 text

STETHO ● DEVELOPED BY FACEBOOK ● https://facebook.github.io/stetho/

Slide 35

Slide 35 text

CHROME DEVTOOLS

Slide 36

Slide 36 text

NETWORK INSPECTION

Slide 37

Slide 37 text

DATABASE INSPECTION

Slide 38

Slide 38 text

VIEW HIERARCHY INSPECTION

Slide 39

Slide 39 text

JAVASCRIPT CONSOLE TO INTERACT WITH APP

Slide 40

Slide 40 text

INSTALLS IN ONE LINE OF CODE public class MyApplication extends Application { public void onCreate() { super.onCreate(); Stetho.initializeWithDefaults(this); } }

Slide 41

Slide 41 text

LEAK CANARY ● DEVELOPED BY SQUARE ● https://github.com/square/leakcanary

Slide 42

Slide 42 text

TIMBER ● DEVELOPED BY JAKE WHARTON ● https://github.com/JakeWharton/timber

Slide 43

Slide 43 text

MAKING THE MOST OF ANDROID STUDIO DEBUGGER @Override public void onBindViewHolder(ViewHolder holder, final int position) { final String name = values.get(position); holder.txtHeader.setText(name); holder.txtFooter.setText("Footer: " + name); }

Slide 44

Slide 44 text

@Override public void onBindViewHolder(ViewHolder holder, final int position) { final String name = values.get(position); holder.txtHeader.setText(name); if (position % 3 == 0) { holder.txtHeader.setTextColor(Color.GREEN); } holder.txtFooter.setText("Footer: " + name); }

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

CREATE A NEW RUN CONFIG

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

GO SPREAD SOME #droidkaigi @droidchef