UnityNativeGallery icon indicating copy to clipboard operation
UnityNativeGallery copied to clipboard

Unity Android Playform Build 'UnauthorizedAccessException' cant read file path is denied

Open ohm0106 opened this issue 2 years ago • 2 comments

Description of the bug

I have been using the native gallery 1.7.1 in Unity version 2018.4.36f1

I'm seeing the same bug as the title. I tracked the issue and found that the bug started when I moved up to target version 12, and the bug log looks like this

[Error Log] type=1400 audit(1701399599.022:406): avc: denied { read } for pid=13761 comm="UnityMain" name="sdcard" dev="tmpfs" ino=11066 scontext=u:r:untrusted_app_30:s0:c138,c258,c512,c768 tcontext=u:object_r:mnt_sdcard_file:s0 tclass=lnk_file permissive=0 SEPF_SM-G991N_12_0001 audit_filtered 2023-12-01 11:59:59.026 882-882 audit auditd E type=1300 audit(1701399599.022:406): arch=c00000b7 syscall=79 success=no exit=-13 a0=ffffff9c a1=b400006e74db0568 a2=6dc0b13ba0 a3=0 items=1 ppid=908 pid=13761 auid=4294967295 uid=10650 gid=10650 euid=10650 suid=10650 fsuid=10650 egid=10650 sgid=10650 fsgid=10650 tty=(none) ses=4294967295 comm="UnityMain" exe="/system/bin/app_process64" subj=u:r:untrusted_app_30:s0:c138,c258,c512,c768 key=(null) 2023-12-01 11:59:59.032 13761-13791 Unity com..********** E UnauthorizedAccessException: Access to the path "/storage/emulated/0/DCIM/하이라이트/hightlight_6_12-01_11-59-59.gif" is denied. at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x00000] in <00000000000000000000000000000000>:0 at System.IO.File.Create (System.String path, System.Int32 bufferSize) [0x00000] in <00000000000000000000000000000000>:0 at System.IO.File.WriteAllBytes (System.String path, System.Byte[] bytes) [0x00000] in <00000000000000000000000000000000>:0 at uGIF.CaptureToGIF+<WaitForBytes>d__32.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0

                                                                                                (Filename: currently not available on il2cpp Line: -1)

How can I resolve this ploblem? Plz give me answer :(

Platform specs

Please provide the following info if this is a Unity 3D repository.

  • Unity version: e.g. 2018.4.36f1
  • Platform: Android
  • Device: Android 13
  • How did you download the plugin: GitHub

Additional info Error : "Unity android build UnauthorizedAccessException: Access to the file path is denied."

ohm0106 avatar Dec 01 '23 03:12 ohm0106

The issue seems to be coming from that logic..

public static string GetAndroidInternalFilesDir()
{
    string[] potentialDirectories = new string[]
    {
        "/mnt/sdcard",
        "/storage/emulated/0",
        "/storage/sdcard0",
        "/storage/sdcard1",
        "/storage",
        "/sdcard",
    };

    if (Application.platform == RuntimePlatform.Android)
    {
        for (int i = 0; i < potentialDirectories.Length; i++)
        {
            if (Directory.Exists(potentialDirectories[i]))
            {
                return potentialDirectories[i];
            }
        }
    }

    return Application.persistentDataPath;
}

ohm0106 avatar Dec 01 '23 03:12 ohm0106

May I see the sections of your code that threw the exception? Particularly uGIF.CaptureToGIF function. Also I'm unaware of the GetAndroidInternalFilesDir function you've pasted above. Could you give more context on it?

yasirkula avatar Dec 01 '23 16:12 yasirkula