BackgroundMatchingService

class BackgroundMatchingService : Service

A Service running in the background, which detects when new photos are taken on the smartphone. A ContentObserver monitors changes in the phone gallery directory and sends match requests once new photos are detected.

Constructors

BackgroundMatchingService
Link copied to clipboard
fun BackgroundMatchingService()

Types

Companion
Link copied to clipboard
object Companion

Companion object for starting/stopping the service.

Functions

calculateInSampleSize
Link copied to clipboard
private fun calculateInSampleSize(options: BitmapFactory.Options, reqWidth: Int, reqHeight: Int): Int

Calculates the inSampleSize for the bitmap decoding.

createForegroundNotification
Link copied to clipboard
private fun createForegroundNotification()

Creates a notification channel for the foreground notification as well as the notification itself.

createForegroundNotificationChannel
Link copied to clipboard
private fun createForegroundNotificationChannel()

Creates the notification channel for the foreground notification.

createMatchNotification
Link copied to clipboard
private fun createMatchNotification(matchResult: Bitmap)

Creates a notification channel for the match notification as well as the notification itself.

createMatchNotificationChannel
Link copied to clipboard
private fun createMatchNotificationChannel()

Creates the notification channel for the match notification.

decodeSampledBitmapFromResource
Link copied to clipboard
fun decodeSampledBitmapFromResource(file: File, reqWidth: Int, reqHeight: Int): Bitmap

Decode a sampled bitmap from a file to a Bitmap.

getConnectedStatusIcon
Link copied to clipboard
private fun getConnectedStatusIcon(): Int

Returns the icon representing the corresponding connected status.

getConnectedStatusString
Link copied to clipboard
private fun getConnectedStatusString(): String

Returns the string representing the corresponding connected status.

getMatchingOptionsFromPref
Link copied to clipboard
private fun getMatchingOptionsFromPref(): HashMap<Any?, Any?>

Returns the matching options for the match request.

getPathFromObserverUri
Link copied to clipboard
fun getPathFromObserverUri(uri: Uri): String?

Returns the file path of a given uri.

isNewCameraPhoto
Link copied to clipboard
private fun isNewCameraPhoto(file: File): Boolean

Checks whether a given file is a new camera photo.

isValidFilePath
Link copied to clipboard
private fun isValidFilePath(path: String?): Boolean

Checks whether a given path is a valid file path.

onBind
Link copied to clipboard
open override fun onBind(intent: Intent?): IBinder?
onCreate
Link copied to clipboard
open override fun onCreate()

Called when the service is created, initializes the service.

onDestroy
Link copied to clipboard
open override fun onDestroy()

On destroy, calls stopService.

onMatch
Link copied to clipboard
private fun onMatch(matchId: String, ba: ByteArray?)

Called when CaptureCallback.onMatchResult of captureCallback is called. Sends a notification to the user with the result of the matching by calling sendMatchNotification.

onStartCommand
Link copied to clipboard
open override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int
queryAbsoluteDataColumn
Link copied to clipboard
private fun queryAbsoluteDataColumn(uri: Uri): String?
queryRelativeDataColumn
Link copied to clipboard
@RequiresApi(value = 29)
fun queryRelativeDataColumn(uri: Uri): String?
rescaleAndSendToServer
Link copied to clipboard
private fun rescaleAndSendToServer(image: Bitmap)

Rescales an image to 512x512 and calls sendCaptureRequest with the scaled image.

sendMatchNotification
Link copied to clipboard
private fun sendMatchNotification(bmp: Bitmap)

Send a match notification to the user with the result of the matching process.

sleepService
Link copied to clipboard
private fun sleepService()

Sleeps the service. Called when the screen is turned off.

startContentObserver
Link copied to clipboard
private fun startContentObserver()

Initializes contentObserver and registers it.

startService
Link copied to clipboard
private fun startService()

Starts the service.

stopService
Link copied to clipboard
private fun stopService()

Stops the service. Called when the service is destroyed.

updateForegroundNotification
Link copied to clipboard
private fun updateForegroundNotification()

Updates the foreground notification with the new connected status.

updateMatchNotification
Link copied to clipboard
private fun updateMatchNotification(matchResult: Bitmap)

Updates the match notification with the new image of the match.

Properties

broadcastReceiver
Link copied to clipboard
private var broadcastReceiver: BroadcastReceiver? = null

BroadcastReceiver instance, which receives broadcasts from the system (screen on/off).

captureCallback
Link copied to clipboard
private val captureCallback: BackgroundMatchingService.<no name provided>

CaptureCallback object that is used to handle the response from the server. Used in rescaleAndSendToServer.

contentObserver
Link copied to clipboard
private var contentObserver: ContentObserver? = null

Instance of ContentObserver which monitors changes in the phone gallery directory and sends match requests once new photos are detected.

foregroundNotificationBuilder
Link copied to clipboard
private lateinit var foregroundNotificationBuilder: NotificationCompat.Builder

The notification builder for the foreground notification.

foregroundNotificationChannelId
Link copied to clipboard
private val foregroundNotificationChannelId: String

The id of the foreground notification channel.

isActive
Link copied to clipboard
private var isActive: Boolean = false

Whether or not the service is active.

isConnected
Link copied to clipboard
var isConnected: Boolean = false

Whether or not the service is connected to the server.

isConnectedObserver
Link copied to clipboard
private val isConnectedObserver: Observer<Boolean>

Observer instance, which observes ServerConnectionModel.isConnected and updates isConnected accordingly.

isWaitingForMatchingResponse
Link copied to clipboard
private var isWaitingForMatchingResponse: Boolean = false

Whether or not the service is waiting for a match response from the server.

MATCHING_MODE_PREF_KEY
Link copied to clipboard
private lateinit var MATCHING_MODE_PREF_KEY: String

The key for the preference that determines the matching mode.

matchNotificationBuilder
Link copied to clipboard
private lateinit var matchNotificationBuilder: NotificationCompat.Builder

The notification builder for the match notification.

matchNotificationChannelId
Link copied to clipboard
private val matchNotificationChannelId: String

The id of the match notification channel.

recentContentObserverPaths
Link copied to clipboard
private var recentContentObserverPaths: LinkedList<String>

Stores the last 10 files dispatched by contentObserver. This is done to avoid double processing, because contentObserver sometimes fires multiple identical events per file.

sp
Link copied to clipboard
private lateinit var sp: SharedPreferences

SharedPreferences instance, stores the preferences.