149fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert/*
249fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert * Copyright (C) 2010 The Android Open Source Project
349fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert *
449fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License");
549fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert * you may not use this file except in compliance with the License.
649fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert * You may obtain a copy of the License at
749fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert *
849fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert *      http://www.apache.org/licenses/LICENSE-2.0
949fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert *
1049fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert * Unless required by applicable law or agreed to in writing, software
1149fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS,
1249fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1349fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert * See the License for the specific language governing permissions and
1449fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert * limitations under the License.
1549fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert */
1649fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert
1749fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringertpackage com.android.quicksearchbox;
1849fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert
1949fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringertimport android.app.Application;
2049fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert
2149fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringertpublic class QsbApplicationWrapper extends Application {
2249fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert
2349fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    private QsbApplication mApp;
2449fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert
2549fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    @Override
2649fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    public void onTerminate() {
2749fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert        synchronized (this) {
2849fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert            if (mApp != null) {
2949fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert                mApp.close();
3049fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert            }
3149fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert        }
3249fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert        super.onTerminate();
3349fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    }
3449fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert
3549fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    public synchronized QsbApplication getApp() {
3649fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert        if (mApp == null) {
3749fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert            mApp = createQsbApplication();
3849fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert        }
3949fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert        return mApp;
4049fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    }
4149fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert
4249fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    protected QsbApplication createQsbApplication() {
4349fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert        return new QsbApplication(this);
4449fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert    }
4549fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert
4649fd8e0994577badc6194c2c3b5f771f2b793fe4Bjorn Bringert}
47