Dev Anecdotes #4 - Development of MIUI 8 Marshmallow ROM through MIUI Patchrom

in #utopian-io6 years ago (edited)

MIUI-8-Banner.jpg

I am a fan of Android ROMs with a custom overlay and extra features like MIUI, EMUI, ColorOS etc. Actually this was the reason for my inclination towards Android development. I started with porting MIUI 7 Lollipop ROM for YUREKA which became very much popular among the users of the device. The MIUI 7 ROM was ported from the Xiaomi device MI4i [will discuss the method in some other post]. But there is one problem with Xiaomi devices and MIUI ROMs. Although Xiaomi updates its custom ROM (MIUI) frequently, yet it doesn’t bother much update the Android version. Because of this attitude of Xiaomi, its device MI4i never got Android Marshmallow update. And because of this Yureka users were also deprived of MIUI Marshmallow ROM (as I was porting MIUI from MI4i).

Then I started learning MIUI PatchROM porting using the official tool. I developed many test build, worked for hundreds of hours and finally made one MIUI 8 Marshmallow ROM along with VoLTE support (which was not available in previous builds) and my special additions. It brought a lot of happiness among the YUREKA users which gave me the worth of my hard-work. It also became one of the most popular ROMs for YUREKA. It has been downloaded 11K+ times.

So let’s discuss how did I achieve this. But before going to the details of the development let’s first learn what a MIUI ROM and a Patchrom is?

What is MIUI?


Miui.jpg

MIUI, which stands for Mi User Interface, is a custom firmware based on Android OS developed by Xiaomi for its android smartphones and tablets and other devices. It includes some advanced features not available in AOSP (Android Open Source Project) ROMs. MIUI also includes theming support which gives users a great freedom to customize the look of OS according to their liking. MIUI also has a theme store where thousands of themes are available. MIUI keeps on adding more and more useful features in its newer versions. The first MIUI ROM was developed at the age of Android 2.2 Froyo.

SS-3.jpg
Theming support in MIUI

At present it has improved a lot and packs some amazing features and tools. Recently MIUI v9 was released. But as in this post I am going to discuss about the development of MIUI 8, let’s see some of the features of MIUI 8 ROM:

  • Redesigned Colorful UI : MIUI comes with a simple and beautiful UI with creatively designed flat style icons. It comes with a single layered launcher unlike AOSP. It also provides users with some incredible shortcuts and gestures for easy access to many things like Camera, Flashlight or any specific app.

  • Powerful Camera and Media Editing Support : MIUI comes with an amazing Camera app with some great features like Beautify, Slow-motion, Fish-Eye Mode, Pro-Mode and lot many filters. After you click a photo you can edit it instantly with its powerful image editor. Image editor also comes with many filters. You can also adjust brightness, contrast, hue and other things through the image editor. And you can also write or draw on the image and can create collage. Along with that, there is a quick and easy-to-use video editor as well.

  • Dual Apps : This is an exclusive feature through which you can make a clone of the same app (e.g. Whatsapp) and login each with your two different accounts or phone number. It’s really a very useful feature when you work with multiple accounts for some chatting or social media apps.

  • Second Space : This is just like making a second account in a Windows PC, where you can keep different apps, photos and files and every setting will be different i.e. just like a different phone!! And you can lock your second space with a password or fingerprint.

  • Scrolling Screenshots: You can take scrolling screenshots of webpages and news articles and apps. So you get a single long screenshot instead of multiple screenshots.

  • And Many More Features : There are yet many incredible features like spam detection, caller ID tracker, auto message oraganizer, search bar in the notification shade, powerful feature rich calculator, quick ball for easy access etc.

What is PatchROM?


MIUI-Patchrom.png

Patchrom is an open-source project maintained by a team of developers at MIUI. It is a set of tools that utilizes the assemble/dissemble technology and reverse engineering techniques to craft a MIUI ROM from an existing ROM (preferably AOSP). However, the technology being used to develop a MIUI ROM can also be used to craft any other custom ROM.

A MIUI Patchrom uses tools like apktool (compile/decompile apk and jar files), zipsigner (to sign apk and zip files), zipalign, boot.img unpacker etc. It also includes some set of written codes (mostly in shell-script) to automate many tasks. So, it works mainly on a linux based system like Ubuntu, Mint etc. Patchrom requires an android device with unlocked bootloader and a TWRP recovery, for it work efficiently. However, it can also work with a device with usb debugging enabled in Developer option of the Settings.

