44

Android booting sequece and setup and debugging

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Android booting sequece and setup and debugging
Page 2: Android booting sequece and setup and debugging

Android SDK introduction

Android SDK library distribution according to functionality

1.Activity, Services and Broadcast Recievers2.View and related classes, List3.Intents, Adapters, AlertDialouge, Notifications.4.SharedPreferences5.ContentProviders and Databases6.Maps, Geocoding7.Widget 8.Multimedia9.Telephony and SMS10.Bluetooth and WiFi11.Sensors

Page 3: Android booting sequece and setup and debugging

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

Page 4: Android booting sequece and setup and debugging

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

Page 5: Android booting sequece and setup and debugging

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

.

Page 6: Android booting sequece and setup and debugging

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

1.Shared Preferences Store private primitive data in key-value pairs.

2.Internal Storage Store private data on the device memory.

3. External Storage Store public data on the shared external storage.

4.SQLite Databases Store structured data in a private database.

5.Network Connection Store data on the web with your own network server.

Page 7: Android booting sequece and setup and debugging

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 – 1.getExternalStorageState() – to check the availability and status of SD card2.getExternalStorageDirectory() – to open the file which represent the root of the external storage file system.

Page 8: Android booting sequece and setup and debugging

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.

Page 9: Android booting sequece and setup and debugging

Maps and GeoCoding

Important classes related to GPS capabilities in Android

1.LocationManager - This class provides access to the system location services. These services allow applications to obtain periodic updates of the device's geographical location.

getLastKnownLocation(provider);2.Proximity alert setting3.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) Geocoder(Context context)

Page 10: Android booting sequece and setup and debugging

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

Page 11: Android booting sequece and setup and debugging

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

Page 12: Android booting sequece and setup and debugging

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.

1.CellLocation, NeighboringCellInfo 2.PhoneNumberUtils3.PhoneStateListener4.ServiceState. 5.SignalStrength. 6.TelephonyManager

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

Page 13: Android booting sequece and setup and debugging

Bluetooth and WiFi

Using the Bluetooth APIs, an Android application can perform the following:Scan for other Bluetooth devicesQuery the local Bluetooth adapter for paired Bluetooth devicesConnect to other devices through service discoveryTransfer data to and from other devicesManage 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

Page 14: Android booting sequece and setup and debugging

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

Page 15: Android booting sequece and setup and debugging

Android Booting Sequence Stage 1

Power on and boot ROM code execution

1. 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.

2. 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.

3. 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.

Page 16: Android booting sequece and setup and debugging

Android Booting Sequence Stage 2

The boot loader loading

1. The first boot loader stage will detect and set up external RAM.2. 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.

3. 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.

4. 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.

5. 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

Page 17: Android booting sequece and setup and debugging

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.

1. Once the memory management units and caches have been initialized the system will be able to use virtual memory and launch user space processes.2. 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.

Page 18: Android booting sequece and setup and debugging

Android Booting Sequence Stage 4

The init process

1. 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.

2. The init process will parse the init script and launch the system service processes.

Page 19: Android booting sequece and setup and debugging

Android Booting Sequence Stage 5

Zygote and Dalvik

1. init runs the C++ program /system/bin/app_process, and gives the resulting process the name "zygote“

2. app_process executes, and executes a runtime environment for a dalvik class

3. app_process does a 'runtime.start("com.android.internal.os.ZygoteInit", startSystemServer)

4. com.android.internal.os.ZygoteInit:main() starts executing5. 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

6. Zygote runs in "select loop mode", where a single process spins waiting for communication to start subsequent apps.

7. Eventually, a call is made to Zygote.forkAndSpecialize(), which does the actual forking

Page 20: Android booting sequece and setup and debugging

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.

Page 21: Android booting sequece and setup and debugging

Steps for setting up Android application development environment

Basic System requirements

Supported Operating Systems1. Windows XP (32-bit), Vista (32- or 64-bit), or Windows 7 (32- or

64-bit)2. Mac OS X 10.5.8 or later (x86 only)3. Linux (tested on Ubuntu Linux, Lucid Lynx)

Supported Development EnvironmentsEclipse IDE

1.JDK 5 or JDK 6 (JRE alone is not sufficient)2.Android Development Tools plugin (recommended)3.Not compatible with Gnu Compiler for Java (gcj)Other development environments or IDEs1.Apache Ant 1.8 or later

Page 22: Android booting sequece and setup and debugging

1. Open the Eclipse IDE, click on the tab "Workbench", this will take you to the work bench.

2. Go to Help -> Install New Software

Page 23: Android booting sequece and setup and debugging

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.

Page 24: Android booting sequece and setup and debugging

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

Page 25: Android booting sequece and setup and debugging

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

Page 26: Android booting sequece and setup and debugging

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

Page 27: Android booting sequece and setup and debugging

1. 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,

2. 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.

3. 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.

4. 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

Page 28: Android booting sequece and setup and debugging

1. 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.

2. 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

Page 29: Android booting sequece and setup and debugging

What you can do with AVD

a. Emulate SD cardb. Emulate GPS, accelerometer, camera, video recorder etcc. Run internetd. Load applications inside the emulated SD card.e. Enter real time dataf. Use QWERTY key boardg. Multiple language support.h. Use native emulator apps like google maps etc.i. Perform real time debuggingj. Customize settings and themes.

Page 30: Android booting sequece and setup and debugging

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.

Page 31: Android booting sequece and setup and debugging

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/.

Page 32: Android booting sequece and setup and debugging

Emulator 1, console: 5554Emulator 1, adb: 5555Emulator 2, console: 5556Emulator 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:7100adb 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>

Page 33: Android booting sequece and setup and debugging

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.

Page 34: Android booting sequece and setup and debugging

1. 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.

2. 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

3. 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

Page 35: Android booting sequece and setup and debugging
Page 36: Android booting sequece and setup and debugging

Using 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:1.In the Devices tab, select the process that you want to see the heap information for.2.Click the Update Heap button to enable heap information for the process.3.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.4.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.

Page 37: Android booting sequece and setup and debugging

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:1.In the Devices tab, select the process that you want to enable allocation tracking for.2.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.3.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.4.To stop tracking or to clear the data and start over, click the Stop Tracking button.5.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.

Page 38: Android booting sequece and setup and debugging

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:1.In the Devices tab, select the emulator that you want to view the file system for.2.To copy a file from the device, locate the file in the File Explorer and click the Pull file button.3.To copy a file to the device, click the Push file button on the File Explorer tab.

Page 39: Android booting sequece and setup and debugging

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.

Page 40: Android booting sequece and setup and debugging

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:1.On the Devices tab, select the process that you want to enable method profiling for.2.Click the Start Method Profiling button.3.Interact with your application to start the methods that you want to profile.4.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.

Page 41: Android booting sequece and setup and debugging

Using LogCat

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:

1.Verbose2.Debug3.Info4.Warn5.ErrorYou 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.

Page 42: Android booting sequece and setup and debugging

Changing network state, speed, and latencyVoice - unregistered, home, roaming, searching, deniedData - unregistered, home, roaming, searching, deniedSpeed - Full, GSM, HSCSD, GPRS, EDGE, UMTS, HSDPALatency - GPRS, EDGE, UMTSSpoofing calls or SMS text messagesVoice - 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 phoneManual - set the location by manually specifying decimal or sexagesimal longitude and latitude values.GPX - GPS eXchange fileKML - Keyhole Markup Language file

Page 44: Android booting sequece and setup and debugging