Skip to content
Snippets Groups Projects
Commit 2ae7e6d3 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

DRingService: implement onTimeout

Change-Id: I99b7d1c41e8e6f055c062a4c9dbb8312d6815531
parent 1b7bdc7a
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -48,7 +48,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<!--<uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" />--> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL" />
<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA" /> <uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA" />
...@@ -332,7 +332,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -332,7 +332,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<service <service
android:name=".service.DRingService" android:name=".service.DRingService"
android:exported="false" android:exported="false"
android:foregroundServiceType="dataSync"> android:foregroundServiceType="dataSync|remoteMessaging">
<intent-filter> <intent-filter>
<action android:name=".service.DRingService" /> <action android:name=".service.DRingService" />
</intent-filter> </intent-filter>
......
...@@ -22,6 +22,7 @@ import android.content.BroadcastReceiver ...@@ -22,6 +22,7 @@ import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.content.pm.ServiceInfo
import android.database.ContentObserver import android.database.ContentObserver
import android.net.* import android.net.*
import android.net.ConnectivityManager.NetworkCallback import android.net.ConnectivityManager.NetworkCallback
...@@ -179,10 +180,22 @@ class DRingService : Service() { ...@@ -179,10 +180,22 @@ class DRingService : Service() {
private fun showSystemNotification(settings: Settings) { private fun showSystemNotification(settings: Settings) {
try { try {
if (settings.enablePermanentService) { if (settings.enablePermanentService) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startForeground(NOTIFICATION_ID, mNotificationService.serviceNotification as Notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING)
} else {
startForeground(NOTIFICATION_ID, mNotificationService.serviceNotification as Notification) startForeground(NOTIFICATION_ID, mNotificationService.serviceNotification as Notification)
}
} else { } else {
stopForeground(true) stopForeground(STOP_FOREGROUND_REMOVE)
}
} catch (e: Exception) {
Log.e(TAG, "Can't start or stop foreground service: ${e.message}")
}
} }
override fun onTimeout(startId: Int, fgsType: Int) {
try {
stopForeground(STOP_FOREGROUND_REMOVE)
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "Can't start or stop foreground service: ${e.message}") Log.e(TAG, "Can't start or stop foreground service: ${e.message}")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment