From 9f047388b0879a9e3757f73e53514f3f706eed51 Mon Sep 17 00:00:00 2001 From: Morten Holmgaard Date: Fri, 22 Jun 2018 09:15:49 +0200 Subject: [PATCH 01/10] Added destroy method LocationControl to make it possible to do a manual fix memory leak of "io.nlopez.smartlocation.location.providers.LocationGooglePlayServicesProvider.context" --- build.gradle | 5 +++-- gradle/wrapper/gradle-wrapper.properties | 4 ++-- .../main/java/io/nlopez/smartlocation/SmartLocation.java | 8 +++++++- .../nlopez/smartlocation/location/LocationProvider.java | 1 + .../providers/LocationBasedOnActivityProvider.java | 5 +++++ .../providers/LocationGooglePlayServicesProvider.java | 5 +++++ .../LocationGooglePlayServicesWithFallbackProvider.java | 5 +++++ .../location/providers/LocationManagerProvider.java | 5 +++++ .../location/providers/MultiFallbackProvider.java | 8 ++++++++ .../location/providers/TestServiceProvider.java | 5 +++++ .../nlopez/smartlocation/util/MockLocationProvider.java | 5 +++++ .../io/nlopez/smartlocation/rx/ObservableFactoryTest.java | 5 +++++ 12 files changed, 56 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 11b596d2..a4ed658e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.smartLocationVersion = "3.3.3" + ext.smartLocationVersion = "3.3.4" // Common dependencies ext.robolectricVersion = "3.1" @@ -12,9 +12,10 @@ buildscript { mavenCentral() maven { url "https://maven.google.com" } jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.0-rc2' + classpath 'com.android.tools.build:gradle:3.1.3' } } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0fec9a5e..7034c45e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Oct 14 10:52:55 BST 2017 +#Fri Jun 22 08:51:40 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/library/src/main/java/io/nlopez/smartlocation/SmartLocation.java b/library/src/main/java/io/nlopez/smartlocation/SmartLocation.java index fd40c7d4..7155f7bf 100644 --- a/library/src/main/java/io/nlopez/smartlocation/SmartLocation.java +++ b/library/src/main/java/io/nlopez/smartlocation/SmartLocation.java @@ -154,7 +154,7 @@ public static class LocationControl { private static final Map MAPPING = new WeakHashMap<>(); - private final SmartLocation smartLocation; + private SmartLocation smartLocation; private LocationParams params; private LocationProvider provider; private boolean oneFix; @@ -212,6 +212,12 @@ public void start(OnLocationUpdatedListener listener) { public void stop() { provider.stop(); } + + public void destroy() { + provider = null; + params = null; + smartLocation = null; + } } public static class GeocodingControl { diff --git a/library/src/main/java/io/nlopez/smartlocation/location/LocationProvider.java b/library/src/main/java/io/nlopez/smartlocation/location/LocationProvider.java index c97d60dc..04494371 100644 --- a/library/src/main/java/io/nlopez/smartlocation/location/LocationProvider.java +++ b/library/src/main/java/io/nlopez/smartlocation/location/LocationProvider.java @@ -19,4 +19,5 @@ public interface LocationProvider { Location getLastLocation(); + void destroy(); } diff --git a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationBasedOnActivityProvider.java b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationBasedOnActivityProvider.java index 10124035..a5b82fee 100644 --- a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationBasedOnActivityProvider.java +++ b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationBasedOnActivityProvider.java @@ -69,4 +69,9 @@ public void onActivityUpdated(DetectedActivity detectedActivity) { public interface LocationBasedOnActivityListener { public LocationParams locationParamsForActivity(DetectedActivity detectedActivity); } + + @Override + public void destroy() { + locationProvider.destroy(); + } } diff --git a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java index 203d19cf..2e8ba5d0 100644 --- a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java +++ b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java @@ -204,6 +204,11 @@ public Location getLastLocation() { return null; } + @Override + public void destroy() { + context = null; + } + @Override public ServiceConnectionListener getServiceListener() { return serviceListener; diff --git a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java index 111feb65..ff8e5f4e 100644 --- a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java +++ b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java @@ -60,6 +60,11 @@ public void stop() { shouldStart = false; } + @Override + public void destroy() { + context = null; + } + @Override public Location getLastLocation() { return provider.getLastLocation(); diff --git a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationManagerProvider.java b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationManagerProvider.java index 75567a5a..e1cfc547 100644 --- a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationManagerProvider.java +++ b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationManagerProvider.java @@ -173,4 +173,9 @@ public void onProviderEnabled(String provider) { public void onProviderDisabled(String provider) { } + + @Override + public void destroy() { + mContext = null; + } } diff --git a/library/src/main/java/io/nlopez/smartlocation/location/providers/MultiFallbackProvider.java b/library/src/main/java/io/nlopez/smartlocation/location/providers/MultiFallbackProvider.java index 8dc88ccf..7ded28fb 100644 --- a/library/src/main/java/io/nlopez/smartlocation/location/providers/MultiFallbackProvider.java +++ b/library/src/main/java/io/nlopez/smartlocation/location/providers/MultiFallbackProvider.java @@ -125,6 +125,14 @@ void fallbackProvider() { } } + @Override + public void destroy() { + context = null; + if (currentProvider != null) { + currentProvider.destroy(); + } + } + /** * Builder class for the {@link MultiFallbackProvider}. */ diff --git a/library/src/test/java/io/nlopez/smartlocation/location/providers/TestServiceProvider.java b/library/src/test/java/io/nlopez/smartlocation/location/providers/TestServiceProvider.java index 38aa4743..ecddcb8d 100644 --- a/library/src/test/java/io/nlopez/smartlocation/location/providers/TestServiceProvider.java +++ b/library/src/test/java/io/nlopez/smartlocation/location/providers/TestServiceProvider.java @@ -79,4 +79,9 @@ public void simulateFailure() { listener.onConnectionFailed(); } } + + @Override + public void destroy() { + + } } diff --git a/library/src/test/java/io/nlopez/smartlocation/util/MockLocationProvider.java b/library/src/test/java/io/nlopez/smartlocation/util/MockLocationProvider.java index fe3c554e..5def0e54 100644 --- a/library/src/test/java/io/nlopez/smartlocation/util/MockLocationProvider.java +++ b/library/src/test/java/io/nlopez/smartlocation/util/MockLocationProvider.java @@ -39,4 +39,9 @@ public Location getLastLocation() { public void fakeEmitLocation(Location location) { listener.onLocationUpdated(location); } + + @Override + public void destroy() { + + } } diff --git a/rxjava/src/test/java/io/nlopez/smartlocation/rx/ObservableFactoryTest.java b/rxjava/src/test/java/io/nlopez/smartlocation/rx/ObservableFactoryTest.java index 1e1f0fb8..c7e9cb22 100644 --- a/rxjava/src/test/java/io/nlopez/smartlocation/rx/ObservableFactoryTest.java +++ b/rxjava/src/test/java/io/nlopez/smartlocation/rx/ObservableFactoryTest.java @@ -120,5 +120,10 @@ public Location getLastLocation() { public void fakeEmit(Location location) { mListener.onLocationUpdated(location); } + + @Override + public void destroy() { + + } } } From 0645209858bbe42a7cee3b9b879921eff27b57d7 Mon Sep 17 00:00:00 2001 From: Morten Holmgaard Date: Fri, 22 Jun 2018 12:45:57 +0200 Subject: [PATCH 02/10] Fix build --- build.gradle | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build.gradle b/build.gradle index a4ed658e..583029ae 100644 --- a/build.gradle +++ b/build.gradle @@ -18,4 +18,14 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.1.3' } + +} + +allprojects { + repositories { + mavenCentral() + maven { url "https://maven.google.com" } + jcenter() + google() + } } \ No newline at end of file From e7a36269eb1a49261de20b54b82bd100d4c29eea Mon Sep 17 00:00:00 2001 From: Morten Holmgaard Date: Fri, 22 Jun 2018 13:30:03 +0200 Subject: [PATCH 03/10] fix version number --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 583029ae..01e4c3a0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.smartLocationVersion = "3.3.4" + ext.smartLocationVersion = "3.3.3" // Common dependencies ext.robolectricVersion = "3.1" From 7d915e6965866c815c8da48d5464b4ce075ef1c6 Mon Sep 17 00:00:00 2001 From: Morten Holmgaard Date: Fri, 22 Jun 2018 13:44:11 +0200 Subject: [PATCH 04/10] Fix --- library/build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/build.gradle b/library/build.gradle index 1c91c5ae..9b3db478 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -51,7 +51,9 @@ android.libraryVariants publishing { publications { maven(MavenPublication) { - artifact "build/libs/SmartLocation-${version}.aar" + artifact ("build/libs/SmartLocation-${version}.aar") { + builtBy assembleRelease + } artifactId 'library' } } From 2a0bce48ab8a8e24aca7175c522d44edaa11b582 Mon Sep 17 00:00:00 2001 From: Morten Holmgaard Date: Fri, 22 Jun 2018 13:47:28 +0200 Subject: [PATCH 05/10] Fix --- library/build.gradle | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index 9b3db478..d0e469e1 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -47,17 +47,17 @@ android { } -android.libraryVariants -publishing { - publications { - maven(MavenPublication) { - artifact ("build/libs/SmartLocation-${version}.aar") { - builtBy assembleRelease - } - artifactId 'library' - } - } -} +//android.libraryVariants +//publishing { +// publications { +// maven(MavenPublication) { +// artifact ("build/libs/SmartLocation-${version}.aar") { +// builtBy assembleRelease +// } +// artifactId 'library' +// } +// } +//} def isReleaseBuild() { return version.contains("SNAPSHOT") == false From eef683011b3e6934df8d530cef30e1c7d4624fd5 Mon Sep 17 00:00:00 2001 From: Morten Holmgaard Date: Fri, 22 Jun 2018 13:49:29 +0200 Subject: [PATCH 06/10] fix --- library/build.gradle | 22 +++++++++++----------- rxjava/build.gradle | 4 +++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index d0e469e1..9b3db478 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -47,17 +47,17 @@ android { } -//android.libraryVariants -//publishing { -// publications { -// maven(MavenPublication) { -// artifact ("build/libs/SmartLocation-${version}.aar") { -// builtBy assembleRelease -// } -// artifactId 'library' -// } -// } -//} +android.libraryVariants +publishing { + publications { + maven(MavenPublication) { + artifact ("build/libs/SmartLocation-${version}.aar") { + builtBy assembleRelease + } + artifactId 'library' + } + } +} def isReleaseBuild() { return version.contains("SNAPSHOT") == false diff --git a/rxjava/build.gradle b/rxjava/build.gradle index 8c39963e..58664dce 100644 --- a/rxjava/build.gradle +++ b/rxjava/build.gradle @@ -52,7 +52,9 @@ android.libraryVariants publishing { publications { maven(MavenPublication) { - artifact "build/libs/SmartLocation-RxJavaExtension-${version}.aar" + artifact ("build/libs/SmartLocation-RxJavaExtension-${version}.aar") { + builtBy assembleRelease + } artifactId 'rx' } } From 179632bf5964fa4534cda9afae9b2f0564aa14b8 Mon Sep 17 00:00:00 2001 From: Morten Holmgaard Date: Fri, 22 Jun 2018 13:53:24 +0200 Subject: [PATCH 07/10] fix --- library/build.gradle | 22 +++++++++++----------- rxjava/build.gradle | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index 9b3db478..d0e469e1 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -47,17 +47,17 @@ android { } -android.libraryVariants -publishing { - publications { - maven(MavenPublication) { - artifact ("build/libs/SmartLocation-${version}.aar") { - builtBy assembleRelease - } - artifactId 'library' - } - } -} +//android.libraryVariants +//publishing { +// publications { +// maven(MavenPublication) { +// artifact ("build/libs/SmartLocation-${version}.aar") { +// builtBy assembleRelease +// } +// artifactId 'library' +// } +// } +//} def isReleaseBuild() { return version.contains("SNAPSHOT") == false diff --git a/rxjava/build.gradle b/rxjava/build.gradle index 58664dce..f4195365 100644 --- a/rxjava/build.gradle +++ b/rxjava/build.gradle @@ -48,17 +48,17 @@ android { } -android.libraryVariants -publishing { - publications { - maven(MavenPublication) { - artifact ("build/libs/SmartLocation-RxJavaExtension-${version}.aar") { - builtBy assembleRelease - } - artifactId 'rx' - } - } -} +//android.libraryVariants +//publishing { +// publications { +// maven(MavenPublication) { +// artifact ("build/libs/SmartLocation-RxJavaExtension-${version}.aar") { +// builtBy assembleRelease +// } +// artifactId 'rx' +// } +// } +//} def isReleaseBuild() { return version.contains("SNAPSHOT") == false From 74ae0f8799de4eb82ef5a864be21d468da1ff1e4 Mon Sep 17 00:00:00 2001 From: Morten Holmgaard Date: Fri, 22 Jun 2018 14:13:21 +0200 Subject: [PATCH 08/10] fix --- build.gradle | 1 + library/build.gradle | 22 ++++++++++------------ rxjava/build.gradle | 20 +++++++++----------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index 01e4c3a0..b8f894f3 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' } } diff --git a/library/build.gradle b/library/build.gradle index d0e469e1..8d1ba069 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -8,7 +8,7 @@ apply plugin: 'com.android.library' apply plugin: 'maven-publish' apply plugin: 'maven' apply plugin: 'signing' - +apply plugin: 'com.github.dcendents.android-maven' version smartLocationVersion group 'io.nlopez.smartlocation' @@ -47,17 +47,15 @@ android { } -//android.libraryVariants -//publishing { -// publications { -// maven(MavenPublication) { -// artifact ("build/libs/SmartLocation-${version}.aar") { -// builtBy assembleRelease -// } -// artifactId 'library' -// } -// } -//} +android.libraryVariants +publishing { + publications { + maven(MavenPublication) { + artifact "build/libs/SmartLocation-${version}.aar" + artifactId 'library' + } + } +} def isReleaseBuild() { return version.contains("SNAPSHOT") == false diff --git a/rxjava/build.gradle b/rxjava/build.gradle index f4195365..8c39963e 100644 --- a/rxjava/build.gradle +++ b/rxjava/build.gradle @@ -48,17 +48,15 @@ android { } -//android.libraryVariants -//publishing { -// publications { -// maven(MavenPublication) { -// artifact ("build/libs/SmartLocation-RxJavaExtension-${version}.aar") { -// builtBy assembleRelease -// } -// artifactId 'rx' -// } -// } -//} +android.libraryVariants +publishing { + publications { + maven(MavenPublication) { + artifact "build/libs/SmartLocation-RxJavaExtension-${version}.aar" + artifactId 'rx' + } + } +} def isReleaseBuild() { return version.contains("SNAPSHOT") == false From c97f5782e7e9e1ee67f7af6c6b683ac6a05783db Mon Sep 17 00:00:00 2001 From: Morten Holmgaard Date: Mon, 25 Jun 2018 08:06:37 +0200 Subject: [PATCH 09/10] set listener to null in destroy --- .../location/providers/LocationGooglePlayServicesProvider.java | 1 + .../LocationGooglePlayServicesWithFallbackProvider.java | 1 + 2 files changed, 2 insertions(+) diff --git a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java index 2e8ba5d0..43ec0986 100644 --- a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java +++ b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java @@ -207,6 +207,7 @@ public Location getLastLocation() { @Override public void destroy() { context = null; + listener = null; } @Override diff --git a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java index ff8e5f4e..b1c47b60 100644 --- a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java +++ b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java @@ -63,6 +63,7 @@ public void stop() { @Override public void destroy() { context = null; + listener = null; } @Override From 1cee777ca9bb142e02b9d71c1945f090426a0fd3 Mon Sep 17 00:00:00 2001 From: Morten Holmgaard Date: Mon, 25 Jun 2018 08:52:21 +0200 Subject: [PATCH 10/10] Remember to call destroy on provider --- .../src/main/java/io/nlopez/smartlocation/SmartLocation.java | 1 + .../location/providers/LocationGooglePlayServicesProvider.java | 2 ++ .../LocationGooglePlayServicesWithFallbackProvider.java | 1 + 3 files changed, 4 insertions(+) diff --git a/library/src/main/java/io/nlopez/smartlocation/SmartLocation.java b/library/src/main/java/io/nlopez/smartlocation/SmartLocation.java index 7155f7bf..18d6171c 100644 --- a/library/src/main/java/io/nlopez/smartlocation/SmartLocation.java +++ b/library/src/main/java/io/nlopez/smartlocation/SmartLocation.java @@ -214,6 +214,7 @@ public void stop() { } public void destroy() { + provider.destroy(); provider = null; params = null; smartLocation = null; diff --git a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java index 43ec0986..35fcc43c 100644 --- a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java +++ b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesProvider.java @@ -208,6 +208,8 @@ public Location getLastLocation() { public void destroy() { context = null; listener = null; + googlePlayServicesListener = null; + serviceListener = null; } @Override diff --git a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java index b1c47b60..30a02b3a 100644 --- a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java +++ b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationGooglePlayServicesWithFallbackProvider.java @@ -62,6 +62,7 @@ public void stop() { @Override public void destroy() { + provider.destroy(); context = null; listener = null; }