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.BadParcelableException; 20 import android.os.Parcel; 21 import android.os.Parcelable; 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 GeofenceHardwareRequestParcelable(int id, GeofenceHardwareRequest request)32 public GeofenceHardwareRequestParcelable(int id, GeofenceHardwareRequest request) { 33 mId = id; 34 mRequest = request; 35 } 36 37 /** 38 * Returns the id of this request. 39 */ getId()40 public int getId() { 41 return mId; 42 } 43 44 /** 45 * Returns the latitude of this geofence. 46 */ getLatitude()47 public double getLatitude() { 48 return mRequest.getLatitude(); 49 } 50 51 /** 52 * Returns the longitude of this geofence. 53 */ getLongitude()54 public double getLongitude() { 55 return mRequest.getLongitude(); 56 } 57 58 /** 59 * Returns the radius of this geofence. 60 */ getRadius()61 public double getRadius() { 62 return mRequest.getRadius(); 63 } 64 65 /** 66 * Returns transitions monitored for this geofence. 67 */ getMonitorTransitions()68 public int getMonitorTransitions() { 69 return mRequest.getMonitorTransitions(); 70 } 71 72 /** 73 * Returns the unknownTimer of this geofence. 74 */ getUnknownTimer()75 public int getUnknownTimer() { 76 return mRequest.getUnknownTimer(); 77 } 78 79 /** 80 * Returns the notification responsiveness of this geofence. 81 */ getNotificationResponsiveness()82 public int getNotificationResponsiveness() { 83 return mRequest.getNotificationResponsiveness(); 84 } 85 86 /** 87 * Returns the last transition of this geofence. 88 */ getLastTransition()89 public int getLastTransition() { 90 return mRequest.getLastTransition(); 91 } 92 93 /** 94 * Returns the type of the geofence for the current request. 95 */ getType()96 int getType() { 97 return mRequest.getType(); 98 } 99 100 /** 101 * Returns the source technologies to track this geofence. 102 */ getSourceTechnologies()103 int getSourceTechnologies() { 104 return mRequest.getSourceTechnologies(); 105 } 106 107 108 @Override toString()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 /** 135 * Method definitions to support Parcelable operations. 136 */ 137 public static final @android.annotation.NonNull Parcelable.Creator<GeofenceHardwareRequestParcelable> CREATOR = 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 throw new BadParcelableException("Invalid Geofence type: " + geofenceType); 144 } 145 146 GeofenceHardwareRequest request = GeofenceHardwareRequest.createCircularGeofence( 147 parcel.readDouble(), 148 parcel.readDouble(), 149 parcel.readDouble()); 150 request.setLastTransition(parcel.readInt()); 151 request.setMonitorTransitions(parcel.readInt()); 152 request.setUnknownTimer(parcel.readInt()); 153 request.setNotificationResponsiveness(parcel.readInt()); 154 request.setSourceTechnologies(parcel.readInt()); 155 156 int id = parcel.readInt(); 157 return new GeofenceHardwareRequestParcelable(id, request); 158 } 159 160 @Override 161 public GeofenceHardwareRequestParcelable[] newArray(int size) { 162 return new GeofenceHardwareRequestParcelable[size]; 163 } 164 }; 165 166 @Override describeContents()167 public int describeContents() { 168 return 0; 169 } 170 171 @Override writeToParcel(Parcel parcel, int flags)172 public void writeToParcel(Parcel parcel, int flags) { 173 parcel.writeInt(getType()); 174 parcel.writeDouble(getLatitude()); 175 parcel.writeDouble(getLongitude()); 176 parcel.writeDouble(getRadius()); 177 parcel.writeInt(getLastTransition()); 178 parcel.writeInt(getMonitorTransitions()); 179 parcel.writeInt(getUnknownTimer()); 180 parcel.writeInt(getNotificationResponsiveness()); 181 parcel.writeInt(getSourceTechnologies()); 182 parcel.writeInt(getId()); 183 } 184 } 185