aboutsummaryrefslogtreecommitdiffstats
path: root/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/OpenPgpServiceConnection.kt
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2021-03-09 14:53:11 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2021-03-18 11:40:30 +0530
commit774fda83ac276a635e3402034b1eedbd10be916f (patch)
tree57783a953fcd193d32f1e3dc8df26e07f03df328 /openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/OpenPgpServiceConnection.kt
parentbe31ae37f443982b377d027cd613f04d0926568d (diff)
downloadHardenedPass-774fda83ac276a635e3402034b1eedbd10be916f.tar.gz
HardenedPass-774fda83ac276a635e3402034b1eedbd10be916f.zip
all: reformat with ktfmt
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/OpenPgpServiceConnection.kt')
-rw-r--r--openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/OpenPgpServiceConnection.kt118
1 files changed, 57 insertions, 61 deletions
diff --git a/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/OpenPgpServiceConnection.kt b/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/OpenPgpServiceConnection.kt
index 4efa6a9d..6a0a9933 100644
--- a/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/OpenPgpServiceConnection.kt
+++ b/openpgp-ktx/src/main/java/me/msfjarvis/openpgpktx/util/OpenPgpServiceConnection.kt
@@ -13,76 +13,72 @@ import org.openintents.openpgp.IOpenPgpService2
public class OpenPgpServiceConnection(context: Context, providerPackageName: String?) {
- // callback interface
- public interface OnBound {
+ // callback interface
+ public interface OnBound {
- public fun onBound(service: IOpenPgpService2)
- public fun onError(e: Exception)
- }
+ public fun onBound(service: IOpenPgpService2)
+ public fun onError(e: Exception)
+ }
- private val mApplicationContext: Context = context.applicationContext
- public var service: IOpenPgpService2? = null
- private set
- private val mProviderPackageName: String? = providerPackageName
- private var mOnBoundListener: OnBound? = null
+ private val mApplicationContext: Context = context.applicationContext
+ public var service: IOpenPgpService2? = null
+ private set
+ private val mProviderPackageName: String? = providerPackageName
+ private var mOnBoundListener: OnBound? = null
- /**
- * Create new connection with callback
- *
- * @param context
- * @param providerPackageName specify package name of OpenPGP provider,
- * e.g., "org.sufficientlysecure.keychain"
- * @param onBoundListener callback, executed when connection to service has been established
- */
- public constructor(
- context: Context,
- providerPackageName: String?,
- onBoundListener: OnBound?
- ) : this(context, providerPackageName) {
- mOnBoundListener = onBoundListener
- }
+ /**
+ * Create new connection with callback
+ *
+ * @param context
+ * @param providerPackageName specify package name of OpenPGP provider, e.g.,
+ * "org.sufficientlysecure.keychain"
+ * @param onBoundListener callback, executed when connection to service has been established
+ */
+ public constructor(
+ context: Context,
+ providerPackageName: String?,
+ onBoundListener: OnBound?
+ ) : this(context, providerPackageName) {
+ mOnBoundListener = onBoundListener
+ }
- public val isBound: Boolean
- get() = service != null
+ public val isBound: Boolean
+ get() = service != null
- private val mServiceConnection: ServiceConnection = object : ServiceConnection {
- override fun onServiceConnected(name: ComponentName, service: IBinder) {
- this@OpenPgpServiceConnection.service = IOpenPgpService2.Stub.asInterface(service)
- mOnBoundListener?.onBound(this@OpenPgpServiceConnection.service!!)
- }
+ private val mServiceConnection: ServiceConnection =
+ object : ServiceConnection {
+ override fun onServiceConnected(name: ComponentName, service: IBinder) {
+ this@OpenPgpServiceConnection.service = IOpenPgpService2.Stub.asInterface(service)
+ mOnBoundListener?.onBound(this@OpenPgpServiceConnection.service!!)
+ }
- override fun onServiceDisconnected(name: ComponentName) {
- service = null
- }
+ override fun onServiceDisconnected(name: ComponentName) {
+ service = null
+ }
}
- /**
- * If not already bound, bind to service!
- */
- public fun bindToService() {
- if (service == null) {
- // if not already bound...
- try {
- val serviceIntent = Intent(OpenPgpApi.SERVICE_INTENT_2)
- // NOTE: setPackage is very important to restrict the intent to this provider only!
- serviceIntent.setPackage(mProviderPackageName)
- val connect = mApplicationContext.bindService(
- serviceIntent, mServiceConnection,
- Context.BIND_AUTO_CREATE
- )
- if (!connect) {
- throw Exception("bindService() returned false!")
- }
- } catch (e: Exception) {
- mOnBoundListener?.onError(e)
- }
- } else {
- // already bound, but also inform client about it with callback
- mOnBoundListener?.onBound(service!!)
+ /** If not already bound, bind to service! */
+ public fun bindToService() {
+ if (service == null) {
+ // if not already bound...
+ try {
+ val serviceIntent = Intent(OpenPgpApi.SERVICE_INTENT_2)
+ // NOTE: setPackage is very important to restrict the intent to this provider only!
+ serviceIntent.setPackage(mProviderPackageName)
+ val connect = mApplicationContext.bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE)
+ if (!connect) {
+ throw Exception("bindService() returned false!")
}
+ } catch (e: Exception) {
+ mOnBoundListener?.onError(e)
+ }
+ } else {
+ // already bound, but also inform client about it with callback
+ mOnBoundListener?.onBound(service!!)
}
+ }
- public fun unbindFromService() {
- mApplicationContext.unbindService(mServiceConnection)
- }
+ public fun unbindFromService() {
+ mApplicationContext.unbindService(mServiceConnection)
+ }
}