コード例 #1
0
            public void Run()
            {
                IntPtr path = JNIEnv.NewString(m_service.m_configPath);

                try
                {
                    m_service.BroadcastStatus(true);

                    var jclass = JNIEnv.FindClass("com.trojan_plus.android.TrojanPlusVPNService");
                    RunMain(JNIEnv.Handle, jclass, path);
                }
                catch (Exception ex)
                {
                    Log.Error(TAG, ex.Message + "\n" + ex.StackTrace);
                }
                finally
                {
                    JNIEnv.DeleteLocalRef(path);
                }

                m_service.CloseFD();
                m_service.StopSelf();
                m_service.m_worker = null;
                m_service.BroadcastStatus(false);
            }
コード例 #2
0
            public override void HandleMessage(Message msg)
            {
                service.replyMessenger = msg.ReplyTo;
                switch (msg.What)
                {
                case TrojanPlusStarter.VPN_START:
                    if (service.worker == null)
                    {
                        Log.Debug(TAG, "on VpnServiceHandler.HandleMessage VPN_START");
                        service.prepareConfigPath = msg.Data.GetString("config");
                        service.showNotification  = msg.Data.GetBoolean("showNotification");

                        service.OpenFD();
                    }

                    break;

                case TrojanPlusStarter.VPN_STATUS_ASK:
                {
                    var reply = Message.Obtain(null, TrojanPlusStarter.VPN_STATUS_ASK);
                    reply.Data = new Bundle();
                    reply.Data.PutBoolean("start", service.worker != null);

                    msg.ReplyTo.Send(reply);
                }

                break;

                case TrojanPlusStarter.VPN_STOP:
                    if (service.worker != null)
                    {
                        Log.Debug(TAG, "on VpnServiceHandler.HandleMessage VPN_STOP");
                        StopMain(IntPtr.Zero, IntPtr.Zero);
                    }
                    else
                    {
                        service.StopSelf();
                    }

                    break;

                default:
                    Log.Error(TAG, $"Unknown msg.what value: {msg.What} . Ignoring this message.");
                    break;
                }
            }
コード例 #3
0
            public void Run()
            {
                IntPtr path = JNIEnv.NewString(service.runConfigPath);

                try
                {
                    if (service.notification != null)
                    {
                        service.notification.Show();
                    }

                    service.BroadcastStatus(true);

                    var jclass = JNIEnv.FindClass("com.trojan_plus.android.TrojanPlusVPNService");
                    RunMain(JNIEnv.Handle, jclass, path);
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                    Log.Error(TAG, ex.Message + "\n" + ex.StackTrace);
                }
                finally
                {
                    JNIEnv.DeleteLocalRef(path);
                }

                if (service.notification != null)
                {
                    service.notification.Destroy();
                }

                service.CloseFD();
                service.StopSelf();
                service.worker = null;
                service.BroadcastStatus(false);
            }