Ejemplo n.º 1
0
        protected void createSockets()
        {
            if (sPipeApi == PIPE_API_LS)
            {
                const String LOCAL_ADDR = "net.majorkernelpanic.streaming-";

                for (int i = 0; i < 10; i++)
                {
                    try {
                        mSocketId = new Java.Util.Random().NextInt();
                        mLss      = new LocalServerSocket(LOCAL_ADDR + mSocketId);
                        break;
                    } catch (Java.IO.IOException e1) {}
                }

                mReceiver = new LocalSocket();
                mReceiver.Connect(new LocalSocketAddress(LOCAL_ADDR + mSocketId));
                mReceiver.ReceiveBufferSize = 500000;
                mReceiver.SoTimeout         = 3000;
                mSender = mLss.Accept();
                mSender.SendBufferSize = 500000;
            }
            else
            {
                Log.e(TAG, "parcelFileDescriptors createPipe version = Lollipop");
                mParcelFileDescriptors = ParcelFileDescriptor.CreatePipe();
                mParcelRead            = new ParcelFileDescriptor(mParcelFileDescriptors[0]);
                mParcelWrite           = new ParcelFileDescriptor(mParcelFileDescriptors[1]);
            }
        }
		public MediaStream():base() {
			IsStreaming = false;
			try {
				lss = new LocalServerSocket("localServer"+id);
			} catch{
				//throw new IOException("Can't create local socket !");
			}
			socketId = id;
			id++;
		}
Ejemplo n.º 3
0
 public MediaStream() : base()
 {
     IsStreaming = false;
     try {
         lss = new LocalServerSocket("localServer" + id);
     } catch {
         //throw new IOException("Can't create local socket !");
     }
     socketId = id;
     id++;
 }
Ejemplo n.º 4
0
 protected void closeSockets()
 {
     if (sPipeApi == PIPE_API_LS)
     {
         try {
             mReceiver.Close();
         } catch (Exception e) {
             System.Diagnostics.Trace.WriteLine(e.StackTrace.ToString());
         }
         try {
             mSender.Close();
         } catch (Exception e) {
             System.Diagnostics.Trace.WriteLine(e.StackTrace.ToString());
         }
         try {
             mLss.Close();
         } catch (Exception e) {
             System.Diagnostics.Trace.WriteLine(e.StackTrace.ToString());
         }
         mLss      = null;
         mSender   = null;
         mReceiver = null;
     }
     else
     {
         try {
             if (mParcelRead != null)
             {
                 mParcelRead.Close();
             }
         } catch (Exception e) {
             System.Diagnostics.Trace.WriteLine(e.StackTrace.ToString());
         }
         try {
             if (mParcelWrite != null)
             {
                 mParcelWrite.Close();
             }
         } catch (Exception e) {
             System.Diagnostics.Trace.WriteLine(e.StackTrace.ToString());
         }
     }
 }
