There are many source codes for the android system. The storage path is as follows
- Android/system The underlying file system library, applications and components, which are owned by Linux
- Some open source modules used by android/external android
- android/frameworks/base/cmds Some important Android commands: am, app_process, etc.
In fact, these tools are small applications. Debug the serial port to connect to the computer, and enable the console to use these tools. If you connect to a USB computer, use the adb debugging tool and enter the adb shell command to enter the console.
- dumpsys: can dump various states of system service.
- dumpstatus: the main implementation places for related information, kernel, process, and related information of Android
- top: CPU usage
- pm: package manager
- am: Activity manager
- tinyalsa: audio debugging, including tinycap, tinymix, tinyplay
- settings: Change the value of SettingsProvider database
- logcat: system log
- monkey: Test tool
- svc: controls the switch status of power supply, data traffic, wifi, usb, and Ethernet
- wm: Check the resolution and density of the setting screen
- screencap: screenshot
- screenrecord: screen recording
The system/bin and system/xbin of the target device have some tools added by Android and tools that come with Linux. These tools may be written by Java, C, C++ or shell instructions. The tools mentioned above are quite fun. For specific usage methods, you can enter the parameters - help to view help or search online.
Here we introduce how to write a tool in C or C++ and add it to the system when compiling Android.
1. Write a widget to test the ioctl interface
Create folder frameworks/base/cmds/dytest
1. Create a file
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ \ LOCAL_SHARED_LIBRARIES := \ libcutils \ liblog \ LOCAL_LDLIBS :=-llog LOCAL_MODULE:= dytest LOCAL_MODULE_TAGS := optional include $(BUILD_EXECUTABLE)
2. Create
#include <linux/> #include <linux/> #include <asm/> #ifndef IO_BASIC_H_ #define IO_BASIC_H_ #define RD_UNIT_SIZE 1024 #define WR_UNIT_SIZE 1024 #define RDWR_UNIT_SIZE 1024 #define S_IRWXU 00700 #define S_IRUSR 00400 #define S_IWUSR 00200 #define S_IXUSR 00100 #define S_IRWXG 00070 #define S_IRGRP 00040 #define S_IWGRP 00020 #define S_IXGRP 00010 #define S_IRWXO 00007 #define S_IROTH 00004 #define S_IWOTH 00002 #define S_IXOTH 00001 #define SI4754_CMDMAGIC 0X81 #define usrdatatype unsigned long enum FM_CMD_TYPE{ FM_START = _IOWR(SI4754_CMDMAGIC, 1, unsigned long), FM_STOP, FM_SEEKUP, FM_SEEKDOWN, FM_SETFREQ, FM_SETVOL, FM_GETFREQ, FM_GETVOL, FM_TEST }; /* ============================================================================ Name : IO_Operation.c Author : DongYi Version : ============================================================================ */ //Open the file with O_RDWR | O_CREAT | O_TRUNC,S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH permissionint open_file(const char* filename); //Open the file with O_RDWR | O_CREAT | O_TRUNC,S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH permissionint open_file_create(const char* filename) ; //byO_RDONLY,S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTHPermission to open file
3. Create
#include <> #include <> #include <asm/> #include <sys/> #include <sys/> #include <> #include <> #include <linux/> #include "" unsigned long qndData; const char* filename = "/dev/fmsi4754"; int open_file(const char* filename) { return open_file_create(filename); } int open_file_create(const char* filename) { int fd; //File descriptor fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH); if (fd == -1) { printf("\nopen_file: File operation failed"); return -1; } printf("\nopen_file: File operation succeeded"); return fd; } int main(void) { int fp; int ret; char buf[1024]={0}; long len; puts("~~~~~~~~~~~~ Test program Linux I/O operation~~~~~~~~~~~~~~~\n\n"); /* prints Linux I/O operation */ // for(len=64000;len>0;len--); sleep(1); fp = open_file_create(filename); if (fp < 0) { printf("open_file:faild!\n"); return -1; }else{ printf("open_file:success!\n"); } qndData=0x12345678; do{ ret=ioctl(fp, FM_START, &qndData); printf("ioctl_file:qndData:0x%x\n ",qndData); if (ret < 0) { printf("ioctl_file:faild!\n"); close(fp); return -1; }else{ printf("ioctl_file:success\n"); } }while(qndData==0x12345678); //Open the computer return 1; }
The code and compilation rules file are ready, enter mm frameworks/base/cmds/dytest/ to compile. It can be used after burning.
This tool can also be usedarm-linux-androideabi-gcc
Tool Compilation
arm-linux-androideabi-gcc -o dytest --sysroot=/home/android/SambShare/dyT3-v1.0/android/prebuilts/ndk/current/platforms/android-18/arch-arm/
If you compile this method, you need to push the dytest tool to the Android system and then modify the permissions. Of course, you can also use the file to copy dytest to the system/bin directory.
Second, add Android permission backdoor tool seustub
This tool is downloaded online and is not convenient to publish the code. In fact, it uses socket to enter instructions on the console.
After obtaining the seustub compressed package, decompressing seustub is placed in external/folder
Created under /seustub/
include external/seustub/seustub/ include external/seustub/seustubtest/
2. Create external/seustub/seustub/
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ \ \ LOCAL_SHARED_LIBRARIES := \ libcutils \ liblog \ LOCAL_LDLIBS :=-llog LOCAL_MODULE:= seustub LOCAL_MODULE_TAGS := optional include $(BUILD_EXECUTABLE)
3. Create external/seustub/seustubtest/
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ \ ../seustub/ \ LOCAL_SHARED_LIBRARIES := \ libcutils \ liblog \ LOCAL_LDLIBS :=-llog LOCAL_MODULE:= seustubtest LOCAL_MODULE_TAGS := optional include $(BUILD_EXECUTABLE)
Add startup service
service seustub /system/bin/seustub class main
Finally enter mmmm android/external/seustub to compile
The usage method is seustubtest + directive + parameters, for example seustubtest chmod 777 /dev/si4754
The company's JAVA application requires temporary root permissions and also needs to obtain the return value to determine the success of the command. Therefore, the seustubtest part was deleted, and a JNI interface for upper-level call was added to seustub, and the return result of the instruction was output to the file. No detailed introduction.
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for your study or work. Thank you for your support. If you want to know more about it, please see the following links