[Xiaomi Redmi Note 4 [Mediatek] ROMs, Kernels, Reco] CosmicDan:
WHAT IS THIS?

CosmicTweaks is my personal collection of changes and tweaks for MIUI. As of 2017.05.05 it is designed for Xiaomi.eu ROM's but it should work with official and probably any other MIUI mod (make a TWRP backup and report any problems you find!). It is not a full ROM, but modifies existing ROM to act like a customized MIUI ROM.

Highlights:

A tested and proven minimal set of tweaks, modular selection with no fluff or nonsense

Designed for Xiaomi.eu ROM's, but is based on AnyKernel2 scripts so should technicall work on *any* MIUI 8 ROM for Redmi Note 4 as it dynamically patches the system and kernel

Does NOT need a 'deodexed' firmware, and provides a tool in the main menu to move 'dalvik-cache' (ART cache) back to system partition which will reclaim space on /data

Option to add minimal Google apps for Chinese ROM's (thanks to Xiaomi.eu for reference on this)

Fully documented list of changes and hosted on GitHub. I encourage other aspiring modders to check out my work as I've done a lot of tricks here e.g. with Aroma and AnyKernel scripts

About updates, license and future:

I am a busy guy with fickle interests, I tend to contribute to XDA/Android stuff in sporadic and intense burts. I made this patch pack with the goal of minimal maintenence and future-proofing. I will try my best to kee it up to date, but no guarantees (we all do this for fun in our spare time afterall.) If I make no reply to this thread for THREE MONTHS, I give permission for moderators to lock it and another XDA member can fork and take over the work (as long as they make it clear that it's only *based* on my work and not endorsed by me).

MY TIPS FOR MIUI:

Can't press "Allow" in Permissions prompt: This is a long-standing MIUI bug. See my explanation of the bug along with workarounds here.

Titanium Backup: Having trouble restoring apps? Be sure to also enable "Install via USB" in Developer Options. If you get a "This device is temporarily restricted" error, just disable your internet access and toggle it again.

Global icon packs via Unicon: If you want to apply Nova/Apex/etc Launcher icon packs on a global scale with Unicon Xposed module, you will need to clear the icon cache after applying icon theme. This can be done by applying default/any theme in MIUI Themes app, OR you can manually delete the folder at /data/system/theme_magic/ (a root explorer required obviously) and THEN REBOOT IMMEDIATELY.

xMIUI Xposed Module: Highly recommended. It's not as extensive as GravityBox, but it's still got a lot.

Broken/crap Weather info: If using Chinese MIUI and you want working Weather, or just want better weather in general, get "Weather M8" from Play Store. The MIUI weather is actually a cut-down version of M8. If using xMIUI, you can also change the weather info in the notification shade to use M8 instead of stock MIUI.

Encryption: Don't be afraid to enable encryption. The Helio X20 is a beast with it thanks to hardware-level AES (benchmarks better than top snapdragons!).

Whetstone removal: It was terribly broken in older MIUI, but in later 7.x.x versions it seems far better. If you remove it, there is no point to "lock" app in memory (with recents) anymore unless you want to keep whole app loaded as long as possible. You will still need to enable Autostart however (in Settings > Permissions) and this will keep app background services (e.g. Push Notifications) running in background, even when you clear memory in recents screen. In short - without Whetstone there's no need to "lock" an app in memory anymore, just enable Autostart.

Push Notifications sometimes not working? Even though you enabled Autostart for source app already? Disable Battery Saver - either globally (recommended) or for that app only via "Settings > Battery and Performance > Manage apps battery usage".

Automatic Brightness is horrible on this device. Try Velis Auto Brightness on Play Store - it looks horrid but works beautifully, once you tune it for your own use.

For better power-savings get 'ForceDoze' from the Play Store. This tweak pack does enable doze capability, but this app will enforce it and providessome fine tuning.

I'll add some more tips here if I remember or find anything I think is worth knowing.

IMPORTANT INFO FIRST for Systemless Root (all SuperSU) users:

If you use Systemless Root via SuperSU, or plan to, make sure you flash it BEFORE this tweak/patch pack. Installing CosmicTweaks after a fresh ROM flash but before SuperSU will result in a broken or missing busybox install!

I have had severe stability issues with Systemless root (SuperSU) and latest China Stable MIUI. Or it could of been a bug/incompatibility with Magisk v9 and Systemless Xposed for MIUI, not sure. If you get a bunch of FC's suddenly for no reason, or any other problems, please try going back to traditional superuser before complaining to me (use phh's superuser) as many apps and the MIUI system seem to have trouble understanding the complexity or being compatible with systemless mods. Right now I am using phh's and SolarWarez xposed and have had no problem.

