[core] Fix in rare case system hooks invalid (#486)
This commit is contained in:
parent
cf3fdbc301
commit
03d5f1b444
|
|
@ -22,6 +22,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <dobby.h>
|
#include <dobby.h>
|
||||||
|
#include <thread>
|
||||||
#include "base/object.h"
|
#include "base/object.h"
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
|
|
@ -199,10 +200,22 @@ namespace lspd {
|
||||||
return {env, nullptr};
|
return {env, nullptr};
|
||||||
}
|
}
|
||||||
auto bridgeServiceName = env->NewStringUTF(SYSTEM_SERVER_BRIDGE_SERVICE_NAME.data());
|
auto bridgeServiceName = env->NewStringUTF(SYSTEM_SERVER_BRIDGE_SERVICE_NAME.data());
|
||||||
auto binder = JNI_CallStaticObjectMethod(env, service_manager_class_,
|
ScopedLocalRef<jobject> binder{env, nullptr};
|
||||||
|
for (int i = 0; i < 3; ++i) {
|
||||||
|
binder = JNI_CallStaticObjectMethod(env, service_manager_class_,
|
||||||
get_service_method_, bridgeServiceName);
|
get_service_method_, bridgeServiceName);
|
||||||
|
if (binder) {
|
||||||
|
LOGD("Got binder for system server");
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
LOGI("Fail to get binder for system server, try again in 1s");
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
std::this_thread::sleep_for(1s);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
if (!binder) {
|
if (!binder) {
|
||||||
LOGD("Fail to get binder for system server");
|
LOGW("Fail to get binder for system server");
|
||||||
return {env, nullptr};
|
return {env, nullptr};
|
||||||
}
|
}
|
||||||
auto method = JNI_GetStaticMethodID(env, bridge_service_class_,
|
auto method = JNI_GetStaticMethodID(env, bridge_service_class_,
|
||||||
|
|
|
||||||
|
|
@ -265,7 +265,7 @@ public class BridgeService {
|
||||||
try {
|
try {
|
||||||
String processName = data.readString();
|
String processName = data.readString();
|
||||||
IBinder heartBeat = data.readStrongBinder();
|
IBinder heartBeat = data.readStrongBinder();
|
||||||
var applicationService = service.requestApplicationService(Binder.getCallingUid(), Binder.getCallingPid(), processName, heartBeat);
|
var applicationService = service == null ? null : service.requestApplicationService(Binder.getCallingUid(), Binder.getCallingPid(), processName, heartBeat);
|
||||||
if (applicationService != null) binder = applicationService.asBinder();
|
if (applicationService != null) binder = applicationService.asBinder();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, Log.getStackTraceString(e));
|
Log.e(TAG, Log.getStackTraceString(e));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue