Read the system log on Android 4.1 - android

Now , I want to read the system log on android 4.1 . But just can only get the application itself log . My code as following:
Process logcatProc = Runtime.getRuntime().exec(new String[] { "logcat","ActivityManager:V","*:S" });
reader = new BufferedReader(new InputStreamReader(logcatProc.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
Log.e("log",line);
}
it Seems can work on android 4.0 or previous version. anybody have tried this ? Or i need the root permission ?

System logs changed in 4.1 and are now accessible only by system apps. (Source: Google I/O Video.) This is an exception on rooted devices, of course, if the installed app is set to be a system app.
Aside from this, there is no way to access the system logs on Android 4.1+. Note: End users can access the system log by using the (very finicky) shortcut of Power + Vol Up + Vol Down.

Related

Permission Denied for access /proc/net/arp ARP table in Android 10

Using ARP table we can access IP and MAC of hotspot connected devices in Android 9 and earlier versions. Now from Android 10 permission denied for the same. Kindly suggest how can I access IP and MAC address of connected devices in Android 10. Below Code working in up-to Android 9 Version but not work in Android 10.
BufferedReader br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = br.readLine()) != null) {
String[] clientInfo = line.split(" +");
if(!clientInfo[3].equalsIgnoreCase("type")) {
String mac = clientInfo[3];
String ip = clientInfo[0];
textView.append("\n\nip: " + ip + " Mac: " + mac);
Log.d("IP : ", ip);
Log.d("Mac : ", mac);
}
}
Run the ip neigh show command and process its output:
val runtime = Runtime.getRuntime()
val proc = runtime.exec("ip neigh show")
proc.waitFor()
val reader = BufferedReader(InputStreamReader(proc.inputStream))
You split the lines the same way, IP is [0], MAC is [4].
Android 10 introduces several privacy-related restrictions that disallow apps to access certain information that could be potentially misused for fingerprinting and data collection. One of among them is the restriction on access to /proc/net filesystem on devices that run Android 10 or higher, apps cannot access /proc/net, which includes information about a device's network state. Apps that need access to this information, such as VPNs, should use the NetworkStatsManager or ConnectivityManager class.
The current APIs in Android doesn't allow apps to access the ARP cache. I see a bug is raised in Google issue tracker that is currently in the below status - https://issuetracker.google.com/issues/130103885
Status: Won't Fix (Infeasible) We've passed along your input to our
internal teams, who are evaluating it for a future release. We're
closing this issue for now, and thanks for sending us your feedback!"
https://developer.android.com/about/versions/10/privacy/changes#proc-net-filesystem
Related thread [ Acccess to /proc/net/tcp in Android Q ] - https://stackoverflow.com/a/58501039/4694013

Why can't my Android APP use tcpdump eventhough I change the permission of tcpdump to 777?

I change the permission of /system/xbin/tcpdump to 777 and write the code in my Android APP like below.
But I still get the error message "stderr=tcpdump: any: You don't have permission to capture on that device" and "stderr=(socket: Operation not permitted)".
Is there anyone know what's the problem here?
Thanks.
Process process
String[] cmd = {"/system/xbin/tcpdump", "-i any", "-w /sdcard/tcpdump.pkt"};
TextUtils.join(" ", cmd);
process = Runtime.getRuntime().exec(cmd);
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
while ((line = errorReader.readLine()) != null) {
Log.d(TAG, "stderr="+line);
}
Android does not support raw sockets, which would include the ability to collect raw frames using a sniffer, by any user space process on non-rooted devices.
If you check the main support site for TCPDump on Android, you'll find that one of the very first requirements is a rooted Android device.

android emulator root access

