[Nexus 4 General] xenyz:
Intro

Over the past while I've finally decided to fix all minor annoyances on my Nexus 4. Here is a guide where I'll share all my modifications to make Mashmallow on the Mako as good as can be.

Kernel

Kernel Proper

The actual kernel included in this guide is HellSpawn kernel by [MENTION=5091819]spezi77[/MENTION] which is based on hells-Core for Marshmallow, with all up-to-date Linux patches (3.4.112) and Google security patches (June 1). (Although I use, advocate, and absolutely recommend HellSpawn, feel free to use another custom kernel in the installer. You'll have to replace zImage and make your own changes to kernel/sema-boot.sh if your kernel doesn't include the same governors, hotplugs, etc.)

Here are a few highlights of HellSpawn itself:

- Includes the elementalx governor from [MENTION=4684315]flar2[/MENTION] and lightweight mako_hotplug driver from [MENTION=3292224]franciscofranco[/MENTION], which are much better than the stock ondemand governor and mpdecision hotplugs.

- Includes franciscofranco's gamma control, which is a much better default gamma for your screen and can be changed with franco's Nexus Display Control app or other Kernel Tweaker Apps.

- Includes a GPU overclock (400 -> 487 MHz) for when really demanding graphics operations require it.

- Includes BFQ, an optimized version of the default kernel's CFQ i/o scheduler. It helps when Play Store updates occur or when apps perform a lot of disk activity.

- Includes double tap to wake feature, which uses minimal extra battery and is much more convenient than the power key.

- When the screen is off, and not sleeping, only one CPU is active and it's limited to 1 GHz, which helps standby battery life with running background services.

Custom Kernel Installer

(original post with r1 was made on reddit)

I've adjusted many default kernel settings, based on a few years experience of running custom kernels. It uses the optimized elementalx governor from ElementalX kernel and lightweight mako_hotplug from franco kernel, with some of flar2's N5 settings, some of [MENTION=647113]hellsgod[/MENTION]'s N6 settings, and some of mine. There are other governors and hotplugs available, but from my experience, these offer the best balance of speed and battery life.

It includes a small, safe, -50 mV undervolt for a bit less heat from the CPU. - a user on reddit reported a reboot with r1, so I've removed voltage settings. It's probably useless to include such a small undervolt anyway. Change voltage settings in an init.d script or Kernel Tweaker app if you wish.

It activates double tap to wake by default, and also turns on power key suspend. If you press the power key with the screen on, double tap to wake will be turned off. Those on custom ROMs or Xposed's GravityBox can activate features to turn the screen off (double tap status bar, lock screen, nav bar, etc.) and keep double tap to wake on. Those without custom ROMs can perhaps use something like Greenify which can remap the home button long-press to turn the screen off.

It includes a patch to sepolicy which allows Viper4Android to work in selinux enforcing mode. You need to have SuperSU installed to have this work.

I've adjusted the io scheduler and page cache for better performance, tuned towards random reads.

It includes stock thermald and a tweaked thermald configuration that scales CPU frequencies up and down a little smoother when your temps get high. It should be noted that most custom kernels disable thermald for their own in-kernel thermal driver. I never liked doing this, as thermald does more than just adjust CPU frequencies - it also throttles GPU, screen brightness, and most importantly, battery charging. When your device gets too hot while charging, the worst thing to do is keep up the current and let the battery go over 45 degrees.

It includes a service to do 'Shared Cpufreq Policy', which lets thermald throttle all cores properly, and also lets the Battery Saver feature work correctly, by limiting all cores. This hasn't worked since KitKat and was one of my biggest annoyances. Many, if not all custom kernels just deleted the Power HAL libraries so battery saver feature doesn't work at all!

Includes Semaphore's 'mpdfake', a service to eat the touch boost spam that the Power HAL generates when not using mpdecision. If a custom kernel does not delete the Power HAL libraries, then your logcat is being spammed and logd process uses a lot of background CPU!

Includes a service to attempt to fix once and for all the location/GPS issues. I'm not going to state it works 100% yet, as I've only had max 24 hr uptime while making changes from the r1 release, but so far so good. Fingers crossed...

Includes a service to give SystemUI and Phone/Dialer higher priority. I haven't had a chance to really test it, as my device is sans-SIM at the moment, but it hopefully will lead to better responsiveness when you receive a call. (Under testing: giving some background processes lower priority, so they don't interrupt app usage.)

Move dalvik-cache to /cache partition and free 300-500 MB:

On each boot, it will check to see if you have a /cache/dalvik-cache folder, and will use it as the dalvik-cache if so.

If you are clean flashing a ROM and want to use /cache for dalvik-cache, create an empty dir in TWRP: /cache/dalvik-cache

If you just want to switch from /data to /cache, copy the /data/dalvik-cache to /cache/dalvik-cache and reboot.

Remember to be careful not to wipe /cache when 'dirty' flashing if you do this!

How to reset the mediaserver process quickly to get videos playing:

While your screen has been on for a few seconds or longer, double press the power key. You'll have to try it a few times to get the timing right, because a quick double press activates the camera in some ROMs. Also you're waiting for the screen to go off, not just dark. Practice a few times in low light, and you'll get the hang of the timing: each press should be followed by about half a second. You'll feel a short vibration when the service resets mediaserver to give some feedback that it's working. If it doesn't run the first time, keep cycling the screen off and on again until you get that vibration.

Remember: you have to start with the screen on, this allows you to quickly check on notifications from screen off without resetting mediaserver.

How to reset the sensors if ambient brightness, auto rotation, GPS, or any other sensors stop working:

Same as above, but this time you do the action twice. That is, screen on - double press power - vibrate once - double press power. You must do the two double presses within a second or two, so a little more practice may be needed. You'll feel two short vibrations when the service resets the sensors.

*** As of mod-r4, the new method to reset both mediaserver and sensors is Hold Volume Up and Power.

How to reset the touch screen if it becomes unresponsive:

If you happen to double tap to wake, the screen comes up, but no touches are being registered, tap on the screen with five fingers. If this doesn't reset it, turn the screen off and on again with the power key, and tap on the screen with both hands, all ten fingers. This will reset the driver and get it going again without a reboot.

Download & Installation

The installer is attached to this post. It's for AOSP ROMs, and uses the UberTC 5.4 toolchain. I'll post up CM versions on request.

Flash the zip with TWRP 3.0.2. If you have made any changes to your Marshmallow ROM (other custom kernels, etc.) you must remember to always flash custom kernels after (dirty) flashing custom ROMs! This is especially important, as if you are missing thermald you're going to have a bad time. FLASH YOUR ROM BEFORE THIS KERNEL INSTALLER UNLESS YOU HAVEN'T MADE

ANY

CHANGES. You can kill your device without thermal throttling!

Wiping dalvik-cache, and /cache is never necessary when flashing a custom kernel only.

ROM

Graphics Drivers

Audio

SuperSU - System or systemless?

Changelog: r14-mod-r3 - r13-mod4 - r16-mod-r5 - r04-mod-r6 - r05-mod-r7