[android] Fixed review notes

This commit is contained in:
Dmitry Donskoy 2018-12-19 18:12:31 +03:00 committed by Aleksandr Zatsepin
parent 65f5634951
commit 4b0d91a3ad
11 changed files with 64 additions and 43 deletions

View file

@ -559,22 +559,21 @@
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name="com.pushwoosh.GCMRegistrationService"
android:exported="false"/>
android:name="com.pushwoosh.GCMRegistrationService"
android:exported="false"/>
<service
android:name="com.pushwoosh.location.GeoLocationService"/>
android:name="com.pushwoosh.location.GeoLocationService"/>
<service android:name="com.mapswithme.util.push.GcmInstanceIDListenerService"/>
<service android:name="com.mapswithme.util.push.GcmMessageHandlerService"/>
<service
android:name="com.mapswithme.maps.location.GeofenceTransitionsIntentService"
android:name="com.mapswithme.maps.geofence.GeofenceTransitionsIntentService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"/>
<receiver android:name="com.mapswithme.maps.location.GeofenceReceiver"
android:enabled="true"
android:exported="true">
<receiver
android:name="com.mapswithme.maps.geofence.GeofenceReceiver"
android:enabled="true"
android:exported="true">
</receiver>
<!-- Catches app upgraded intent -->
<receiver android:name=".background.UpgradeReceiver">

View file

@ -3,7 +3,6 @@ package com.mapswithme.maps;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.location.Location;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
@ -20,9 +19,8 @@ import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.downloader.CountryItem;
import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.maps.editor.Editor;
import com.mapswithme.maps.location.GeofenceLocation;
import com.mapswithme.maps.location.GeofenceRegistry;
import com.mapswithme.maps.location.GeofenceRegistryImpl;
import com.mapswithme.maps.geofence.GeofenceRegistry;
import com.mapswithme.maps.geofence.GeofenceRegistryImpl;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.location.TrackRecorder;
import com.mapswithme.maps.maplayer.subway.SubwayManager;

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.location;
package com.mapswithme.maps.geofence;
import android.location.Location;
import android.support.annotation.NonNull;

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.location;
package com.mapswithme.maps.geofence;
import android.content.BroadcastReceiver;
import android.content.Context;

View file

@ -0,0 +1,11 @@
package com.mapswithme.maps.geofence;
import android.support.annotation.NonNull;
import com.mapswithme.maps.location.LocationPermissionNotGrantedException;
public interface GeofenceRegistry
{
void registerGeofences(@NonNull GeofenceLocation location) throws LocationPermissionNotGrantedException;
void unregisterGeofences() throws LocationPermissionNotGrantedException;
}

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.location;
package com.mapswithme.maps.geofence;
import android.app.Application;
import android.app.PendingIntent;
@ -11,8 +11,9 @@ import com.google.android.gms.location.GeofencingRequest;
import com.google.android.gms.location.LocationServices;
import com.mapswithme.maps.LightFramework;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.geofence.GeoFenceFeature;
import com.mapswithme.maps.location.LocationPermissionNotGrantedException;
import com.mapswithme.util.PermissionsUtils;
import com.mapswithme.util.concurrency.UiThread;
import java.util.ArrayList;
import java.util.Iterator;
@ -21,7 +22,7 @@ import java.util.List;
public class GeofenceRegistryImpl implements GeofenceRegistry
{
private static final int GEOFENCE_MAX_COUNT = 100;
private static final float PREFERRED_GEOFENCE_RADIUS = 125.0f;
private static final float PREFERRED_GEOFENCE_RADIUS = 100.0f;
@NonNull
private final Application mApplication;
@ -38,7 +39,7 @@ public class GeofenceRegistryImpl implements GeofenceRegistry
}
@Override
public void registryGeofences(@NonNull GeofenceLocation location)
public void registerGeofences(@NonNull GeofenceLocation location) throws LocationPermissionNotGrantedException
{
checkThread();
checkPermission();
@ -67,18 +68,16 @@ public class GeofenceRegistryImpl implements GeofenceRegistry
}
@Override
public void invalidateGeofences()
public void unregisterGeofences() throws LocationPermissionNotGrantedException
{
checkThread();
checkPermission();
if (mGeofences.isEmpty())
return;
Iterator<GeofenceAndFeature> iterator = mGeofences.iterator();
List<String> expiredGeofences = new ArrayList<>();
while (iterator.hasNext())
for (GeofenceAndFeature current: mGeofences)
{
GeofenceAndFeature current = iterator.next();
String requestId = current.getGeofence().getRequestId();
expiredGeofences.add(requestId);
}
@ -107,17 +106,15 @@ public class GeofenceRegistryImpl implements GeofenceRegistry
}
private void checkPermission()
private void checkPermission() throws LocationPermissionNotGrantedException
{
if (!PermissionsUtils.isLocationGranted(mApplication))
throw new UnsupportedOperationException("Geofence registry required android.Manifest" +
".permission\n" +
" .ACCESS_FINE_LOCATION");
throw new LocationPermissionNotGrantedException();
}
private static void checkThread()
{
if (!com.mapswithme.util.concurrency.UiThread.isUiThread())
if (!UiThread.isUiThread())
throw new IllegalStateException("Must be call from Ui thread");
}

