destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 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 | |
| 17 | package android.hardware.location; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | import android.util.Log; |
| 22 | |
| 23 | /** |
| 24 | * Geofence Hardware Request used for internal location services communication. |
| 25 | * |
| 26 | * @hide |
| 27 | */ |
| 28 | public 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 | /** |
destradaa | f9a274c | 2014-07-25 15:11:56 -0700 | [diff] [blame] | 101 | * Returns the source technologies to track this geofence. |
| 102 | */ |
| 103 | int getSourceTechnologies() { |
| 104 | return mRequest.getSourceTechnologies(); |
| 105 | } |
| 106 | |
| 107 | |
| 108 | @Override |
| 109 | public String toString() { |
| 110 | StringBuilder builder = new StringBuilder(); |
| 111 | builder.append("id="); |
| 112 | builder.append(mId); |
| 113 | builder.append(", type="); |
| 114 | builder.append(mRequest.getType()); |
| 115 | builder.append(", latitude="); |
| 116 | builder.append(mRequest.getLatitude()); |
| 117 | builder.append(", longitude="); |
| 118 | builder.append(mRequest.getLongitude()); |
| 119 | builder.append(", radius="); |
| 120 | builder.append(mRequest.getRadius()); |
| 121 | builder.append(", lastTransition="); |
| 122 | builder.append(mRequest.getLastTransition()); |
| 123 | builder.append(", unknownTimer="); |
| 124 | builder.append(mRequest.getUnknownTimer()); |
| 125 | builder.append(", monitorTransitions="); |
| 126 | builder.append(mRequest.getMonitorTransitions()); |
| 127 | builder.append(", notificationResponsiveness="); |
| 128 | builder.append(mRequest.getNotificationResponsiveness()); |
| 129 | builder.append(", sourceTechnologies="); |
| 130 | builder.append(mRequest.getSourceTechnologies()); |
| 131 | return builder.toString(); |
| 132 | } |
| 133 | |
| 134 | /** |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 135 | * Method definitions to support Parcelable operations. |
| 136 | */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 137 | public static final @android.annotation.NonNull Parcelable.Creator<GeofenceHardwareRequestParcelable> CREATOR = |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 138 | new Parcelable.Creator<GeofenceHardwareRequestParcelable>() { |
| 139 | @Override |
| 140 | public GeofenceHardwareRequestParcelable createFromParcel(Parcel parcel) { |
| 141 | int geofenceType = parcel.readInt(); |
| 142 | if(geofenceType != GeofenceHardwareRequest.GEOFENCE_TYPE_CIRCLE) { |
| 143 | Log.e( |
| 144 | "GeofenceHardwareRequest", |
| 145 | String.format("Invalid Geofence type: %d", geofenceType)); |
| 146 | return null; |
| 147 | } |
| 148 | |
| 149 | GeofenceHardwareRequest request = GeofenceHardwareRequest.createCircularGeofence( |
| 150 | parcel.readDouble(), |
| 151 | parcel.readDouble(), |
| 152 | parcel.readDouble()); |
| 153 | request.setLastTransition(parcel.readInt()); |
| 154 | request.setMonitorTransitions(parcel.readInt()); |
| 155 | request.setUnknownTimer(parcel.readInt()); |
| 156 | request.setNotificationResponsiveness(parcel.readInt()); |
destradaa | f9a274c | 2014-07-25 15:11:56 -0700 | [diff] [blame] | 157 | request.setSourceTechnologies(parcel.readInt()); |
| 158 | |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 159 | int id = parcel.readInt(); |
| 160 | return new GeofenceHardwareRequestParcelable(id, request); |
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public GeofenceHardwareRequestParcelable[] newArray(int size) { |
| 165 | return new GeofenceHardwareRequestParcelable[size]; |
| 166 | } |
| 167 | }; |
| 168 | |
| 169 | @Override |
| 170 | public int describeContents() { |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public void writeToParcel(Parcel parcel, int flags) { |
| 176 | parcel.writeInt(getType()); |
| 177 | parcel.writeDouble(getLatitude()); |
| 178 | parcel.writeDouble(getLongitude()); |
| 179 | parcel.writeDouble(getRadius()); |
| 180 | parcel.writeInt(getLastTransition()); |
| 181 | parcel.writeInt(getMonitorTransitions()); |
| 182 | parcel.writeInt(getUnknownTimer()); |
| 183 | parcel.writeInt(getNotificationResponsiveness()); |
destradaa | f9a274c | 2014-07-25 15:11:56 -0700 | [diff] [blame] | 184 | parcel.writeInt(getSourceTechnologies()); |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 185 | parcel.writeInt(getId()); |
| 186 | } |
| 187 | } |