Android: Fix ANR when QtService and QtActivity load in same process

This patch is a fix to prevent the ANR. In this patch, the QtService
queries QtNative if there is a QtActivity or QtService started and,
in case there is, it does not begin the loading process. When that
happens, the QtService will be a regular android Service.

Fixes: QTBUG-99691
Pick-to: 5.15 6.2 6.3
Change-Id: Ibd8aa8554107a9744b53cca4e0dd7e6f9b25baea
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
bb10
Samuel Mira 2022-04-27 22:57:02 +03:00
parent 189bcbea07
commit 08a4fd3570
1 changed files with 12 additions and 1 deletions

View File

@ -37,6 +37,7 @@
package org.qtproject.qt.android.bindings;
import android.app.Service;
import android.util.Log;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
@ -54,7 +55,17 @@ public class QtService extends Service
/////////////// PLEASE DO NOT CHANGE THE FOLLOWING CODE //////////////////////////
//////////////////////////////////////////////////////////////////////////////////
protected void onCreateHook() {
m_loader.onCreate();
// the application has already started
// do not reload everything again
if (QtNative.isStarted()) {
m_loader = null;
Log.w(QtNative.QtTAG,
"A QtService tried to start in the same process as an initiated " +
"QtActivity. That is not supported. This results in the service " +
"functioning as an Android Service detached from Qt.");
} else {
m_loader.onCreate();
}
}
@Override
public void onCreate()