If you are on Systemless root and you factory reset, be sure to re-flash your SuperSU followed by this ZIP (you should already know that systemless is located on userdata partition) because the systemless busybox is needed by the MIUI system.

If you want to use Unicon Xposed module, use phh's Superuser instead - incompatible with SuperSU.

THINGS I CANNOT CHANGE WITH THIS PATCH PACK:

China ROM App Store (Mi Market) cannot be removed from China ROM without modifying app/framework code, which requires full deodex (beyond the scope of this tweak pack). It also cannot be disabled/frozen, it will either re-enable itself or bootloop as if it's been removed.

China ROM Video and Game Center are kept, despite being Chinese, to prevent the system reporting "System Modification detected" security alert. You can manually disable/freeze these apps yourself with e.g. Titanium Backup.

ADDITIONAL PERFORMANCE RECOMMENDATIONS THAT I CANNOT INCLUDE:

Developer Options - Disable animations (the the three different scales) will frees almost 100MB RAM.

Developer Options - Memory optimization. Turn it to Middle or High tp enable zRAM (trade a little CPU to provide RAM compression. I strongly recommend it, the X20 can handle it). Note that this may also kill background apps prematurely if you still have Whetstone installed (and don't lock the app in memory with Recents).

LIST OF CURRENT FEATURES:

- boot.img changes:
- Disabled dm-verity (aka verified boot) in fstab, permits /system modification and probably improves read performance.
- Disabled forced userdata encryption in fstab, now optional. If you want to disable encryption, you need to do "Format Data" (not just swipe to wipe in TWRP, it's the second button) which will also erase internal storage.
- init.d support
- /cust partition changes:
- Completely wiped, it was all either unwanted Chinese stuff or was moved to system partition
- BusyBox installer/upgrader
- v1.25.1 build by YashdSaraf - http://xdaforums.com/android/software-hacking/tool-busybox-flashable-archs-t3348543
- Any existing version of Busybox will be cleanly removed beforehand
- Systemless support
- init.d tweaks
- asusm930's Tweaks - "UPDATE 3.0 (C)"
- Set noop scheduler for internal storage only (better for faster storage)
- OOM/LMK tweaks (overcommit_ratio to 80%, less aggressive LMK = much better RAM utilization)
- Clear icon cache on boot (may be useful for Unicon or other themers)
- additional tools:
- Integrate ART Cache. Useful for deodexed ROM's and those using Xposed to reclaim some space on /data
- Enable insecure ADB On Boot, and an optional rootmode-hacked adbd I compiled myself. Useful for hackers and developers.
- /system changes:
- Disable OTA app ZIP validation (etc/device_features/nickel.xml)
- Remove everything in /system/data-app/ (Chinese stuff)
- Delete install-recovery.sh and recovery-from-boot.p
- Remove Chinese carrier app selection (install_app_filter.xml)
- Remove from system (optional):
- Disable MTK PerfService (May help battery life but also cause lag and gaming FPS issues)
- AMAPNetworkLocation (only exists on China ROM, must be removed for Google Location to work)
- AnalyticsCore; Xiaomi stats collection. Has a LOT of suspicious dataminer-like permissions. Already removed on EU
- AutoTest; MTK engineering and diagnostics app. Should be safe to remove
- SogouInput; Chinese IME (Keyboard). Check to let Google Keyboard be the default on China ROM.
- Whetstone; MIUI's memory manager. Buggy on some older versions. See CosmicTweaks thread for details.
- YellowPage; Only useful for China. EU ROM seems to have a custom/translated version so will only be default checked for removal on official ROM.
- Various Chinese-only services
- build.prop (non-optional):
- ro.product.locale=en-US
- ro.setupwizard.mode=OPTIONAL
- build.prop (optional)
- Camera quality tweaks; various improvements to camera image/video quality and capability
- Fast Dormancy; Improves battery life if carrier supports it. RELEVENCE UNCONFIRMED FOR MTK DEVICES (but won't hurt if not)
- Force 4G Disabled; fix deep sleep issue for users with 3G-only SIM cards
- Set Google location service as default; useful for China ROM
- Disable MIUI Optimization; it causes compatibility issues with many apps. You can manually re-enable in Developer options if you want it back
- Scrolling Tweaks; Smaller scrolling cache (saves memory) and fling velocity tweak
- /system additions (all are optional):
- Google apps:
- BookmarkProvider
- GoogleCalendarSyncAdapter
- GoogleContactsSyncAdapter
- GoogleTTS
- GoogleBackupTransport
- GoogleFeedback
- GoogleLoginService
- GoogleKeyboard
- GoogleOneTimeInitializer
- GooglePartnerSetup
- GoogleServicesFramework
- MusicFX (already exists in /apps, but Xiaomi.eu also has two MusicFX.apk... not sure if this is right)
- Phonesky (Google Play Store)
- PrebuiltGmsCore (Google Play Services)
- AOSP Provision (replace MIUI setup wizard, DOES NOT BYPASS ACTIVATION)
- vendor/overlay RRO:
- framework-res (includes all of these):
- Add Google's Location Provider
- Change NTP server to Europe
- Enable Doze, but using ForceDoze app still recommended
- Enable Network Location Overlay
- Disable unsafe media volume warning
- Quick Search Box
- Global-ize and English-ify (useful for China ROM)

CHANGELOG:

2017.05.05
- Tested with Xiami.eu 7.4.27 but should still work with all others
- New - 'Integrate ART Cache' tool
- New - 'Disable PerfService' and 'asusm930's Tweaks' options
- Change - Google Apps now optional, default-checked for official ROM's only
- Change - Quick Search Box RRO default-checked for official ROM's only
- Change - Update Whetstone description, now unchecked by default as it's not a broken mess like it used to be
- Remove - Google Feedback option (not actually useful, I was confused by ignorance on how system vs data app bug reports work)

2017.02.07
- New - Aroma Installer
- Made lots of existing features optional
- Add Insecure ADB On Boot option
- Probably more awesome stuff that I can't remember because I didn't take full notes
- New - QuickSearchBox translation/globalize overlay
- New - Init.d script - Clear icon cache every boot (useful for Unicon users... Unicon still only works sometimes sadly)
- Remove - MiRemote APK replacement (not very interesting, just keep the original firmware one)
- Remove - WallpaperCarousel APK replacement (as above)
- Remove - /cust wipe feature (no longer useful)
- Fix - Init.d scripts shouldn't block flow control

2016.11.26
- Initial release
- Based on China Stable 8.1.3.0

DOWNLOAD:

Please read all above info AT LEAST once!

Please see Post #2 for known problems/compatibilities and bug reporting guidelines!

Factory Reset should NOT be required, UNLESS you select the Google Apps option. Feel free to report any bugs resulting from dirty flashing as long as Google Apps were left alone.

Download flashable ZIP's from the GitHub releases page

Old Version (Not recommended):

v2016.11.26 @ Google Drive

CREDITS AND THANKS:

asusm930 for some useful tweaks

YashdSaraf for his BusyBox installer script

phhusson for his sepolicy-injector builds & scripts used in his Superuser (I used them as reference for injecting init.d support)

osm0sis for AnyKernel2, it's totally awesome

Xiaomi.eu ROM's and community for some tweak references and some translated/globalized resources

icons8.com for Aroma icons