Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oreo Background Service Crash #157

Merged
merged 7 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ buildscript {

allprojects {
repositories {
maven { url 'https://plugins.gradle.org/m2' }
maven { url "https://maven.google.com" }
maven { url 'https://plugins.gradle.org/m2' }
jcenter()
}

Expand Down
29 changes: 17 additions & 12 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ ext {

androidVersions = [
minSdkVersion : 14,
targetSdkVersion : 25,
compileSdkVersion: 25,
targetSdkVersion : 26,
compileSdkVersion: 26,
buildToolsVersion: '27.0.2'
]

version = [
mapboxServices : '2.2.6',
gmsLocation : '11.0.4',
junit : '4.12',
supportLibVersion: '25.4.0',
constraintLayout : '1.0.2',
mockito : '2.11.0',
testRunnerVersion: '1.0.1',
okhttp3 : '3.10.0',
gson : '2.8.2',
espressoVersion : '3.0.1'
mapboxServices : '2.2.6',
gmsLocation : '11.0.4',
junit : '4.12',
supportLibVersion : '26.1.0',
constraintLayout : '1.0.2',
mockito : '2.11.0',
testRunnerVersion : '1.0.1',
okhttp3 : '3.10.0',
gson : '2.8.2',
espressoVersion : '3.0.1',
archLifecycleVersion: "1.1.1"
]

pluginVersion = [
Expand All @@ -33,6 +34,10 @@ ext {
// play services
gmsLocation : "com.google.android.gms:play-services-location:${version.gmsLocation}",

//architecture components
archLifecycleExtensions: "android.arch.lifecycle:extensions:${version.archLifecycleVersion}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can save some weight here by using android.arch.lifecycle:runtime:${version.archLifecycleVersion} dependency instead of extensions as we are not using ViewModel or LiveData.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capturing from a chat that it seems like runtime does not contain ProcessLifecycleOwner so we need to stick to extensions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@electrostat any good reason why @LukasPaczos suggestion to cut on weight was not addressed and PR still got merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrlee Yes, per the above comment we discussed that ProcessLifecycleOwner' is not included in runtime, so we had to keep extensions`. We tested and discussed over slack the issue and was just captures in the brief above comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could still exclude livedata and viewmodel right? We shouldn't be including unnecessary deps.

archLifecycleCompiler : "android.arch.lifecycle:compiler:${version.archLifecycleVersion}",

// okhttp
okhttp3 : "com.squareup.okhttp3:okhttp:${version.okhttp3}",
okhttp3Mockwebserver : "com.squareup.okhttp3:mockwebserver:${version.okhttp3}",
Expand Down
2 changes: 2 additions & 0 deletions libtelemetry/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ dependencies {
compile dependenciesList.okhttp3
compile dependenciesList.gson
compile dependenciesList.supportAppcompatV7
compile dependenciesList.archLifecycleExtensions
annotationProcessor dependenciesList.archLifecycleCompiler

testCompile dependenciesList.junit
testCompile dependenciesList.mockito
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@


import android.app.ActivityManager;
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.OnLifecycleEvent;
import android.arch.lifecycle.ProcessLifecycleOwner;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.IBinder;

import com.mapbox.android.core.location.LocationEnginePriority;
Expand All @@ -22,7 +27,8 @@
import okhttp3.Callback;
import okhttp3.Response;

public class MapboxTelemetry implements FullQueueCallback, EventCallback, ServiceTaskCallback, Callback {
public class MapboxTelemetry implements FullQueueCallback, EventCallback, ServiceTaskCallback, Callback,
LifecycleObserver {
private static final String EVENTS_USER_AGENT = "MapboxEventsAndroid/";
private static final String TELEMETRY_USER_AGENT = "MapboxTelemetryAndroid/";
private static final String UNITY_USER_AGENT = "MapboxEventsUnityAndroid/";
Expand Down Expand Up @@ -488,7 +494,15 @@ private PermissionCheckRunnable obtainPermissionCheckRunnable() {
}

private void startLocation() {
applicationContext.startService(obtainLocationServiceIntent());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (ProcessLifecycleOwner.get().getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
applicationContext.startService(obtainLocationServiceIntent());
} else {
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
}
} else {
applicationContext.startService(obtainLocationServiceIntent());
}
}

private void startAlarm() {
Expand Down Expand Up @@ -528,4 +542,10 @@ private boolean unbindServiceConnection() {

return false;
}

@OnLifecycleEvent(Lifecycle.Event.ON_START)
void onEnterForeground() {
startLocation();
ProcessLifecycleOwner.get().getLifecycle().removeObserver(this);
}
}