-
Notifications
You must be signed in to change notification settings - Fork 48
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
Changes from 3 commits
439dc3d
35d006b
acd1f05
4433cc3
14299d8
fd6b77d
afb487f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.0.0" | ||
] | ||
|
||
pluginVersion = [ | ||
|
@@ -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}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can save some weight here by using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capturing from a chat that it seems like There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andrlee Yes, per the above comment we discussed that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could still exclude |
||
archLifecycleCompiler : "android.arch.lifecycle:compiler:${version.archLifecycleVersion}", | ||
|
||
// okhttp | ||
okhttp3 : "com.squareup.okhttp3:okhttp:${version.okhttp3}", | ||
okhttp3Mockwebserver : "com.squareup.okhttp3:mockwebserver:${version.okhttp3}", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.mapbox.android.telemetry; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.arch.lifecycle.Lifecycle; | ||
import android.arch.lifecycle.LifecycleObserver; | ||
import android.arch.lifecycle.OnLifecycleEvent; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
class ApplicationLifecycleObserver implements LifecycleObserver { | ||
private static TelemetryService telemetryService; | ||
private Context applicationContext; | ||
private Intent locationServiceIntent = null; | ||
|
||
ApplicationLifecycleObserver(Context applicationContext) { | ||
this.applicationContext = applicationContext; | ||
} | ||
|
||
static void setTelemetryService(TelemetryService telemeService) { | ||
telemetryService = telemeService; | ||
} | ||
|
||
@SuppressLint("NewApi") | ||
@OnLifecycleEvent(Lifecycle.Event.ON_START) | ||
void onEnterForeground() { | ||
if (telemetryService != null) { | ||
locationServiceIntent = new Intent(applicationContext, TelemetryService.class); | ||
applicationContext.startForegroundService(locationServiceIntent); | ||
} | ||
|
||
} | ||
|
||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) | ||
void onEnterBackground() { | ||
if (telemetryService != null) { | ||
telemetryService.stopForegroundService(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package com.mapbox.android.telemetry; | ||
|
||
|
||
import android.app.Notification; | ||
import android.app.Service; | ||
import android.content.Intent; | ||
import android.content.IntentFilter; | ||
import android.location.Location; | ||
import android.os.Binder; | ||
import android.os.Build; | ||
import android.os.IBinder; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.content.LocalBroadcastManager; | ||
|
@@ -41,6 +43,10 @@ public void onCreate() { | |
createLocationReceiver(); | ||
createTelemetryReceiver(); | ||
createServiceTaskCallbacks(); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
initiateForegroundService(); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -254,4 +260,16 @@ TelemetryService obtainService() { | |
return TelemetryService.this; | ||
} | ||
} | ||
|
||
private void initiateForegroundService() { | ||
Notification notification = new Notification(); | ||
startForeground(1375, notification); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this result in showing a notification to the end user?
also:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per the above comment, I actually disable the foreground service when the application enters the background, thus removing the notification. The Android P permission is a new one to me. Haven't looked at the documentation for that yet, but will give it a look. I'm planning on being |
||
|
||
ApplicationLifecycleObserver.setTelemetryService(this); | ||
} | ||
|
||
void stopForegroundService() { | ||
stopForeground(true); | ||
stopSelf(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be any benefits to bumping arch components version? I think
1.1.1
requires support lib 27+, but maybe we could use1.1.0
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope 1.1.1 is good with
supportLib
of 26.1.0