[RK3399][Android7.1] 调试笔记 --- MTP主机已停止运行问题

Platform: RK3399
OS: Android 7.1
Kernel: v4.4.83

现象:
插拔USB打印机,会提示 MTP主机已停止运行
[RK3399][Android7.1] 调试笔记 --- MTP主机已停止运行问题_第1张图片


异常Log:

  • logcat部分:
05-10 14:10:19.125   459   611 I ActivityManager: Start proc 1338:com.android.mtp/u0a5 for broadcast com.android.mtp/.UsbIntentReceiver
05-10 14:10:19.251   459  1014 D VoldConnector: SND -> {7 appfuse mount 10005 1338 MtpDocumentsProvider}
05-10 14:10:19.256   459   634 V UsbDeviceManager: USB UEVENT: {SUBSYSTEM=bdi, SEQNUM=1936, ACTION=add, DEVPATH=/devices/virtual/bdi/0:29}
05-10 14:10:19.256   459   634 D UsbDeviceManager: subSystem:bdi,devPath:/devices/virtual/bdi/0:29
05-10 14:10:19.257   459   634 V UsbDeviceManager: USB UEVENT: {SUBSYSTEM=bdi, SEQNUM=1937, ACTION=remove, DEVPATH=/devices/virtual/bdi/0:29}
05-10 14:10:19.257   459   634 D UsbDeviceManager: subSystem:bdi,devPath:/devices/virtual/bdi/0:29
05-10 14:10:19.257  1355  1355 E vold    : Failed to mount /mnt/appfuse/10005_MtpDocumentsProvider: Invalid argument
05-10 14:10:19.259   459   638 D VoldConnector: RCV <- {400 7 Command failed}
05-10 14:10:19.263  1338  1338 D AndroidRuntime: Shutting down VM
05-10 14:10:19.265  1338  1338 E AndroidRuntime: FATAL EXCEPTION: main
05-10 14:10:19.265  1338  1338 E AndroidRuntime: Process: com.android.mtp, PID: 1338
05-10 14:10:19.265  1338  1338 E AndroidRuntime: java.lang.RuntimeException: Unable to get provider com.android.mtp.MtpDocumentsProvider: java.lang.IllegalStateException: command '7 appfuse mount 10005 1338 MtpDocumentsProvider' failed with '400 7 Command failed'
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.app.ActivityThread.installProvider(ActivityThread.java:5858)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.app.ActivityThread.installContentProviders(ActivityThread.java:5447)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5386)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.app.ActivityThread.-wrap2(ActivityThread.java)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1546)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:102)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:154)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6121)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: Caused by: java.lang.IllegalStateException: command '7 appfuse mount 10005 1338 MtpDocumentsProvider' failed with '400 7 Command failed'
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.os.Parcel.readException(Parcel.java:1692)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.os.Parcel.readException(Parcel.java:1637)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.os.storage.IMountService$Stub$Proxy.mountAppFuse(IMountService.java:1368)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.os.storage.StorageManager.mountAppFuse(StorageManager.java:1304)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at com.android.mtp.AppFuse.mount(AppFuse.java:69)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at com.android.mtp.MtpDocumentsProvider.onCreate(MtpDocumentsProvider.java:136)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.content.ContentProvider.attachInfo(ContentProvider.java:1751)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.content.ContentProvider.attachInfo(ContentProvider.java:1726)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.provider.DocumentsProvider.attachInfo(DocumentsProvider.java:177)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	at android.app.ActivityThread.installProvider(ActivityThread.java:5855)
05-10 14:10:19.265  1338  1338 E AndroidRuntime: 	... 10 more
05-10 14:10:19.488   459   612 E Typeface: Error mapping font file /system/fonts/DroidSansFallback.ttf

log中SND -> {7 appfuse mount 10005 1338 MtpDocumentsProvider}对应在mountAppFuse()@MountService.java中
Failed to mount /mnt/appfuse/10005_MtpDocumentsProvider: Invalid argument提示mount失败。

  • kernel部分:
unable to set superblock options before the security server is initialized

对应代码位于selinux_set_mnt_opts()@hooks.c
根据log字面意思应该就是因为selinux没有初始化(默认被我给disable了),所以无法设置options信息。


解决方法:

  1. 设置parameter.txt中的android.selinux=permissive
  2. 修改驱动
static int selinux_set_mnt_opts(struct super_block *sb,
				struct security_mnt_opts *opts,
				unsigned long kern_flags,
				unsigned long *set_kern_flags)
{
......
	mutex_lock(&sbsec->lock);

	if (!ss_initialized) {
		if (!num_opts) {
			//其他文件系统的挂载没有opts,所以直接跑到这里来而没报错误。
			/* Defer initialization until selinux_complete_init,
			   after the initial policy is loaded and the security
			   server is ready to handle calls. */
			goto out;
		}
-		rc = -EINVAL;
		printk(KERN_WARNING "SELinux: Unable to set superblock options "
			"before the security server is initialized\n");
		goto out;
	}
......
}

参考:
Android 中的安全增强型 Linux

你可能感兴趣的:(RK3399,子类__Android)