Я пытаюсь помешать телефону получить реальное местоположение. Можете ли вы сказать мне, что я делаю все правильно, пытаясь помешать телефону получить реальное местоположение, подобное этому (следующий код), и помочь мне выяснить, как определяется местоположение.
Я решил изменить код метода handleLocationChanged из этого (я опубликую код на Java):
private void handleLocationChanged(Location location, boolean passive) {
// create a working copy of the incoming Location so that the service can modify it without
// disturbing the caller's copy
Location myLocation = new Location(location);
String provider = myLocation.getProvider();
// set "isFromMockProvider" bit if location came from a mock provider. we do not clear this
// bit if location did not come from a mock provider because passive/fused providers can
// forward locations from mock providers, and should not grant them legitimacy in doing so.
if (!myLocation.isFromMockProvider() && isMockProvider(provider)) {
myLocation.setIsFromMockProvider(true);
}
synchronized (mLock) {
if (isAllowedByCurrentUserSettingsLocked(provider)) {
if (!passive) {
// notify passive provider of the new location
mPassiveProvider.updateLocation(myLocation);
}
handleLocationChangedLocked(myLocation, passive);
}
}
}
К этому:
private void handleLocationChanged(Location location, boolean passive) {
// create a working copy of the incoming Location so that the service can modify it without
// disturbing the caller's copy
Location myLocation = new Location(location);
String provider = myLocation.getProvider();
boolean isMocked = false;//controls that location given to the method is mocked
// set "isFromMockProvider" bit if location came from a mock provider. we do not clear this
// bit if location did not come from a mock provider because passive/fused providers can
// forward locations from mock providers, and should not grant them legitimacy in doing so.
if (!myLocation.isFromMockProvider() && isMockProvider(provider)) {
isMocked = true;
myLocation.setIsFromMockProvider(false);
}
if (stopRealWhenMocking){// variable which I will add to LocationManagerSevices to disable and enable getting real location
if(isMocked){
synchronized (mLock) {
if (isAllowedByCurrentUserSettingsLocked(provider)) {
if (!passive) {
// notify passive provider of the new location
mPassiveProvider.updateLocation(myLocation);
}
handleLocationChangedLocked(myLocation, passive);
}
}
}
}
else {
synchronized (mLock) {
if (isAllowedByCurrentUserSettingsLocked(provider)) {
if (!passive) {
// notify passive provider of the new location
mPassiveProvider.updateLocation(myLocation);
}
handleLocationChangedLocked(myLocation, passive);
}
}
}
}
Есть ли лучший способ или мой путь хорош вообще?