I need to execute a C program in my App by simply adding the executable to the android project and building the .apk. Then I try to execute the program in my application like this:
Process result = Runtime.getRuntime().exec("su");
String cmd = "PROGRAM_NAME";
DataOutputStream dos = new DataOutputStream(result.getOutputStream());
DataInputStreamdis = new DataInputStream(result.getInputStream());
dos.writeBytes(cmd + "\n");
dos.writeBytes("exit\n");
dos.flush();
I know I need root access to do this so I installed Superuser.apk but that didn't work. Is there another possible way to do this? Btw the code is not fully extended it should just give a look at the way the program should be executed
I'm running the emulator with Android 4.2.1
Edit:
Checking root permission first with
Process suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
DataInputStream osRes = new DataInputStream(suProcess.getInputStream());
if (null != os && null != osRes) {
os.writeBytes("id\n");
os.flush();
String currUid = osRes.readLine();
boolean exitSu = false;
if (null == currUid) {
Log.d("ROOT", "Can't get root access or denied by user");
}
I have got the same problem as you. you can find many answers like here , but they are too old and they are not working anymore (in the new sdk).
I found the best answer here which says that the Security Tips of Android are not allowing to any developer to have root access :
A central design point of the Android security architecture is that no application, by default,
has permission to perform any operations that would adversely impact other applications, the
operating system, or the user. This includes reading or writing the user's private data (such as
contacts or e-mails), reading or writing another application's files, performing network access,
keeping the device awake, etc.
So the only access that you have under the Application Layer is by permissions.

How can I get logcat on my device to show logs from all processes

I'm trying to write an app that reads all logs on my device. I've got a client/service architecture, and I see log messages from both the client and service processes but I don't see any messages from any other applications on the phone (I do see other messages using the desktop logcat).
Do I need root?
Code Snippets
Manifest
<uses-permission android:name="android.permission.READ_LOGS" />
Log Reader
Runtime.getRuntime().exec("logcat -c").waitFor();
Process process = Runtime.getRuntime().exec("logcat -v long *:*");
BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
while (true) {
String nextLine = reader.readLine();
if (!nextLine.contains("LogWatcher-D")) {
Log.w("LogWatcher-D", "See: " + nextLine);
}
// Process line
}
On Android 4.1+, you can only access log messages logged by your process, unless you hold the READ_LOGS permission. That permission requires either that your app be signed by the same signing key that signed the device's firmware, or that your app is installed on the system partition.
To read logs from other applications programmatically, you will need to assign the same android:sharedUserId in all apks' manifest files.
There is another way to access all logs for all applications without root. It requires enabling remote debugging. Take a look at the open source rootless Logcat app.

required root permissions to an android application

I am writing an application to access the many of the system device nodes. To open the device nodes, I wrote native methods, When I am trying to execute it, I am unable to open the device node as there is no root permissions to my application. Could any one please tell give root permission to my android application. device details: android 2.0.1 - motorola milestone.
rtc_fd=open("/dev/rtc",0777);
if(rtc_fd == -1) {
__android_log_write(ANDROID_LOG_ERROR, "","UNABLE TO OPEN THE DEVICE....");
strcpy(result_string,"Fail: /dev/rtc open error\n");
__android_log_write(ANDROID_LOG_ERROR, ""," DEVICE...ERROR. ");
return result_string;
}
ret = ioctl(rtc_fd, RTC_RD_TIME, &rtc_tm);
if (ret == -1) {
strcpy(result_string,"Fail: rtc ioctl RTC_RD_TIME error\r\n");
return result_string;
}
It is always saying UNABLE TO OPEN DEVICE, could any one please suggest a solution to open a device node.
First and foremost, you will obviously need a rooted phone for any of this to work.
That being said, Android does not allow for a user-application to gain super-user rights, even on a rooted phone. Instead, it allows you to launch a new process with super-user rights.
The easiest method for running things as super-user is to create a virtual terminal, as follows:
Process proc = Runtime.getRuntime().exec("su");
DataOutputStream standard_in = new DataOutputStream(proc.getOutputStream());
DataInputStream standard_out = new DataInputStream(proc.getInputStream());
Using the input and output streams you now effectively have console access as root, which you can use to run typical command-line commands, or to run the process that accesses your device for you.

Categories

Resources