{"id":21124569,"url":"https://github.com/malbolgee/handson","last_synced_at":"2026-05-11T14:31:22.947Z","repository":{"id":59050143,"uuid":"525953449","full_name":"malbolgee/handson","owner":"malbolgee","description":null,"archived":false,"fork":false,"pushed_at":"2022-11-23T19:27:31.000Z","size":40275,"stargazers_count":0,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T11:29:22.303Z","etag":null,"topics":["android","aosp","kernel","linux"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/malbolgee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-17T21:04:57.000Z","updated_at":"2022-11-23T19:27:38.000Z","dependencies_parsed_at":"2023-01-22T17:30:40.914Z","dependency_job_id":null,"html_url":"https://github.com/malbolgee/handson","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/malbolgee/handson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malbolgee%2Fhandson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malbolgee%2Fhandson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malbolgee%2Fhandson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malbolgee%2Fhandson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/malbolgee","download_url":"https://codeload.github.com/malbolgee/handson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malbolgee%2Fhandson/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32898900,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-10T13:40:02.631Z","status":"online","status_checked_at":"2026-05-11T02:00:05.975Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","aosp","kernel","linux"],"created_at":"2024-11-20T04:17:01.942Z","updated_at":"2026-05-11T14:31:22.647Z","avatar_url":"https://github.com/malbolgee.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Projeto HandsOn para o curso DevTITANS - Motorola | UFAM\n\n\n\n## How to sync and compile Android on your machine\n\n### install Git and Repo\n\n```sh\n$ sudo apt update\n$ sudo apt install git\n$ sudo apt install wget python3 python-is-python3\n```\n\nTo verify if git was successfully installed\n\n```sh\n$ git --version\n```\n\nConfigure git to use your name and e-mail\n\n```sh\n$ git config --global user.name \u003cyour name\u003e\n$ git config --global user.email \u003cyour e-mail\u003e\n```\n\nTo install repo, on your home directory, do:\n\n```sh\n$ mkdir opt; cd bin\n$ wget https://storage.googleapis.com/git-repo-downloads/repo\n$ chmod 755 repo\n```\n\nNow, export this directory to your .bashrc  (or .zshrc, if you're using zsh shell).\n\n```sh\n$ echo \"export PATH=$PATH:~/opt/\" \u003e\u003e ~/.bashrc\n```\n\nClose the terminal and open a new one (or do ```source .bashrc``` in your home directory).\n\nTest to see if repo is 'visible'.\n\n```sh\n$ repo version\n```\n\nIf something like this is the output, you're good to go.\n\n```sh\n\u003crepo not installed\u003e\nrepo launcher version 2.21\n       (from /home/user/opt/repo)\ngit 2.25.1\nPython 3.8.10 (default, Jun 22 2022, 20:18:18) \n[GCC 9.4.0]\nOS Linux 5.15.0-46-generic (#49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022)\nCPU x86_64 (x86_64)\nBug reports: https://bugs.chromium.org/p/gerrit/issues/entry?template=Repo+tool+issue\n\n```\n\n### Initializing the AOSP Repo\n\nCreate a directory to store the AOSP source code\n\n```sh\n$ cd ~\n$ mkdir aosp\n$ cd aosp\n```\n\nInitialize the Repo repository inside the directory:\n\n```sh\n$ repo init --depth=1 -u https://android.googlesource.com/platform/manifest -b android-12.0.0_r3\n```\n\nThe --depth=1 configures Git to download only the most up-to-date version of the source code, without having to download all the repository's history. This brings the download down to 'only' 20GB, instead of 80GB.\n\n### Downloading AOSP\n\nThe process of leaving your local directory with the same code as the remote server is called \"*synchronization*\". On first run, sync basically downloads all the AOSP source code. To sync your local repository, run:\n\n```sh\n$ repo sync -c -j8\n```\n\nThe -c flag (current) will synchronize only the current branch. The -j flag indicates how many processos/threads to use during the synchronization.\n\n**NOTE**: Too many threads will actually make the AOSP server complain about too many connections. If your internet is average, this process should not take too long even if with 8 threads.\n\n### Creating a new product\n\nGo inside your newly synched AOSP repository\n\n```sh\n$ cd device\n$ mkdir devtitans; cd devtitans\n$ git clone https://github.com/malbolgee/handson.git\n```\n\nThe ```handson``` product directory will be created.\n\nOf course, the process of creating a new product is already done by this repository, if you want to create a really new product, follow the steps below\n\n### TBD\n\n## Compiling AOSP\n\nFirst, lets install some necessary packages\n\n```sh\n$ sudo apt install vim git git-core python3 python-is-python3 python-mako openjdk-8-jdk android-tools-adb bc bison build-essential curl flex g++-multilib gcc-multilib gnupg gperf imagemagick lib32ncurses-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc yasm zip zlib1g-dev libtinfo5 libncurses5 zip libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev libgl1-mesa-dev screen unzip fontconfig kpartx libcurl4\n```\n\n**NOTE**: If you're using Ubuntu, chances are that you'll not be able to install some of these packages, others you'll already have on your machine. You probably only need the following packages:\n\n```sh\n$ sudo apt install build-essential libncurses5 zram-config libncurses5-dev android-tools-adb lib32ncurses-dev lib32readline-dev lib32z1-dev libsdl1.2-dev libssl-dev lzop pngcrush schedtool flex kpartx tmux\n```\n\nAfter this installation, restart you machine, the ```zram-config``` package requires it to be activated.\n\n### Configuring the enviroment\n\nBefore compiling or using any AOSP specific command, we must first configure the enviroment using the envsetup.sh script\n\n```sh\n$ cd ~/aosp\n$ source build/envsetup.sh\n```\n\nThe envsetup.sh is a script that brings a set of useful functions that makes the use of AOSP a little bit easier.\n\nHere are some usefull commands that this script declares:\n\n| **Command** | **Description**                                              |\n| ----------- | ------------------------------------------------------------ |\n| lunch       | Selects the target product that will be work in the terminal session |\n| croot       | Go back to the AOSP root directory                           |\n| m           | Compiles Android                                             |\n\nAs shown above, one of the declared commands by envsetup.sh is the ```lunch``` command. This command selects which product will be worked on in the current terminal session. Basically, it configures a set of environment variables on your shell session related to the selected device. Just like envsetup.sh, this command needs to be executed in each open shell. To see the list of products, simply do:\n\n```sh\n$ lunch\n```\n\n| **Product**                    | **Description**                                              |\n| ------------------------------ | ------------------------------------------------------------ |\n| aosp_barbet-userdebug          | Product to be used in [Google Pixel 5a](https://store.google.com/us/product/pixel_5a_5g?hl=en-US) devices. |\n| aosp_car_x86_64-userdebug      | Used to emulate an Android being executed in a vehicle.      |\n| aosp_cf_x86_64_phone-userdebug | Android being emulated in [Cuttlefish](https://source.android.com/setup/create/cuttlefish), using a X86 64 bits processor. |\n| aosp_cf_x86_64_tv-userdebug    | Used to emulate an Android being executed in a TV.           |\n| aosp_flame-userdebug           | Product to be used in a Google Pixel 4 device.               |\n| beagle_x15-userdebug           | Product specifically for the [Beagle x15](https://beagleboard.org/x15) board. |\n| sdk_phone_x86_64-userdebug     | Product for the emulator executing in a X86 64 bits processor. |\n| devtitans_handson-eng          | Product that this repository creates. **We'll use this one**. |\n\nIn addition, one can observe the end of the names, notice three compilation variations:\n\n| **Variation** | **Description**                                              |\n| ------------- | ------------------------------------------------------------ |\n| user          | Android final version that will be executed by users, without debug information a no root access. |\n| userdebug     | Same as the previous, but with debug information and root access. |\n| eng           | Development version, with extra tools, debug information and root access. |\n\n```sh\n$ lunch devtitans_handson-eng\n```\n\n### Compiling Android\n\nIt is time to compile. To do it:\n\n```sh\n$ m -j$(nproc)\n```\n\nIt could (*will*) take a while if this is the first compilation, but after it is done:\n\n```sh\n$ emulator \u0026\n```\n\n## The Android Kernel\n\nThis project uses a kernel module in order to be able to use the esp32 board that captures the packets in promiscuous mode. We'll recompile the kernel including this module written for this project.\n\n### Downloading, configuring and compiling the kernel\n\nThe official Linux kernel is developed and maintained by Linus Torvalds and can be found on [GitHub](https://github.com/torvalds/linux). However, Android includes a set of modules, configurations, and modifications that they do upon the original kernel. To make it easier, this modified kernel is available [here](https://android.googlesource.com/kernel/manifest/+refs).\n\nTo compile the kernel, some packages are necessary\n\n```sh\n$ sudo apt install kernel-package bzip2 lib32z1 libelf-dev qt5-default qttools5-dev-tools qttools5-dev meld geany gtk+-2.0 libgtk-3-dev libwebkit2gtk-4.0-dev autogen libgtk2.0-dev libglade2-dev\n```\n\nAlthough the kernel source code is available from Google, it is not part of the AOSP source code. So we'll need to create a new directory (outside of AOSP) to store the code\n\n```sh\n$ cd ~\n$ mkdir kernel\n$ cd kernel\n```\n\nAfter that, we'll use repo to download the kernel source code.\n\n**NOTE**: Use a different terminal session to do this, or the kernel repo will overwrite the AOSP repo.\n\n```sh\n$ init --depth=1 -u https://android.googlesource.com/kernel/manifest -b common-android12-5.10-lts\n$ repo sync --force-sync --no-clone-bundle --no-tags -j$(nproc)\n```\n\nApproximately 5 GB will be downloaded. As we are going to copy the compiled files manually to the AOSP directory, we are going to change the kernel configuration file. Put the code below at the ***end*** of the file\n\n```sh\n$ vim common-modules/virtual-device/build.config.virtual_device.x86_64\n```\n\n```makefile\nSKIP_CP_KERNEL_HDR=1\nFILES=\"\narch/x86/boot/bzImage\nvmlinux\nSystem.map\n\"\nMAKE_GOALS=\"\nbzImage\nmodules\n\"\n```\n\nNow, lets compile the kernel\n\n```sh\n$ time BUILD_CONFIG=common-modules/virtual-device/build.config.virtual_device.x86_64 build/build.sh -j$(nproc)\n```\n\nIt might take between 10 to 12 minutes to compile. The final result will be the kernel itself, called ```bzImage``` alongside the modules, which are the ```.ko``` files.\n\n```sh\n$ ls -lh out/android12-5.10/dist/bzImage\n```\n\n### Copying the new kernel to AOSP\n\n```sh\n$ mkdir -p ~/aosp/device/devtitans/handson/kernel/image/\n```\n\nNow, lets copy the kernel and its modules to the new directory\n\n```sh\n$ cp out/android12-5.10/dist/bzImage ~/aosp/device/devtitans/handson/kernel/image/\n$ cp out/android12-5.10/dist/*.ko ~/aosp/device/devtitans/handson/kernel/image/\n```\n\n**NOTE**: This repository already comes with a pre-compiled kernel image and modules. Only do this (compile) to test or if you want to update the kernel or its modules.\n\nNext, we need to tell the build system that we are going to use our new kernel. To do this, we'll need to change an emulator configuration file\n\n```sh\n$ cd ~/aosp\n$ vim device/generic/goldfish/x86_64-kernel.mk\n```\n\nChange the lines\n\n```makefile\nKERNEL_MODULES_PATH := device/devtitans/handson/kernel/image/\nEMULATOR_KERNEL_FILE := device/devtitans/handson/kernel/image/bzImage\n```\n\nNext\n\n```sh\n$ source build/envsetup.sh\n$ lunch devtitans_handson-eng\n$ m -j$(nproc)\n```\n\nTo test if the new kernel is on your Android image\n\n```sh\n$ emulator \u0026\n$ adb shell\n$ cat /proc/version\n```\n\nThe old kernel version starts with something like this\n\n\u003e *Linux version 5.10.43-android12-9-00031-g5b153f189546-ab7618735 (build-user@build-host) (Android (7284624, based on r416183b) clang version 12.0.5 (https://android.googlesource.com/toolchain/llvm-project c935d99d7cf2016289302412d708641d52d2f7ee), LLD 12.0.5 (/buildbot/src/android/llvm-toolchain/out/llvm-project/lld c935d99d7cf2016289302412d708641d52d2f7ee)) #1 SMP PREEMPT Fri Aug 6 17:53:30 UTC 2021*\n\nAnd the new one\n\n\u003e *Linux version 5.10.120-android12-9-g2de0a17df44a-dirty (build-user@build-host) (Android (7284624, based on r416183b) clang version 12.0.5 (https://android.googlesource.com/toolchain/llvm-project c935d99d7cf2016289302412d708641d52d2f7ee), LLD 12.0.5 (/buildbot/src/android/llvm-toolchain/out/llvm-project/lld c935d99d7cf2016289302412d708641d52d2f7ee)) #1 SMP PREEMPT Sat Jul 23 14:09:48 UTC 2022*\n\n### Including the sniffer module\n\nFor this project, we'll use a custom module that can communicate with the esp32 board, sending commands and managing responses. Because of that, we need to include this module in the compilation process to generate the ```.ko``` file module file that will later be loaded into the kernel.\n\nLet's begin copying the Sniffer code to the kernel directory\n\n```sh\n$ cp ~/kernel\n$ cp -r -p ~/aosp/device/devtitans/handson/kernel/modules/sniffer-module .\n```\n\nNow, let's edit the kernel compiling configuration file to add our module\n\n```makefile\nFILES=\"\"\nMAKE_GOALS=\"modules\"\n\nSKIP_CP_KERNEL_HDR=1\nFILES=\"\narch/x86/boot/bzImage\nvmlinux\nSystem.map\n\"\nMAKE_GOALS=\"\nbzImage\nmodules\n\"\n\nEXT_MODULES+=\" sniffer-module\"\n```\n\nNext, let's compile\n\n```sh\n$ time BUILD_CONFIG=common-modules/virtual-device/build.config.virtual_device.x86_64 SKIP_MRPROPER=1 build/build.sh -j$(nproc)\n```\n\nThis time, we do not need to compile the whole kernel again, we use the ```SKIP_MRPROPER``` flag to tell the make command not to remove the files already compiled.\n\nWhen it's done, the compilation must have generated our compiled module\n\n```sh\nls -lh out/android12-5.10/dist/sniffer.ko\n```\n\nNext, copy the module to the AOSP directory\n\n```sh\n$ cp out/android12-5.10/dist/sniffer.ko ~/aosp/device/devtitans/handson/kernel/image/\n```\n\nClose your emulator, in case it's open, and recompile\n\n```sh\n$ cd ~/aosp\n$ m -j$(nproc)\n```\n\nFinally, lets test if our new module is loaded into the kernel\n\n```sh\n$ emulator \u0026\n$ adb shell\n$ lsmod | grep sniffer\n$ dmesg | grep sniffer\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalbolgee%2Fhandson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalbolgee%2Fhandson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalbolgee%2Fhandson/lists"}