1 /* 2 * Copyright (C) 2020 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.location.injector; 18 19 import android.os.PackageTagsList; 20 import android.util.IndentingPrintWriter; 21 22 import java.io.FileDescriptor; 23 import java.util.Set; 24 25 /** 26 * Provides accessors and listeners for all location related settings. 27 */ 28 public abstract class SettingsHelper { 29 30 /** 31 * Listener for user-specific settings changes. 32 */ 33 public interface UserSettingChangedListener { 34 /** 35 * Called when setting changes. 36 */ onSettingChanged(int userId)37 void onSettingChanged(int userId); 38 } 39 40 /** 41 * Listener for global settings changes. 42 */ 43 public interface GlobalSettingChangedListener extends UserSettingChangedListener { 44 /** 45 * Called when setting changes. 46 */ onSettingChanged()47 void onSettingChanged(); 48 49 @Override onSettingChanged(int userId)50 default void onSettingChanged(int userId) { 51 onSettingChanged(); 52 } 53 } 54 55 /** 56 * Retrieve if location is enabled or not. 57 */ isLocationEnabled(int userId)58 public abstract boolean isLocationEnabled(int userId); 59 60 /** 61 * Set location enabled for a user. 62 */ setLocationEnabled(boolean enabled, int userId)63 public abstract void setLocationEnabled(boolean enabled, int userId); 64 65 /** 66 * Add a listener for changes to the location enabled setting. Callbacks occur on an unspecified 67 * thread. 68 */ addOnLocationEnabledChangedListener(UserSettingChangedListener listener)69 public abstract void addOnLocationEnabledChangedListener(UserSettingChangedListener listener); 70 71 /** 72 * Remove a listener for changes to the location enabled setting. 73 */ removeOnLocationEnabledChangedListener( UserSettingChangedListener listener)74 public abstract void removeOnLocationEnabledChangedListener( 75 UserSettingChangedListener listener); 76 77 /** 78 * Retrieve the background throttle interval. 79 */ getBackgroundThrottleIntervalMs()80 public abstract long getBackgroundThrottleIntervalMs(); 81 82 /** 83 * Add a listener for changes to the background throttle interval. Callbacks occur on an 84 * unspecified thread. 85 */ addOnBackgroundThrottleIntervalChangedListener( GlobalSettingChangedListener listener)86 public abstract void addOnBackgroundThrottleIntervalChangedListener( 87 GlobalSettingChangedListener listener); 88 89 /** 90 * Remove a listener for changes to the background throttle interval. 91 */ removeOnBackgroundThrottleIntervalChangedListener( GlobalSettingChangedListener listener)92 public abstract void removeOnBackgroundThrottleIntervalChangedListener( 93 GlobalSettingChangedListener listener); 94 95 /** 96 * Check if the given package is denylisted for location access. 97 */ isLocationPackageBlacklisted(int userId, String packageName)98 public abstract boolean isLocationPackageBlacklisted(int userId, String packageName); 99 100 /** 101 * Add a listener for changes to the location package denylist. Callbacks occur on an 102 * unspecified thread. 103 */ addOnLocationPackageBlacklistChangedListener( UserSettingChangedListener listener)104 public abstract void addOnLocationPackageBlacklistChangedListener( 105 UserSettingChangedListener listener); 106 107 /** 108 * Remove a listener for changes to the location package denylist. 109 */ removeOnLocationPackageBlacklistChangedListener( UserSettingChangedListener listener)110 public abstract void removeOnLocationPackageBlacklistChangedListener( 111 UserSettingChangedListener listener); 112 113 /** 114 * Retrieve the background throttle package allowlist. 115 */ getBackgroundThrottlePackageWhitelist()116 public abstract Set<String> getBackgroundThrottlePackageWhitelist(); 117 118 /** 119 * Add a listener for changes to the background throttle package allowlist. Callbacks occur on 120 * an unspecified thread. 121 */ addOnBackgroundThrottlePackageWhitelistChangedListener( GlobalSettingChangedListener listener)122 public abstract void addOnBackgroundThrottlePackageWhitelistChangedListener( 123 GlobalSettingChangedListener listener); 124 125 /** 126 * Remove a listener for changes to the background throttle package allowlist. 127 */ removeOnBackgroundThrottlePackageWhitelistChangedListener( GlobalSettingChangedListener listener)128 public abstract void removeOnBackgroundThrottlePackageWhitelistChangedListener( 129 GlobalSettingChangedListener listener); 130 131 /** 132 * Retrieve the gnss measurements full tracking enabled setting. 133 */ isGnssMeasurementsFullTrackingEnabled()134 public abstract boolean isGnssMeasurementsFullTrackingEnabled(); 135 136 /** 137 * Add a listener for changes to the background throttle package allowlist. Callbacks occur on 138 * an unspecified thread. 139 */ addOnGnssMeasurementsFullTrackingEnabledChangedListener( GlobalSettingChangedListener listener)140 public abstract void addOnGnssMeasurementsFullTrackingEnabledChangedListener( 141 GlobalSettingChangedListener listener); 142 143 /** 144 * Remove a listener for changes to the background throttle package allowlist. 145 */ removeOnGnssMeasurementsFullTrackingEnabledChangedListener( GlobalSettingChangedListener listener)146 public abstract void removeOnGnssMeasurementsFullTrackingEnabledChangedListener( 147 GlobalSettingChangedListener listener); 148 149 /** Retrieve adas allowlist. */ getAdasAllowlist()150 public abstract PackageTagsList getAdasAllowlist(); 151 152 /** 153 * Add a listener for changes to the ADAS settings package allowlist. Callbacks occur on an 154 * unspecified thread. 155 */ addAdasAllowlistChangedListener(GlobalSettingChangedListener listener)156 public abstract void addAdasAllowlistChangedListener(GlobalSettingChangedListener listener); 157 158 /** 159 * Remove a listener for changes to the ADAS package allowlist. 160 */ removeAdasAllowlistChangedListener(GlobalSettingChangedListener listener)161 public abstract void removeAdasAllowlistChangedListener(GlobalSettingChangedListener listener); 162 163 /** 164 * Retrieve the ignore location settings package+tags allowlist setting. 165 */ getIgnoreSettingsAllowlist()166 public abstract PackageTagsList getIgnoreSettingsAllowlist(); 167 168 /** 169 * Add a listener for changes to the ignore settings package allowlist. Callbacks occur on an 170 * unspecified thread. 171 */ addIgnoreSettingsAllowlistChangedListener( GlobalSettingChangedListener listener)172 public abstract void addIgnoreSettingsAllowlistChangedListener( 173 GlobalSettingChangedListener listener); 174 175 /** 176 * Remove a listener for changes to the ignore settings package allowlist. 177 */ removeIgnoreSettingsAllowlistChangedListener( GlobalSettingChangedListener listener)178 public abstract void removeIgnoreSettingsAllowlistChangedListener( 179 GlobalSettingChangedListener listener); 180 181 /** 182 * Retrieve the background throttling proximity alert interval. 183 */ getBackgroundThrottleProximityAlertIntervalMs()184 public abstract long getBackgroundThrottleProximityAlertIntervalMs(); 185 186 /** 187 * Retrieve the accuracy for coarsening location, ie, the grid size used for snap-to-grid 188 * coarsening. 189 */ getCoarseLocationAccuracyM()190 public abstract float getCoarseLocationAccuracyM(); 191 192 /** 193 * Dump info for debugging. 194 */ dump(FileDescriptor fd, IndentingPrintWriter ipw, String[] args)195 public abstract void dump(FileDescriptor fd, IndentingPrintWriter ipw, String[] args); 196 } 197