Basically, the patchrom extracts all the stock firmware contents from your android device. Then it decompiles all the important framework files (like framework.jar, services.jar, telephony-common.jar etc.) and apk files (like TeleService.apk, framework-res.apk etc.). After that when you command it, it starts patching the extracted files by adding new codes and removing the unnecessary ones. But, a machine is machine, many-a-times it fails to patch corectly and produces rejects (.rej files) in temp/reject/ directory. Then, we devs have to fix those rejects by manually patching the rejected files (mostly .smali files).

After completing the patching process, the MIUI port ROM is built by the patchrom. After that the output ROM has to be flashed to the device. If the ROM boots, then it’s good. But, if not, then devs have to take the logcat of the bootloop to find the issue and fix it. After that, when the ROM boots devs and testers check for bugs and fix them one-by one. And this is how a MIUI ROM is ported with the Patchrom.

How PatchROM based MIUI ROM was Developed?


MIUI-8-Port-SS.jpg
Screenshots from the ported ROM

I undertook MIUI Patchrom porting for YUREKA (code name: tomato). As GitHub users and devs already know, I first had to clone the official Patchrom repo to my Ubuntu. Then, I created a project name “tomato” (device codename) inside the patchrom directory. After that as I have discussed, we need to pull the stock firmware from our android device (here YUREKA) to our project and then make our firstpatch and fix the rejects.

Then I created the port ROM and flashed it to the device. Unfortunately, it didn’t boot but bootlooped. So, I talked with many other patchrom devs about the issue and found that the patchrom was based on older sources and my stock ROM was based on the latest sources and security patches from google, which was preventing it from booting.

I needed a CyanogenMod ROM for my device (YUREKA) which was released back in 2016 Aug-Sep. And this was the time when Cyanogenmod had rebranded itself into LineageOS and deleted all the older CM builds from its server. But fortunately, there was an archive site (don’t remember the name) which had cloned all the previous ROMs that were deleted from the Cyanogenmod server. And this was where I got the older ROM and extracted the required files (android_runtime.so) which made the ported ROM boot. Here is the github commit for the same: https://github.com/nitesh-prasad/patchrom_tomato_volte/commit/1614739ccfc9311fa65a83026b3c3ef2f476f9f0

Fixing Bugs

After starting the ROM, it was the time to check for bugs. There were numerous bugs, but I will discuss just the important ones here:

  • Fix MIUI recents card display: As I said MIUI is themed differently from AOSP, the design of its ‘recents’ is much different from that of AOSP. But my ported MIUI ROM was showing AOSP styled recents cards. So, I had to fix it by adding some lines in the ActivityStack.smali file of services.jar. This enabled the MIUI styled recents. Here is the commit that was carried out: 37fc88f

  • Fix three finger screenshot: MIUI as an awesome gesture support through which you can instantly take a screenshot just by swiping three fingers on the screen. But this handy feature was not working in the ported ROM even after enabling it in the Settings. So, I had to fix it by replacing lines containing AOSP InputManagerService with that of MiuiInputManagerService in SystemServer.smali of services.jar, as shown in this commit: 2b96a0c

  • Fix pattern lock: In AOSP/CM we find a 4x4 pattern lock but in MIUI there is a 3x3 pattern lock. So pattern lock was not working properly in the ported ROM. So, this had to be fixed by adding some lines to LockPatternUtils.smali of framework.jar file. Here is the commit: 6165f3b

  • Fix MIUI Backup Restore Service: MIUI Rom supports backup-restore feature, using which you can backup all of your settings, contacts, messages and apps locally on your device and you can restore it later on when you format of change your ROM. However, this important feature was not working in my ported MIUI ROM. So to fix that I had to edit a bunch of files in services.jar as you can see this commit: 1439aee

  • Fix signal display on the statusbar: Another bug was that, although my device (YUREKA) supported dual-sim, yet in the MIUI ROM it was showing signal clusters only for the first SIM. It was basically a SystemUI bug. Fortunately, my friend a136fei (from Team XTS), a Chinese dev had developed a simple app in Chinese which could work as a workaround for the bug. But as the app was in Chinese I had to translate it into English. Here is the commit: 88ffa23

Adding Extra Features

Even after fixing the bugs I tried to improve it and add my own flavor to it. I used my years of knowledge of ROM development to add some nice features and tweaks to the ported ROM. Here are the tweaks and features that I added to the ROM:

  • Add build.prop tweaks: These tweaks were to improve the battery backup of the ROM by turning off cores while in sleep mode. Also lines were added to improve internet connectivity. Here are the lines that were added to the build.prop:
#Additional Tweaks OSBUSTERS.NET
#####
wifi.supplicant_scan_interval=497
power.saving.mode=1
pm.sleep_mode=1
ro.ril.disable.power.collapse=0
ro.vold.umsdirtyratio=20
net.dns1=8.8.8.8
net.dns2=8.8.4.4