Ejemplo n.º 5
0
        protected override void onCreate(Bundle savedInstanceState)
        {
            var activity = this;

            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);



            var t = typeof(MemoryFile);

            //var m = Activator.CreateInstance(t);

            //E/AndroidRuntime( 4217): Caused by: java.lang.InstantiationException: class android.os.MemoryFile has no zero argument constructor
            //E/AndroidRuntime( 4217):        at java.lang.Class.newInstance(Class.java:1641)
            //E/AndroidRuntime( 4217):        at ScriptCoreLibJava.BCLImplementation.System.__Activator.CreateInstance(__Activator.java:27)
            //E/AndroidRuntime( 4217):        ... 14 more
            //E/AndroidRuntime( 4217): Caused by: java.lang.NoSuchMethodException: <init> []
            //E/AndroidRuntime( 4217):        at java.lang.Class.getConstructor(Class.java:531)
            //E/AndroidRuntime( 4217):        at java.lang.Class.getDeclaredConstructor(Class.java:510)
            //E/AndroidRuntime( 4217):        at java.lang.Class.newInstance(Class.java:1639)
            //E/AndroidRuntime( 4217):        ... 15 more

            var m_descriptor = 0;
            var m_fd         = default(java.io.FileDescriptor);
            var pid          = android.os.Process.myPid();
            var uid          = android.os.Process.myUid();

            //try { m = new MemoryFile(default(string), 0); }
            try { m = new MemoryFile("name1", 0x07); }
            catch { throw; }

            try
            {
                m.writeBytes(
                    new byte[] { 7, 6, 5, 4, 3, 2, 1 }, 0, 0, 0x07
                    );
            }
            catch { }

            var buffer = new byte[0x07];

            try
            {
                m.readBytes(buffer, 0, 0, 0x07);
            }
            catch { }
            var buffer0 = buffer[0];

            //new Button(this).AttachTo(ll).WithText(new { t, m, buffer0 }.ToString());
            new Button(this).AttachTo(ll).WithText(new { buffer0 }.ToString());

            #region fields
            var fields = t.GetFields(
                System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                );

            new Button(this).AttachTo(ll).WithText("fields: " + new { fields.Length }.ToString());

            fields.WithEach(
                SourceField =>
            {
                //E/AndroidRuntime( 9919): Caused by: java.lang.IllegalAccessException: Cannot access field: java.io.FileDescriptor android.os.MemoryFile.mFD
                //E/AndroidRuntime( 9919):        at java.lang.reflect.Field.get(Native Method)
                //E/AndroidRuntime( 9919):        at java.lang.reflect.Field.get(Field.java:279)
                //E/AndroidRuntime( 9919):        at ScriptCoreLibJava.BCLImplementation.System.Reflection.__FieldInfo.GetValue(__FieldInfo.java:46)

                var value = SourceField.GetValue(m);

                var xFileDescriptor = value as java.io.FileDescriptor;
                if (xFileDescriptor != null)
                {
                    m_fd = xFileDescriptor;

                    var xfields = typeof(java.io.FileDescriptor).GetFields(
                        System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                        );

                    xfields.WithEach(
                        xFileDescriptor_SourceField =>
                    {
                        var xvalue = xFileDescriptor_SourceField.GetValue(value);

                        //if (xFileDescriptor_SourceField.FieldType == typeof(int))
                        if (xFileDescriptor_SourceField.Name == "descriptor")
                        {
                            m_descriptor = (int)xvalue;
                        }

                        new Button(this).AttachTo(ll).WithText(xFileDescriptor_SourceField + new { xvalue }.ToString());
                    }
                        );
                }
                else
                {
                    new Button(this).AttachTo(ll).WithText(new { SourceField, value }.ToString());
                }
            }
                );
            #endregion

            //var pfd = default(android.os.ParcelFileDescriptor);

            //try
            //{
            //    pfd = android.os.ParcelFileDescriptor.dup(
            //        m_fd
            //    );
            //}
            //catch
            //{
            //}

            new Button(activity).WithText("Next \n " + new
            {
                pid,
                uid
                //,
                //pfd = pfd.getFd(),
                //size = pfd.getStatSize()
            }).AttachTo(ll).AtClick(
                delegate
            {
                Intent intent = new Intent(activity, typeof(SecondaryActivity).ToClass());
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

                // share scope
                intent.putExtra("m_descriptor", m_descriptor);
                intent.putExtra("pid", pid);

                //intent.putExtra("pfd", pfd);

                //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

                try
                {
                    Console.WriteLine("new LocalServerSocket");
                    var ss = new LocalServerSocket("MemoryFileDescriptor0");

                    // cached backgroun process?
                    // switching to another process.. easy...
                    activity.startActivity(intent);

                    Console.WriteLine("before LocalServerSocket accept");


                    // http://alvinalexander.com/java/jwarehouse/android/core/tests/coretests/src/android/net/LocalSocketTest.java.shtml
                    var ls = ss.accept();
                    Console.WriteLine("after LocalServerSocket accept");

                    ls.setFileDescriptorsForSend(new[] { m_fd });
                    ls.getOutputStream().write(42);
                }
                catch
                {
                    throw;
                }
            }
                );

            this.setContentView(sv);

            // https://developer.android.com/training/run-background-service/create-service.html
        }