marlin/sailfish: fix MediaProvider using 100% CPU

- by disabling mtp over functionfs
- affects both GrapheneOS and LineageOS
- might need to be applied to other devices

[pid  2482] ppoll([{fd=42, events=POLLIN}, {fd=51, events=POLLIN}], 2, {tv_sec=0, tv_nsec=0}, NULL, 0) = 0 (Timeout)
lrwx------ 1 u0_a13 u0_a13 64 2019-09-05 18:47 42 -> /dev/usb-ffs/mtp/ep0
lrwx------ 1 u0_a13 u0_a13 64 2019-09-05 18:47 51 -> anon_inode:[eventfd]

https://forum.xda-developers.com/android/help/pixel2-help-diagnose-android-process-t3863274
https://bugs.chromium.org/p/chromium/issues/detail?id=947901
This commit is contained in:
Tad 2019-09-06 09:38:01 -04:00
parent 1a7291aa36
commit 09b38c1f04
6 changed files with 93 additions and 5 deletions

View File

@ -15,8 +15,7 @@ PRODUCT_PROPERTY_OVERRIDES += \
ro.config.notification_sound=Pong.ogg \
ro.config.alarm_alert=Alarm_Buzzer.ogg \
keyguard.no_require_sim=true \
ro.build.selinux=1 \
ro.storage_manager.enabled=false
ro.build.selinux=1
# ro.control_privapp_permissions=log
# ro.control_privapp_permissions=enforce
@ -25,6 +24,4 @@ PRODUCT_COPY_FILES += \
vendor/divested/prebuilts/etc/additional_fdroid_repos.xml:system/etc/org.fdroid.fdroid/additional_repos.xml
#Include packages
#PRODUCT_PACKAGES += BlobBlocker
#PRODUCT_PACKAGES += ModuleBlocker
include vendor/divested/packages.mk

View File

@ -31,7 +31,6 @@ LOCAL_OVERRIDES_PACKAGES := \
CtsShimPrebuilt \
CtsShimPrivPrebuilt \
Traceur \
StorageManager \
PrintRecommendationService \
CompanionDeviceManager \
MusicFX

View File

@ -0,0 +1,42 @@
diff --git a/init.common.usb.rc b/init.common.usb.rc
index 632b6495..23bdb19f 100644
--- a/init.common.usb.rc
+++ b/init.common.usb.rc
@@ -12,18 +12,13 @@ on boot
write /sys/class/android_usb/android0/f_rndis_qc/rndis_transports BAM2BAM_IPA
write /sys/module/g_android/parameters/mtp_tx_req_len 131072
write /sys/module/g_android/parameters/mtp_rx_req_len 131072
- setprop sys.usb.ffs.max_write 524288
- setprop sys.usb.ffs.max_read 524288
- setprop sys.usb.mtp.device_type 3
setprop sys.usb.rps_mask 0
on post-fs
- write /sys/class/android_usb/android0/f_ffs/aliases adb,mtp
+ write /sys/class/android_usb/android0/f_ffs/aliases adb
mkdir /dev/usb-ffs 0775 shell shell
mkdir /dev/usb-ffs/adb 0770 shell shell
mount functionfs adb /dev/usb-ffs/adb noatime uid=2000,gid=2000,no_disconnect=1
- mkdir /dev/usb-ffs/mtp 0770 mtp mtp
- mount functionfs mtp /dev/usb-ffs/mtp noatime rmode=0770,fmode=0660,uid=1024,gid=1024,no_disconnect=1
on property:sys.usb.config=mtp
stop adbd
@@ -81,7 +76,7 @@ on property:sys.usb.config=ptp
write /sys/class/android_usb/android0/bDeviceClass 0
write /sys/class/android_usb/android0/bDeviceSubClass 0
write /sys/class/android_usb/android0/bDeviceProtocol 0
- write /sys/class/android_usb/android0/functions mtp
+ write /sys/class/android_usb/android0/functions ${sys.usb.config}
write /sys/class/android_usb/android0/enable 1
setprop sys.usb.state ${sys.usb.config}
@@ -92,7 +87,7 @@ on property:sys.usb.config=ptp,adb
write /sys/class/android_usb/android0/bDeviceClass 0
write /sys/class/android_usb/android0/bDeviceSubClass 0
write /sys/class/android_usb/android0/bDeviceProtocol 0
- write /sys/class/android_usb/android0/functions mtp,adb
+ write /sys/class/android_usb/android0/functions ${sys.usb.config}
write /sys/class/android_usb/android0/enable 1
start adbd
setprop sys.usb.state ${sys.usb.config}

