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 android.hardware.location;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.util.Log;
22
23/**
24 * Geofence Hardware Request used for internal location services communication.
25 *
26 * @hide
27 */
28public final class GeofenceHardwareRequestParcelable implements Parcelable {
29    private GeofenceHardwareRequest mRequest;
30    private int mId;
31
32    public GeofenceHardwareRequestParcelable(int id, GeofenceHardwareRequest request) {
33        mId = id;
34        mRequest = request;
35    }
36
37    /**
38     * Returns the id of this request.
39     */
40    public int getId() {
41        return mId;
42    }
43
44    /**
45     * Returns the latitude of this geofence.
46     */
47    public double getLatitude() {
48        return mRequest.getLatitude();
49    }
50
51    /**
52     * Returns the longitude of this geofence.
53     */
54    public double getLongitude() {
55        return mRequest.getLongitude();
56    }
57
58    /**
59     * Returns the radius of this geofence.
60     */
61    public double getRadius() {
62        return mRequest.getRadius();
63    }
64
65    /**
66     * Returns transitions monitored for this geofence.
67     */
68    public int getMonitorTransitions() {
69        return mRequest.getMonitorTransitions();
70    }
71
72    /**
73     * Returns the unknownTimer of this geofence.
74     */
75    public int getUnknownTimer() {
76        return mRequest.getUnknownTimer();
77    }
78
79    /**
80     * Returns the notification responsiveness of this geofence.
81     */
82    public int getNotificationResponsiveness() {
83        return mRequest.getNotificationResponsiveness();
84    }
85
86    /**
87     * Returns the last transition of this geofence.
88     */
89    public int getLastTransition() {
90        return mRequest.getLastTransition();
91    }
92
93    /**
94     * Returns the type of the geofence for the current request.
95     */
96    int getType() {
97        return mRequest.getType();
98    }
99
100    /**
101     * Method definitions to support Parcelable operations.
102     */
103    public static final Parcelable.Creator<GeofenceHardwareRequestParcelable> CREATOR =
104            new Parcelable.Creator<GeofenceHardwareRequestParcelable>() {
105        @Override
106        public GeofenceHardwareRequestParcelable createFromParcel(Parcel parcel) {
107            int geofenceType = parcel.readInt();
108            if(geofenceType != GeofenceHardwareRequest.GEOFENCE_TYPE_CIRCLE) {
109                Log.e(
110                        "GeofenceHardwareRequest",
111                        String.format("Invalid Geofence type: %d", geofenceType));
112                return null;
113            }
114
115            GeofenceHardwareRequest request = GeofenceHardwareRequest.createCircularGeofence(
116                    parcel.readDouble(),
117                    parcel.readDouble(),
118                    parcel.readDouble());
119            request.setLastTransition(parcel.readInt());
120            request.setMonitorTransitions(parcel.readInt());
121            request.setUnknownTimer(parcel.readInt());
122            request.setNotificationResponsiveness(parcel.readInt());
123
124            int id = parcel.readInt();
125            return new GeofenceHardwareRequestParcelable(id, request);
126        }
127
128        @Override
129        public GeofenceHardwareRequestParcelable[] newArray(int size) {
130            return new GeofenceHardwareRequestParcelable[size];
131        }
132    };
133
134    @Override
135    public int describeContents() {
136        return 0;
137    }
138
139    @Override
140    public void writeToParcel(Parcel parcel, int flags) {
141        parcel.writeInt(getType());
142        parcel.writeDouble(getLatitude());
143        parcel.writeDouble(getLongitude());
144        parcel.writeDouble(getRadius());
145        parcel.writeInt(getLastTransition());
146        parcel.writeInt(getMonitorTransitions());
147        parcel.writeInt(getUnknownTimer());
148        parcel.writeInt(getNotificationResponsiveness());
149        parcel.writeInt(getId());
150    }
151}
152