GNSS Satellite Blocklist Renaming
Test: on device Bug: 168111993 Change-Id: I2ee4414fbc1fcb7abe8a3d5b1099a3e6e58a6777
This commit is contained in:
@@ -3825,7 +3825,8 @@ package android.location {
|
||||
method public boolean hasMeasurementCorrectionsReflectingPane();
|
||||
method public boolean hasMeasurements();
|
||||
method public boolean hasNavMessages();
|
||||
method public boolean hasSatelliteBlacklist();
|
||||
method @Deprecated public boolean hasSatelliteBlacklist();
|
||||
method public boolean hasSatelliteBlocklist();
|
||||
}
|
||||
|
||||
public final class GnssMeasurementCorrections implements android.os.Parcelable {
|
||||
|
||||
@@ -3765,7 +3765,8 @@ package android.location {
|
||||
method public boolean hasMeasurementCorrectionsReflectingPane();
|
||||
method public boolean hasMeasurements();
|
||||
method public boolean hasNavMessages();
|
||||
method public boolean hasSatelliteBlacklist();
|
||||
method @Deprecated public boolean hasSatelliteBlacklist();
|
||||
method public boolean hasSatelliteBlocklist();
|
||||
}
|
||||
|
||||
public final class GnssMeasurementCorrections implements android.os.Parcelable {
|
||||
|
||||
@@ -14283,18 +14283,17 @@ public final class Settings {
|
||||
"backup_agent_timeout_parameters";
|
||||
|
||||
/**
|
||||
* Blacklist of GNSS satellites.
|
||||
* Blocklist of GNSS satellites.
|
||||
*
|
||||
* This is a list of integers separated by commas to represent pairs of (constellation,
|
||||
* svid). Thus, the number of integers should be even.
|
||||
*
|
||||
* E.g.: "3,0,5,24" denotes (constellation=3, svid=0) and (constellation=5, svid=24) are
|
||||
* blacklisted. Note that svid=0 denotes all svids in the
|
||||
* constellation are blacklisted.
|
||||
* blocklisted. Note that svid=0 denotes all svids in the constellation are blocklisted.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final String GNSS_SATELLITE_BLACKLIST = "gnss_satellite_blacklist";
|
||||
public static final String GNSS_SATELLITE_BLOCKLIST = "gnss_satellite_blocklist";
|
||||
|
||||
/**
|
||||
* Duration of updates in millisecond for GNSS location request from HAL to framework.
|
||||
|
||||
@@ -535,7 +535,7 @@ message GlobalSettingsProto {
|
||||
// If set to 1, {@link Secure#LOCATION_MODE} will be set to {@link
|
||||
// Secure#LOCATION_MODE_OFF} temporarily for all users.
|
||||
optional SettingProto global_kill_switch = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
|
||||
optional SettingProto gnss_satellite_blacklist = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
|
||||
optional SettingProto gnss_satellite_blocklist = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
|
||||
optional SettingProto gnss_hal_location_request_duration_millis = 7 [ (android.privacy).dest = DEST_AUTOMATIC ];
|
||||
// Packages that are whitelisted for ignoring location settings (during emergencies)
|
||||
optional SettingProto ignore_settings_package_whitelist = 8 [ (android.privacy).dest = DEST_AUTOMATIC ];
|
||||
|
||||
@@ -29,10 +29,10 @@ public final class GnssCapabilities {
|
||||
public static final long LOW_POWER_MODE = 1L << 0;
|
||||
|
||||
/**
|
||||
* Bit mask indicating GNSS chipset supports blacklisting satellites.
|
||||
* Bit mask indicating GNSS chipset supports blocklisting satellites.
|
||||
* @hide
|
||||
*/
|
||||
public static final long SATELLITE_BLACKLIST = 1L << 1;
|
||||
public static final long SATELLITE_BLOCKLIST = 1L << 1;
|
||||
|
||||
/**
|
||||
* Bit mask indicating GNSS chipset supports geofencing.
|
||||
@@ -110,14 +110,27 @@ public final class GnssCapabilities {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if GNSS chipset supports blacklisting satellites, {@code false}
|
||||
* Returns {@code true} if GNSS chipset supports blocklisting satellites, {@code false}
|
||||
* otherwise.
|
||||
*
|
||||
* @hide
|
||||
* @deprecated use {@link #hasSatelliteBlocklist} instead.
|
||||
*/
|
||||
@SystemApi
|
||||
@Deprecated
|
||||
public boolean hasSatelliteBlacklist() {
|
||||
return hasCapability(SATELLITE_BLOCKLIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if GNSS chipset supports blocklisting satellites, {@code false}
|
||||
* otherwise.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public boolean hasSatelliteBlacklist() {
|
||||
return hasCapability(SATELLITE_BLACKLIST);
|
||||
public boolean hasSatelliteBlocklist() {
|
||||
return hasCapability(SATELLITE_BLOCKLIST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -888,8 +888,8 @@ class SettingsProtoDumpUtil {
|
||||
Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
|
||||
GlobalSettingsProto.Location.SETTINGS_LINK_TO_PERMISSIONS_ENABLED);
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.GNSS_SATELLITE_BLACKLIST,
|
||||
GlobalSettingsProto.Location.GNSS_SATELLITE_BLACKLIST);
|
||||
Settings.Global.GNSS_SATELLITE_BLOCKLIST,
|
||||
GlobalSettingsProto.Location.GNSS_SATELLITE_BLOCKLIST);
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.GNSS_HAL_LOCATION_REQUEST_DURATION_MILLIS,
|
||||
GlobalSettingsProto.Location.GNSS_HAL_LOCATION_REQUEST_DURATION_MILLIS);
|
||||
|
||||
@@ -3342,7 +3342,7 @@ public class SettingsProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
private final class UpgradeController {
|
||||
private static final int SETTINGS_VERSION = 194;
|
||||
private static final int SETTINGS_VERSION = 195;
|
||||
|
||||
private final int mUserId;
|
||||
|
||||
@@ -4761,6 +4761,22 @@ public class SettingsProvider extends ContentProvider {
|
||||
currentVersion = 194;
|
||||
}
|
||||
|
||||
if (currentVersion == 194) {
|
||||
// Version 194: migrate the GNSS_SATELLITE_BLOCKLIST setting
|
||||
final SettingsState globalSettings = getGlobalSettingsLocked();
|
||||
final Setting newSetting = globalSettings.getSettingLocked(
|
||||
Global.GNSS_SATELLITE_BLOCKLIST);
|
||||
final String oldName = "gnss_satellite_blacklist";
|
||||
final Setting oldSetting = globalSettings.getSettingLocked(oldName);
|
||||
if (newSetting.isNull() && !oldSetting.isNull()) {
|
||||
globalSettings.insertSettingLocked(
|
||||
Global.GNSS_SATELLITE_BLOCKLIST, oldSetting.getValue(), null, true,
|
||||
SettingsState.SYSTEM_PACKAGE_NAME);
|
||||
globalSettings.deleteSettingLocked(oldName);
|
||||
}
|
||||
currentVersion = 195;
|
||||
}
|
||||
|
||||
// vXXX: Add new settings above this point.
|
||||
|
||||
if (currentVersion != newVersion) {
|
||||
|
||||
@@ -290,7 +290,7 @@ public class SettingsBackupTest {
|
||||
Settings.Global.GLOBAL_HTTP_PROXY_PAC,
|
||||
Settings.Global.GLOBAL_HTTP_PROXY_PORT,
|
||||
Settings.Global.GNSS_HAL_LOCATION_REQUEST_DURATION_MILLIS,
|
||||
Settings.Global.GNSS_SATELLITE_BLACKLIST,
|
||||
Settings.Global.GNSS_SATELLITE_BLOCKLIST,
|
||||
Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS,
|
||||
Settings.Global.HDMI_CEC_SWITCH_ENABLED,
|
||||
Settings.Global.HDMI_CEC_VERSION,
|
||||
|
||||
@@ -29,7 +29,7 @@ public class GnssCapabilitiesProvider {
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
private static final long GNSS_CAPABILITIES_TOP_HAL =
|
||||
GnssCapabilities.LOW_POWER_MODE | GnssCapabilities.SATELLITE_BLACKLIST
|
||||
GnssCapabilities.LOW_POWER_MODE | GnssCapabilities.SATELLITE_BLOCKLIST
|
||||
| GnssCapabilities.GEOFENCING | GnssCapabilities.MEASUREMENTS
|
||||
| GnssCapabilities.NAV_MESSAGES;
|
||||
|
||||
@@ -65,8 +65,8 @@ public class GnssCapabilitiesProvider {
|
||||
gnssCapabilities |= GnssCapabilities.LOW_POWER_MODE;
|
||||
}
|
||||
if (hasCapability(topHalCapabilities,
|
||||
GnssLocationProvider.GPS_CAPABILITY_SATELLITE_BLACKLIST)) {
|
||||
gnssCapabilities |= GnssCapabilities.SATELLITE_BLACKLIST;
|
||||
GnssLocationProvider.GPS_CAPABILITY_SATELLITE_BLOCKLIST)) {
|
||||
gnssCapabilities |= GnssCapabilities.SATELLITE_BLOCKLIST;
|
||||
}
|
||||
if (hasCapability(topHalCapabilities, GnssLocationProvider.GPS_CAPABILITY_GEOFENCING)) {
|
||||
gnssCapabilities |= GnssCapabilities.GEOFENCING;
|
||||
|
||||
@@ -202,8 +202,8 @@ class GnssConfiguration {
|
||||
/**
|
||||
* Updates the GNSS HAL satellite denylist.
|
||||
*/
|
||||
void setSatelliteBlacklist(int[] constellations, int[] svids) {
|
||||
native_set_satellite_blacklist(constellations, svids);
|
||||
void setSatelliteBlocklist(int[] constellations, int[] svids) {
|
||||
native_set_satellite_blocklist(constellations, svids);
|
||||
}
|
||||
|
||||
HalInterfaceVersion getHalInterfaceVersion() {
|
||||
@@ -414,7 +414,7 @@ class GnssConfiguration {
|
||||
|
||||
private static native boolean native_set_emergency_supl_pdn(int emergencySuplPdn);
|
||||
|
||||
private static native boolean native_set_satellite_blacklist(int[] constellations, int[] svIds);
|
||||
private static native boolean native_set_satellite_blocklist(int[] constellations, int[] svIds);
|
||||
|
||||
private static native boolean native_set_es_extension_sec(int emergencyExtensionSeconds);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ import com.android.server.DeviceIdleInternal;
|
||||
import com.android.server.FgThread;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.location.AbstractLocationProvider;
|
||||
import com.android.server.location.gnss.GnssSatelliteBlacklistHelper.GnssSatelliteBlacklistCallback;
|
||||
import com.android.server.location.gnss.GnssSatelliteBlocklistHelper.GnssSatelliteBlocklistCallback;
|
||||
import com.android.server.location.gnss.NtpTimeHelper.InjectNtpTimeCallback;
|
||||
import com.android.server.location.util.Injector;
|
||||
|
||||
@@ -97,7 +97,7 @@ import java.util.Set;
|
||||
*/
|
||||
public class GnssLocationProvider extends AbstractLocationProvider implements
|
||||
InjectNtpTimeCallback,
|
||||
GnssSatelliteBlacklistCallback {
|
||||
GnssSatelliteBlocklistCallback {
|
||||
|
||||
private static final String TAG = "GnssLocationProvider";
|
||||
|
||||
@@ -171,7 +171,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
|
||||
public static final int GPS_CAPABILITY_MEASUREMENTS = 0x0000040;
|
||||
public static final int GPS_CAPABILITY_NAV_MESSAGES = 0x0000080;
|
||||
public static final int GPS_CAPABILITY_LOW_POWER_MODE = 0x0000100;
|
||||
public static final int GPS_CAPABILITY_SATELLITE_BLACKLIST = 0x0000200;
|
||||
public static final int GPS_CAPABILITY_SATELLITE_BLOCKLIST = 0x0000200;
|
||||
public static final int GPS_CAPABILITY_MEASUREMENT_CORRECTIONS = 0x0000400;
|
||||
public static final int GPS_CAPABILITY_ANTENNA_INFO = 0x0000800;
|
||||
|
||||
@@ -374,7 +374,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
|
||||
private final GnssBatchingProvider mGnssBatchingProvider;
|
||||
private final GnssGeofenceProvider mGnssGeofenceProvider;
|
||||
private final GnssCapabilitiesProvider mGnssCapabilitiesProvider;
|
||||
private final GnssSatelliteBlacklistHelper mGnssSatelliteBlacklistHelper;
|
||||
private final GnssSatelliteBlocklistHelper mGnssSatelliteBlocklistHelper;
|
||||
|
||||
// Available only on GNSS HAL 2.0 implementations and later.
|
||||
private GnssVisibilityControl mGnssVisibilityControl;
|
||||
@@ -494,11 +494,11 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements {@link GnssSatelliteBlacklistCallback#onUpdateSatelliteBlacklist}.
|
||||
* Implements {@link GnssSatelliteBlocklistCallback#onUpdateSatelliteBlocklist}.
|
||||
*/
|
||||
@Override
|
||||
public void onUpdateSatelliteBlacklist(int[] constellations, int[] svids) {
|
||||
mHandler.post(() -> mGnssConfiguration.setSatelliteBlacklist(constellations, svids));
|
||||
public void onUpdateSatelliteBlocklist(int[] constellations, int[] svids) {
|
||||
mHandler.post(() -> mGnssConfiguration.setSatelliteBlocklist(constellations, svids));
|
||||
mGnssMetrics.resetConstellationTypes();
|
||||
}
|
||||
|
||||
@@ -622,8 +622,8 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
|
||||
|
||||
mGnssMetrics = new GnssMetrics(mContext, mBatteryStats);
|
||||
mNtpTimeHelper = new NtpTimeHelper(mContext, mLooper, this);
|
||||
mGnssSatelliteBlacklistHelper =
|
||||
new GnssSatelliteBlacklistHelper(mContext,
|
||||
mGnssSatelliteBlocklistHelper =
|
||||
new GnssSatelliteBlocklistHelper(mContext,
|
||||
mLooper, this);
|
||||
mGnssBatchingProvider = new GnssBatchingProvider();
|
||||
mGnssGeofenceProvider = new GnssGeofenceProvider();
|
||||
@@ -655,7 +655,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
|
||||
}, UserHandle.USER_ALL);
|
||||
|
||||
sendMessage(INITIALIZE_HANDLER, 0, null);
|
||||
mHandler.post(mGnssSatelliteBlacklistHelper::updateSatelliteBlacklist);
|
||||
mHandler.post(mGnssSatelliteBlocklistHelper::updateSatelliteBlocklist);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2046,7 +2046,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
|
||||
if (hasCapability(GPS_CAPABILITY_MEASUREMENTS)) s.append("MEASUREMENTS ");
|
||||
if (hasCapability(GPS_CAPABILITY_NAV_MESSAGES)) s.append("NAV_MESSAGES ");
|
||||
if (hasCapability(GPS_CAPABILITY_LOW_POWER_MODE)) s.append("LOW_POWER_MODE ");
|
||||
if (hasCapability(GPS_CAPABILITY_SATELLITE_BLACKLIST)) s.append("SATELLITE_BLACKLIST ");
|
||||
if (hasCapability(GPS_CAPABILITY_SATELLITE_BLOCKLIST)) s.append("SATELLITE_BLOCKLIST ");
|
||||
if (hasCapability(GPS_CAPABILITY_MEASUREMENT_CORRECTIONS)) {
|
||||
s.append("MEASUREMENT_CORRECTIONS ");
|
||||
}
|
||||
|
||||
@@ -33,72 +33,72 @@ import java.util.List;
|
||||
/**
|
||||
* Detects denylist change and updates the denylist.
|
||||
*/
|
||||
class GnssSatelliteBlacklistHelper {
|
||||
class GnssSatelliteBlocklistHelper {
|
||||
|
||||
private static final String TAG = "GnssBlacklistHelper";
|
||||
private static final String BLACKLIST_DELIMITER = ",";
|
||||
private static final String TAG = "GnssBlocklistHelper";
|
||||
private static final String BLOCKLIST_DELIMITER = ",";
|
||||
|
||||
private final Context mContext;
|
||||
private final GnssSatelliteBlacklistCallback mCallback;
|
||||
private final GnssSatelliteBlocklistCallback mCallback;
|
||||
|
||||
interface GnssSatelliteBlacklistCallback {
|
||||
void onUpdateSatelliteBlacklist(int[] constellations, int[] svids);
|
||||
interface GnssSatelliteBlocklistCallback {
|
||||
void onUpdateSatelliteBlocklist(int[] constellations, int[] svids);
|
||||
}
|
||||
|
||||
GnssSatelliteBlacklistHelper(Context context, Looper looper,
|
||||
GnssSatelliteBlacklistCallback callback) {
|
||||
GnssSatelliteBlocklistHelper(Context context, Looper looper,
|
||||
GnssSatelliteBlocklistCallback callback) {
|
||||
mContext = context;
|
||||
mCallback = callback;
|
||||
ContentObserver contentObserver = new ContentObserver(new Handler(looper)) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
updateSatelliteBlacklist();
|
||||
updateSatelliteBlocklist();
|
||||
}
|
||||
};
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Global.getUriFor(
|
||||
Settings.Global.GNSS_SATELLITE_BLACKLIST),
|
||||
Settings.Global.GNSS_SATELLITE_BLOCKLIST),
|
||||
true,
|
||||
contentObserver, UserHandle.USER_ALL);
|
||||
}
|
||||
|
||||
void updateSatelliteBlacklist() {
|
||||
void updateSatelliteBlocklist() {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
String blacklist = Settings.Global.getString(
|
||||
String blocklist = Settings.Global.getString(
|
||||
resolver,
|
||||
Settings.Global.GNSS_SATELLITE_BLACKLIST);
|
||||
if (blacklist == null) {
|
||||
blacklist = "";
|
||||
Settings.Global.GNSS_SATELLITE_BLOCKLIST);
|
||||
if (blocklist == null) {
|
||||
blocklist = "";
|
||||
}
|
||||
Log.i(TAG, String.format("Update GNSS satellite blacklist: %s", blacklist));
|
||||
Log.i(TAG, String.format("Update GNSS satellite blocklist: %s", blocklist));
|
||||
|
||||
List<Integer> blacklistValues;
|
||||
List<Integer> blocklistValues;
|
||||
try {
|
||||
blacklistValues = parseSatelliteBlacklist(blacklist);
|
||||
blocklistValues = parseSatelliteBlocklist(blocklist);
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "Exception thrown when parsing blacklist string.", e);
|
||||
Log.e(TAG, "Exception thrown when parsing blocklist string.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (blacklistValues.size() % 2 != 0) {
|
||||
Log.e(TAG, "blacklist string has odd number of values."
|
||||
+ "Aborting updateSatelliteBlacklist");
|
||||
if (blocklistValues.size() % 2 != 0) {
|
||||
Log.e(TAG, "blocklist string has odd number of values."
|
||||
+ "Aborting updateSatelliteBlocklist");
|
||||
return;
|
||||
}
|
||||
|
||||
int length = blacklistValues.size() / 2;
|
||||
int length = blocklistValues.size() / 2;
|
||||
int[] constellations = new int[length];
|
||||
int[] svids = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
constellations[i] = blacklistValues.get(i * 2);
|
||||
svids[i] = blacklistValues.get(i * 2 + 1);
|
||||
constellations[i] = blocklistValues.get(i * 2);
|
||||
svids[i] = blocklistValues.get(i * 2 + 1);
|
||||
}
|
||||
mCallback.onUpdateSatelliteBlacklist(constellations, svids);
|
||||
mCallback.onUpdateSatelliteBlocklist(constellations, svids);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static List<Integer> parseSatelliteBlacklist(String blacklist) throws NumberFormatException {
|
||||
String[] strings = blacklist.split(BLACKLIST_DELIMITER);
|
||||
static List<Integer> parseSatelliteBlocklist(String blocklist) throws NumberFormatException {
|
||||
String[] strings = blocklist.split(BLOCKLIST_DELIMITER);
|
||||
List<Integer> parsed = new ArrayList<>(strings.length);
|
||||
for (String string : strings) {
|
||||
string = string.trim();
|
||||
@@ -3514,10 +3514,11 @@ static jboolean android_location_GnssConfiguration_set_gnss_pos_protocol_select(
|
||||
return gnssConfigurationIface->setGlonassPositioningProtocol(gnssPosProtocol);
|
||||
}
|
||||
|
||||
static jboolean android_location_GnssConfiguration_set_satellite_blacklist(
|
||||
JNIEnv* env, jobject, jintArray constellations, jintArray sv_ids) {
|
||||
static jboolean android_location_GnssConfiguration_set_satellite_blocklist(JNIEnv* env, jobject,
|
||||
jintArray constellations,
|
||||
jintArray sv_ids) {
|
||||
if (gnssConfigurationIface == nullptr) {
|
||||
ALOGI("IGnssConfiguration interface does not support satellite blacklist.");
|
||||
ALOGI("IGnssConfiguration interface does not support satellite blocklist.");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
return gnssConfigurationIface->setBlocklist(env, constellations, sv_ids);
|
||||
@@ -3800,8 +3801,8 @@ static const JNINativeMethod sConfigurationMethods[] = {
|
||||
reinterpret_cast<void*>(android_location_GnssConfiguration_set_gps_lock)},
|
||||
{"native_set_emergency_supl_pdn", "(I)Z",
|
||||
reinterpret_cast<void*>(android_location_GnssConfiguration_set_emergency_supl_pdn)},
|
||||
{"native_set_satellite_blacklist", "([I[I)Z",
|
||||
reinterpret_cast<void*>(android_location_GnssConfiguration_set_satellite_blacklist)},
|
||||
{"native_set_satellite_blocklist", "([I[I)Z",
|
||||
reinterpret_cast<void*>(android_location_GnssConfiguration_set_satellite_blocklist)},
|
||||
{"native_set_es_extension_sec", "(I)Z",
|
||||
reinterpret_cast<void*>(android_location_GnssConfiguration_set_es_extension_sec)},
|
||||
};
|
||||
|
||||
@@ -43,101 +43,101 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GnssSatelliteBlacklistHelper}.
|
||||
* Unit tests for {@link GnssSatelliteBlocklistHelper}.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Presubmit
|
||||
public class GnssSatelliteBlacklistHelperTest {
|
||||
public class GnssSatelliteBlocklistHelperTest {
|
||||
|
||||
private ContentResolver mContentResolver;
|
||||
@Mock
|
||||
private GnssSatelliteBlacklistHelper.GnssSatelliteBlacklistCallback mCallback;
|
||||
private GnssSatelliteBlocklistHelper.GnssSatelliteBlocklistCallback mCallback;
|
||||
|
||||
/**
|
||||
* Initialize mocks and create GnssSatelliteBlacklistHelper with callback.
|
||||
* Initialize mocks and create GnssSatelliteBlocklistHelper with callback.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
Context context = RuntimeEnvironment.application;
|
||||
mContentResolver = context.getContentResolver();
|
||||
new GnssSatelliteBlacklistHelper(context, Looper.myLooper(), mCallback);
|
||||
new GnssSatelliteBlocklistHelper(context, Looper.myLooper(), mCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blacklist two satellites and verify callback is called.
|
||||
* Blocklist two satellites and verify callback is called.
|
||||
*/
|
||||
@Test
|
||||
public void blacklistOf2Satellites_callbackIsCalled() {
|
||||
String blacklist = "3,0,5,24";
|
||||
updateBlacklistAndVerifyCallbackIsCalled(blacklist);
|
||||
public void blocklistOf2Satellites_callbackIsCalled() {
|
||||
String blocklist = "3,0,5,24";
|
||||
updateBlocklistAndVerifyCallbackIsCalled(blocklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blacklist one satellite with spaces in string and verify callback is called.
|
||||
* Blocklist one satellite with spaces in string and verify callback is called.
|
||||
*/
|
||||
@Test
|
||||
public void blacklistWithSpaces_callbackIsCalled() {
|
||||
String blacklist = "3, 11";
|
||||
updateBlacklistAndVerifyCallbackIsCalled(blacklist);
|
||||
public void blocklistWithSpaces_callbackIsCalled() {
|
||||
String blocklist = "3, 11";
|
||||
updateBlocklistAndVerifyCallbackIsCalled(blocklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass empty blacklist and verify callback is called.
|
||||
* Pass empty blocklist and verify callback is called.
|
||||
*/
|
||||
@Test
|
||||
public void emptyBlacklist_callbackIsCalled() {
|
||||
String blacklist = "";
|
||||
updateBlacklistAndVerifyCallbackIsCalled(blacklist);
|
||||
public void emptyBlocklist_callbackIsCalled() {
|
||||
String blocklist = "";
|
||||
updateBlocklistAndVerifyCallbackIsCalled(blocklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass blacklist string with odd number of values and verify callback is not called.
|
||||
* Pass blocklist string with odd number of values and verify callback is not called.
|
||||
*/
|
||||
@Test
|
||||
public void blacklistWithOddNumberOfValues_callbackIsNotCalled() {
|
||||
String blacklist = "3,0,5";
|
||||
updateBlacklistAndNotifyContentObserver(blacklist);
|
||||
verify(mCallback, never()).onUpdateSatelliteBlacklist(any(int[].class), any(int[].class));
|
||||
public void blocklistWithOddNumberOfValues_callbackIsNotCalled() {
|
||||
String blocklist = "3,0,5";
|
||||
updateBlocklistAndNotifyContentObserver(blocklist);
|
||||
verify(mCallback, never()).onUpdateSatelliteBlocklist(any(int[].class), any(int[].class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass blacklist string with negative value and verify callback is not called.
|
||||
* Pass blocklist string with negative value and verify callback is not called.
|
||||
*/
|
||||
@Test
|
||||
public void blacklistWithNegativeValue_callbackIsNotCalled() {
|
||||
String blacklist = "3,-11";
|
||||
updateBlacklistAndNotifyContentObserver(blacklist);
|
||||
verify(mCallback, never()).onUpdateSatelliteBlacklist(any(int[].class), any(int[].class));
|
||||
public void blocklistWithNegativeValue_callbackIsNotCalled() {
|
||||
String blocklist = "3,-11";
|
||||
updateBlocklistAndNotifyContentObserver(blocklist);
|
||||
verify(mCallback, never()).onUpdateSatelliteBlocklist(any(int[].class), any(int[].class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass blacklist string with non-digit characters and verify callback is not called.
|
||||
* Pass blocklist string with non-digit characters and verify callback is not called.
|
||||
*/
|
||||
@Test
|
||||
public void blacklistWithNonDigitCharacter_callbackIsNotCalled() {
|
||||
String blacklist = "3,1a,5,11";
|
||||
updateBlacklistAndNotifyContentObserver(blacklist);
|
||||
verify(mCallback, never()).onUpdateSatelliteBlacklist(any(int[].class), any(int[].class));
|
||||
public void blocklistWithNonDigitCharacter_callbackIsNotCalled() {
|
||||
String blocklist = "3,1a,5,11";
|
||||
updateBlocklistAndNotifyContentObserver(blocklist);
|
||||
verify(mCallback, never()).onUpdateSatelliteBlocklist(any(int[].class), any(int[].class));
|
||||
}
|
||||
|
||||
private void updateBlacklistAndNotifyContentObserver(String blacklist) {
|
||||
private void updateBlocklistAndNotifyContentObserver(String blocklist) {
|
||||
Settings.Global.putString(mContentResolver,
|
||||
Settings.Global.GNSS_SATELLITE_BLACKLIST, blacklist);
|
||||
notifyContentObserverFor(Settings.Global.GNSS_SATELLITE_BLACKLIST);
|
||||
Settings.Global.GNSS_SATELLITE_BLOCKLIST, blocklist);
|
||||
notifyContentObserverFor(Settings.Global.GNSS_SATELLITE_BLOCKLIST);
|
||||
}
|
||||
|
||||
private void updateBlacklistAndVerifyCallbackIsCalled(String blacklist) {
|
||||
updateBlacklistAndNotifyContentObserver(blacklist);
|
||||
private void updateBlocklistAndVerifyCallbackIsCalled(String blocklist) {
|
||||
updateBlocklistAndNotifyContentObserver(blocklist);
|
||||
|
||||
ArgumentCaptor<int[]> constellationsCaptor = ArgumentCaptor.forClass(int[].class);
|
||||
ArgumentCaptor<int[]> svIdsCaptor = ArgumentCaptor.forClass(int[].class);
|
||||
verify(mCallback).onUpdateSatelliteBlacklist(constellationsCaptor.capture(),
|
||||
verify(mCallback).onUpdateSatelliteBlocklist(constellationsCaptor.capture(),
|
||||
svIdsCaptor.capture());
|
||||
|
||||
int[] constellations = constellationsCaptor.getValue();
|
||||
int[] svIds = svIdsCaptor.getValue();
|
||||
List<Integer> values = GnssSatelliteBlacklistHelper.parseSatelliteBlacklist(blacklist);
|
||||
List<Integer> values = GnssSatelliteBlocklistHelper.parseSatelliteBlocklist(blocklist);
|
||||
assertThat(values.size()).isEqualTo(constellations.length * 2);
|
||||
assertThat(svIds.length).isEqualTo(constellations.length);
|
||||
for (int i = 0; i < constellations.length; i++) {
|
||||
Reference in New Issue
Block a user