Commit: a03f1d4

  • Enable MIUI Dirac Sound Enhancement: I enabled MIUI Dirac Audio Enhancement technology which is not available for Patchrom ported MIUI ROMs. But as I had ported the Sound Enhancement technology for my Quasar AtmoX Ultimate Sound Mod, I used the same in the ported ROM and it worked. Here is the commit for the same: aec692f

  • Add WAVES MaxxAudio®: I added another sound enhancement and equalizer MaxxAudio ported from Aclatel Idol 4S. Here is the commit for the same: d1d4016

    Screenshot-Music.jpg
    MIUI Music and WAVES MaxxAudio

  • Add Stock Settings: Many awesome features of Cyanogenmod (Stock ROM) was missing in the MIUI ROM. So thought to add that as well to the ROM. I added custom app named StockSettings.apk to the ROM and all the important Cyanogenmod featurs back in the MIUI ROM: LCD Density, Live Display, Button Backlight Settings, Vibrator Intensity, Button Settings etc. Here is the commit for the same: c261325
    Screenshot-Extra-Features.jpg
    Extra settings available after addition of StockSettings.apk
  • Enable Additional Device Features: This was an important commit to add some awesome features for Camera and settings not available for patchrom ported MIUI ROMs. I had to modify an auto-generated xml file named YUREKA.xml and add some new boolean values to it. Like to add more filters, HDR effect and High Framerate Recording to the Camera these lines were added to the file:
    (html comment removed: whether support shader effect in camera)
    <bool name="support_camera_shader_effect">true</bool>
    (html comment removed: whether support aohdr in camera)
    <bool name="support_camera_aohdr">true</bool>
    (html comment removed: whether support high frame recording in camera)
    <bool name="support_camera_hfr">true</bool>

However, there were lot many features that were added to the ROM by this method. Here is the full commit: 76200d0

  • Add Other Features: The ported MIUI ROM supported NTFS and exFAT file system which was not supported by original MIUI ROMs, thanks to the Cyanogenmod kernel used in the ported ROM. Also root access was enabled in the ported MIUI ROM. Support of off-screen gestures was added to the ROM. VoLTE support was added to the ROM. Also screen display settings like color saturation, hue, RGB etc. was enabled in the ROM.

Project Information


This project costed me a lot of time and energy. But as I was working for the fellow members of the YU Community, it kept me motivated. I first started working with this Git repo with Cyanogenmod as base:
https://github.com/nitesh-prasad/patchrom_tomato

Then after learning the process I again started the project from the first after changing the base to LineageOS:
https://github.com/nitesh-prasad/patchrom_tomato_volte

And finally the ROM was published in these forums:
XDA Forums | MIUI Forums | YU Forums

Credits


I would like to thank these awesome people who helped me in the project:
Huge thanks to LineageOS and MIUI Team.
Special thanks to sir Prince Paul, without your help and suggestion this was not possible.
Special thanks to @DRohan for his help and suggestions.
Special thanks to SK83 (Soubhik) for stable LineageOS 13.
Special thanks to a136fei (from Team XTS) , a Chinese dev and friend of mine, without you I could not make the ROM boot.

Video Review



Thanks to Mr. Junior Tech Youtube Channel.

Proof of Work


Here are some screenshots taken during working on the project:

Project-Working.jpgGot errors during development. :p

Proof of GitHub Profile:

GitHub-Login.png

Hope this post will add fuel to popularity of Android development here. Thanks to all. :)



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thank you so much. :)

Looks like a good post and work, tho I'm unable to grasp the finer details!

Amazing Post, although i couldn't grasp some high end technical language. But It seems awesome. The features of the ROM developed and Bug Fixes would definitely make it outshine in Developer World. Have you posted this ROM on XDA?
Bhai, Can you please DM me the MIUI v7 or v8 ROM Link for ZTE NUBIA Z9 MINI or Even Develop one coz i hae not been able to find one and if i did it was too buggy and very unstable Chinese ROM.

Thanks for appreciating the work. :)
However, porting a ROM for a device which I don't have is near to impossible for me. As I don't have a Z9 Mini I cannot port the ROM.

However, you can get MIUI ROM for your Z9 Mini here: https://4pda.ru/forum/index.php?showtopic=702119 (Site is in Russian, use Google Translate)

I used MIUI way back on my Galaxy S 2. Its a great ROM and beautiful to use and look at. So Customizable! Thank you!! <3

Hey @nitesh9 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.27
TRX 0.13
JST 0.032
BTC 62668.08
ETH 2908.37
USDT 1.00
SBD 3.58