I am trying to get the canonical path / proc / self / exe. When I do this in the main thread, it works, when I do it in another thread, it crashes using IOException: "Permission denied":
DBG E Thread: main E Path: /system/bin/app_process32 E Thread: Thread-21656 System.err W java.io.IOException: Permission denied W at java.io.File.canonicalizePath(Native Method) W at java.io.File.getCanonicalPath(File.java:414) W at java.io.File.getCanonicalFile(File.java:428) W at com.quanturium.testbugprocselfexe.MyActivity.getPathOfExecutable(MyActivity.java:36) W at com.quanturium.testbugprocselfexe.MyActivity.access$000(MyActivity.java:12) W at com.quanturium.testbugprocselfexe.MyActivity$1.run(MyActivity.java:26) W at java.lang.Thread.run(Thread.java:818)
The code:
@Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getPathOfExecutable(); // Works as expected new Thread(new Runnable() { @Override public void run () { getPathOfExecutable(); // Trigger the IOException: Permission denied } }).start(); } private void getPathOfExecutable() { try { Log.e("DBG", "Thread: " + Thread.currentThread().getName()); Log.e("DBG", "Path: " + new File("/proc/self/exe").getCanonicalFile().getPath()); } catch (IOException e) { e.printStackTrace(); } }
This error only occurs when debuggable is set to false in the build.gradle file
Verification code: https://github.com/quanturium/TestBugProcSelfExe
Is this a mistake or an alleged behavior? What will be the workaround to get the path to the current executable?
source share