1 /*
2  * Copyright (C) 2023 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 com.android.server.wifi;
18 
19 import android.location.Location;
20 
21 import org.json.JSONObject;
22 
23 /**
24  * Helper class to store a coarse location used to send to the AFC server.
25  */
26 public abstract class AfcLocation {
27     // Reference level for the value of the height field.
28     // "AGL": Above Ground Level. Antenna height as measured relative to the local
29     // ground level.
30     // "AMSL": Above Mean Sea Level. Antenna height as measured with respect to
31     // WGS84 datum.
32     enum HeightType {
33         AGL,
34         AMSL;
35     }
36 
37     // Indicator for whether the deployment of the AP or Fixed Client device is located indoors,
38     // outdoor, or is unknown.
39     enum LocationType {
40         LOCATION_TYPE_UNKNOWN,
41         INDOOR,
42         OUTDOOR;
43     }
44 
45     int mLocationType = LocationType.LOCATION_TYPE_UNKNOWN.ordinal();
46     double mHeight;
47     double mVerticalUncertainty;
48     String mHeightType;
49 
AfcLocation(Location location)50     public AfcLocation(Location location) {
51         mHeight = location.getAltitude();
52         mVerticalUncertainty = location.getVerticalAccuracyMeters();
53         mHeightType = AfcEllipseLocation.HeightType.AMSL.name();
54     }
55 
56     /**
57      * Converts this AfcLocation class to JSON format needed for AFC queries.
58      */
toJson()59     public abstract JSONObject toJson();
60 
61     /**
62      * Determine if location comparingLocation is within bounds of this AfcLocation object.
63      */
checkLocation(Location comparingLocation)64     public abstract AfcLocationUtil.InBoundsCheckResult checkLocation(Location comparingLocation);
65 }
66