• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Socket exception Permission denied in VirtualBox (with Ubuntu) from Device

mdsousa

Newbie
Hi

I'm running Android Studio 4.0.1 (it has api 27, 28 and 29 installed). The physical device is a Samsung Active2 (Model SM-T390) and has Android version 9 (api 28) on it.

I am running Android Studio in a Virtualbox (version 6.1) with Ubuntu 20.04 installed in it. The Virtualbox is running on Windows 10. There is some port forwarding being done in the Virutalbox as seen in the pic below
upload_2020-10-6_11-22-18.png



When trying to open an AsynchronousSocketChannel, it throws an exception and complains about 'Permission denied', the stack trace is here (relevant lines are bold):
Code:
aunching 'app' on samsung SM-T390.
$ adb shell am start -n "com.elbit.elbittoandroidtest/com.elbit.edmandroidtest.EDMtoAndroidTest" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 17757 on device 'samsung-sm_t390-5200bd485e8766fd'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/ittoandroidtes: The ClassLoaderContext is a special shared library.
I/MultiWindowDecorSupport: updateCaptionType >> com.android.internal.policy.MultiWindowDecorSupport@a6ae311, isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
D/MultiWindowDecorSupport: setCaptionType = 0
W/ittoandroidtes: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking)
W/ittoandroidtes: Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking)
    Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking)
    Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking)
    Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking)
D/NetworkManagementSocketTagger: tagSocket(-1) with statsTag=0xffffffff, statsUid=-1
I/AsynchronousSocketChannel IOException: java.net.SocketException: Permission denied
        at sun.nio.ch.Net.socket0(Native Method)
        at sun.nio.ch.Net.socket(Net.java:420)
        at sun.nio.ch.Net.socket(Net.java:413)
        at sun.nio.ch.AsynchronousSocketChannelImpl.<init>(AsynchronousSocketChannelImpl.java:90)
        at sun.nio.ch.UnixAsynchronousSocketChannelImpl.<init>(UnixAsynchronousSocketChannelImpl.java:102)
        at sun.nio.ch.LinuxAsynchronousChannelProvider.openAsynchronousSocketChannel(LinuxAsynchronousChannelProvider.java:88)
        at java.nio.channels.AsynchronousSocketChannel.open(AsynchronousSocketChannel.java:169)
        at java.nio.channels.AsynchronousSocketChannel.open(AsynchronousSocketChannel.java:190)
        at (EDMtoAndroidTest.java:101)
        at android.app.Activity.performCreate(Activity.java:7335)
        at android.app.Activity.performCreate(Activity.java:7326)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1275)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3121)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3284)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1972)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7179)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
W/System.err: java.net.SocketException: Permission denied
        at sun.nio.ch.Net.socket0(Native Method)
W/System.err:     at sun.nio.ch.Net.socket(Net.java:420)
        at sun.nio.ch.Net.socket(Net.java:413)
        at sun.nio.ch.AsynchronousSocketChannelImpl.<init>(AsynchronousSocketChannelImpl.java:90)
        at sun.nio.ch.UnixAsynchronousSocketChannelImpl.<init>(UnixAsynchronousSocketChannelImpl.java:102)
W/System.err:     at sun.nio.ch.LinuxAsynchronousChannelProvider.openAsynchronousSocketChannel(LinuxAsynchronousChannelProvider.java:88)
        at java.nio.channels.AsynchronousSocketChannel.open(AsynchronousSocketChannel.java:169)
        at java.nio.channels.AsynchronousSocketChannel.open(AsynchronousSocketChannel.java:190)
        at android.app.Activity.performCreate(Activity.java:7335)
        at android.app.Activity.performCreate(Activity.java:7326)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1275)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3121)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3284)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1972)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)


The line of code referred to in the exception stack trace is here:
Java:
        try
        {
[B][SIZE=5]            java.nio.channels.AsynchronousSocketChannel client = java.nio.channels.AsynchronousSocketChannel.open(); // this is [B]EDMtoAndroidTest.java:101[/B][/SIZE][/B]
//            InetSocketAddress host = new InetSocketAddress("127.0.0.1",1870);
            InetSocketAddress host = new InetSocketAddress("10.0.2.2",1870);
            Future<Void> future = client.connect(host);
            future.get(); // wait for connection to succeed
            Log.i("AsynchronousChannel", "Connection Successful");
        catch (InterruptedException e)
        {
            Log.i("AsynchronousSocketChannel IOException", Log.getStackTraceString(e));
            e.printStackTrace();
        }

Any idea what I am missing when trying to get a physical device to open a socket to Ubuntu running in a Virtualbox which it self is running on Windows 10?

Thanks...
 
Back
Top Bottom