| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package com.v2ray.ang.service
- import android.app.Service
- import android.content.Context
- import android.content.Intent
- import android.os.Build
- import android.os.IBinder
- import androidx.annotation.RequiresApi
- import com.v2ray.ang.handler.SettingsManager
- import com.v2ray.ang.handler.V2RayServiceManager
- import com.v2ray.ang.util.MyContextWrapper
- import java.lang.ref.SoftReference
- class V2RayProxyOnlyService : Service(), ServiceControl {
- /**
- * Initializes the service.
- */
- override fun onCreate() {
- super.onCreate()
- V2RayServiceManager.serviceControl = SoftReference(this)
- }
- /**
- * Handles the start command for the service.
- * @param intent The intent.
- * @param flags The flags.
- * @param startId The start ID.
- * @return The start mode.
- */
- override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
- V2RayServiceManager.startCoreLoop()
- return START_STICKY
- }
- /**
- * Destroys the service.
- */
- override fun onDestroy() {
- super.onDestroy()
- V2RayServiceManager.stopCoreLoop()
- }
- /**
- * Gets the service instance.
- * @return The service instance.
- */
- override fun getService(): Service {
- return this
- }
- /**
- * Starts the service.
- */
- override fun startService() {
- // do nothing
- }
- /**
- * Stops the service.
- */
- override fun stopService() {
- stopSelf()
- }
- /**
- * Protects the VPN socket.
- * @param socket The socket to protect.
- * @return True if the socket is protected, false otherwise.
- */
- override fun vpnProtect(socket: Int): Boolean {
- return true
- }
- /**
- * Binds the service.
- * @param intent The intent.
- * @return The binder.
- */
- override fun onBind(intent: Intent?): IBinder? {
- return null
- }
- /**
- * Attaches the base context to the service.
- * @param newBase The new base context.
- */
- @RequiresApi(Build.VERSION_CODES.N)
- override fun attachBaseContext(newBase: Context?) {
- val context = newBase?.let {
- MyContextWrapper.wrap(newBase, SettingsManager.getLocale())
- }
- super.attachBaseContext(context)
- }
- }
|