Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e71d3b1 authored by Greg Kaiser's avatar Greg Kaiser Committed by android-build-merger
Browse files

ContextHubService: Update caches on nanoapp unload am: 0d052c95 am: e7a0e1a7

am: 27452edb

Change-Id: I1afc8ea3d02b15e330908794346cd8a4a2cbf822
parents bed286dc 27452edb
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -386,24 +386,30 @@ 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;

    return_id(id);
    if (db.appInstances.count(id)) {
        db.appInstances.erase(id);
    if (env->CallIntMethod(db.jniInfo.jContextHubService,
    } else {
        ALOGW("Cannot delete App id (%d) from the JNI C++ cache", id);
        fullyDeleted = false;
    }
    return_id(id);

    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;
    }

    if (fullyDeleted) {
        ALOGI("Deleted App id : %d", id);

        return 0;
    }
    return -1;
}

static int startLoadAppTxn(uint64_t appId, int hubHandle) {
    app_instance_info_s *txnInfo = (app_instance_info_s *)malloc(sizeof(app_instance_info_s));
@@ -615,7 +621,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);
    }
@@ -670,6 +683,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();