10682809ad08db284d7110aab44108d5e9c310e6bdestradaa/* 20682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Copyright (C) 2013 The Android Open Source Project 30682809ad08db284d7110aab44108d5e9c310e6bdestradaa * 40682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Licensed under the Apache License, Version 2.0 (the "License"); 50682809ad08db284d7110aab44108d5e9c310e6bdestradaa * you may not use this file except in compliance with the License. 60682809ad08db284d7110aab44108d5e9c310e6bdestradaa * You may obtain a copy of the License at 70682809ad08db284d7110aab44108d5e9c310e6bdestradaa * 80682809ad08db284d7110aab44108d5e9c310e6bdestradaa * http://www.apache.org/licenses/LICENSE-2.0 90682809ad08db284d7110aab44108d5e9c310e6bdestradaa * 100682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Unless required by applicable law or agreed to in writing, software 110682809ad08db284d7110aab44108d5e9c310e6bdestradaa * distributed under the License is distributed on an "AS IS" BASIS, 120682809ad08db284d7110aab44108d5e9c310e6bdestradaa * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130682809ad08db284d7110aab44108d5e9c310e6bdestradaa * See the License for the specific language governing permissions and 140682809ad08db284d7110aab44108d5e9c310e6bdestradaa * limitations under the License. 150682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 160682809ad08db284d7110aab44108d5e9c310e6bdestradaa 170682809ad08db284d7110aab44108d5e9c310e6bdestradaapackage android.hardware.location; 180682809ad08db284d7110aab44108d5e9c310e6bdestradaa 190682809ad08db284d7110aab44108d5e9c310e6bdestradaaimport android.os.Parcel; 200682809ad08db284d7110aab44108d5e9c310e6bdestradaaimport android.os.Parcelable; 210682809ad08db284d7110aab44108d5e9c310e6bdestradaaimport android.util.Log; 220682809ad08db284d7110aab44108d5e9c310e6bdestradaa 230682809ad08db284d7110aab44108d5e9c310e6bdestradaa/** 240682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Geofence Hardware Request used for internal location services communication. 250682809ad08db284d7110aab44108d5e9c310e6bdestradaa * 260682809ad08db284d7110aab44108d5e9c310e6bdestradaa * @hide 270682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 280682809ad08db284d7110aab44108d5e9c310e6bdestradaapublic final class GeofenceHardwareRequestParcelable implements Parcelable { 290682809ad08db284d7110aab44108d5e9c310e6bdestradaa private GeofenceHardwareRequest mRequest; 300682809ad08db284d7110aab44108d5e9c310e6bdestradaa private int mId; 310682809ad08db284d7110aab44108d5e9c310e6bdestradaa 320682809ad08db284d7110aab44108d5e9c310e6bdestradaa public GeofenceHardwareRequestParcelable(int id, GeofenceHardwareRequest request) { 330682809ad08db284d7110aab44108d5e9c310e6bdestradaa mId = id; 340682809ad08db284d7110aab44108d5e9c310e6bdestradaa mRequest = request; 350682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 360682809ad08db284d7110aab44108d5e9c310e6bdestradaa 370682809ad08db284d7110aab44108d5e9c310e6bdestradaa /** 380682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Returns the id of this request. 390682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 400682809ad08db284d7110aab44108d5e9c310e6bdestradaa public int getId() { 410682809ad08db284d7110aab44108d5e9c310e6bdestradaa return mId; 420682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 430682809ad08db284d7110aab44108d5e9c310e6bdestradaa 440682809ad08db284d7110aab44108d5e9c310e6bdestradaa /** 450682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Returns the latitude of this geofence. 460682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 470682809ad08db284d7110aab44108d5e9c310e6bdestradaa public double getLatitude() { 480682809ad08db284d7110aab44108d5e9c310e6bdestradaa return mRequest.getLatitude(); 490682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 500682809ad08db284d7110aab44108d5e9c310e6bdestradaa 510682809ad08db284d7110aab44108d5e9c310e6bdestradaa /** 520682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Returns the longitude of this geofence. 530682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 540682809ad08db284d7110aab44108d5e9c310e6bdestradaa public double getLongitude() { 550682809ad08db284d7110aab44108d5e9c310e6bdestradaa return mRequest.getLongitude(); 560682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 570682809ad08db284d7110aab44108d5e9c310e6bdestradaa 580682809ad08db284d7110aab44108d5e9c310e6bdestradaa /** 590682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Returns the radius of this geofence. 600682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 610682809ad08db284d7110aab44108d5e9c310e6bdestradaa public double getRadius() { 620682809ad08db284d7110aab44108d5e9c310e6bdestradaa return mRequest.getRadius(); 630682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 640682809ad08db284d7110aab44108d5e9c310e6bdestradaa 650682809ad08db284d7110aab44108d5e9c310e6bdestradaa /** 660682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Returns transitions monitored for this geofence. 670682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 680682809ad08db284d7110aab44108d5e9c310e6bdestradaa public int getMonitorTransitions() { 690682809ad08db284d7110aab44108d5e9c310e6bdestradaa return mRequest.getMonitorTransitions(); 700682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 710682809ad08db284d7110aab44108d5e9c310e6bdestradaa 720682809ad08db284d7110aab44108d5e9c310e6bdestradaa /** 730682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Returns the unknownTimer of this geofence. 740682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 750682809ad08db284d7110aab44108d5e9c310e6bdestradaa public int getUnknownTimer() { 760682809ad08db284d7110aab44108d5e9c310e6bdestradaa return mRequest.getUnknownTimer(); 770682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 780682809ad08db284d7110aab44108d5e9c310e6bdestradaa 790682809ad08db284d7110aab44108d5e9c310e6bdestradaa /** 800682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Returns the notification responsiveness of this geofence. 810682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 820682809ad08db284d7110aab44108d5e9c310e6bdestradaa public int getNotificationResponsiveness() { 830682809ad08db284d7110aab44108d5e9c310e6bdestradaa return mRequest.getNotificationResponsiveness(); 840682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 850682809ad08db284d7110aab44108d5e9c310e6bdestradaa 860682809ad08db284d7110aab44108d5e9c310e6bdestradaa /** 870682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Returns the last transition of this geofence. 880682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 890682809ad08db284d7110aab44108d5e9c310e6bdestradaa public int getLastTransition() { 900682809ad08db284d7110aab44108d5e9c310e6bdestradaa return mRequest.getLastTransition(); 910682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 920682809ad08db284d7110aab44108d5e9c310e6bdestradaa 930682809ad08db284d7110aab44108d5e9c310e6bdestradaa /** 940682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Returns the type of the geofence for the current request. 950682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 960682809ad08db284d7110aab44108d5e9c310e6bdestradaa int getType() { 970682809ad08db284d7110aab44108d5e9c310e6bdestradaa return mRequest.getType(); 980682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 990682809ad08db284d7110aab44108d5e9c310e6bdestradaa 1000682809ad08db284d7110aab44108d5e9c310e6bdestradaa /** 101f9a274c9b8578dda6afeda422bff18b1577028b9destradaa * Returns the source technologies to track this geofence. 102f9a274c9b8578dda6afeda422bff18b1577028b9destradaa */ 103f9a274c9b8578dda6afeda422bff18b1577028b9destradaa int getSourceTechnologies() { 104f9a274c9b8578dda6afeda422bff18b1577028b9destradaa return mRequest.getSourceTechnologies(); 105f9a274c9b8578dda6afeda422bff18b1577028b9destradaa } 106f9a274c9b8578dda6afeda422bff18b1577028b9destradaa 107f9a274c9b8578dda6afeda422bff18b1577028b9destradaa 108f9a274c9b8578dda6afeda422bff18b1577028b9destradaa @Override 109f9a274c9b8578dda6afeda422bff18b1577028b9destradaa public String toString() { 110f9a274c9b8578dda6afeda422bff18b1577028b9destradaa StringBuilder builder = new StringBuilder(); 111f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append("id="); 112f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(mId); 113f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(", type="); 114f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(mRequest.getType()); 115f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(", latitude="); 116f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(mRequest.getLatitude()); 117f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(", longitude="); 118f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(mRequest.getLongitude()); 119f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(", radius="); 120f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(mRequest.getRadius()); 121f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(", lastTransition="); 122f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(mRequest.getLastTransition()); 123f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(", unknownTimer="); 124f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(mRequest.getUnknownTimer()); 125f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(", monitorTransitions="); 126f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(mRequest.getMonitorTransitions()); 127f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(", notificationResponsiveness="); 128f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(mRequest.getNotificationResponsiveness()); 129f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(", sourceTechnologies="); 130f9a274c9b8578dda6afeda422bff18b1577028b9destradaa builder.append(mRequest.getSourceTechnologies()); 131f9a274c9b8578dda6afeda422bff18b1577028b9destradaa return builder.toString(); 132f9a274c9b8578dda6afeda422bff18b1577028b9destradaa } 133f9a274c9b8578dda6afeda422bff18b1577028b9destradaa 134f9a274c9b8578dda6afeda422bff18b1577028b9destradaa /** 1350682809ad08db284d7110aab44108d5e9c310e6bdestradaa * Method definitions to support Parcelable operations. 1360682809ad08db284d7110aab44108d5e9c310e6bdestradaa */ 137f9a274c9b8578dda6afeda422bff18b1577028b9destradaa public static final Parcelable.Creator<GeofenceHardwareRequestParcelable> CREATOR = 1380682809ad08db284d7110aab44108d5e9c310e6bdestradaa new Parcelable.Creator<GeofenceHardwareRequestParcelable>() { 1390682809ad08db284d7110aab44108d5e9c310e6bdestradaa @Override 1400682809ad08db284d7110aab44108d5e9c310e6bdestradaa public GeofenceHardwareRequestParcelable createFromParcel(Parcel parcel) { 1410682809ad08db284d7110aab44108d5e9c310e6bdestradaa int geofenceType = parcel.readInt(); 1420682809ad08db284d7110aab44108d5e9c310e6bdestradaa if(geofenceType != GeofenceHardwareRequest.GEOFENCE_TYPE_CIRCLE) { 1430682809ad08db284d7110aab44108d5e9c310e6bdestradaa Log.e( 1440682809ad08db284d7110aab44108d5e9c310e6bdestradaa "GeofenceHardwareRequest", 1450682809ad08db284d7110aab44108d5e9c310e6bdestradaa String.format("Invalid Geofence type: %d", geofenceType)); 1460682809ad08db284d7110aab44108d5e9c310e6bdestradaa return null; 1470682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 1480682809ad08db284d7110aab44108d5e9c310e6bdestradaa 1490682809ad08db284d7110aab44108d5e9c310e6bdestradaa GeofenceHardwareRequest request = GeofenceHardwareRequest.createCircularGeofence( 1500682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.readDouble(), 1510682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.readDouble(), 1520682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.readDouble()); 1530682809ad08db284d7110aab44108d5e9c310e6bdestradaa request.setLastTransition(parcel.readInt()); 1540682809ad08db284d7110aab44108d5e9c310e6bdestradaa request.setMonitorTransitions(parcel.readInt()); 1550682809ad08db284d7110aab44108d5e9c310e6bdestradaa request.setUnknownTimer(parcel.readInt()); 1560682809ad08db284d7110aab44108d5e9c310e6bdestradaa request.setNotificationResponsiveness(parcel.readInt()); 157f9a274c9b8578dda6afeda422bff18b1577028b9destradaa request.setSourceTechnologies(parcel.readInt()); 158f9a274c9b8578dda6afeda422bff18b1577028b9destradaa 1590682809ad08db284d7110aab44108d5e9c310e6bdestradaa int id = parcel.readInt(); 1600682809ad08db284d7110aab44108d5e9c310e6bdestradaa return new GeofenceHardwareRequestParcelable(id, request); 1610682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 1620682809ad08db284d7110aab44108d5e9c310e6bdestradaa 1630682809ad08db284d7110aab44108d5e9c310e6bdestradaa @Override 1640682809ad08db284d7110aab44108d5e9c310e6bdestradaa public GeofenceHardwareRequestParcelable[] newArray(int size) { 1650682809ad08db284d7110aab44108d5e9c310e6bdestradaa return new GeofenceHardwareRequestParcelable[size]; 1660682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 1670682809ad08db284d7110aab44108d5e9c310e6bdestradaa }; 1680682809ad08db284d7110aab44108d5e9c310e6bdestradaa 1690682809ad08db284d7110aab44108d5e9c310e6bdestradaa @Override 1700682809ad08db284d7110aab44108d5e9c310e6bdestradaa public int describeContents() { 1710682809ad08db284d7110aab44108d5e9c310e6bdestradaa return 0; 1720682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 1730682809ad08db284d7110aab44108d5e9c310e6bdestradaa 1740682809ad08db284d7110aab44108d5e9c310e6bdestradaa @Override 1750682809ad08db284d7110aab44108d5e9c310e6bdestradaa public void writeToParcel(Parcel parcel, int flags) { 1760682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.writeInt(getType()); 1770682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.writeDouble(getLatitude()); 1780682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.writeDouble(getLongitude()); 1790682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.writeDouble(getRadius()); 1800682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.writeInt(getLastTransition()); 1810682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.writeInt(getMonitorTransitions()); 1820682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.writeInt(getUnknownTimer()); 1830682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.writeInt(getNotificationResponsiveness()); 184f9a274c9b8578dda6afeda422bff18b1577028b9destradaa parcel.writeInt(getSourceTechnologies()); 1850682809ad08db284d7110aab44108d5e9c310e6bdestradaa parcel.writeInt(getId()); 1860682809ad08db284d7110aab44108d5e9c310e6bdestradaa } 1870682809ad08db284d7110aab44108d5e9c310e6bdestradaa} 188