2012年10月16日 星期二

Android / Linux Shell Commands


Preface:

Android is running on Linux System and a Java based operating system. As you can see on Google Development Site, the architecture is as follows.


Android is working on dark green (Android Runtime) and light blue (Applications & Application Framework) portion of above graph. The Dalvik VM is involved in Android Runtime block, which is used to run the Java Based Application or System on Application Framework and Application Layer.
Linux is working on light green (Libraries) and pink (Linux Kernel) portion of above graph.
This architecture can be always a reference for any Android powered device. However, there're something needed to be added or modified in real case.

Introduction

Android SDK provides a tool - ADB. There's a ADB server inside the Android powered devices and a ADB client in desktop/NB devices for connecting to ADB server. There're a lot of useful command in Android or Linux layer we can use for our interesting purpose. One of easy way to use them is to use ADB tool to invoke those commands for our purpose.

Explore the folder in Android emulator with JB build, there're a lot of command existed in /system/bin. To explore the file list in this folder by using adb shell "ls system/bin".

For instance,
am - Activity Manager, Java based command, the source code is located at platform_frameworks_base/blob/master/cmds/am/src/com/android/commands/am/Am.java
am is activity manager which can control application components in Android. Look at am page for more information

monkey - a stability test tool which generates random events for Android powered device, Java based command. The source code is located at platform_development/blob/master/cmds/monkey/src/com/android/commands/monkey/Monkey.java

pm - Package Manager which can manipulate package relative task, Java based command. The source code is located at platform_frameworks_base/blob/master/cmds/pm/src/com/android/commands/pm/Pm.java

dmesg - Linux Debug Message which can output Linux relative message, a C language based, the same usage with Linux System. The source code is located at platform_system_core/blob/master/toolbox/dmesg.c

ps - Process State, which output the process state with process id (pid), ram usage...etc, a C language based, the same usage with Linux System. The source code is located at android/platform_system_core/blob/master/toolbox/ps.c

From above examples, we know the commands in Android powered devices can be separated to C and Java language based. Either one can be used on Android. However the layer to execute these commands is different. There're many other language can be run on Linux such as python, perl, bash...etc. Hence, it's not only C or Java based executable file but also other languages can be run on Android powered devices.

Reference
Android Architecture, http://source.android.com/tech/security/
Android Source Code Mirror Site, https://github.com/android/
Package Manager, http://developer.android.com/reference/android/content/pm/PackageManager.html

沒有留言:

張貼留言