ContextHubService: Update caches on nanoapp unload
When we unloaded a nanoapp, we weren't updating the cache of nanoapp information at the ContextHubServer java layer. Also, we were leaking the handle. We fix both of these by invoking the shared delete_app_instance() function which properly handles all of this. Furthermore, we allow delete_app_instance() to accept a nullptr for the JNIEnv, and fix invalidateNanoApps() so that it won't crash if it's unable to connect to the JVM. Note that our Java communication in general here should be cleaned up, but we're too late in the release cycle for that, and leave that for b/30961119. Bug: 30951974, 30968860 Change-Id: Ibb07666a8d54618bddaa3eaf36f9578926eb2b0f
This commit is contained in:
@@ -386,23 +386,29 @@ static int add_app_instance(const hub_app_info *appInfo, uint32_t hubHandle,
|
||||
}
|
||||
|
||||
int delete_app_instance(int id, JNIEnv *env) {
|
||||
if (!db.appInstances.count(id)) {
|
||||
ALOGW("Cannot find App id : %d", id);
|
||||
return -1;
|
||||
}
|
||||
bool fullyDeleted = true;
|
||||
|
||||
if (db.appInstances.count(id)) {
|
||||
db.appInstances.erase(id);
|
||||
} else {
|
||||
ALOGW("Cannot delete App id (%d) from the JNI C++ cache", id);
|
||||
fullyDeleted = false;
|
||||
}
|
||||
return_id(id);
|
||||
db.appInstances.erase(id);
|
||||
if (env->CallIntMethod(db.jniInfo.jContextHubService,
|
||||
|
||||
if ((env == nullptr) ||
|
||||
(env->CallIntMethod(db.jniInfo.jContextHubService,
|
||||
db.jniInfo.contextHubServiceDeleteAppInstance,
|
||||
id) != 0) {
|
||||
ALOGW("Could not delete App id : %d", id);
|
||||
return -1;
|
||||
id) != 0)) {
|
||||
ALOGW("Cannot delete App id (%d) from Java cache", id);
|
||||
fullyDeleted = false;
|
||||
}
|
||||
|
||||
ALOGI("Deleted App id : %d", id);
|
||||
|
||||
return 0;
|
||||
if (fullyDeleted) {
|
||||
ALOGI("Deleted App id : %d", id);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int startLoadAppTxn(uint64_t appId, int hubHandle) {
|
||||
@@ -613,7 +619,14 @@ void closeUnloadTxn(bool success) {
|
||||
|
||||
if (success && fetchTxnData(&txnId, &txnData) == 0 &&
|
||||
txnId == CONTEXT_HUB_UNLOAD_APP) {
|
||||
db.appInstances.erase(*(uint32_t *)txnData);
|
||||
JNIEnv *env;
|
||||
if ((db.jniInfo.vm)->AttachCurrentThread(&env, nullptr) != JNI_OK) {
|
||||
ALOGW("Could not attach to JVM !");
|
||||
env = nullptr;
|
||||
}
|
||||
// TODO(b/30806218): Stop treating 'int' and uint32_t as the same type.
|
||||
int handle = *(uint32_t *)txnData;
|
||||
delete_app_instance(handle, env);
|
||||
} else {
|
||||
ALOGW("Could not unload the app successfully ! success %d, txnData %p", success, txnData);
|
||||
}
|
||||
@@ -668,6 +681,7 @@ static void invalidateNanoApps(uint32_t hubHandle) {
|
||||
|
||||
if ((db.jniInfo.vm)->AttachCurrentThread(&env, nullptr) != JNI_OK) {
|
||||
ALOGW("Could not attach to JVM !");
|
||||
env = nullptr;
|
||||
}
|
||||
|
||||
auto end = db.appInstances.end();
|
||||
|
||||
Reference in New Issue
Block a user