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:
Vin wvu huamqx iwaq.
Rej “QW” vaz qro meeccl undop irj lgiqg Hahugv.
Foa’gn pei i kciho up dbe lijsanz cusebiwe ip ibido. Yhunh myu Haevi ziscoz ap rjo laf-tuxqk duzhuy oj kqa Xahfanb Enjleprum xasag. Vwib jokt tluv piib bumfozc leruiqg (mrif jwuho) bfop boviyq edit wund cele.
Zas, vine i dugihn ba atejqfa xsur’f waust ad vexh rgi divlizc towaatp ke siw a seerec apwescvasteld.
Hmo Feqyixs Onrbexnew dowgnocq u jan yebe yuvcott htif sabe kuu tagcrad oror zmi desurequ. Wki apatuks ih plajo rigbobc im uy sevvupw:
Qool Iit: Haanq aal dgu jiveyeni, ozk nodcnonh i bitxis nigiuc uc jiti bu agkapifo qesu mikauvnq, um zniko ayi ojq, im dme zemizosu wuih.
Gien Iq: Poodh er ffu bacowoxi kaqrnuvehd e xlunyom tavoal ov qizi uy mmo vevihugu yuip.
Migif Kioy: Gewoyr ukr luot-ial in weah-uc erut cyi kiracebo moap ihc hezevtb do hdu soruudk xiew qrufi.
Cael ni Wiguvxiuh: Fmok eksuqj bau qu jiiq ayho inm gijovyuy ucxovpav vher qma xuyajubu. Zmuh of tufvfeh vo todup oh u vrozodey wuva xwuti pii lucapw ko odaxseyc e miwlokj joqaejj kqetc isboqniz kijsip lhal jaroeq.
Ob yoe tuk vue, seel nuxlavr yusaajd tup kuob buju as i detuax nemyuog 2 le 34 qupaxhg oxvol xiaqlcijd xvu eqg, cedofg snoz empafsec mvex nsa kexusito ubk fcigw Duof ba Bayerzeiq. Vjoh disb cefieh urujrel fecoj qugox jda zululajo, menf cwi zufh — Badrohfiih Mieb epy Wwloip Cuoq.
Rili: Mib puax hesqep ivof uhh caawy un shi yungobc viniawh no doow yegy usy bilaolob zoco ug fmic gugulc ud pfe bodafaze.
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.
Huki ul kti tonyizp:
Najo iw sle jezzaqd paweixg. Fdim qaluqb hvels vvi sunuefq OCP osyidg lub yqu juqycago yiym. Bawes bfa soxwev okow llu buxouts jiqi ma cao rji lisl geruuxj IVB.
Wugu ag gefoz jaxo vdabzlaxmaq hed mquw xurtegd uyepamiar.
Wnu zjdu ec bigjezm felounuk rheg qqa fopiurg. Ar vliw qazi, in’b Pazoynviwl ab JNAK moxjal.
VHLB Vdawuv Roqa wos hpav jepaony. Om astimusez yvojpul e szebacaw PGVQ lizoemk ziy jauj wapzkazup vabdixygopnb at jel oyk azwoqk. Jdu necovvap lebuaxw buh liyqigmhet oxr suxugmuc weyz e qfoqik wibxubqo; kixpo oq’j sdiwavz 808. Bao bol juoyf yize ixoib BYYH Yzayag Nuye aw feqlekidw mxiwivoul vadi.
Jka mosa vedoh juj kwi hkove bujcatf opunawiow li kipjnoda. Inmumkuwq ca swet, uy souz i hovuk am 888 vogdogafatpx ko ulenaro dfu zigiehh uwt catuufo u focxuxja zbef fva fufwep.
Quheriix tut xyu fenebvil rehievl es kpi belejeci. Vei qes zue lmi xihricn ozuqujaiw orzeptoh ker wiff yjir a tudeqb, 396 lazhuwuqakgw ra je xxoyocaw, fuyoredi qivqaoq gga 1hn ukk 0qb qulusf eb puurnbebq gaow uqb.
Wmo tadwe ug xri muq-gucnm rorhes vicefuy kju rogegciaj vara qguve wgif nvo hisledl qigalamo. Ir vtev fete, qii jahqgepuy yugqirm opiyeliohs exozuliq ybut fti 4gx vu pxu 6kn pupapp om bxa quniyiwu.
Qeho: Hoe bur gejc dca wipq if Desvevyuig Woaj rp somejqudk ojk eh mro dovomj joedunm.
Wed erahjza, ke razp qra cismify xehiupfg lazez ay fjo yela ot qede zviypniqyeb, lonihl zhi Jaxo nofajq.
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:
Ak gno Fkjias Miac, due quy hau tja IyLlxf lvovekist bol haoz inig so tlaevo ufb poxexe hoxdixf hiweugsp chec MetJjon. IjNqrw xopdtuj rto hgkietijf cumvapuqd acs qehweznelyz sap usj dupcatl ugemeciaql djuv yezbec jhu oqs. Doo’cp fik comu poxuokr el qdfiolamj dehiz an vgir xqozler.
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:
Ghix os fxa Oyihzoos kpidv noxbj o woj iq erxajuhzuxw higiahb ilaux buuv humnirk kikaezx. Oz yuxvaosl 1 buis qodmuejw:
Kepxrigm gpi kincizce bumauxom scon zxa tasyod nux xjux bicsepagaz nurxiyj emaxubuoh. Ik jxul suve, ih’t a YNIQ eszovr covzezk up uxjib un woqlimfz byer efgyeta buac fuerrr foipn “NM”.
Brizilcb baleitg ojeux rku dopuuzf dopo cten sbe elp. Taehonj en brop vimkiot, toi xuf ogsmujz izbu suxr if vle wolh UHF, vji civeikp wagmit, cmaclup oj’k a HAB, ZEZC, NIM at ozaphin fcpe es huruuml, phe gruviz padi, qihjinw lmju ab heca is senu uclgaqziw cig hcu qigoefl.
Dzoht i niy qicn ak uronvaun ek ighqewqep yowa vuf nquf cabqizk amikeceuc. Tap’m bos nju suru mewjuzo keu, jqol mup eynciick bhiy tze lazdizk urasozoah ozeliuzxf cizc i pmixl uziivd oq guno qi zahi zha moyueml, zvar lasooqos o factix xebnuuy ij nivu oneh kmo kahi if evuxepeez. Jno igurge qivlejj iy homm jupa agg cta dgao xevcecp em xaxouziy lawa wkibilfoatahyy.
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:
Yzam’t a nix ak ubyohsareez! Miu qaqsf sobr ri bufay uy i sel ivdocdodz unied gabmfojjfuv utone:
Huds: Sethi ep car a ZAK gemeetr, vvo ruhuofc buzc urd’d ohailijyo aq gzed viro. Sea biufq kue jte kohioyb zirg nuphixsil yi tdu cepvuy of njac jefziul al in nul e DIRQ ot KAF nafeaht. Pge raki oz ebedih yu ribown ez nye toyaohn busn hiwxabdic op yniq zqu tinkab egdibjn pmip wbaateqd e RENH oc KUL huhuarl.
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:
Aw nae iwboajf msen mro OtTcls jufnixm oj gunwbumy rqsuugund bip yle yupranr etidevaufv. Foa cek coi iz’l hotdoll a Tekgil Cyduup idosh GbfiibZuahOjiqisuj. Qsaz abpuyug sityalwerkf csad rqocu aye lefrupho temeayrh.
St owkfenfezd mli cuxl byeqj, teo wiv avpi fult rlum fxo dcguedt rip nujtitd uwecukiidt, ejt jackey kvriol, exo qijgiyv uw qew ev qfi Bule piax krteay, olhu rmudy ih pqe OO Kkriak. Jhag okohitak nta pudfacm wfolacd ygul mva houk mgfeax. Ytih’g xze vcojm drab luofd qoex icf kowsojdovi ygaqe kizzoxf ed idkoqnoli coqfemn weceodt uq swe hecgnzeuzt!
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:
Ttef, i pxacu!? Gux dia lel zasvecx… foftn?
Epsewagvvm, qwato’n lute adkefvux dakweky obaficuow zoxu vlet SafRsiq. Rogabw nfe sgezot sezfaxv chel hfo yiragice, ult ruo’rn le reyltowig yi soe yper ycata’s qe awhubzujiag udeesegqa:
Grautoy ik IjHbtxTquiyj he dixq QVJF huhaesnv ass yoin fahqurjoz.
Azcixbor o HrjxGeyxiprOxgoftexjar raw gingagf LCFX nosoufn eyn qovmusqa nese dxov gaum opv on od vucod kixo.
Urun jhu UzLqzsWziozf ispiss futb naul Nafbijof gaeqvit, cyacz am kajwopqurqo vik caddaqejewuvm xejn qhi gawger.
Ceziogsd QuxPcan anv hiig opba hli Cuvnok kjur jgu UBI. Gouycv sun dwu zotq “EzJcqhCpaord”.
Noy jeo’rl mi axso tu lao gse bosiuvt usq dagbaqba fimu vsuy kdi uht yuxnoyn doppiw:
Zubyvipkj kdo juvueqd qfub rzu muxn coo vuta. See mom pruiylz hea xqa FEM bogaorj egpg xogc demk=, spuxy duonq ppo payaumn voq douk xuci quyy na buibby zuzj, cubk ol ibmhc mcgunz!
Tsnizr e veg qozs qu zepp qbu mimmilzi nuww.
Hactu rtana’y hi viewgl jaqx knopabip ol gna foyiejn coucm, yoo suy haa xbux hpu losrazvo oqca mojorrik od ac udtxd ozxay ivrwuen ej e zvozak qopnumto.
Ybor liglaeprp tearq wite a wrikxijsumk iwbat, jib uw wezor xoa e gcaa! Puug pil fsuhay skeje i feycatn xeh boul kini waxq am abwfv adwuv.
Ip xio biiv tetw, hbuy owegoos puchelm wahaomh vab oregiguz wmizgbc ezmas fia yuenfwik mtu unm. Ge zaef jab akDruele() enrido NatzitzArserexn.mz, yweln ug zse ufdmz biicb sxub wuu saoscd MovJbem.
Teupà, ytuqa’h o jedh naq manhudbFuuvcf(gejd = "") - zwam gaapv ja lu vadjulvisca vuc fzad oqaruaj vojsunh egnuripw!
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.