[Nexus 7 Android Development] Jay Aristide:
Getting the Most Out of Your Nexus 7

Jay's Recipe for Buttery Goodness

for Android 4.1.2/4.2/4.2.1​

What we're going to do here is remount /data and /cache with discard and noauto_da_alloc, disable fsync, enable a 128mb zRAM and setup a good, stable starting point for further modification. The result is a stable, considerably smoother multitasking powerhouse with overall better power management and performance.

This recipe will work on pretty much any 4.1.2 ROM, and instructions are given for stock-based (with and without init.d support) and CM-based ROMs. If you have any questions, comments, or suggestions, please leave them below. I'll be happy to address whatever I can in a timely manner :)

[Common] Determining which script to use:

Download: SecretSauce4.1.2.zip - Contains 4 scripts. Unzip and choose which one you want

This all depends on how much you multitask (how many different things you do at once). If you usually have 4 or 5 apps open that you switch between regularly, then you do a moderate amount of multitasking, and would choose the 256mb script. If you tend to do only one thing at a time, you may decide to save the RAM and run with no zRAM. That's fine, too (I've even got a script for that, it's a favorite among gamers :)). If you feel you fall somewhere in between, there are 64mb and 128mb scripts, as well.

If in doubt, try each for a day or two. Decide for yourself (and let me know what you find). Feel free to modify the script to suit you. If you don't understand anything in there, don't worry about it. It's set up pretty well as-is, and the defaults should suit you fine.

Please read this post to help you decide which script to install :)

[Common] To init.d or not to init.d:

If you run a custom ROM that supports /system/etc/init.d/ (and sometimes even /data/local/userinit.d), then you definitely want to go the init.d route, as it's pretty much bulletproof and needs virtually no resources to operate - it's built-in to the system.

If your ROM is stock-based, it probably doesn't support init.d - but it might. Ask the developer of your ROM if it has init.d support (and then let me know :)). This recipe can be done on stock with init.d support! I include a link to a stock 4.1.2 kernel with init.d support in the ramdisk that you can flash before the M-Kernel Plus. Then just create /system/etc/init.d, chmod it 0755, and drop your script in there.

If your ROM is CyanogenMod (CM) based, then not only does it have init.d support, it has userinit.d support, which is great because it persists between dirty flashes. userinit.d is a directory you create in /data/local and chmod 0755. Any script you put in there (chmod 0755) will be run as it would were it in /system/etc/init.d

If you're completely stock but rooted (hey, it happens), and you want the buttery goodness but you don't want to flash a kernel - don't fret! I've even included a way for you to get what you can from the recipe! You'll be using an app called Script Manager (it's free, but you can donate, too. It's totally worth it) to autoload the script at boot-time. A couple of extra steps, but absolutely no mucking around under the hood :)

Personally, whether I'm on stock or something CM-based, I prefer having init.d (and userinit.d) support, as like I said, it's pretty much bulletproof and requires no extra resources. I, myself, run ParanoidAndroid 2.23, which is CM-based. It's the best-running, sturdiest, most usefully customized ROM I have ever used on any device, and I can't recommend it enough. Team Paranoid Android is top-notch!

...Now that you've decided on, flashed, setup and customized a ROM (or maybe you stayed stocked)...

BEYOND THIS POINT, THERE BE DRAGONS!

I'm not responsible if you FUBAR your device. But, if you follow my directions and pay attention to what you're doing, you won't.​

This tutorial assumes basic knowledge of the Android operating system, related terminology, and the most basic of Linux understanding. Any term I use in this guide can be quickly and easily Googled.​

[Stock, rooted, no init.d] Installing the Special Sauce script and Script Manager:

* Open the Play Store and get the Stericson's Busybox Installer and install it

* Run the program, let it boot up and figure out what's where (takes a bit)

* Install Busybox 1.20.2 to /system/xbin

* Create /sdcard/scriptinit.d

* Copy the script you decided on into /sdcard/scriptinit.d

* Open the Play Store and get Script Manager and install it

* Run Script Manager, find your script, load it up, click the little root icon, and set it to run at boot

* Close Script Manager

* Skip to [Common (except CM-based)] Install M-Kernel Plus

[Stock, has init.d] Installing the Special Sauce script:

* Open the Play Store and get the Stericson's Busybox Installer and install it

* Run the program, let it boot up and figure out what's where (takes a bit)

* Install Busybox 1.20.2 to /system/xbin

* Copy the script you decided on into /system/etc/init.d/ and chmod it 0755

* Skip to [Common (except CM-based)] Install M-Kernel Plus

[Stock, needs init.d] Installing the Special Sauce script and creating init.d:

Download:Nexus7Stock_Insecure_InitD_4.1.2.zip by Metallice

* Reboot into recovery

* Flash Nexus7Stock_Insecure_InitD_4.1.2.zip

* Go to advanced and fix permissions

* Go back and reboot system

* Open the Play Store and get the Stericson's Busybox Installer and install it

* Run the program, let it boot up and figure out what's where (takes a bit)

* Install Busybox 1.20.2 to /system/xbin

* If /system/etc/init.d/ does not exist, create it, and make sure it's chmod 0755

* Copy the script you decided on into /system/etc/init.d/ and chmod it 0755

* Skip to [Common (except CM-based)] Install M-Kernel Plus

[CM-Based] Installing the ramdisk, M-Kernel Plus and Special Sauce script:

CM really should have busybox. If it doesn't, install it.

Download: Nexus7_CM10_PA22_4.1.2_complete.zip

and

the M-Kernel Plus of your choice from Metallice's M-Kernel Classic/Plus thread

* Reboot into recovery

* Flash Nexus7_CM10_PA22_4.1.2_complete.zip

* Go to advanced and fix permissions

* Go back and flash the M-Kernel Plus you downloaded

* Go to advanced and fix permissions again

* Go back and reboot system

* If /data/local/userinit.d/ does not exist, create it and chmod it 0755

* Copy the script you decided on into /data/local/userinit.d/ and chmod it 0755

* Skip to [Common] Verifying Installation

[Common (except CM-based)] Install M-Kernel Plus

Download: the M-Kernel Plus of your choice from Metallice's M-Kernel Classic/Plus thread

* Reboot into recovery

* Flash M-Kernel_alpha1_446GPU.zip

* Go into advanced and fix permissions

* Go back and reboot system

* Profit - You're done!

[Common] Verifying Installation

Pretty easy to verify if it's working. First off, it'll be really fast and snappy! Second, if you're using zRAM, you can open a terminal or adb shell from your PC and

free

The last line it outputs will be for swap (this is actually your compressed zRAM). For total and free, there should be numbers. If there are, then you have a page file and it's working.

Finally, you can open a terminal or adb shell from your PC and

mount | grep discard

It should output 2 lines, one for /data and one for /cache. That means it's working.

[Common] Further Optimization:

I recommend the Play Store app System Tuner for further customization. The customizations I recommend are

* Undervolt the entire system by -50mV

* Try that for a day or two and then try another -25mV

* If you end up stable at -75mV, leave it be. That's a good unvervolt

* CPU Governor should be set to either interactive or ondemand, unless you're a hardcore gamer, in which case you might want to use performance

* CPU Frequencies can be set. I use 100-1300. Use whatever floats your boat

* I/O Scheduler can be specified. I recommend deadline in every situation, as it's specially modified by _motley

* Go to Boot Settings from any of those screens, and save cpu and sd via the 'on boot complete' or init.d method (if you chose not to implement init.d, choose upon boot completion).

* Back out of System Tuner and reboot

* Profit

Feel free to take it from there, and post your experiences here :)