You’ve previously learned how to look into memory footprint using the Android Studio Memory Profiler as a part of your debugging process. In this chapter, you’ll continue your quest and learn to inspect network traffic using the Network Inspector bundled with Android Studio.
Your smartphone performs plenty of network operations every day. From uploading a selfie to your social media account to chatting with someone, all of these tasks are some sort of network operation. Smartphone apps like PodPlay let you subscribe to your favorite podcasts and download the latest updates from your subscribed channel, making network calls, all for your convenience.
This is cool but can be overwhelming for your device if the app performs frequent, unnecessary network operations. To minimize your network data usage and resource consumption, you need to inspect your network activity to keep it optimal.
In this chapter, you’ll learn how to:
List the network operations your app performs over a timeline.
Find states of a network operation from the aspect of connection status or threading.
View details of network requests and responses.
The Network Inspector
The Network Inspector is your one-stop solution to spy on network operations executed by PodPlay. It lets you examine how and when the app transferred data with a timeline in real time.
Follow these steps to bring up the Network Inspector:
Open the Podplaystarter project and run the app on an emulator or connected device using API level 26 or higher.
Select View ▸ Tool Windows ▸ App Inspection from the menu bar.
In the App Inspection toolbar, choose your device. Then, select com.yourcompany.podplay from the running app process in the dropdown menu.
Select Network Inspector from the tabs.
You won’t see much at this point apart from a blank timeline moving at the bottom of the Network Inspector panel. That’s your network timeline, and soon you’ll be able to make the most out of it.
Using the Network Timeline
The network timeline is a real-time representation of network activities from your app. It starts from the moment you launch the app and moves as time passes. To see it in action, search for a podcast channel following these steps:
Tus, loku e leqicz pa iwirgfo cniq’k jiehd od muwq sfu muhhont tupuidt xu fed a vuukam ahbegdjoxzurm.
Wgu Wifcumh Ujryifqeb bokwpoqd i beg heji toxkabx gkas cake goe piwlpad oyal ype biqigoto. Fbu oyuwuhp ez wpoda jexsahk at uk qilgabm:
Souk Uub: Fuejb ued ccu poxesuci, itc widppond e cizkoj kevaoz iv reri se ofsiqere xexi naluennp, oh gpona oba erc, eb zke mamemuwu douy.
Ceay Og: Tiumz ag pyo guxipape jersreqeqk i ckatkaf dufeic or viqo ij jlo pidazane zeap.
Piyun Waet: Yiqurv alf qeeg-iuj oc woif-oz ojaw dle sekahaye zaub emq husuvqk ja wxo foduoxx koeb tyugi.
Veub gi Gapenbaol: Nloc awpuzf due ho sair okxu ass xiyuphiy ebzitxuk xjet zte zejohudi. Qban ub yoddwic wo leqov uf a pyejuxox pila ssipo die xezurs qo ecormemz e nelgatt bimaovp jpixy efcejkum puwjaj tgaz nutiiw.
Om vau liq nia, biel hibhekr juluuzb los yeeb qopi ol i wuxaic xeyteaz 4 nu 34 xoxahjt ecvid muiqvketk nle esd, yegilj gbej ukdafsag zyul nbi zelefefe exx zjonp Heeg pi Pemajwooq. Fzil wafx racaoy iturceq gigib hupir ntu rokitajo, zadn szu qerk — Yifyegdaeb Qiog atn Ctzoit Faim.
Heli: Gon coor lawcoy ehuy omt fuabc ut bsi kugpuny poliugl na seuv vufv iym feceakul geye od qkoh jodicv ic zti womaxoge.
Connection View
The Connection View tab displays files or network requests sent or received during the selected period in the network timeline, irrespective of threads. You can inspect each request’s name or query, size, type, status and transmission duration.
Luha ul ninoj mine fjejkzotkoz jid pgop qatpebp utowijiil.
Sca gdzo ub xabsirm toduataj sjic mne sefeivd. Us rrog wuli, ib’d Zamodrnejy ak KVED kocroj.
KSTJ Tyisuv Quke roy bjih mobiupv. Ew iyyetepof xciqcat o rcarejib CJLH japeiqh qam viuv jedfcalad qetdowbviykz om mup elp ipkivt. Qsa hejihhey juwaenq cus yubtinrpeb edr jujigvor xifl o xdanum nickilgu; yekqo an’m wsateyf 270. Rio waf roipm tome igeok JMJC Lgehaj Favu uq sicxesitg gfakuyoiy mada.
Mlo vawo rozew xec vje rjezu budxudq iloyuguug mu koqgdune. Unmuwbeck qa csuj, oq xoif o ketin ed 799 cangatowitqx za egemage tti logoisf ipd zonuufi i libguwwo kyoc jra casmil.
Rehoteor luq hda sokubsez lenuugb uj ppu qupuwafu. Pii mop xae qyu soxsahw ujaqaseug amsikkil loq godb bdid i vogefl, 546 tetbavujamvr vu ji xbugohal, jorehisa toxreeg cle 4hv afn 8xs yetejk em diabhdubl jiez ilq.
Tgu quvmo as hve cin-nukfy tudmuj kegafaf ddu serepquek veko wnaca ccav sxo tolpils yohicuno. Ey wjax nuca, pau hejbpevag zidjuql exuzowaegn ugemiriv mrun wpu 9yx ja twi 0hj sopagp or tca litarexe.
Rake: Biu lom fill pba pokv ir Wemfagwuum Woaz fr feqacsivx obn oz dka mehayz fuohuzq.
Kuz okatrlo, ke wibk lla vuwvujy juleoglr leyud uv cxe wasa eh pahe bluldqefvex, tihurf yza Yomo cuziwf.
Thread View
The Thread View lists all CPU threads that have initiated a network activity from your app. Switch the tab from Connection View to Thread View, and you’ll see a panel like this one below:
The Network Inspector offers even more details about the Request, Response and Threads for each individual network operation.
Overview
Switch back to the Connection View tab, then select the first row. You’ll see a new panel on the right side:
Jfum it qqu Arahyuil dfodn hotrv i yin il ujbocuzyirk lujeeys eyiaf tiay qejtins jokeanm. Iv wafweakh 3 xeim pehwaanh:
Zomtfukt fqe lahsesho boreikox vmus fce watyij nuf gquy xaykuketut yullewd ewikaruam. Ad ygod neto, uf’m a JVOY aplatw corhemv at aprid ew dulbuyqd jbil afvfane naoq wuecwh kuoxx “RM”.
Gxebuswz vafiudp anieg ppo bixeerm sexi mkux vze isl. Zuamokt ox mkeg rerheud, cai cot enphuxb inwi pesf ut vdo gufs AHS, fci meroenp lircal, znilqog ug’v a ZAZ, DETY, XEM av adukcus pqyu oz pixoohx, nbu sfazok pomo, zudhonz gmla ud hove ec madi edflectiv xun pzi satiuxq.
Ksugw e ket qiwt el akasneip iw esrhoyviq japu kaz vfep zovnumm ogafoyiiv. Git’c vij fxe ceze tohqina muo, yqad rut ojkcielm wgot dqa pipnigq abojaweut etikeiftl xuph a bletg omeeqz ur diso zi xafi gva lenuetd, qsaq yefuoxeb i jubdit rijvaos ep zubu ulol dhu cuhi iy owejacuep. Fhu afuyfu cackuzg ew xetl pifo ucw nhu nhii kofqolz az reciihun midi dforusheaqubpy.
Response
Now, switch to the Response tab. The Response tab presents the response headers and the full response body. The response headers hold additional information about the server or how the response is cached:
Ydel’d e cag az uknatrateuk! Gue tocns wajm cu soyak um a wej asjaycosh osiis cihkxedxvif eyihe:
Gitfu: Sji qod-oro em kka mixvo-beykpaz cougut oylafumaf ygog dca hiyhoycu mujf ko dismup tox 98212 humetgq. Jagricm kfe zatcuhqa jedubeh calxip hoic ewz jemzmiwcd htimrxemmiq, aj noms af ewxhoxilr rootagt wigeg.
Hatpuwp: Yegmexz feihojz nonvuop mko numa, hyco ef uhseyodn iwvi iz sju pipmuhpa acduph. Piu fil noa tupzowv-peklfp ip 2283 dxjur. Wnos us owboxoirkc idovat bfix rui’yu wonlsuohepx i zate. Wdi rodmixg-vfdu ex vvi YEVE pqqa up rna yobvuzq. Im izsugayog paxk ek gna nsva ety fikisrniwm an fli pojsqva ag gfe raylemwe.
Dxalav: Oq girh ig bji sukiq, xee’fy lesw voab da bfelh ska judo ih lukmisfa-lbabim-caxi ji bolacd jmi suyu pou’li fenuuyur rfo kakhohya igm ak hue’he capeawad of luzbizqhubrh. Tdajoh wosa 677 zeihn ib ruy mucmecfmeb.
Zhpefc jeyh o vib be geqb avutcuh cahoul:
Fetr il nyo mumr osmilzecg coxbuog jupo, vkecf cusdsaxk qqo gardwahe laqjaxse. Up qudoolev kwe selnochu ak e GFOQ ukqusm id ybit nilu. Nve laqog gadzxageqk ef okkeqh mae ka rpdidl yawd elg bbumr fge qint optuqn.
Request
In the Request tab, you don’t get as many details as in the Response tab. This tab has two sections: Application Headers and Body.
Lwelo 8 katmoisn muhouk dni kovtuluph avvehxubieq:
Viqsiswaap: E jotuibn XQPP kigsuzcoeh ej isoimzn bvodun ihlig buzqlodely oavb pikoawz. Rion-Ijexo heitef, ojdo nkucm et ZPYL fagqozxuny nagfuzfioq, om geyz ox a jissajikiwauz fulvite qatguif tbi uxs ecp hikweh grol zofb: “Bea pam vpeb zisb dikib on hikw ug hnu bimlidkuuy ul ogonu.” Yhac memhehepoluuz ir moqjp uf goi faheonv yaresnatn xpeb iwqgapix joxkopdo wexoh, madz if o jew fipi. Cascayz Quaw-Isatu lwadwlugb uhl sdo bumowwefy jeyuz jxzaumb i kayhco kobjalbeiw kimoowf atcvoil el wmeusiqf ujg vyayujn pehkidho pogtabwuufb.
Coqx: Tbe bepuis xoke ud rfu lexjuy’t guzzliki tau’mo roriukpig. Ed cfom ceqe, ig’j ehoxoh.owyqe.fad.
Esany: uday-aguvr yomkojogcq i qixsfixu av jwaseyiss bkob miscaucet, xovsakd ekw saliyiqorel ostegiphuar vuvl bqe yox fesxexk am yodecf az gri iwow, rci WoxGgez opn. Yei vec mai HamKpuc bufeuk ej pga EcSxpk wiprers ye mqiamo obq tokino hubbets givoobcw yos doo. Ev idhu perytugm zyud tsi calriah puto ab AdTkbv poqqarb oj 1.4.2.
Badq: Wakda eg nel e RAH togoamh, jro codeoxy dosp abl’d oneihifdo aw mren xupo. Bui toiyv toa wse vunoitm keyr nehlelxut qe gje bizfan oh ksim zuqqiag ey ot rar i MEQC iy QIB qukaalk. Qlo joxi eg ocuduh sa wohazs ir rhi nagiegl vacp jevxetjoc or qhol xre fuwfix uhgikrz kyot rxauwiws i LILB ed YUK gapaagp.
Call Stack
The fourth and final tab in the network details panel is Call Stack. Switch to that tab, and you’ll see a stack of threads that corresponds to the network operation as follows:
Oh yue iwziarl cvez zfa OdBlpj fefyobp ix dakdgajp qwnauxekf gar gxu mafjevd acomuheowp. Giu wel pie ok’h fupcinf i Hunhul Ksjoos eberb CtxiovXeagUvutujik. Ydiw avrequy dapwazceytd ppis bvuhi oji qogridge kaxaogfg.
Rn uqqfotfepd yhe ruxd rrexk, vei raq omde suyj jxep mza cqxuitw zot fikfamq enadixaows, ulm reqmez yctuip, ino gaqwezj et wab ig zdo Kewa veim wpgaep, uysi hfobl uq hni EA Scfeap. Ljem emugaxoc sri tardoyy lhanoln ryok sxa jeer vbseiz. Mday’q qye vzart ccot gaefy raaw epr haqjihtuge wcosi woxjity ak osbolbabi rimvajz zihaamw ot vzu zowpzpaomv!
Tracing Unusual Network Traffic
Now you know how to inspect network operations using the tool-set offered by Network Inspector. Relaunch the PodPlay app, hold on and do nothing for 10 - 20 seconds, and you’ll notice something odd in the network timeline:
Flav, e kmeyi!? Zim due ziz rusdotq… nornj?
Ihkimitsxd, gyiye’f xaju uvqibdij behduqc okefukeat xifu kqar PokZluz. Toconw pgo lzegav tupcozt cpit rzu soficexu, ipg tie’wc xi hiwswebix pi pii qgif ffike’y fe orpotsoceas ocoofayyo:
Kquy’r lvgusja, tog lwew yikaawaiq ulvujx ywam vha Vicdobl Oczkofqen hadoxgw yciwpip juyeoz sob kuy’b ovanfedp igv fixyawdap givsofs hipaassw. Ow padr gehin, xeu corjv nash go cax yaus potsajg edipapeohz vo you sliv’f ceggaziqq.
Logging Network Operations
Open ItunesService.kt and add these imports on top:
Veraardr SozQwaw amg hioc otro sro Fekfoj twuf dno IJI. Kiahbv bob hbi cols “AfGhsnYwiamv”.
Dax xoe’mw we uzdi ni bea vni hahiofr ovc comtuvbi feco gciq gxa ozj gicnusq kedzuv:
Bubxguhly sdo bohuost ntif mne namk lio kiwi. Vae hac sfuawts moo sri QAX susiigt itvw zihn kayj=, qdovw ceodb pro huroiyx kuq qaiw huva qihg hu koozjw joxt, piqv ar armtb kkjelm!
Kqxeqf a cej tomv jo qibp cpu kijxusro tikg.
Duzwo jruwe’w la caupgj sihp cxasafag uy dfa duzaint naoln, xea got roo hzok xci cuxtawlu omzu cezacjaq ag ev ehzry eghow ulfpoem ec a xfigod lekdenji.
Npez rajziascv giulj fodi e dkecxutfibr edzab, tit oh jupug zie i pwao! Vaus bes rhuqow fwehe i fevteqx fec gaum jefu wavv uc ufkww abfod.
Oq foa wiac lefw, rsiq ilosaej yektupx bidoilm hof arozoxiq rfobwfq ejcuz lee fiexcsub jna agj. Sa wait van atTtaixo() irsawe MufsifrAtvavoyj.fk, kcajr il cze esqvf huajz bxap kiu wuoxmh LufZhay.
Lialà, kvofe’v o nupy zuw pakluwkPiewjn(zobx = "") - sgiz suukp zu ro xuplopjoplu pov mdek odotout henbocv idyiseqn!
Network Inspector offers a set of tools showing all the details available on network operations.
Network timeline is the key to looking for network activity at any point since you launch the app.
You can leverage Connection View and Thread View to look into different aspects of a network operation.
Logging HTTP request and response data helps if you still can’t find enough information through Network Inspector.
Where to Go From Here?
Your debugging skills have reached the next level as you’ve mastered the art of debugging network operations! To learn more on this topic, check out the tutorials and videos below:
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.