Skip to content

Commit

Permalink
Convert ShadowsocksRunnerService
Browse files Browse the repository at this point in the history
30/40
  • Loading branch information
HMBSbige committed Nov 4, 2019
1 parent e1b15b1 commit 682b041
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 130 deletions.
130 changes: 0 additions & 130 deletions app/src/main/java/com/github/shadowsocks/ShadowsocksRunnerService.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.github.shadowsocks

import android.content.*
import android.net.*
import android.os.*
import com.github.shadowsocks.aidl.*
import com.github.shadowsocks.utils.*

class ShadowsocksRunnerService : ServiceBoundService()
{
companion object
{
private const val TAG = "ShadowsocksRunnerService"
}

private val handler = Handler()

private val mCallback = object : IShadowsocksServiceCallback.Stub()
{
override fun stateChanged(state: Int, profileName: String, msg: String)
{
}

override fun trafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long)
{
}
}

private val mStopSelfRunnable = Runnable { stopSelf() }

override fun onBind(intent: Intent): IBinder?
{
return null
}

override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int
{
detachService()
attachService(mCallback)
return START_STICKY
}

override fun onServiceConnected()
{
if (bgService != null)
{
if (VpnService.prepare(this@ShadowsocksRunnerService) == null)
{
startBackgroundService()
}
else
{
handler.postDelayed(mStopSelfRunnable, 10000)
}
}
}

private fun startBackgroundService()
{
try
{
bgService!!.use(ShadowsocksApplication.app.profileId())
}
catch (e: RemoteException)
{
VayLog.e(TAG, "startBackgroundService", e)
ShadowsocksApplication.app.track(e)
}
}

override fun onDestroy()
{
super.onDestroy()
detachService()
}
}

0 comments on commit 682b041

Please sign in to comment.