I am developing an Android App that I am targeting for Android 13 or higher. In the APP I am performing continuous updates and for each update, I want to collect logs of the full device including update_engine's logs, so in case any update fails I can tell what was the issue. For each update, I am saving logs in a different file.
For collecting full device logs I am using system permission
<uses-permission android:name="android.permission.READ_LOGS" />
Though system permission will be only granted if our APP is having same system signature as the device, in Android 13 Google made it more restrictive now only prv app can be granted by default and I can not make my APP as prv app, because for that Google needs to approve the request.
It's okay if we can't collect full device logs but still I want to collect my own APPs logs, unfortunately, I am able to collect only half of the logs of my APP.
Currently, I am using -
StringBuilder command = new StringBuilder(); // Start to get logcat log to new file
command.append("logcat -v threadtime -f ");
command.append(Constants.LOGCAT_LOG_PATH);
try {
mProcess = Runtime.getRuntime().exec(command.toString());
} catch(Exception e) {
Log.e(TAG, "Logcat exec ERROR ");
}
I also tried '-d' option that will dump the logs into a file but still I am not getting full logs sometimes or sometimes I am getting repeated logs in the log file.
Note - I am calling reboot once the payload is applied to confirm if the device is updated successfully. Seems like when logs are still in the buffer (not yet written into the file) and the device got rebooted. I also tried a postRunnable() of 30 seconds so that logs can be written into the file form buffer but no help.
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
pm.reboot(null);
What can be a possible workaround after this Android 13 READ_LOG permission behavior change? Though the device is showing a pop-up for allow/ deny permission dialog if I allow it is collecting full device logs but I can not allow/ deny it all the time because it's a long-running process.