Real-World Android by Tutorials (Ricardo Costeira, Subhrajyoti Sen Kolin Stürt) (z-library.sk, 1lib.sk, z-lib.sk)
历史Author:Ricardo Costeira, Subhrajyoti Sen & Kolin Stürt
No description
Tags
Support Statistics
¥.00 ·
0times
Text Preview (First 20 pages)
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
Real-World Android by Tutorials By Ricardo Costeira, Subhrajyoti Sen & Kolin Stürt Copyright ©2021 Razeware LLC. Notice of Rights All rights reserved. No part of this book or corresponding materials (such as text, images, or source code) may be reproduced or distributed by any means without prior written permission of the copyright owner. Notice of Liability This book and all corresponding materials (such as source code) are provided on an “as is” basis, without warranty of any kind, express of implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in action of contract, tort or otherwise, arising from, out of or in connection with the software or the use of other dealing in the software. Trademarks All trademarks and registered trademarks appearing in this book are the property of their own respective owners. Real-World Android by Tutorials raywenderlich.com 2
Page
3
Dedications To my parents, Céu and Manuel, and sister, Joana, who always gave everything they could and more to ensure my education, happiness and well-being. To my partner, Joana, for all the love, support and unbelievable patience while I was writing the book. To my friend, Carlos, for all the support and understanding every time I told him I didn’t have the time to help him with GDG and Kotlin Knights events. And finally, to the amazing Android devs from my team at Mindera - Maja, Rita, Garcês, Belchi and Gui - for all the incredible discussions, for teaching me so much and for making me love what I do even more. — Ricardo Costeira I’d like to thank my parents, @StephanieBraganza, Pom-Pom the Pomeranian (IG @PomThePomeranian) and 0xAKBArt, as well as The Wildlife Trade Monitoring Network and The Save Movement for inspiration of the app concepts. — Kolin Stürt I’d like to thank my parents, friends, and colleagues, who have always been very supportive and pushed me to achieve more. This book would not have been possible without them. — Subhrajyoti Sen Real-World Android by Tutorials raywenderlich.com 3
Page
4
About the authors Ricardo Costeira is an author of this book. He is an Android dev with a crush on clean code and software architecture. Based in Portugal, Ricardo works as a senior Android engineer at Mindera, where he builds and maintains a retailer app with tens of thousands of daily active users. Ricardo loves Android and the community, so it’s only natural that he tries to have an active part in it! He’s a co-organizer of GDG Coimbra and a co-founder of Kotlin Knights. He occasionally writes (mostly about Android) at his site, ricardocosteira.com, or for raywenderlich.com. He loves cats, food and the gym and he’s a specialty coffee hobbyist. You can find him on Twitter at @rcosteira79. Subhrajyoti Sen is an author of this book. He is an Android Engineer at KeepTruckin, where he develops apps to improve the trucking industry. Before that, he also worked on apps to improve the experience of Indian investors. He believes in the power of open source and communities, and actively tries to give back. When not writing code, you can find him binge-watching anime, reading up on public policy or playing Rocket League. Kolin Stürt is an author of this book. He is a software team lead with a focus on encryption, reverse-engineering, forensics and application hardening. He’s worked on many platforms, most notably Android, iOS and Linux. He has an interest in networking and has been hacking and developing apps since 2009. Outside of cybersecurity, he composes and performs music, as well as practicing and holding a black belt in Aikido. You can find him at https://kolinsturt.github.io. Real-World Android by Tutorials About the Team raywenderlich.com 4
Page
5
About the editors Andy Gibel is a technical editor of this book. He started with Android around 2010 and never looked back. He’s written Android apps that run on phones, tablets, embedded devices and even a dog (long story). He once learned himself a Haskell and is fascinated by functional programming and general CS theory. Eric Crawford is a technical editor of this book. He is a Senior Software Developer at John Deere, where he bounces between iOS and Android development. Before coming to Deere, he did freelance mobile development and server side web development using Java. In his free time, he likes to dabble in other platforms, like IOT and cloud computing. Sandra Grauschopf is the editor of this book. She is a freelance writer, editor and content strategist as well as the Editing Team Lead at raywenderlich.com. She loves to untangle tortured sentences and to travel the world with a trusty book in her hand. Massimo Carli is the final pass editor of this book. Massimo has been working with Java since 1995, when he co-founded the first Italian magazine about this technology http://www.mokabyte.it. After many years creating Java desktop and enterprise applications, Massimo started to work in the mobile world. In 2001, he wrote his first book about J2ME. After many J2ME and Blackberry apps, he then started to work with Android in 2008. The same year, Massimo wrote the first Italian book about Android, and it became a best seller on Amazon.it; that was the first of a series of 12 books. Massimo has worked at Yahoo and Facebook and he’s currently working as a Senior Engineer at Spotify. Massimo is a musical theater lover and a supporter of the soccer team, S.P.A.L. Real-World Android by Tutorials About the Team raywenderlich.com 5
Page
6
About the artist Vicki Wenderlich is the designer and artist of the cover of this book. She is Ray’s wife and business partner. She’s a digital artist who creates illustrations, game art and a lot of other art or design work for the tutorials and books on raywenderlich.com. When she’s not making art, she loves hiking, a good glass of wine and attempting to create the perfect cheese plate. Real-World Android by Tutorials About the Team raywenderlich.com 6
Page
7
Table of Contents: Overview Book License 16............................................................................................. Before You Begin 17................................................................ What You Need 18........................................................................................ Book Source Code & Forums 19............................................................. About the Cover 20...................................................................................... Introduction 22.............................................................................................. Section I: Developing Real World Apps 24...................... Chapter 1: Introduction 25........................................................... Chapter 2: Starting from the Beginning 30............................ Chapter 3: Domain Layer 46......................................................... Chapter 4: Data Layer — Network 66....................................... Chapter 5: Data Layer — Caching 93........................................ Chapter 6: Building Features — Animals Near You 124.... Chapter 7: Building Features — Search 157........................... Section II: Modularizing Your App 198............................. Chapter 8: Multi-Module Apps 199.......................................... Chapter 9: Dynamic Features Theory 221............................. Chapter 10: Building a Dynamic Feature 229....................... Section III: Enhancing Your UI 257..................................... Chapter 11: Animations 258........................................................ Chapter 12: MotionLayout & Motion Editor 281................ Real-World Android by Tutorials raywenderlich.com 7
Page
8
Chapter 13: Custom Views 304.................................................. Chapter 14: Style & Theme 330.................................................. Section IV: Securing Your App 356..................................... Chapter 15: User Privacy 357...................................................... Chapter 16: Securing Data at Rest 372................................... Chapter 17: Securing Data in Transit 396............................... Chapter 18: App Hardening 419................................................. Section V: Maintaining Your App 437................................ Chapter 19: Firebase Integration 438...................................... Chapter 20: Release Optimizations 460................................. Chapter 21: Advanced Debugging 473.................................... Chapter 22: App Analysis 499..................................................... Conclusion 520.............................................................................................. Real-World Android by Tutorials raywenderlich.com 8
Page
9
Table of Contents: Extended Book License 16. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Before You Begin 17. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What You Need 18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Book Source Code & Forums 19. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About the Cover 20. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction 22. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How to read this book 22. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section I: Developing Real World Apps 24. . . . . . . . . . . . Chapter 1: Introduction 25. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is this book about? 26. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Who is this book for? 27. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The sample project 28. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Signing up for an API key 29. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 29. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 2: Starting from the Beginning 30. . . . . . . . . . . . . . . . . . . . . Package by feature approach 31. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Full stack features through layers 36. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bridging requirements and implementation 38. . . . . . . . . . . . . . . . . . . . . . . . . . Devising a plan of attack 41. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 45. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 3: Domain Layer 46. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a domain layer? 47. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating your domain model 49. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Inverting dependencies with repositories 61. . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing your domain logic 62. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Real-World Android by Tutorials raywenderlich.com 9
Page
10
Key points 65. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 4: Data Layer — Network 66. . . . . . . . . . . . . . . . . . . . . . . . . . . What is a data layer? 67. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Network data models 69. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Connecting to the API with Retrofit 71. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interceptors 73. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing the network code 82. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 92. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 5: Data Layer — Caching 93. . . . . . . . . . . . . . . . . . . . . . . . . . . . Cache data models 94. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Caching data with Room 101. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Managing cache dependencies with Hilt 106. . . . . . . . . . . . . . . . . . . . . . . . . . . . Putting it all together 108. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing your repository 113. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 123. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 6: Building Features — Animals Near You 124. . . . . . . . . What is a presentation layer? 125. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Making your life easier with architecture 126. . . . . . . . . . . . . . . . . . . . . . . . . . . Building animals near you 129. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the UI components 131. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the view state 135. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the data flow 137. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Your first use case 142. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Connecting the layers 143. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Hilt on Android components 145. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying cute animals 147. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Allowing an infinite scroll 153. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 156. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 7: Building Features — Search 157. . . . . . . . . . . . . . . . . . . . . Building a search feature 158. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Real-World Android by Tutorials raywenderlich.com 10
Page
11
Getting started 158. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Searching locally 159. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Triggering the search 170. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding search to the Repository 176. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding search to the ViewModel 178. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Searching remotely 182. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Canceling old search requests 186. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Finishing touches 188. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing 190. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ViewModel tests 190. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . UI tests 194. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 197. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section II: Modularizing Your App 198. . . . . . . . . . . . . . . . Chapter 8: Multi-Module Apps 199. . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is modularization? 200. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Types of modules 200. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Why modularization is good 202. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Gradle with modules 203. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Looking back over your decisions so far 204. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the onboarding feature module 209. . . . . . . . . . . . . . . . . . . . . . . . . . . Navigating between feature modules 216. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Additional improvements 219. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 220. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 9: Dynamic Features Theory 221. . . . . . . . . . . . . . . . . . . . . . Android app bundle 222. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Dynamic delivery 223. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What are dynamic features? 224. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Navigation with dynamic features 227. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 228. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 10: Building a Dynamic Feature 229. . . . . . . . . . . . . . . . . . . Real-World Android by Tutorials raywenderlich.com 11
Page
12
PetSave’s new features 230. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Deciding how to create your dynamic feature 232. . . . . . . . . . . . . . . . . . . . . . Preparing the app module 232. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Preparing the feature module 236. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Handling navigation 240. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Handling dependency injection 243. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing module install 252. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 255. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 256. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section III: Enhancing Your UI 257. . . . . . . . . . . . . . . . . . . . Chapter 11: Animations 258. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lottie 259. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Animated Vector Drawables 266. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Physics-based animations 271. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 280. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 12: MotionLayout & Motion Editor 281. . . . . . . . . . . . . . . Getting to know MotionLayout 282. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Getting started 283. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding your first constraint 287. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Motion Editor 288. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding a trigger 290. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Overriding visibility 293. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Animating more features 294. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding non-linear motion 296. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ImageFilterView 299. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 303. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 13: Custom Views 304. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating Custom Views 305. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Implementing a Progress Button 306. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Initializing the Paint objects 311. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Real-World Android by Tutorials raywenderlich.com 12
Page
13
Designing the animation logic 312. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Painting your shape 313. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Previewing your shape 314. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding animation 316. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Drawing the check icon 321. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Putting everything together 323. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Manually stopping the animation 325. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Enhancing performance 325. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 329. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 14: Style & Theme 330. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Defining styles and themes 331. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Structure of a style 331. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Structure of a theme 332. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Style hierarchy 333. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Theme overlay 333. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TextAppearance 336. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting up dark themes 338. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Styling custom views 349. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 355. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section IV: Securing Your App 356. . . . . . . . . . . . . . . . . . . . Chapter 15: User Privacy 357. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Securing the foundations 358. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using permissions 359. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Opting out 365. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Clearing caches 366. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Disabling logging 368. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Disabling screenshots 368. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Wiping memory securely 370. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 371. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 371. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Real-World Android by Tutorials raywenderlich.com 13
Page
14
Chapter 16: Securing Data at Rest 372. . . . . . . . . . . . . . . . . . . . . . . . . Implementing the login 373. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Securing data with biometrics 380. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Customizing encryption 385. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 394. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 17: Securing Data in Transit 396. . . . . . . . . . . . . . . . . . . . . . . Understanding HTTPS 397. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Updating security providers 400. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Understanding certificate and public key pinning 400. . . . . . . . . . . . . . . . . . . Using Certificate Transparency 405. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Preventing information leaks with OCSP stapling 407. . . . . . . . . . . . . . . . . . Understanding authentication 408. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . End-to-end encryption 417. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 418. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 418. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 18: App Hardening 419. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introducing overflows 420. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Paying attention to warnings 421. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sanitizing data 423. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Validating input 425. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Nullability and safety checks 429. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Concurrency 433. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Checking app integrity 435. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 436. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section V: Maintaining Your App 437. . . . . . . . . . . . . . . . . Chapter 19: Firebase Integration 438. . . . . . . . . . . . . . . . . . . . . . . . . . Setting up Firebase 439. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Crashlytics 442. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Remote Config 446. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Firebase Test Lab 452. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Real-World Android by Tutorials raywenderlich.com 14
Page
15
Key points 459. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 20: Release Optimizations 460. . . . . . . . . . . . . . . . . . . . . . . . Using APK Analyzer 461. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Enabling an optimizer 461. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ProGuard versus R8 462. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Fixing compilation errors 463. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Fixing runtime errors 467. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Enabling more optimizations 469. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A few things to keep in mind… 471. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 472. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 21: Advanced Debugging 473. . . . . . . . . . . . . . . . . . . . . . . . . Memory leaks 474. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Android Studio Profiler 480. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Layout Inspector 492. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 498. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 22: App Analysis 499. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debugging versus investigating 500. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Extracting data 501. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Recovering deleted data 509. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Black box testing and reverse-engineering 510. . . . . . . . . . . . . . . . . . . . . . . . . . Using reverse-engineering tools 515. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debugging with ProGuard output files 516. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some final notes 518. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 519. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Conclusion 520. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Real-World Android by Tutorials raywenderlich.com 15
Page
16
LBook License By purchasing Real-World Android by Tutorials, you have the following license: • You are allowed to use and/or modify the source code in Real-World Android by Tutorials in as many apps as you want, with no attribution required. • You are allowed to use and/or modify all art, images and designs that are included in Real-World Android by Tutorials in as many apps as you want, but must include this attribution line somewhere inside your app: “Artwork/images/designs: from Real-World Android by Tutorials, available at www.raywenderlich.com”. • The source code included in Real-World Android by Tutorials is for your personal use only. You are NOT allowed to distribute or sell the source code in Real-World Android by Tutorials without prior authorization. • This book is for your personal use only. You are NOT allowed to sell this book without prior authorization, or distribute it to friends, coworkers or students; they would need to purchase their own copies. All materials provided with this book are provided on an “as is” basis, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software. All trademarks and registered trademarks appearing in this guide are the properties of their respective owners. raywenderlich.com 16
Page
17
Before You Begin This section tells you a few things you need to know before you get started, such as what hardware and software you’ll need, where to find the project files for this book and more. raywenderlich.com 17
Page
18
iWhat You Need To follow along with this book, you’ll need the following: • Android Studio 4.1.x: Available at https://developer.android.com/studio/. This is the environment in which you’ll develop most of the sample code in this book. raywenderlich.com 18
Page
19
iiBook Source Code & Forums Where to download the materials for this book The materials for this book can be cloned or downloaded from the GitHub book materials repository: • https://github.com/raywenderlich/adva-materials/tree/editions/1.0 Forums We’ve also set up an official forum for the book at https://forums.raywenderlich.com/ c/books/real-world-android-by-tutorials. This is a great place to ask questions about the book or to submit any errors you may find. raywenderlich.com 19
Page
20
iiiAbout the Cover Real-World Android by Tutorials In a far-reaching swath of boreal forests across North America and Europe lives the Northern Hawk Owl, featured here on the cover of our book. While not particularly large — its body being 14-16 inches long, weighing around 11 oz — it is a formidable and capable hunter. Most interesting is that this bird looks like an owl but behaves like a hawk. It is one of the only owls that are active during the day, but it still boasts the impressive hearing and sight of its nocturnal cousins: It can spot prey up to half a mile away and hear an animal stirring even under a foot of snow. raywenderlich.com 20
Comments 0
Loading comments...
Reply to Comment
Edit Comment