我试图防止电话获取真实位置。您能说我做对了吗?尝试阻止电话获取这样的真实位置(以下代码),并帮助我弄清楚位置如何建立。 我的决定是从以下更改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);
}
}
}
}
有更好的方法还是我的方法很好?