View file

@ -1,4 +1,4 @@
package com.mapswithme.maps.location;
package com.mapswithme.maps.geofence;
import android.app.Application;
import android.content.Context;
@ -11,10 +11,18 @@ import android.support.v4.app.JobIntentService;
import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.GeofencingEvent;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.location.LocationPermissionNotGrantedException;
import com.mapswithme.maps.scheduling.JobIdMap;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;
public class GeofenceTransitionsIntentService extends JobIntentService
{
private static final Logger LOG = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
private static final String TAG = GeofenceTransitionsIntentService.class.getSimpleName();
@NonNull
private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper());
@ -61,9 +69,15 @@ public class GeofenceTransitionsIntentService extends JobIntentService
GeofenceRegistry geofenceRegistry = GeofenceRegistryImpl.from(mApplication);
if (mGeofencingEvent.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_EXIT)
{
geofenceRegistry.invalidateGeofences();
geofenceRegistry.registryGeofences(GeofenceLocation.from(currentLocation));
try
{
geofenceRegistry.unregisterGeofences();
geofenceRegistry.registerGeofences(GeofenceLocation.from(currentLocation));
}
catch (LocationPermissionNotGrantedException e)
{
LOG.d(TAG, "Location permission not granted!", e);
}
}
}
}

View file

@ -1,9 +0,0 @@
package com.mapswithme.maps.location;
import android.support.annotation.NonNull;
public interface GeofenceRegistry
{
void registryGeofences(@NonNull GeofenceLocation location);
void invalidateGeofences();
}

View file

@ -0,0 +1,11 @@
package com.mapswithme.maps.location;
public class LocationPermissionNotGrantedException extends Exception
{
private static final long serialVersionUID = -1053815743102694164L;
public LocationPermissionNotGrantedException()
{
super("Location permission not granted!");
}
}

View file

@ -3,7 +3,7 @@ package com.mapswithme.maps.scheduling;
import com.mapswithme.maps.background.NotificationService;
import com.mapswithme.maps.background.WorkerService;
import com.mapswithme.maps.bookmarks.SystemDownloadCompletedService;
import com.mapswithme.maps.location.GeofenceTransitionsIntentService;
import com.mapswithme.maps.geofence.GeofenceTransitionsIntentService;
import com.mapswithme.maps.location.TrackRecorderWakeService;
import com.mapswithme.util.Utils;

View file

@ -50,7 +50,7 @@ public final class PermissionsUtils
public static boolean isLocationGranted(@NonNull Context context)
{
return checkPermissions(context).isExternalStorageGranted();
return checkPermissions(context).isLocationGranted();
}
/**