Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proccess is not given in android N #1

Open
rafiip opened this issue Feb 23, 2017 · 5 comments
Open

Proccess is not given in android N #1

rafiip opened this issue Feb 23, 2017 · 5 comments

Comments

@rafiip
Copy link

rafiip commented Feb 23, 2017

Hello . execuring this netstat is fine with adb shell without root permission and it gives process name but when i try to get processname through shell in y application , the name pf the process is empty .
sample result from netstat executed inside application :

D/BBB: Line Proto Recv-Q Send-Q Local Address               Foreign Address             State       Process
D/BBB: Line tcp6       1      0 ::ffff:10.0.2.15:38568      ::ffff:88.99.44.131:80      CLOSE_WAIT  
D/BBB: Line tcp6       1      0 ::ffff:10.0.2.15:38567      ::ffff:88.99.44.131:80      CLOSE_WAIT  
D/BBB: Line tcp6       0      0 ::ffff:10.0.2.15:48296      ::ffff:119.147.146.168:80   ESTABLISHED 
@LipiLee
Copy link
Owner

LipiLee commented Feb 23, 2017

I think probably it will be user permission issue because adb shell's user id(uid) is different from your app's user id(uid) in (Android) Linux. This netstat command can succeed every system call when you run it in your adb shell. But, your app's some system call can fail even though your app runs it through shell.
Both of them haven't the same permission.
And If you can see it on only Android N system, you should check a Android Developer Blog article.
If you can show your code, I will follow it.

@rafiip
Copy link
Author

rafiip commented Feb 23, 2017

I appreciate your response to this issue .
The code is nothing particular , the code is as follows :

Process process = Runtime.getRuntime().exec(getFilesDirectory+"/netstat2");
 process.waitFor();
 Thread.sleep(3000);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
  while ((line = bufferedReader.readLine()) != null) {
   Log.d("BBB","Line "+line);
  }
				    	 

@LipiLee
Copy link
Owner

LipiLee commented Feb 25, 2017

I have checked this issue. Android application can't read "/proc" directory except for its own process directory in only Android N system. Because it fail to read other process's /proc directory(/proc/$PID), the process list is empty though netstat command is working in adb shell. If I find another solution, I will share it.

@rafiip
Copy link
Author

rafiip commented Feb 25, 2017

Well , i have found a working solution . instead of packagename i return UID from netstat and from there , there is a command in packagemanager that returns packagename from UID
String packagename = pm.getPackagesForUid(UID)[0];

@LipiLee
Copy link
Owner

LipiLee commented Feb 25, 2017

Good job! Thanks for sharing your solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants