1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.location.provider;
18
19import android.hardware.location.GeofenceHardware;
20import android.hardware.location.IGeofenceHardware;
21import android.os.IBinder;
22
23import android.location.IGeofenceProvider;
24
25/**
26 * Base class for geofence providers implemented as unbundled services.
27 *
28 * <p>Geofence providers can be implemented as services and return the result of
29 * {@link com.android.location.provider.GeofenceProvider#getBinder()} in its getBinder() method.
30 *
31 * <p>IMPORTANT: This class is effectively a public API for unbundled
32 * applications, and must remain API stable. See README.txt in the root
33 * of this package for more information.
34 */
35public abstract class GeofenceProvider {
36
37    private GeofenceHardware mGeofenceHardware;
38
39    private IGeofenceProvider.Stub mProvider = new IGeofenceProvider.Stub() {
40        public void setGeofenceHardware(IGeofenceHardware hardwareProxy) {
41            mGeofenceHardware = new GeofenceHardware(hardwareProxy);
42            onGeofenceHardwareChange(mGeofenceHardware);
43        }
44    };
45
46    /**
47     * Returns the Binder interface for the geofence provider.
48     * This is intended to be used for the onBind() method of
49     * a service that implements a geofence service.
50     *
51     * @return the IBinder instance for the provider
52     */
53    public IBinder getBinder() {
54        return mProvider;
55    }
56
57    /**
58     * Called when GeofenceHardware object becomes available.
59     *
60     * @param geofenceHardware Geofence Hardware object. This can be null
61     *        when for some reason the service connection gets disconnected.
62     */
63    public abstract void onGeofenceHardwareChange(GeofenceHardware geofenceHardware);
64}
65