I am working on a custom android for my master thesis which is based on CM12.1.
The use case for the custom rom is capturing usage data for arbitrary apps including e.g. startup, shutdown and calls to different system resources. All this should happen with normal usage of the phone. Currently I want to utilize the Application class so that it sends a broadcast intent in its onCreate() method.
[...]
class Application extends ContextWrapper implements ComponentCallbacks2 {
[...]
public void onCreate() {
// fire intent for capturing
Bundle bundle = new Bundle();
if (mLoadedApk != null) {
bundle.putString("PACKAGE_NAME", mLoadedApk.getApplicationInfo().packageName);
bundle.putLong("CREATION_DATE", System.currentTimeMillis());
}
Intent intent = new Intent(Intent.ACTION_START_APP) // custom action added to Intent.java
.putExtras(bundle);
getApplicationContext().sendBroadcastAsUser(intent, android.os.Process.myUserHandle());
}
[...]
}
That way I could log the exact times when an app starts, but sadly my approach results in the device not booting anymore. After flashing the custom image and booting I am stuck at the cyanogen boot animation (which is animating, it is not frozen). A working image leaves the animation and starts android after about 2 minutes (also first boot after flash) but my rom with customized Application.java still shows the boot animation after >15 minutes.
I know it would be possible to periodic check running apps with ActivityManager but since this is inaccurate and would prevent the cpu to enter power saving modes I want to use this approach.
If I outcomment the sendBroadcast everything works fine. So I guess the problem is that the ActivityManagerNative is not running yet but I am uncertain about this.
Since I cannot obtain the logs with adb I don't know at which point/why the boot fails.
Can you tell me how to check if all prerequisites for sending requests are met? Alternative I could send my Intent only if the device boot process is completed and scan all open apps in my corresponding BroadcastReceiver but I don't know how (or even if it is possible) to check if boot process is finished.
Thanks in advance.