Skip to content
Open
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
29 changes: 0 additions & 29 deletions vector/src/main/java/im/vector/app/core/extensions/Service.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ServiceInfo
import android.os.Binder
import android.support.v4.media.session.MediaSessionCompat
import android.view.KeyEvent
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.ServiceCompat
import androidx.core.content.ContextCompat
import androidx.media.session.MediaButtonReceiver
import com.airbnb.mvrx.Mavericks
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.singletonEntryPoint
import im.vector.app.core.extensions.startForegroundCompat
import im.vector.app.features.call.CallArgs
import im.vector.app.features.call.VectorCallActivity
import im.vector.app.features.call.audio.MicrophoneAccessService
Expand Down Expand Up @@ -178,7 +179,12 @@ class CallAndroidService : VectorAndroidService() {
fromBg = fromBg
)
if (knownCalls.isEmpty()) {
startForegroundCompat(callId.hashCode(), notification)
ServiceCompat.startForeground(
this,
callId.hashCode(),
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL
  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL

)
} else {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
Timber.w("Not allowed to notify.")
Expand All @@ -201,8 +207,12 @@ class CallAndroidService : VectorAndroidService() {
return
}
val notification = notificationUtils.buildCallEndedNotification(false)
val notificationId = callId.hashCode()
startForegroundCompat(notificationId, notification)
ServiceCompat.startForeground(
this,
callId.hashCode(),
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL
  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL

)
if (knownCalls.isEmpty()) {
Timber.tag(loggerTag.value).v("No more call, stop the service")
stopForegroundCompat()
Expand Down Expand Up @@ -240,7 +250,12 @@ class CallAndroidService : VectorAndroidService() {
title = callInformation.opponentMatrixItem?.getBestName() ?: callInformation.opponentUserId
)
if (knownCalls.isEmpty()) {
startForegroundCompat(callId.hashCode(), notification)
ServiceCompat.startForeground(
this,
callId.hashCode(),
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL
  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL

)
} else {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
Timber.w("Not allowed to notify.")
Expand Down Expand Up @@ -268,7 +283,12 @@ class CallAndroidService : VectorAndroidService() {
title = callInformation.opponentMatrixItem?.getBestName() ?: callInformation.opponentUserId
)
if (knownCalls.isEmpty()) {
startForegroundCompat(callId.hashCode(), notification)
ServiceCompat.startForeground(
this,
callId.hashCode(),
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL
  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL

)
} else {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
Timber.w("Not allowed to notify.")
Expand All @@ -285,9 +305,19 @@ class CallAndroidService : VectorAndroidService() {
callRingPlayerOutgoing?.stop()
val notification = notificationUtils.buildCallEndedNotification(false)
if (callId != null) {
startForegroundCompat(callId.hashCode(), notification)
ServiceCompat.startForeground(
this,
callId.hashCode(),
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL
  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL

)
} else {
startForegroundCompat(DEFAULT_NOTIFICATION_ID, notification)
ServiceCompat.startForeground(
this,
DEFAULT_NOTIFICATION_ID,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL
  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_PHONE_CALL

)
}
if (knownCalls.isEmpty()) {
mediaSession?.isActive = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Build
import androidx.core.app.ServiceCompat
import androidx.core.content.getSystemService
import androidx.work.Constraints
import androidx.work.Data
Expand All @@ -22,7 +24,6 @@ import androidx.work.WorkRequest
import androidx.work.Worker
import androidx.work.WorkerParameters
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.startForegroundCompat
import im.vector.app.core.platform.PendingIntentCompat
import im.vector.app.features.notifications.NotificationUtils
import im.vector.app.features.settings.BackgroundSyncMode
Expand Down Expand Up @@ -90,7 +91,12 @@ class VectorSyncAndroidService : SyncAndroidService() {
CommonStrings.notification_listening_for_notifications
}
val notification = notificationUtils.buildForegroundServiceNotification(notificationSubtitleRes, false)
startForegroundCompat(NotificationUtils.NOTIFICATION_ID_FOREGROUND_SERVICE, notification)
ServiceCompat.startForeground(
this,
NotificationUtils.NOTIFICATION_ID_FOREGROUND_SERVICE,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_DATA_SYNC
  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_DATA_SYNC

)
}

override fun onRescheduleAsked(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
package im.vector.app.features.call.audio

import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Binder
import android.os.IBinder
import androidx.core.app.ServiceCompat
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.startForegroundCompat
import im.vector.app.core.services.VectorAndroidService
import im.vector.app.features.notifications.NotificationUtils
import im.vector.lib.core.utils.timer.Clock
Expand All @@ -42,7 +43,12 @@ class MicrophoneAccessService : VectorAndroidService() {
private fun showMicrophoneAccessNotification() {
val notificationId = clock.epochMillis().toInt()
val notification = notificationUtils.buildMicrophoneAccessNotification()
startForegroundCompat(notificationId, notification)
ServiceCompat.startForeground(
this,
notificationId,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 30 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE
  • ⚠️ Field requires API level 30 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_MICROPHONE

)
}

override fun onBind(intent: Intent?): IBinder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
package im.vector.app.features.call.webrtc

import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Binder
import android.os.IBinder
import androidx.core.app.ServiceCompat
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.startForegroundCompat
import im.vector.app.core.services.VectorAndroidService
import im.vector.app.features.notifications.NotificationUtils
import im.vector.lib.core.utils.timer.Clock
Expand All @@ -33,7 +34,12 @@ class ScreenCaptureAndroidService : VectorAndroidService() {
private fun showStickyNotification() {
val notificationId = clock.epochMillis().toInt()
val notification = notificationUtils.buildScreenSharingNotification()
startForegroundCompat(notificationId, notification)
ServiceCompat.startForeground(
this,
notificationId,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION

)
}

override fun onBind(intent: Intent?): IBinder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package im.vector.app.features.lifecycle

import android.annotation.SuppressLint
import android.app.Activity
import android.app.ActivityManager
import android.app.Application
Expand Down Expand Up @@ -50,6 +51,7 @@ class VectorActivityLifecycleCallbacks constructor(private val popupAlertManager

override fun onActivityStopped(activity: Activity) {}

@SuppressLint("WrongConstant")
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
if (activitiesInfo == null) {
val context = activity.applicationContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ package im.vector.app.features.location.live.tracking
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ServiceInfo
import android.os.IBinder
import android.os.Parcelable
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.ServiceCompat
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.startForegroundCompat
import im.vector.app.core.services.VectorAndroidService
import im.vector.app.core.utils.PermissionChecker
import im.vector.app.features.location.LocationData
Expand Down Expand Up @@ -114,7 +115,12 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
NotificationManagerCompat.from(this).notify(FOREGROUND_SERVICE_NOTIFICATION_ID, notification)
}
} else {
startForegroundCompat(FOREGROUND_SERVICE_NOTIFICATION_ID, notification)
ServiceCompat.startForeground(
this,
FOREGROUND_SERVICE_NOTIFICATION_ID,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_LOCATION
  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_LOCATION

)
foregroundModeStarted = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
package im.vector.app.features.start

import android.content.Intent
import android.content.pm.ServiceInfo
import androidx.core.app.ServiceCompat
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.di.NamedGlobalScope
import im.vector.app.core.extensions.startForegroundCompat
import im.vector.app.core.services.VectorAndroidService
import im.vector.app.features.notifications.NotificationUtils
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -50,6 +51,11 @@ class StartAppAndroidService : VectorAndroidService() {
private fun showStickyNotification() {
val notificationId = Random.nextInt()
val notification = notificationUtils.buildStartAppNotification()
startForegroundCompat(notificationId, notification)
ServiceCompat.startForeground(
this,
notificationId,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_DATA_SYNC
  • ⚠️ Field requires API level 29 (current min is 21): android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_DATA_SYNC

)
}
}
Loading