1 /*
2  * Copyright (C) 2014 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.annotation.SystemApi;
20 import android.location.Location;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 /**
25  * A class that represents an event for each change in the state of a monitoring system.
26  *
27  * @hide
28  */
29 @SystemApi
30 public class GeofenceHardwareMonitorEvent implements Parcelable {
31     private final int mMonitoringType;
32     private final int mMonitoringStatus;
33     private final int mSourceTechnologies;
34     private final Location mLocation;
35 
GeofenceHardwareMonitorEvent( int monitoringType, int monitoringStatus, int sourceTechnologies, Location location)36     public GeofenceHardwareMonitorEvent(
37             int monitoringType,
38             int monitoringStatus,
39             int sourceTechnologies,
40             Location location) {
41         mMonitoringType = monitoringType;
42         mMonitoringStatus = monitoringStatus;
43         mSourceTechnologies = sourceTechnologies;
44         mLocation = location;
45     }
46 
47     /**
48      * Returns the type of the monitoring system that has a change on its state.
49      */
getMonitoringType()50     public int getMonitoringType() {
51         return mMonitoringType;
52     }
53 
54     /**
55      * Returns the new status associated with the monitoring system.
56      */
getMonitoringStatus()57     public int getMonitoringStatus() {
58         return mMonitoringStatus;
59     }
60 
61     /**
62      * Returns the source technologies that the status is associated to.
63      */
getSourceTechnologies()64     public int getSourceTechnologies() {
65         return mSourceTechnologies;
66     }
67 
68     /**
69      * Returns the last known location according to the monitoring system.
70      */
getLocation()71     public Location getLocation() {
72         return mLocation;
73     }
74 
75     public static final Creator<GeofenceHardwareMonitorEvent> CREATOR =
76             new Creator<GeofenceHardwareMonitorEvent>() {
77                 @Override
78                 public GeofenceHardwareMonitorEvent createFromParcel(Parcel source) {
79                     ClassLoader classLoader = GeofenceHardwareMonitorEvent.class.getClassLoader();
80                     int monitoringType = source.readInt();
81                     int monitoringStatus = source.readInt();
82                     int sourceTechnologies = source.readInt();
83                     Location location = source.readParcelable(classLoader);
84 
85                     return new GeofenceHardwareMonitorEvent(
86                             monitoringType,
87                             monitoringStatus,
88                             sourceTechnologies,
89                             location);
90                 }
91 
92                 @Override
93                 public GeofenceHardwareMonitorEvent[] newArray(int size) {
94                     return new GeofenceHardwareMonitorEvent[size];
95                 }
96             };
97 
98     @Override
describeContents()99     public int describeContents() {
100         return 0;
101     }
102 
103     @Override
writeToParcel(Parcel parcel, int flags)104     public void writeToParcel(Parcel parcel, int flags) {
105         parcel.writeInt(mMonitoringType);
106         parcel.writeInt(mMonitoringStatus);
107         parcel.writeInt(mSourceTechnologies);
108         parcel.writeParcelable(mLocation, flags);
109     }
110 
111     @Override
toString()112     public String toString() {
113         return String.format(
114                 "GeofenceHardwareMonitorEvent: type=%d, status=%d, sources=%d, location=%s",
115                 mMonitoringType,
116                 mMonitoringStatus,
117                 mSourceTechnologies,
118                 mLocation);
119     }
120 }
121