Repository: square/leakcanary
File: leakcanary-android-core/src/main/java/leakcanary/internal/LeakCanaryFileProvider.kt (Kotlin)

Code before:
import android.content.pm.PackageManager
import android.content.pm.ProviderInfo
import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.os.ParcelFileDescriptor
import android.os.StrictMode
import android.provider.OpenableColumns
import android.text.TextUtils
import android.webkit.MimeTypeMap
import org.xmlpull.v1.XmlPullParser.END_DOCUMENT
import org.xmlpull.v1.XmlPullParser.START_TAG
import org.xmlpull.v1.XmlPullParserException
import java.io.File
import java.io.FileNotFoundException
import java.io.IOException
import java.util.HashMap

/**
 * Copy of androidx.core.content.FileProvider, converted to Kotlin.
 */
internal class LeakCanaryFileProvider : ContentProvider() {

  private var mStrategy: PathStrategy? = null

  /**
   * The default FileProvider implementation does not need to be initialized. If you want to
   * override this method, you must provide your own subclass of FileProvider.
   */
  override fun onCreate(): Boolean {
    return true
  }

  /**
   * After the FileProvider is instantiated, this method is called to provide the system with
   * information about the provider.
   *
   * @param context A [Context] for the current component.
   * @param info A [ProviderInfo] for the new provider.
   */
  override fun attachInfo(
    context: Context,
    info: ProviderInfo
  ) {
    super.attachInfo(context, info)

    // Sanity check our security
    if (info.exported) {
      throw SecurityException("Provider must not be exported")

Review comment (suggestion):
Make `mStrategy` lateinit instead of nullable, as it was called with assert for times.

Code after:
import android.content.pm.PackageManager
import android.content.pm.ProviderInfo
import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.os.ParcelFileDescriptor
import android.os.StrictMode
import android.provider.OpenableColumns
import android.text.TextUtils
import android.webkit.MimeTypeMap
import java.io.File
import java.io.FileNotFoundException
import java.io.IOException
import java.util.HashMap
import org.xmlpull.v1.XmlPullParser.END_DOCUMENT
import org.xmlpull.v1.XmlPullParser.START_TAG
import org.xmlpull.v1.XmlPullParserException

/**
 * Copy of androidx.core.content.FileProvider, converted to Kotlin.
 */
internal class LeakCanaryFileProvider : ContentProvider() {

  private lateinit var mStrategy: PathStrategy

  /**
   * The default FileProvider implementation does not need to be initialized. If you want to
   * override this method, you must provide your own subclass of FileProvider.
   */
  override fun onCreate(): Boolean = true

  /**
   * After the FileProvider is instantiated, this method is called to provide the system with
   * information about the provider.
   *
   * @param context A [Context] for the current component.
   * @param info A [ProviderInfo] for the new provider.
   */
  override fun attachInfo(
    context: Context,
    info: ProviderInfo
  ) {
    super.attachInfo(context, info)

    // Sanity check our security
    if (info.exported) {
      throw SecurityException("Provider must not be exported")
    }
    if (!info.grantUriPermissions) {