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 
20 import android.location.Location;
21 
22 import java.util.Random;
23 
24 /**
25  * Class that converts a Location object to a new AfcLocation and checks if a Location object is in
26  * bounds of an AfcLocation object.
27  */
28 public class AfcLocationUtil {
29     // Enum that has values for inside, on the border, and outside the ellipse
30     public enum InBoundsCheckResult {
31         INSIDE_AFC_LOCATION,
32         ON_BORDER,
33         OUTSIDE_AFC_LOCATION,
34     }
35 
36     /**
37      * Return a new AfcEllipseLocation object with default values.
38      */
createAfcLocation(Location location)39     public AfcLocation createAfcLocation(Location location) {
40         return new AfcEllipseLocation(AfcEllipseLocation.DEFAULT_SEMI_MINOR_AXIS_METERS,
41                 AfcEllipseLocation.DEFAULT_SEMI_MAJOR_AXIS_METERS,
42                 AfcEllipseLocation.DEFAULT_ORIENTATION,
43                 AfcEllipseLocation.DEFAULT_CENTER_LEEWAY_DEGREES,
44                 new Random(), location
45         );
46     }
47 
48     /**
49      * Determine if location comparingLocation is within bounds of the afcLocation object.
50      */
checkLocation(AfcLocation afcLocation, Location comparingLocation)51     public AfcLocationUtil.InBoundsCheckResult checkLocation(AfcLocation afcLocation,
52             Location comparingLocation) {
53         return afcLocation.checkLocation(comparingLocation);
54     }
55 }
56