16fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly/*
26fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * Copyright (C) 2012 The Android Open Source Project
36fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly *
46fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * Licensed under the Apache License, Version 2.0 (the "License");
56fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * you may not use this file except in compliance with the License.
66fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * You may obtain a copy of the License at
76fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly *
86fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly *      http://www.apache.org/licenses/LICENSE-2.0
96fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly *
106fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * Unless required by applicable law or agreed to in writing, software
116fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * distributed under the License is distributed on an "AS IS" BASIS,
126fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * See the License for the specific language governing permissions and
146fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly * limitations under the License.
156fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly */
166fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
176fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellypackage com.android.location.fused;
186fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
196fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellyimport android.app.Service;
206fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellyimport android.content.Intent;
216fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellyimport android.os.IBinder;
226fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
236fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pellypublic class FusedLocationService extends Service {
246fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    private FusedLocationProvider mProvider;
256fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
266fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    @Override
276fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    public IBinder onBind(Intent intent) {
286fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        if (mProvider == null) {
296fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            mProvider = new FusedLocationProvider(getApplicationContext());
306fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        }
316fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        return mProvider.getBinder();
326fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    }
336fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
346fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    @Override
356fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    public boolean onUnbind(Intent intent) {
366fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        // make sure to stop performing work
376fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        if (mProvider != null) {
386fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly            mProvider.onDisable();
396fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        }
406fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly      return false;
416fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    }
426fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly
436fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    @Override
446fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    public void onDestroy() {
456fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly        mProvider = null;
466fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly    }
476fa9ad4afcd762aea519ff61811386c23d18ddb2Nick Pelly}
48