soundtrigger: add size check on sound model and recogntion data

Bug: 30148546

Change-Id: I082f535a853c96571887eeea37c6d41ecee7d8c0
(cherry picked from commit bb00d8f139ff51336ab3c810d35685003949bcf8)
(cherry picked from commit ef0c91518446e65533ca8bab6726a845f27c73fd)

void SoundTriggerHwService::Module::detach() {
    ALOGV("detach()");
 if (!captureHotwordAllowed()) {
 return;
 }
 {
 AutoMutex lock(mLock);
 for (size_t i = 0; i < mModels.size(); i++) {
            sp<Model> model = mModels.valueAt(i);
            ALOGV("detach() unloading model %d", model->mHandle);
 if (model->mState == Model::STATE_ACTIVE) {
                mHwDevice->stop_recognition(mHwDevice, model->mHandle);
 }
            mHwDevice->unload_sound_model(mHwDevice, model->mHandle);
 }
        mModels.clear();
 }
 if (mClient != 0) {
 IInterface::asBinder(mClient)->unlinkToDeath(this);
 }
    sp<SoundTriggerHwService> service = mService.promote();
 if (service == 0) {
 return;
 }
    service->detachModule(this);
}

void SoundTriggerHwService::Module::detach() {
    ALOGV("detach()");
 if (!captureHotwordAllowed()) {
 return;
 }
 {
 AutoMutex lock(mLock);
 for (size_t i = 0; i < mModels.size(); i++) {
            sp<Model> model = mModels.valueAt(i);
            ALOGV("detach() unloading model %d", model->mHandle);
 if (model->mState == Model::STATE_ACTIVE) {
                mHwDevice->stop_recognition(mHwDevice, model->mHandle);
 }
            mHwDevice->unload_sound_model(mHwDevice, model->mHandle);
 }
        mModels.clear();
 }
 if (mClient != 0) {
 IInterface::asBinder(mClient)->unlinkToDeath(this);
 }
    sp<SoundTriggerHwService> service = mService.promote();
 if (service == 0) {
 return;
 }
    service->detachModule(this);
}
