Inside the AndroidTM OS 9780134096346_print.indb 1 25/06/21 6:27 PM Android™ Deep Dive Series Visit informit.com/android for a complete list of available publications. The Android™ Deep Dive Series is for intermediate and expert developers who use Android Studio and Java, but do not have comprehensive knowledge of Android APIs and want to bolster their knowledge of fundamentally important topics. Each book in the series stands alone and provides idioms, frameworks, and engineering approaches. They provide in-depth information, correct patterns and idioms, and ways of avoiding bugs and other problems. Make sure to connect with us! informit.com/socialconnect Android_DeepDive_7x9.indd 1 5/21/2021 3:45:50 PM 9780134096346_print.indb 2 25/06/21 6:27 PM Android™ Deep Dive Series Inside the AndroidTM OS Visit informit.com/android for a complete list of available publications. Building, Customizing, The Android™ Deep Dive Series is for intermediate and expert developers who use Android Studio and Java, but do not have comprehensive knowledge of Android APIs and want to bolster their Managing and Operating knowledge of fundamentally important topics. Android System Services Each book in the series stands alone and provides idioms, frameworks, and engineering approaches. They provide in-depth information, correct patterns and idioms, and ways of avoiding bugs and other problems. G. Blake Meike Larry Schiefer Boston • Columbus • New York • San Francisco • Amsterdam • Cape Town Dubai • London • Madrid • Milan • Munich • Paris • Montreal • Toronto • Delhi • Mexico City São Paulo • Sydney • Hong Kong • Seoul • Singapore • Taipei • Tokyo Make sure to connect with us! informit.com/socialconnect Android_DeepDive_7x9.indd 1 5/21/2021 3:45:50 PM 9780134096346_print.indb 3 25/06/21 6:27 PM Many of the designations used by manufacturers and sellers to distinguish their products Editor-in-Chief are claimed as trademarks. Where those designations appear in this book, and the Mark Taub publisher was aware of a trademark claim, the designations have been printed with initial Acquisitions Editor capital letters or in all capitals. Malobika Android is a trademark of Google, Inc. Chakraborty Development Editor The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or Sheri Replin omissions. No liability is assumed for incidental or consequential damages in connection Managing Editor with or arising out of the use of the information or programs contained herein. Sandra Schroeder For information about buying this title in bulk quantities, or for special sales opportunities Senior Project Editor (which may include electronic versions; custom cover designs; and content particular to Lori Lyons your business, training goals, marketing focus, or branding interests), please contact our Copy Editor corporate sales department at [email protected] or (800) 382-3419. Paula Lowell For government sales inquiries, please contact [email protected]. Production Manager For questions about sales outside the U.S., please contact [email protected]. Aswini Kumar/ codeMantra Visit us on the Web: informit.com/aw Indexer Library of Congress Control Number: 2021940286 Ken Johnson Proofreader Copyright © 2022 Pearson Education, Inc. Donna E. Mulder All rights reserved. This publication is protected by copyright, and permission must be Compositor obtained from the publisher prior to any prohibited reproduction, storage in a retrieval codeMantra system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, request forms and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearsoned.com/permissions/. ISBN-13: 978-0-13-409634-6 ISBN-10: 0-13-409634-7 ScoutAutomatedPrintCode 9780134096346_print.indb 4 25/06/21 6:27 PM v Blake: For my siblings: Rusty, Annemarie. Mercy, and Roger. One! Larry: For Aidan and Ian. Don’t ever stop exploring and learning. v 9780134096346_print.indb 5 25/06/21 6:27 PM This page intentionally left blank 9780134096346_print.indb 6 25/06/21 6:27 PM Contents at a Glance Preface xiii 1 Why Android? 1 2 Booting Acme 9 3 Getting Started 35 4 The Kernel 49 5 Platform Security 67 6 System Startup: Installing and Booting the System 93 7 Android Startup: Dalvik and Zygote 115 8 Getting to Android: The HAL 133 9 Getting to Java: The JNI 153 10 Project Treble: Binderized HAL 183 11 Creating a Custom Binderized HAL 199 12 Clients for a Custom Binderized HAL 219 Index 233 9780134096346_print.indb 7 25/06/21 6:27 PM This page intentionally left blank 9780134096346_print.indb 6 25/06/21 6:27 PM Contents Preface xiii 1 Why Android? 1 Adopting Android 1 Full Stack 2 Broad Acceptance 2 Beautiful UI 2 Linux Based 2 Powerful Development Environment 3 Open Source 3 AOSP and Google 5 Other Choices 6 Micro-Controllers 6 Other RTOSs 7 Summary 8 2 Booting Acme 9 Setting Up a Build Machine 10 Downloading the Code 11 Repo 11 Forking the Source 15 Android Version Selection 16 Local Mirror 17 Hosted Git Repositories 18 Tree Snapshot 19 Repository Commit Pinning 19 Example: Local Mirror of Forked Repositories 19 Building an Image 24 Device Tools 27 fastboot 28 adb 29 Flashing the Device 30 Summary 33 9780134096346_print.indb 9 25/06/21 6:27 PM