We are creating internal app which needs to have unkillable or very long living websocket connection. How can I achieve that? I have it working in foreground service, disabled battery optimization etc. but it doesnt seem to work. I tried all standard options.
Command adb shell dumpsys deviceidle whitelist +PACKAGE
doesnt seem to help either.
Would rooting phone and setting app as system app help? Are there enterprise Custom ROMs which give control over battery optimizations and other stuff?
You should use a Foreground Service with a partial wakelock, in order to prevent the phone from sleeping. Here below an example of Foreground Service Class that implements a Wakelock:
Obviously you still have also to disable battery optimization for your app. You can browse a real working example of this service (but used for GPS) here.