Skip to content

topl-service / io.matthewnelson.topl_service / TorServiceController / Builder / useCustomTorConfigFiles

useCustomTorConfigFiles

fun useCustomTorConfigFiles(torConfigFiles:TorConfigFiles): Builder (source)

If you wish to customize the file structure of how Tor is installed in your app, you can do so by instantiating your own TorConfigFiles and customizing it via the TorConfigFiles.Builder, or overridden method TorConfigFiles.createConfig.

By default, TorService will call TorConfigFiles.createConfig using your Context.getApplicationContext to set up a standard directory hierarchy for Tor to operate with.

//  fun customTorConfigFilesSetup(context: Context): TorConfigFiles {

        // This is modifying the directory hierarchy from TorService's
        // default setup. For example, if you are using binaries for Tor that
        // are named differently that that expressed in TorConfigFiles.createConfig()

        // Post Android API 28 requires that executable files be contained in your
        // application's data/app directory, as they can no longer execute from data/data.
        val installDir = File(context.applicationInfo.nativeLibraryDir)

        // Will create a directory within your application's data/data dir
        val configDir = context.getDir("torservice", Context.MODE_PRIVATE)

        val builder = TorConfigFiles.Builder(installDir, configDir)

        // Customize the tor executable file name. Requires that the executable file
        // be in your module's src/main/jniLibs directory. If you are getting your
        // executable files via a dependency be sure to consult that Library's documentation.
        builder.torExecutable(File(installDir, "libtor.so"))

        // customize further via the builder methods...

        return builder.build()
//  }

Return Builder

See Also

Builder.build