• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.phone.satellite.accesscontrol;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 
21 import com.android.internal.telephony.flags.FeatureFlags;
22 
23 import java.io.Closeable;
24 import java.io.File;
25 import java.io.IOException;
26 
27 /**
28  * A class that performs location-based access control for satellite communication synchronously
29  * without exposing implementation details.
30  */
31 public abstract class SatelliteOnDeviceAccessController implements Closeable {
32 
33     /**
34      * Returns the default {@link SatelliteOnDeviceAccessController}. This method will open the
35      * underlying storage and may carry some CPU and I/O expense; callers may want to hold the
36      * {@link SatelliteOnDeviceAccessController} object for multiple lookups to amortize that cost
37      * but at the cost of some memory, or close it immediately after a single use.
38      *
39      * @param file The input file that contains the location-based access restriction information.
40      * @throws IOException              in the unlikely event of errors when reading underlying
41      *                                  file(s)
42      * @throws IllegalArgumentException if the input file format does not match the format defined
43      *                                  by the device overlay configs.
44      */
create( @onNull File file, @NonNull FeatureFlags featureFlags)45     public static SatelliteOnDeviceAccessController create(
46             @NonNull File file, @NonNull FeatureFlags featureFlags)
47             throws IOException, IllegalArgumentException {
48         return S2RangeSatelliteOnDeviceAccessController.create(file, featureFlags);
49     }
50 
51     /**
52      * Returns a token for a given location. See {@link LocationToken} for details.
53      */
createLocationTokenForLatLng(double latDegrees, double lngDegrees, int s2Level)54     public static LocationToken createLocationTokenForLatLng(double latDegrees, double lngDegrees,
55             int s2Level) {
56         return S2RangeSatelliteOnDeviceAccessController
57                 .createLocationTokenForLatLng(latDegrees, lngDegrees, s2Level);
58     }
59 
60     /**
61      * Returns {@code true} if the satellite communication is allowed at the provided location,
62      * {@code false} otherwise.
63      *
64      * @throws IOException in the unlikely event of errors when reading the underlying file
65      */
isSatCommunicationAllowedAtLocation(LocationToken locationToken)66     public abstract boolean isSatCommunicationAllowedAtLocation(LocationToken locationToken)
67             throws IOException;
68 
69     /**
70      * Returns the S2 level of the file.
71      */
getS2Level()72     public abstract int getS2Level();
73 
74     /**
75      * A class that represents an area with the same value. Two locations with tokens that
76      * {@link #equals(Object) equal each other} will definitely return the same value.
77      *
78      * <p>Depending on the implementation, it may be cheaper to obtain a {@link LocationToken} than
79      * doing a full lookup.
80      */
81     public abstract static class LocationToken {
82         @Override
equals(Object other)83         public abstract boolean equals(Object other);
84 
85         @Override
hashCode()86         public abstract int hashCode();
87 
88         /** This will print out the location information */
toPiiString()89         public abstract String toPiiString();
90     }
91 
92     /**
93      * Returns an unsigned integer if a regional access control config ID is found for the current
94      * location, {@code null} otherwise.
95      *
96      * @throws IOException in the unlikely event of errors when reading the underlying file
97      */
98     @Nullable
getRegionalConfigIdForLocation(LocationToken locationToken)99     public abstract Integer getRegionalConfigIdForLocation(LocationToken locationToken)
100             throws IOException;
101 }
102