Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 375 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
375
Dung lượng
13,71 MB
Nội dung
Shelve in Mobile Computing User level: Beginning–Advanced BOOKS FOR PROFESSIONALS BY PROFESSIONALS ® Android on x86 Android on x86: an Introduction to Optimizing for Intel ® Architecture serves two main purposes. First, it makes the case for adapting your applications onto Intel’s x86 architecture, including discussions of the business potential, the changing landscape of the Android marketplace, and the unique challenges and opportunities that arise from x86 devices. The fundamental idea is that extending your applications to support x86 or creating new ones is not difficult, but it is imperative to know all of the technicalities. This book is dedicated to providing you with an awareness of these nuances and an understanding of how to tackle them. Second, and most importantly, this book provides a one-stop detailed resource for best practices and procedures associated with the installation issues, hardware optimization issues, software requirements, programming tasks, and perfor- mance optimizations that emerge when developers consider the x86 Android devices. Optimization discussions dive into native code, hardware acceleration, and advanced profiling of multimedia applications. The authors have collected this information so that you can use the book as a guide for the specific require- ments of each application project. This book is not dedicated solely to code; instead it is filled with the information you need in order to take advantage of x86 architecture. It will guide you through installing the Android SDK for Intel Architecture, help you understand the differ- ences and similarities between processor architectures available in Android devices, teach you to create and port applications, debug existing x86 appli- cations, offer solutions for NDK and C++optimizations, and introduce the Intel Hardware Accelerated Execution Manager. This book provides the most useful information to help you get the job done quickly while utilizing best practices. Krajci Cummings 2613087814309 ISBN 978-1-4302-6130-8 53999 www.it-ebooks.info For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. www.it-ebooks.info v Contents at a Glance About the Authors ��������������������������������������������������������������������������� xxi Acknowledgments ������������������������������������������������������������������������ xxiii Introduction ������������������������������������������������������������������������������������xxv Chapter 1: History and Evolution of the Android OS ■ ����������������������� 1 Chapter 2: The Mobile Device and Operating System Landscape ■ ������ 9 Chapter 3: Beyond the Mobile App—A Technology Foundation ■ ��� 17 Chapter 4: Android Development—Business Overview ■ and Considerations ����������������������������������������������������������������������� 25 Chapter 5: The Intel Mobile Processor ■ ����������������������������������������� 33 Chapter 6: Installing the Android SDK for Intel ■ Application Development �������������������������������������������������������������� 47 Chapter 7: Creating and Porting NDK-Based ■ Android Applications �������������������������������������������������������������������� 75 Chapter 8: Debugging Android ■ ��������������������������������������������������� 131 Chapter 9: Performance Optimizations for Android ■ Applications on x86 �������������������������������������������������������������������� 185 Chapter 10: x86 NDK and C/C++ Optimizations ■ ������������������������� 259 Chapter 11: Using Intel Hardware Accelerated Execution ■ Manager on Windows, Mac OS, and Linux to Speed Up Android on x86 Emulation ���������������������������������������������������������� 285 www.it-ebooks.info ■ Contents at a GlanCe vi Chapter 12: Performance Testing and Profiling Apps ■ with Platform Tuning ������������������������������������������������������������������ 303 Appendix A: References ■ �������������������������������������������������������������� 331 Index ���������������������������������������������������������������������������������������������� 343 www.it-ebooks.info xxv Introduction We wrote Android on x86: an Introduction to Optimizing for Intel® Architecture to provide a one-stop, detailed resource for the topic’s best practices and procedures. e book encompasses the installation issues, hardware optimization issues, software requirements, programming tasks, and performance optimizations that emerge when you consider programming for x86-based Android devices. Having worked on related projects ourselves, we committed to collecting our experience and information into one book which could be used as a guide through any project’s specic requirements. We dove into ne-tuned optimizations, native code adjustments, hardware acceleration, and advanced proling of multimedia applications. e book is not dedicated solely to code, although you’ll nd plenty of code samples and case studies inside. Instead, we’ve lled Android on x86 with the information you need in order to take advantage of the x86 architectures. We will guide you through installing the Android Software Development Kit for Intel Architectures, help you understand the dierences and similarities between the processors available for commercial Android devices, teach you to create and port applications, debug existing x86 applications, oer solutions for NDK and C++ optimizations, and introduce the Intel Hardware Accelerated Execution Manager. e information we’ve pulled together provides the most useful help for getting your development job done quickly and well. Why Android on x86? In 2011, we experienced a paradigm shift in how we communicate. Smart device sales outpaced personal computer sales for the rst time. is changing of the guard emerged from three sources: Our increasing professional and social need for open, constant • communication e lower cost and compelling new features of smartphones and • tablets e increased ease of use and availability of mobile apps • In the next few years, mobile access to the Internet is likely to exceed access via laptops and desktops; the hardware we use to communicate may change, but our passion for connectivity anytime, anywhere is sure to continue. www.it-ebooks.info ■ IntroduCtIon xxvi Holding more than 80% of the market share for smartphone shipments worldwide, Google’s Android operating system has proven to be the leader of this mobile revolution. e key reasons for the success of Android are its open platform and exible partnerships. e wealth of open-source resources available for Android developers spurs the creation of more apps, giving consumers more choices. In addition, the open platform supports a competitive and diverse hardware environment. As the market for high-performing mobile devices widens, Google has teamed up with Intel to envision the next frontier for Android: getting the OS to run on devices with Intel architectures inside. e journey towards Android on Intel architectures began unocially in 2009, when a group of developers started the open source Android-x86 initiative in order to port Android onto devices running on Intel x86 processors. Soon after, with the ocial Android on Intel architecture project, Intel started contributing code and resources to the Android Open Source Project (AOSP). In 2012, the rst Android smartphones featuring Intel processors were released to market worldwide; by late 2013, Android smartphones and tablets with unprecedented processing power were entering United States’ markets. Most recently, the two groups committed to getting Android to run on 64-bit devices, including netbooks, laptops, and traditional desktop PCs, meaning that in 2014, Android will break into a market historically dominated by Microsoft Windows and Apple OSX. Android will bring its enormous, thriving community of application developers forward to a wide range of devices and hardware architectures. e collaboration brings a number of benets from both groups. Intel’s x86 architecture comes with 35 years of well-documented processing excellence, a mature developer ecosystem, and a sophisticated set of development tools. In terms of performance, Intel’s latest chips strike a balance between high performance and low power consumption that is ideal for smartphones, tablets, and netbooks. Native x86 emulator support is a key feature of the latest Android SDK versions, and Intel is dedicated to providing developers with a host of tools for optimizing Android application performance for their chips. By expanding onto both 32-bit and 64-bit architectures, the Android landscape is opening wide. More Android-equipped mobile devices with Intel processors are hitting shelves and our ngertips every day, and the upcoming addition of Intel-powered netbooks and laptops will shape the environment into something amazing. A new Android experience will take shape, one that remains diverse and becomes optimized for larger screens, robust multi-windowing, and ever-faster processor speeds. It’s an exciting time, and we hope that developers will seize this new opportunity to expand Android’s horizons. Who Is This Book For? is book is aimed at two general categories of people: developers and those interested in choosing Android x86 as a platform for their applications. With this in mind, the beginning chapters focus on much more high-level, nontechnical questions, so that people from all technical backgrounds can make informed choices. e later chapters focus heavily on the developers’ side of the world, starting with a basic foundation of microprocessor architectures and Android development environments and then building www.it-ebooks.info ■ IntroduCtIon xxvii to very advanced, performance-focused content. Our goal is to reach the entire spectrum of people who are interested in Android on x86, and to do our best at getting you the answers you need. We really hope you enjoy the book. We certainly have enjoyed exploring this topic, and look forward to seeing what will happen in this rapidly-expanding eld in the upcoming years. We would also like to note that while we may know a thing or two about Android, we recognize that we are certainly not the most knowledgeable about everything. Feel free to challenge any information that you nd in this book – we encourage you to use outside resources and really involve yourself in the communities that surround this technology! www.it-ebooks.info 1 Chapter 1 History and Evolution of the Android OS I’m going to destroy Android, because it’s a stolen product. I’m willing to go thermonuclear war on this. —Steve Jobs, Apple Inc. Android, Inc. started with a clear mission by its creators. According to Andy Rubin, one of Android’s founders, Android Inc. was to develop “smarter mobile devices that are more aware of its owner’s location and preferences.” Rubin further stated, “If people are smart, that information starts getting aggregated into consumer products.” The year was 2003 and the location was Palo Alto, California. This was the year Android was born. While Android, Inc. started operations secretly, today the entire world knows about Android. It is no secret that Android is an operating system (OS) for modern day smartphones, tablets, and soon-to-be laptops, but what exactly does that mean? What did Android used to look like? How has it gotten where it is today? All of these questions and more will be answered in this brief chapter. Origins Android first appeared on the technology radar in 2005 when Google, the multibillion- dollar technology company, purchased Android, Inc. At the time, not much was known about Android and what Google intended on doing with it. Information was sparse until 2007, when Google announced the world’s first truly open platform for mobile devices. The First Distribution of Android On November 5, 2007, a press release from the Open Handset Alliance set the stage for the future of the Android platform. The alliance stated some of the goals of Android as, “fostering innovation on mobile devices and giving consumers a far better user experience than much of what is available on today’s mobile platforms.” www.it-ebooks.info CHAPTER 1 ■ HisToRy And EvoluTion of THE AndRoid os 2 At that time, more than 2 billion mobile phones were used worldwide, compared to the 4.6 billion used as of 2010. However, there was no coordination of platforms between the various companies that provided mobile devices. With the introduction of Android, a single operating system removed the need for reimplementation of phone applications and middleware. The companies creating new devices could now focus much more intently on the hardware and underlying components. But these companies weren’t the only ones who benefited from the launch of Android; software developers could now release applications to multiple devices with very few changes to the underlying code base. This allowed developers to spend more time working on the applications these phones were running and create the rich and impressive applications that we are all used to. This was in part due to the open source philosophy behind Android, and the Apache license, which is the license used on most of the Android source code. Open Source Apache License The Apache License is just one of many different licenses that exist in the open source community. While there are differences in all of these licenses, they all facilitate the same open source mindset that is best summed up as follows: “Free software” is a matter of liberty, not price. To understand the concept, you should think of “free” as in “free speech,” not as in “free beer.” —Richard M. Stallman The Apache License specifically grants freedom to use the software for any purpose, as well as the ability to distribute, modify, or distribute modified versions. The Apache License is also permissive, meaning that modified versions do not have to succumb to the Apache License. For more information about the Apache License, go to http://www.apache.org/licenses/LICENSE-2.0. What Is Android? So what exactly is Android? Android OS is the open source technology stack that runs on over 400 million devices worldwide. This technology stack consists of various components that allow developers and device manufacturers to work independently. This can be broken into five primary pieces—applications, application frameworks, native libraries, Android runtime, and the Linux kernel—as shown in Figure 1-1. www.it-ebooks.info CHAPTER 1 ■ HisToRy And EvoluTion of THE AndRoid os 3 Applications The applications exist at the highest level. These are the tools that everyone who uses Android is most familiar with. Android comes with various robust applications that support everyday phone needs, such as messaging, e-mail, Internet browsing, and various third-party applications. These applications are primarily written in the Java programming language. In a recent legal case with Oracle, Google’s Android chief Andy Rubin explained why he chose Java as the language of use for developers. Rubin’s primary points were that Java had a well-known brand name and that Java is taught in almost all universities worldwide. These applications are distributed through various means, most commonly from the Google Play Store (formerly Android Marketplace); however, the Android OS also supports installation of applications over a USB connection and from an SD card. Figure 1-1. The Android System Architecture Android OS (Wikipedia) http://en.wikipedia.org/wiki/File:Android-System- Architecture.svg www.it-ebooks.info [...]... applications developed years before It is important to note that new applications cannot run on old systems If you use the Android Software Development Kit version 4.1 to develop an application, that application cannot run on a 2.3 Android device However, an application that is written for a 2.3 Android device will run without modification on a 4.1 device Why x86 and Android Are Right for You Android. .. permission, the application simply crashes Another major section of application security is the separation of information between applications If an application can freely interact with other applications on the phone, malicious things can occur There are various situations when users need applications to be able to send messages to each other Android s inner-application messaging system uses the concept... Applications written for Android will run on all Android devices that are the same version, regardless of the underlying processor This means that applications written and tested on ARM Android devices require little to no effort to be used to their full capabilities on Intel x86 Android devices The exception to this is applications that use Android s NDK However, with a simple recompile, the application... the introduction of x86 to the Android software stack, applications written for x86 systems are now supported, which expands the market even further The Android Market Share According to International Data Corporation (IDC), Android s second quarter 2013 sales have reached 187 million units shipped The previous record–100 million units sold–was broken by Android in 2012 These numbers bring Android up... study conducted by U.S Energy Information Administration, just fewer than 30 million Americans do not have a home computer of some kind Compared to the 80 million Americans who have one or more personal computers, the United States is more connected than ever before 17 www.it-ebooks.info CHAPTER 3 ■ Beyond the Mobile App—A Technology Foundation Applications on personal computers have come a long way... the creation and induction of smartphones into the marketplace The ability to use and control your home computer from your smartphone, and vice versa, has taken off You can view your desktop on the go, sync files and contacts from your phone to your laptop, use your phone as a remote control, or stream videos from your phone directly to your television Automotive Modern cars are loaded with tons of new... iPhone is the lack of cellular communications on the iPod Touch Most applications created for the iPhone run on the iPod Touch with little to no code modifications on the developer’s side The iPod Touch offers an option to play with the iOS without having to pay the subscription fee of iPhone’s cellular plan, or the added cost of the iPad BlackBerry Sometimes referred to as the original smartphone,... back to the phones of the early 21st Century Simon Personal Communicator Many credit IBM and BellSouth’s Simon Personal Communicator (1994) with being the first smartphone Simon combined many of the features of personal digital assistants (PDAs) with the features of existing cellular devices In addition to being able to do cellular communication, Simon had a touch screen and various applications such as... for virtual keyboards, support for widgets on the home screen, animations added in various places, and auto-pairing and stereo support for Bluetooth-capable devices On a humorous side note, from Cupcake and onward all Android versions to date have been named after desserts Donut (1.6) On September 15, 2009, Google released Android version 1.6, named Donut With Donut came an updated Linux kernel from 2.6.27... concern to the provider than the customer A good security system can be explained in depth, without being compromised Android is one of these systems The security that surrounds the platform and its components is well documented and researched For more information and technical details about the system, consult Android on x86 Security Guide Application Security With the introduction of an application . source Android- x86 initiative in order to port Android onto devices running on Intel x86 processors. Soon after, with the ocial Android on Intel architecture project, Intel started contributing. in Mobile Computing User level: Beginning–Advanced BOOKS FOR PROFESSIONALS BY PROFESSIONALS ® Android on x86 Android on x86: an Introduction to Optimizing for Intel ® Architecture serves two main purposes application developers only have to deal with a few different situations. iOS is featured on three main platforms—iPhone, iPad, and iPod Touch. • iPhone—The iPhone is Apple’s version of a smartphone,