1da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh/*
2da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh * Copyright (C) 2013 The Android Open Source Project
3da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh *
4da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh * Licensed under the Apache License, Version 2.0 (the "License");
5da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh * you may not use this file except in compliance with the License.
6da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh * You may obtain a copy of the License at
7da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh *
8da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh *      http://www.apache.org/licenses/LICENSE-2.0
9da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh *
10da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh * Unless required by applicable law or agreed to in writing, software
11da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh * distributed under the License is distributed on an "AS IS" BASIS,
12da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh * See the License for the specific language governing permissions and
14da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh * limitations under the License.
15da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh */
16da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
17da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganeshpackage android.hardware.location;
18da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
19c4e1e59561884afc2c71b4b52697f62bd6b38f99destradaaimport android.annotation.SystemApi;
20c4e1e59561884afc2c71b4b52697f62bd6b38f99destradaa
21da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh/**
22da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh * This class represents the characteristics of the geofence.
23da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh *
24da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh * <p> Use this in conjunction with {@link GeofenceHardware} APIs.
25c4e1e59561884afc2c71b4b52697f62bd6b38f99destradaa *
26c4e1e59561884afc2c71b4b52697f62bd6b38f99destradaa * @hide
27da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh */
28c4e1e59561884afc2c71b4b52697f62bd6b38f99destradaa@SystemApi
29da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganeshpublic final class GeofenceHardwareRequest {
30da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    static final int GEOFENCE_TYPE_CIRCLE = 0;
31da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    private int mType;
32da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    private double mLatitude;
33da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    private double mLongitude;
34da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    private double mRadius;
35da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    private int mLastTransition = GeofenceHardware.GEOFENCE_UNCERTAIN;
36da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    private int mUnknownTimer = 30000; // 30 secs
37da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    private int mMonitorTransitions = GeofenceHardware.GEOFENCE_UNCERTAIN |
38da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        GeofenceHardware.GEOFENCE_ENTERED | GeofenceHardware.GEOFENCE_EXITED;
39da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    private int mNotificationResponsiveness = 5000; // 5 secs
40f9a274c9b8578dda6afeda422bff18b1577028b9destradaa    private int mSourceTechnologies = GeofenceHardware.SOURCE_TECHNOLOGY_GNSS;
41da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
42da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    private void setCircularGeofence(double latitude, double longitude, double radius) {
43da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        mLatitude = latitude;
44da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        mLongitude = longitude;
45da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        mRadius = radius;
46da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        mType  = GEOFENCE_TYPE_CIRCLE;
47da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
48da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
49da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
50da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Create a circular geofence.
51da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *
52da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * @param latitude Latitude of the geofence
53da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * @param longitude Longitude of the geofence
54da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * @param radius Radius of the geofence (in meters)
55da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
56da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public static GeofenceHardwareRequest createCircularGeofence(double latitude,
57da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh            double longitude, double radius) {
58da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        GeofenceHardwareRequest geofenceRequest = new GeofenceHardwareRequest();
59da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        geofenceRequest.setCircularGeofence(latitude, longitude, radius);
60da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        return geofenceRequest;
61da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
62da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
63da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
64da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Set the last known transition of the geofence.
65da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *
66da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * @param lastTransition The current state of the geofence. Can be one of
67da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *        {@link GeofenceHardware#GEOFENCE_ENTERED}, {@link GeofenceHardware#GEOFENCE_EXITED},
68da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *        {@link GeofenceHardware#GEOFENCE_UNCERTAIN}.
69da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
70da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public void setLastTransition(int lastTransition) {
71da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        mLastTransition = lastTransition;
72da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
73da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
74da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
75da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Set the unknown timer for this geofence.
76da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *
77da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * @param unknownTimer  The time limit after which the
78da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *        {@link GeofenceHardware#GEOFENCE_UNCERTAIN} transition
79da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *        should be triggered. This paramter is defined in milliseconds.
80da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
81da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public void setUnknownTimer(int unknownTimer) {
82da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        mUnknownTimer = unknownTimer;
83da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
84da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
85da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
86da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Set the transitions to be monitored.
87da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *
88da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * @param monitorTransitions Bitwise OR of {@link GeofenceHardware#GEOFENCE_ENTERED},
89da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *        {@link GeofenceHardware#GEOFENCE_EXITED}, {@link GeofenceHardware#GEOFENCE_UNCERTAIN}
90da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
91da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public void setMonitorTransitions(int monitorTransitions) {
92da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        mMonitorTransitions = monitorTransitions;
93da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
94da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
95da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
96da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Set the notification responsiveness of the geofence.
97da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *
98da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * @param notificationResponsiveness (milliseconds) Defines the best-effort description
99da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *        of how soon should the callback be called when the transition
100da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *        associated with the Geofence is triggered. For instance, if
101da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *        set to 1000 millseconds with {@link GeofenceHardware#GEOFENCE_ENTERED},
102da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *        the callback will be called 1000 milliseconds within entering
103da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     *        the geofence.
104da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
105da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public void setNotificationResponsiveness(int notificationResponsiveness) {
106da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh       mNotificationResponsiveness = notificationResponsiveness;
107da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
108da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
109da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
110f9a274c9b8578dda6afeda422bff18b1577028b9destradaa     * Set the source technologies to use while tracking the geofence.
111f9a274c9b8578dda6afeda422bff18b1577028b9destradaa     * The value is the bit-wise of one or several source fields defined in
112f9a274c9b8578dda6afeda422bff18b1577028b9destradaa     * {@link GeofenceHardware}.
113f9a274c9b8578dda6afeda422bff18b1577028b9destradaa     *
114f9a274c9b8578dda6afeda422bff18b1577028b9destradaa     * @param sourceTechnologies The set of source technologies to use.
115f9a274c9b8578dda6afeda422bff18b1577028b9destradaa     */
116f9a274c9b8578dda6afeda422bff18b1577028b9destradaa    public void setSourceTechnologies(int sourceTechnologies) {
117f9a274c9b8578dda6afeda422bff18b1577028b9destradaa        int sourceTechnologiesAll = GeofenceHardware.SOURCE_TECHNOLOGY_GNSS
118f9a274c9b8578dda6afeda422bff18b1577028b9destradaa                | GeofenceHardware.SOURCE_TECHNOLOGY_WIFI
119f9a274c9b8578dda6afeda422bff18b1577028b9destradaa                | GeofenceHardware.SOURCE_TECHNOLOGY_SENSORS
120f9a274c9b8578dda6afeda422bff18b1577028b9destradaa                | GeofenceHardware.SOURCE_TECHNOLOGY_CELL
121f9a274c9b8578dda6afeda422bff18b1577028b9destradaa                | GeofenceHardware.SOURCE_TECHNOLOGY_BLUETOOTH;
122f9a274c9b8578dda6afeda422bff18b1577028b9destradaa
123f9a274c9b8578dda6afeda422bff18b1577028b9destradaa        int sanitizedSourceTechnologies = (sourceTechnologies & sourceTechnologiesAll);
124f9a274c9b8578dda6afeda422bff18b1577028b9destradaa        if (sanitizedSourceTechnologies == 0) {
125f9a274c9b8578dda6afeda422bff18b1577028b9destradaa            throw new IllegalArgumentException("At least one valid source technology must be set.");
126f9a274c9b8578dda6afeda422bff18b1577028b9destradaa        }
127f9a274c9b8578dda6afeda422bff18b1577028b9destradaa
128f9a274c9b8578dda6afeda422bff18b1577028b9destradaa        mSourceTechnologies = sanitizedSourceTechnologies;
129f9a274c9b8578dda6afeda422bff18b1577028b9destradaa    }
130f9a274c9b8578dda6afeda422bff18b1577028b9destradaa
131f9a274c9b8578dda6afeda422bff18b1577028b9destradaa    /**
132da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Returns the latitude of this geofence.
133da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
134da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public double getLatitude() {
135da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        return mLatitude;
136da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
137da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
138da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
139da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Returns the longitude of this geofence.
140da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
141da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public double getLongitude() {
142da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        return mLongitude;
143da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
144da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
145da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
146da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Returns the radius of this geofence.
147da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
148da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public double getRadius() {
149da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        return mRadius;
150da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
151da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
152da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
153da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Returns transitions monitored for this geofence.
154da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
155da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public int getMonitorTransitions() {
156da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        return mMonitorTransitions;
157da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
158da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
159da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
160da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Returns the unknownTimer of this geofence.
161da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
162da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public int getUnknownTimer() {
163da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        return mUnknownTimer;
164da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
165da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
166da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
167da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Returns the notification responsiveness of this geofence.
168da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
169da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public int getNotificationResponsiveness() {
170da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        return mNotificationResponsiveness;
171da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
172da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
173da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    /**
174da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     * Returns the last transition of this geofence.
175da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh     */
176da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    public int getLastTransition() {
177da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        return mLastTransition;
178da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
179da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh
180f9a274c9b8578dda6afeda422bff18b1577028b9destradaa    /**
181f9a274c9b8578dda6afeda422bff18b1577028b9destradaa     * Returns the source technologies to track this geofence.
182f9a274c9b8578dda6afeda422bff18b1577028b9destradaa     */
183f9a274c9b8578dda6afeda422bff18b1577028b9destradaa    public int getSourceTechnologies() {
184f9a274c9b8578dda6afeda422bff18b1577028b9destradaa        return mSourceTechnologies;
185f9a274c9b8578dda6afeda422bff18b1577028b9destradaa    }
186f9a274c9b8578dda6afeda422bff18b1577028b9destradaa
187da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    int getType() {
188da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh        return mType;
189da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh    }
190da6508954a492f3dd4397e70e4fa08ee54bd2741Jaikumar Ganesh}
191