main

square/leakcanary

Last updated at: 29/12/2023 09:39

PlumberInstaller.kt

TLDR

The PlumberInstaller file is a content provider in the LeakCanary library. It is used to install Android leak fixes on application start.

Classes

PlumberInstaller

The PlumberInstaller class is a content provider that extends the ContentProvider class. It is responsible for installing leak fixes on application start. The onCreate method is overridden to apply the leak fixes using the AndroidLeakFixes.applyFixes method. The other methods (query, getType, insert, delete, update) are overridden but do not have any implementation.

package leakcanary.internal

import android.app.Application
import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri
import leakcanary.AndroidLeakFixes

/**
 * Content providers are loaded before the application class is created. [PlumberInstaller] is
 * used to install [leakcanary.AndroidLeakFixes] fixes on application start.
 */
internal class PlumberInstaller : ContentProvider() {

  override fun onCreate(): Boolean {
    val application = context!!.applicationContext as Application
    AndroidLeakFixes.applyFixes(application)
    return true
  }

  override fun query(
    uri: Uri,
    projectionArg: Array<String>?,
    selection: String?,
    selectionArgs: Array<String>?,
    sortOrder: String?
  ): Cursor? = null

  override fun getType(uri: Uri): String? = null

  override fun insert(uri: Uri, contentValues: ContentValues?): Uri? = null

  override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0

  override fun update(
    uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?
  ): Int = 0
}