Sunday, 3 August 2014

What is the directory structure of android AOSP root tree?

This is short version of what you will find when you download the Android source. I will leave out some minor directories and dig deeper into a couple of the important ones. Basically what you will get (based on the (Kit Kat - 4.4.4), in alphabetical order:
  • Bionic - the C-runtime for Android. Note that Android is not using glibc like most Linux distributions. Instead the c-library is called bionic and is based mostly on BSD-derived sources. In this folder you will find the source for the c-library, math and other core runtime libraries.
  • Bootable - boot and startup related code. Some of it is legacy, the fastboot protocol info could be interesting since it is implemented by boot loaders in a number of devices such as the Nexus ones.
  • Build - the build system implementation including all the core make file templates. An important file here is the script that will help you a lot when working with the platform source. Running this script in a shell will enable commands to setup environment variables, build specific modules and grep in source code files.
  • Cts - the compatability tests. The test suite to ensure that a build complies with the Android specification.
  • Dalvik - the source code for the implementation of the Dalvik Virtual Machine
  • Development - projects related to development such as the source code for the sdk and ndk tools. Normally not a folder you touch when working with the platform for a target.
  • Device - product specific code for different devices. This is the place to find hardware modules for the different Nexus devices, build configurations and more.
  • External - contains source code for all external open source projects such as SQLite, Freetype and webkit.
  • Frameworks - this folder is essential to Android since it contains the sources for the framework. Here you will find the implementation of key services such as the System Server with the Package- and Activity managers. A lot of the mapping between the java application APIs and the native libraries is also done here.
  • Hardware - hardware related source code such as the Android hardware abstraction layer specification and implementation. This folder also contains the reference radio interface layer (to communicate with the modem side) implementation.
  • Kernel - not part of the default source download but you can get access to this code either by downloading it manually or by adding the repository to the repo tool. Contains the sources for the Android version of the Linux kernel.
  • Out - the build output will be placed here after you run make. The folder structure is out/target/product/. In the default build for the emulator the output will be placed in out/target/product/generic. This is where you will find the images used by the emulator to start (or to be downloaded and flashed to a device if you are building for a hardware target).
  • Packages - contains the source code for the default applications such as contacts, calendar, browser.
  • Prebuilt - contains files that are distributed in binary form for convenience. Examples include the cross compilations toolchains for different development machines.
  • System - source code files for the core Android system. That is the minimal Linux system that is started before the Dalvik VM and any java based services are enabled. This includes the source code for the init process and the default init.rc script that provide the dynamic configuration of the platform

How To Run Compatibility Test Suite (CTS) ?

How does the CTS work?

The CTS is an automated testing harness that includes two major software components:

The CTS test harness runs on your desktop machine and manages test execution.

Individual test cases are executed on attached mobile devices or on an emulator. The test cases are written in Java as JUnit tests and packaged as Android .apk files to run on the actual device target.

Pre-Requirements :

  1. Linux System 
  2. Mobile or Emulator with User Build.
  3. Download latest CTS.
  4. Download CTS Media files.
  5. Download Android SDK for Linux and keep it ready. 

Setup the System for CTS:

1.Create 3 folders in your system root directory. 

  1. CTS
  2. CTS_Media
  3. ADT

2. Extract and Copy downloaded CTS files into the CTS folder which you have created now . It will have below folder structure 
3. Extract and Copy downloaded CTS Media files into the CTS_Media folder which you have created now .It will have below folder structure 
        1. Change the permission for file
                $ export chmod 544

4.  Extract and Copy downloaded android-adt files into the ADT folder which you have created now .It will have below folder structure 

5. Open Terminal and Set ADT path by running below command form root directory.

    $ export PATH=$PATH:/home/root/ADT/android-sdk-linux/sdk/platform-toots
    Note : Run any adb command to check path is set properly or not. (exp:  adb devices )

Set up the Device/Emulator :

CTS can be executed only on consumer devices. This section is important as not following these instructions will lead to test timeouts/ failures:
1. Your device should be running a user build (Android 4.0 and later)from
2. Please refer to this link on the Android developer site and set up your device accordingly.
3. Make sure that your device has been flashed with a user build (Android 4.0 and later) before you run CTS.
4. You need to ensure the Text To Speech files are installed on the device. You can check via Settings > Speech synthesis > Install voice data before running CTS tests. (Note that this assumes you have Android Market installed on the device, if not you will need to install the files manually via adb)
5. Make sure the device has a SD card plugged in and the card is empty. Warning: CTS may modify/erase data on the SD card plugged in to the device.
6. Do a factory data reset on the device (Settings > storage > Factory data reset). Warning: This will erase all user data from the device.
7. Make sure no lock pattern is set on the device (Settings > Security > Screen Lock should be 'None').
8. Make sure the "USB Debugging" development option is checked (Settings > Developer options > USB debugging). Google Confidential
9. Make sure Settings > Developer options > Stay Awake is checked
10. Make sure Settings > Developer options > Allow mock locations is checked
11. Make sure device is connected to a functioning Wi-Fi network (Settings > Wi-Fi)
12. Make sure the device is at the home screen at the start of CTS (Press the home button).
13. While a device is running tests, it must not be used for any other tasks.
14. Do not press any keys on the device while CTS is running. Pressing keys or touching the screen of a test device will interfere with the running tests and may lead to test failures.
15. Set up accessibility tests:
   1. adb install CTS/android-cts/repository/testcases/ CtsDelegatingAccessibilityService.apk
   2.On the device, enable Settings > Accessibility > Delegating Accessibility Service
16. Set up device administration tests: 
  1. adb install CTS/android-cts/repository/testcases/CtsDeviceAdmin.apk
  2. On the device, enable Settings > Security > Device Administrators > android.deviceadmin.cts.CtsDeviceAdmin* settings

17. Copy the CTS media files to your device using ADB with the instructions below:
   The CTS media stress tests require video clips to be on external storage (/sdcard). Most of the clips are from Big Buck Bunny which is copyrighted by the Blender Foundation under the Creative Commons Attribution 3.0license. The required space depends on the maximum video playback resolution supported by the device. By default, 176x144 and 480x360 SHOULD be supported. Note that the video playback capabilities of the device under test will be checked via the APIs.
Here are the storage requirements by maximum video playback resolution:
  • 480x360: 91.4MB
  • 720x480: 151.9MB
  • 1280x720: 401.6MB
  • 920x1080: 1008.2MB

Instructions to copy the media files to a device:
  • To copy clips for just the default resolutions, run ./ Google Confidential 
  • To copy clips up to a resolution of 720x480, run ./ 720x480. 
  • If you are not sure about the maximum resolution, try 1920x1080 so that all files are copied. ○ If there are multiple devices under adb, add -s serial option to the end. 
Syntax  :  $.<space>./CTS_Media/ <resolution>
Example :  $. ./CTS_Media/ 1920x1080

For example, to copy up to 720x480 to device with serial 1234567, run 720x480 -s 1234567.
Now , Start Using CTS commands :

1. Run the below command to start cts . 
   Syntax  $./CTS/tools/cts-treadfed run cts --plan <plan-name>
   Command $./CTS/tools/cts-treadfed run cts --plan CTS
     Note : It will take around 10 hours to complete test and it will create report in CTS/android-cts/repository/results folder.  To list the reports follow the below step.

2. Run the below command to list results . 
   Command $./CTS/tools/cts-treadfed list results
      Results will be shown as below :

3. Run the below command to continue the session if there is a "NotExecuted" cases  . 
      Syntax   $./CTS/tools/cts-treadfed add derivedplan --p <new-plan-name> --s <session-id> --r notexecuted
   Command $./CTS/tools/cts-treadfed add derivedplan --p CTS-FAIL --s 0 --r notexecuted

4. Run the below command to create new plan with Failed cases . 
      Syntax   $./CTS/tools/cts-treadfed add derivedplan --p <new-plan-name> --s <session-id> --r fail 
   Command $./CTS/tools/cts-treadfed add derivedplan --p CTS-FAIL --s 0 --r fail

5. Run the below command to create new plan with Passed cases . 
       Syntax   $./CTS/tools/cts-treadfed add derivedplan --p <new-plan-name> --s <session-id> --r pass
   Command $./CTS/tools/cts-treadfed add derivedplan --p CTS-FAIL --s 0 --r pass

6. Run the below command to run individual methods in class . 
       Syntax   $./CTS/tools/cts-treadfed run cts --class <class-name> --method <method-name>
      Command $./CTS/tools/cts-treadfed run cts --class android.permission.cts.FileSystemPermissionTest --method testOtherRandomDirectoriesNotWritable

7. Run the below command to run all methods in class . 
       Syntax   $./CTS/tools/cts-treadfed run cts -c <class-name>
       Command $./CTS/tools/cts-treadfed run cts -c android.permission.cts.FileSystemPermissionTest