ssiyad's wiki



ADB push error in scrcpy

Issue

The error#1 I faced was:

adb: error: stat failed when trying to push to /data/local/tmp/scrcpy-server.jar: Permission denied
ERROR: "adb push" returned with value 1

Due to

SELinux denied shell permissons and adb root was not available

Fix

  1. Disable SELinux

    I had to do this to circumevent error#2, need root (Magisk)

    adb shell
    su
    setenforce 0
    
  2. Find relevant SELinux contexts (Optional)
    adb shell cat '/system/etc/selinux/*' | grep 'u:.*shell.*'
    
    cat: /system/etc/selinux/mapping: Is a directory
    /(odm|vendor/odm)/bin/sh		u:object_r:vendor_shell_exec:s0
    /(vendor|system/vendor)/bin/sh		u:object_r:vendor_shell_exec:s0
    /mnt/expand/[^/]+/local/tmp(/.*)?		u:object_r:shell_data_file:s0
    /data/local/tmp(/.*)?		u:object_r:shell_data_file:s0
    /system/bin/sh		--	u:object_r:shell_exec:s0
    /system/xbin/bash		u:object_r:shell_exec:s0
    security.perf_harden    u:object_r:shell_prop:s0
    service.adb.root        u:object_r:shell_prop:s0
    service.adb.tcp.port    u:object_r:shell_prop:s0
    
  3. Rename the SELinux context from system_data_file to shell_data_file

    From here

    adb shell
    su
    chcon -R u:object_r:shell_data_file:s0 /data/local/tmp
    
    chcon: '/data/local/tmp' to u:object_r:shell_prop:s0: Permission denied