Android booting sequece and setup and debuggingPresentation Transcript
Android SDK introduction
Android SDK library distribution according to functionality
Activity, Services and Broadcast Recievers
View and related classes, List
Intents, Adapters, AlertDialouge, Notifications.
ContentProviders and Databases
Telephony and SMS
Bluetooth and WiFi
Activity, Services and Broadcast Receivers Activities – The entry class into Android application, responsible for loading the first screen and take user inputs -onCreate() -onDestroy(); -onPause(); -onStart(); Services – The class used to create programs that run in background, and have no UI Broadcast receiver – The android component responsible to receive responses from system wide processes and send the event notification to the registered processes
Views View – Responsible for the UI in the application. A view is put on a layout and then as per programming directives a layout is laid
Intents, Adapters, AlertDialogue and Notifications
Intents - Intents are used as a message-passing mechanism that works both within application, and between applications. Intents can be used to:
Start an Activity or service
Broadcast an event
Explicitly start an Activity
Adapters - Adapters are bridging classes that bind data to Views used in the user interface. And load dynamic data in the UI
AlertDialouge – To show the user the Alert and seek any response, and then perform any action on it
Notification - notify the user on any
event in the notification bar
Content Providers and Data storage
Content Providers - Content providers are interfaces to store and retrieve data and make it accessible to all applications. They're the only way to share data across applications
Data Storage - Android provides several options for you to save persistent application data. The solution you choose depends on your specific needs
Shared Preferences Store private primitive data in key-value pairs .
Internal Storage Store private data on the device memory.
External Storage Store public data on the shared external storage.
SQLite Databases Store structured data in a private database .
Network Connection Store data on the web with your own network server.
Data storage methods in brief
Shared preferences - The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types
getSharedPreferences(), getPreferences() – use these methods to obtain multiple or single preferences for the application respectively .
Edit() or putBoolean(), putString() etc – use the former method to use SharedPreference.Editor, and later methods to directly specify and enter the data
Internal Storage - We can save files directly on the device's internal storage, by using the FileStream class and its methods – write() and read() etc.
External Storage – The external storage device in Android mobiles is the SD card. We can save and retrieve data on SD card using some of the methods –
getExternalStorageState() – to check the availability and status of SD card
getExternalStorageDirectory() – to open the file which represent the root of the external storage file system.
SQLite Database Android provides full support for SQLite databases. Any databases you create will be accessible by name to any class in the application, but not outside the application. To create a new SQLite database is to create a subclass of SQLiteOpenHelper and override the onCreate() method, in which you can execute a SQLite command to create tables in the database. getWritableDatabase() and getReadableDatabase() To write and read from database, their return type is SQLiteDatabase class that provides methods for database operations . SQLiteDatabase query() methods – to execute queries, these methods takes various parameters, for various quires. Cursor It’s the return type of any SQLite query and the mechanism with which you can navigate results from a database query and read rows and columns .
Maps and GeoCoding
Important classes related to GPS capabilities in Android
LocationManager - This class provides access to the system location services. These services allow applications to obtain periodic updates of the device's geographical location.
Proximity alert setting
Geocoding - Geocoding is the process of transforming a street address or other description of a location into a (latitude, longitude) coordinate. Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into a (partial) address.
Geocoder(Context context, Locale locale)
Android App Widgets App Widgets are miniature application views that can be embedded in other applications (such as the Home screen) and receive periodic updates. AppWidgetProviderInfo object Describes the metadata for an App Widget. AppWidgetProvider class implementation Defines the basic methods that allow you to programmatically interface with the App Widget, based on broadcast events. onUpdate() onDeleted(Context, int) onEnabled(Context) onReceive(Context, Intent) View class to draw the widget layout
Multimedia content Multimedia playback in Android is handled by the MediaPlayer class. You can play media stored in application resources, local files, Content Providers, or streamed from a network URL create(appContext, R.raw.my_audio); setDataSource("/sdcard/test2.3gp"); prepare(); For playing Video, we have to use a VideoView to act a surface to display the video MediaRecorder class and associated methods are used for recording video Using Intents Actions we can use camera and audio recording features
Telephony and SMS
Provides APIs for monitoring the basic phone information, such as the network type and connection state, plus utilities for manipulating phone number strings.
SmsManager - Manages SMS operations such as sending data, text, and pdu SMS messages. Get this object by calling the static method SmsManager.getDefault()
sendTextMessage() – to send text SMS
Bluetooth and WiFi
Using the Bluetooth APIs, an Android application can perform the following:
Scan for other Bluetooth devices
Query the local Bluetooth adapter for paired Bluetooth devices
Connect to other devices through service discovery
Transfer data to and from other devices
Manage multiple connections
BluetoothAdapter - The BluetoothAdapter is the entry-point for all Bluetooth interaction.
BluetoothDevice - Represents a remote Bluetooth device.
BluetoothSocket - This is the connection point that allows an application to exchange data with another Bluetooth device via InputStream and OutputStream.
BluetoothServerSocket - - Represents an open server socket that listens for incoming requests (similar to a TCP ServerSocket).
The WifiManager represents the Android Wi-Fi Connectivity Service. It can be used to configure Wi-Fi network connections, manage the current Wi-Fi connection, scan for access points, and monitor changes in Wi-Fi connectivity
Android Booting Sequence Stages In Booting of Android OS from power on Stage 1 : Power on and boot ROM code execution Stage 2 : The boot loader loading Stage 3 : Starting of Linux kernel Stage 4 : The init process Stage 5 : Zygote and Dalvik Stage 6 : The system server initiation
Android Booting Sequence Stage 1 Power on and boot ROM code execution
At power on the CPU will be in a state where no initializations have been done. Internal clocks are not set up and the only memory available is the internal RAM.
When power supplies are stable the execution will start with the Boot ROM code. The Boot ROM code will detect the boot media using a system register that maps to some physical balls on the ASIC. This is to determine where to find the first stage of the boot loader.
Once the boot media sequence is established the boot ROM will try to load the first stage boot loader to internal RAM. Once the boot loader is in place the boot ROM code will perform a jump and execution continues in the boot loader.
Android Booting Sequence Stage 2 The boot loader loading
The first boot loader stage will detect and set up external RAM.
Once external RAM is available and the system is ready the to run something more significant the first stage will load the main boot loader and place it in external RAM.
The second stage of the boot loader is the first major program that will run. This may contain code to set up file systems, additional memory, network support, loading code for the modem CPU and setting up low level memory protections and security options.
Once the boot loader is done with any special tasks it will look for a Linux kernel to boot. It will load this from the boot media (or some other source depending on system configuration) and place it in the RAM.
Once the boot loader is done it will perform a jump to the Linux kernel, usually some decompression routine, and the kernel assumes system responsibility
Android Booting Sequence Stage 3 Starting of Linux kernel
It will set up everything that is needed for the system to run. Initialize interrupt controllers, set up memory protections, caches and scheduling.
Once the memory management units and caches have been initialized the system will be able to use virtual memory and launch user space processes.
The kernel will look in the root file system for the init process (found under system/core/init in the Android open source tree) and launch it as the initial user space process.
Android Booting Sequence Stage 4 The init process
The init process in Android will look for a file called init.rc. This is a script that describes the system services, file system and other parameters that need to be set up. The init.rc script is placed in system/core/rootdir in the Android open source project.
The init process will parse the init script and launch the system service processes.
Android Booting Sequence Stage 5 Zygote and Dalvik
init runs the C++ program /system/bin/app_process, and gives the resulting process the name "zygote“
app_process executes, and executes a runtime environment for a dalvik class
app_process does a 'runtime.start("com.android.internal.os.ZygoteInit", startSystemServer)
The profiler is started the Zygote socket is registered (for later communication to start apps) classes and resources are preloaded if startSystemServer is set, then the system server is started
Zygote runs in "select loop mode", where a single process spins waiting for communication to start subsequent apps.
Eventually, a call is made to Zygote.forkAndSpecialize(), which does the actual forking
Android Booting Sequence Stage 6 The system server initiation The system server is the first java component to run in the system. It will start all the Android services such as telephony manager and bluetooth. Start up of each service is currently written directly into the run method of the system server. source can be found in the file frameworks/base/services/java/com/android/server/SystemServer.java in the open source project. Once the System Server is up and running and the system boot has completed there is a standard broadcast action called ACTION_BOOT_COMPLETED. To start your own service, register an alarm or otherwise make your application perform some action after boot you should register to receive this broadcast intent .
Steps for setting up Android application development environment
Basic System requirements
Supported Operating Systems
Windows XP (32-bit), Vista (32- or 64-bit), or Windows 7 (32- or 64-bit)
Mac OS X 10.5.8 or later (x86 only)
Linux (tested on Ubuntu Linux, Lucid Lynx)
Supported Development Environments
JDK 5 or JDK 6 (JRE alone is not sufficient)
Android Development Tools plugin (recommended)
Not compatible with Gnu Compiler for Java (gcj)
Other development environments or IDEs
Apache Ant 1.8 or later
Open the Eclipse IDE, click on the tab "Workbench", this will take you to the work bench.
Go to Help -> Install New Software
3. Now in the work with tab, click on Add button, and then follow the instructions given in the ADT(Android Development Tool) installation link - The ADT URL is - follow the instructions in the installation, and then you must see the following screen. Then click on next, and then let the installation finish.
4 . Once the IDE has restarted, go to Window -> Preferences. Then click on the "Android" tab on the screen coming on the left hand side
Then, again go to Windows -> Android Device and AVD manager, then click on Available packages tab, in the list coming on the left hand side of the screen, in the main window, a list of currently available Android version and other extensions for development of Samsung Galaxy Tab device application development will be shown
Set up AVD An Android Virtual Device (AVD) is an emulator configuration that lets you model an actual device by defining hardware and software options to be emulated by the Android Emulator
A hardware profile : Defines the hardware features of the virtual device. For example, you can define whether the device has a camera, whether it uses a physical QWERTY keyboard or a dialing pad, how much memory it has,
A mapping to a system image: You can define what version of the Android platform will run on the virtual device. You can choose a version of the standard Android platform or the system image packaged with an SDK add-on.
Other options : You can specify the emulator skin you want to use with the AVD, which lets you control the screen dimensions, appearance, and so on. You can also specify the emulated SD card to use with the AVD.
A dedicated storage area on your development machine: the device's user data (installed applications, settings, and so on) and emulated SD card are stored in this area .
Features of AVD
Go to Windows -> Android Device and AVD manager -> Virtual devices. Then click on the "New" tab on the left side of the screen. This will pop a device box, which will ask for details of the AVD.
Select your SDK, and the functionalities you want to include in your device - this includes - Camera, internet, SD card, GPS etc and all the functionalities supported by Android APIs. Once done, click on "Create Device" tab.
Steps to setup AVD
What you can do with AVD
Emulate SD card
Emulate GPS, accelerometer, camera, video recorder etc
Load applications inside the emulated SD card.
Enter real time data
Use QWERTY key board
Multiple language support.
Use native emulator apps like google maps etc.
Perform real time debugging
Customize settings and themes.
Debugging Android applications The main components that comprise a typical Android debugging environment are: adb adb acts as a middleman between a device and your development system. It provides various device management capabilities, including moving and syncing files to the emulator, running a UNIX shell on the device or emulator, and providing a general means to communicate with connected emulators and devices. Dalvik Debug Monitor Server DDMS is a graphical program that communicates with your devices through adb. DDMS can capture screenshots, gather thread and stack information, spoof incoming calls and SMS messages, and has many other features. Device or Android Virtual Device Your application must run in a device or in an AVD so that it can be debugged. An adb device daemon runs on the device or emulator and provides a means for the adb host daemon to communicate with the device or emulator.
ADB : Android Debugger bridge
Android Debug Bridge (adb) is a versatile tool lets you manage the state of an emulator instance or Android-powered device. It is a client-server program that includes three components:
A client , which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
A server , which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
A daemon , which runs as a background process on each emulator or device instance.
You can find the adb tool in <sdk>/platform-tools/.
Emulator 1, console: 5554 Emulator 1, adb: 5555 Emulator 2, console: 5556 Emulator 2, adb: 5557 ... Install Application on ADB - adb install <path_to_apk> Port forwarding - You can use the forward command to set up arbitrary port forwarding adb forward tcp:6100 tcp:7100 adb forward tcp:6100 local:logd File transfer across system and ADB - You can use the adb commands pull and push to copy files to and from an emulator/device instance's data file. adb pull <remote> <local> adb push <local> <remote>
Dalvik Debug Monitor Server : DDMS Android ships with a debugging tool called the Dalvik Debug Monitor Server (DDMS), which provides port-forwarding services, screen capture on the device, thread and heap information on the device, logcat, process, and radio state information, incoming call and SMS spoofing, location data spoofing, and more. Running DDMS DDMS is integrated into Eclipse and is also shipped in the tools/ directory of the SDK. DDMS works with both the emulator and a connected device. If both are connected and running simultaneously, DDMS defaults to the emulator. From Eclipse: Click Window > Open Perspective > Other... > DDMS . From the command line: Type ddms (or ./ddms on Mac/Linux) from the tools/ directory.
When DDMS starts, it connects to adb. When a device is connected, a VM monitoring service is created between adb and DDMS, which notifies DDMS when a VM on the device is started or terminated. Once a VM is running, DDMS retrieves the the VM's process ID (pid), via adb, and opens a connection to the VM's debugger, through the adb daemon (adbd) on the device. DDMS can now talk to the VM using a custom wire protocol.
DDMS assigns a debugging port to each VM on the device. Typically, DDMS assigns port 8600 for the first debuggable VM, the next on 8601, and so on
By default, DDMS also listens on another debugging port, the DDMS "base port" (8700, by default). The base port is a port forwarder, which can accept VM traffic from any debugging port and forward it to the debugger on port 8700.
ADB - DDMS
Viewing heap usage for a process
DDMS allows you to view how much heap memory a process is using. This information is useful in tracking heap usage at a certain point of time during the execution of your application.
To view heap usage for a process:
In the Devices tab, select the process that you want to see the heap information for.
Click the Update Heap button to enable heap information for the process.
In the Heap tab, click Cause GC to invoke garbage collection, which enables the collection of heap data. When the operation completes, you will see a group of object types and the memory that has been allocated for each type. You can click Cause GC again to refresh the data.
Click on an object type in the list to see a bar graph that shows the number of objects allocated for a particular memory size in bytes.
Tracking memory allocation of objects
DDMS provides a feature to track objects that are being allocated to memory and to see which classes and threads are allocating the objects. This allows you to track, in real time, where objects are being allocated when you perform certain actions in your application
To track memory allocation of objects:
In the Devices tab, select the process that you want to enable allocation tracking for.
In the Allocation Tracker tab, click the Start Tracking button to begin allocation tracking. At this point, anything you do in your application will be tracked.
Click Get Allocations to see a list of objects that have been allocated since you clicked on the Start Tracking button. You can click on Get Allocations again to append to the list new objects that that have been allocated.
To stop tracking or to clear the data and start over, click the Stop Tracking button .
Click on a specific row in the list to see more detailed information such as the method and line number of the code that allocated the object.
Working with an emulator or device's file system
DDMS provides a File Explorer tab that allows you to view, copy, and delete files on the device. This feature is useful in examining files that are created by your application or if you want to transfer files to and from the device.
To work with an emulator or device's file system:
In the Devices tab, select the emulator that you want to view the file system for.
To copy a file from the device, locate the file in the File Explorer and click the Pull file button.
To copy a file to the device, click the Push file button on the File Explorer tab.
Examining thread information The Threads tab in DDMS shows you the currently running threads for a selected process. In the Devices tab, select the process that you want to examine the threads for. Click the Update Threads button. In the Threads tab, you can view the thread information for the selected process.
Starting method profiling
Method profiling is a means to track certain metrics about a method, such as number of calls, execution time, and time spent executing the method.
Before you start method profiling in DDMS, be aware of the following restrictions:
To start method profiling:
On the Devices tab, select the process that you want to enable method profiling for.
Click the Start Method Profiling button.
Interact with your application to start the methods that you want to profile.
Click the Stop Method Profiling button. DDMS stops profiling your application and opens Traceview with the method profiling information that was collected between the time you clicked on Start Method Profiling and Stop Method Profiling .
LogCat is integrated into DDMS, and outputs the messages that you print out using the Log class along with other system messages such as stack traces when exceptions are thrown. View the Reading and Writing Log Messages. topic for more information on how to log messages to the LogCat.
When you have set up your logging, you can use the LogCat feature of DDMS to filter certain messages with the following buttons:
You can also setup your own custom filter to specify more details such as filtering messages with the log tags or with the process id that generated the log message. The add filter, edit filter, and delete filter buttons let you manage your custom filters .
Changing network state, speed, and latency Voice - unregistered, home, roaming, searching, denied Data - unregistered, home, roaming, searching, denied Speed - Full, GSM, HSCSD, GPRS, EDGE, UMTS, HSDPA Latency - GPRS, EDGE, UMTS Spoofing calls or SMS text messages Voice - Enter a number in the Incoming number field and click Call to send a simulated call to the emulator or phone. Click the Hang up button to terminate the call. SMS - Enter a number in the Incoming number field and a message in the Message : field and click the Send button to send the message. Setting the location of the phone Manual - set the location by manually specifying decimal or sexagesimal longitude and latitude values. GPX - GPS eXchange file KML - Keyhole Markup Language file
References http://www.developer.android.com What is Android? Android Developers Debugging Managing Virtual Devices Android Debug Bridge App Widgets Data Storage Content Providers Bluetooth Activity ActivityManager Service SharedPreferences Geocoder LocationManager WifiManager SmsManager android.telephony Topics from Android developer website