View File

@ -0,0 +1,44 @@
diff --git a/init.common.usb.rc b/init.common.usb.rc
index 58743917..23bdb19f 100644
--- a/init.common.usb.rc
+++ b/init.common.usb.rc
@@ -10,18 +10,15 @@ on boot
write /sys/class/android_usb/f_mass_storage/lun/nofua 1
write /sys/class/android_usb/android0/f_rndis_qc/rndis_transports BAM2BAM_IPA
- setprop sys.usb.mtp.device_type 3
+ write /sys/module/g_android/parameters/mtp_tx_req_len 131072
+ write /sys/module/g_android/parameters/mtp_rx_req_len 131072
setprop sys.usb.rps_mask 0
on post-fs
- write /sys/class/android_usb/android0/f_ffs/aliases adb,mtp,ptp
+ write /sys/class/android_usb/android0/f_ffs/aliases adb
mkdir /dev/usb-ffs 0775 shell shell
mkdir /dev/usb-ffs/adb 0770 shell shell
mount functionfs adb /dev/usb-ffs/adb noatime uid=2000,gid=2000,no_disconnect=1
- mkdir /dev/usb-ffs/mtp 0770 mtp mtp
- mkdir /dev/usb-ffs/ptp 0770 mtp mtp
- mount functionfs mtp /dev/usb-ffs/mtp rmode=0770,fmode=0660,uid=1024,gid=1024,no_disconnect=1
- mount functionfs ptp /dev/usb-ffs/ptp rmode=0770,fmode=0660,uid=1024,gid=1024,no_disconnect=1
on property:sys.usb.config=mtp
stop adbd
@@ -79,7 +76,7 @@ on property:sys.usb.config=ptp
write /sys/class/android_usb/android0/bDeviceClass 0
write /sys/class/android_usb/android0/bDeviceSubClass 0
write /sys/class/android_usb/android0/bDeviceProtocol 0
- write /sys/class/android_usb/android0/functions ptp
+ write /sys/class/android_usb/android0/functions ${sys.usb.config}
write /sys/class/android_usb/android0/enable 1
setprop sys.usb.state ${sys.usb.config}
@@ -90,7 +87,7 @@ on property:sys.usb.config=ptp,adb
write /sys/class/android_usb/android0/bDeviceClass 0
write /sys/class/android_usb/android0/bDeviceSubClass 0
write /sys/class/android_usb/android0/bDeviceProtocol 0
- write /sys/class/android_usb/android0/functions ptp,adb
+ write /sys/class/android_usb/android0/functions ${sys.usb.config}
write /sys/class/android_usb/android0/enable 1
start adbd
setprop sys.usb.state ${sys.usb.config}

View File

@ -196,6 +196,9 @@ if [ "$DOS_HOSTS_BLOCKING" = false ]; then echo "PRODUCT_PACKAGES += $DOS_HOSTS_
#
#START OF DEVICE CHANGES
#
enterAndClear "device/google/marlin";
patch -p1 < "$DOS_PATCHES/android_device_google_marlin/0001-Fix_MediaProvider_Deadlock.patch"; #Fix MediaProvider using 100% CPU (due to broken ppoll on functionfs?)
enterAndClear "device/lge/g2-common";
sed -i '3itypeattribute hwaddrs misc_block_device_exception;' sepolicy/hwaddrs.te;

View File

@ -190,6 +190,9 @@ echo "PRODUCT_PACKAGES += vendor.lineage.trust@1.0-service" >> packages.mk; #All
#
#START OF DEVICE CHANGES
#
enterAndClear "device/google/marlin";
patch -p1 < "$DOS_PATCHES/android_device_google_marlin/0001-Fix_MediaProvider_Deadlock.patch"; #Fix MediaProvider using 100% CPU (due to broken ppoll on functionfs?)
enterAndClear "device/lge/g2-common";
sed -i '3itypeattribute hwaddrs misc_block_device_exception;' sepolicy/hwaddrs.te;