Android Question My thread was shut down while getting USB temporary permissions.

MomoWen

Member
Licensed User
My thread:
Sub thread2_start
    Dim args(0) As Object
    If TestRunningTime.Running Then       
        TestRunningTime.Interrupt               
    End If

    If TestRunningTime.IsInitialized Then
        TestRunningTimeLock.Initialize(True)
        TestRunningTime.Name = "B4A Thread 2"
        TestRunningTime.Start(Null,"thread2Start", args)
    End If
End Sub
Sub thread2Start
    Dim args(0) As Object
         Do While SubDown
        Log("thread2Start")
        TestRunningTime.Sleep(2000)
    Loop
'    TestRunningTime.RunOnGuiThread("Update2",args)
End Sub
get USB dev:
Sub SelectedDevice
    
    For i=0 To UsbManager.GetDevices.Length-1
        Dim dev As UsbDevice=UsbManager.GetDevices(i)
        If dev.VendorId=6790 And dev.ProductId=29987 Then
        If UsbManager.HasPermission(dev) = False Then
                Debug.DebugLog(Debug.LogTypes.System,"HasPermission")
                UsbManager.RequestPermission(dev)
        End If
            If Uusbdev.IsInitialized And Uusbdev.DeviceName.CompareTo(dev.DeviceName)=0 Then
                PreserveUSBDeviceLock.Unlock
                Return
            End If
            Log("authorization!")
            Uusbdev=dev
            IsusbReset=True
            If IsRecord Then
                xml.tabe1.UpdateCell(UsbSetRow.Col,UsbSetRow.Row,Uusbdev.DeviceName.SubString(Uusbdev.DeviceName.LastIndexOf("/")+1))
            End If
            PreserveUSBDeviceLock.Unlock
            Log("PreserveUSBDeviceLock.Unlock")
            Return
        End If
    Next
    Uusbdev=Null
    PreserveUSBDeviceLock.Unlock
End Sub
 

MomoWen

Member
Licensed User
Note: Getting the USB device function is done in a thread through a call to RunOnGuiThread ().However, any thread that Thread.sleep () will exit with an exception when the USB permission pop-up box appears ( English is not my first language. )
 
Upvote 0

MomoWen

Member
Licensed User
My error message:
Data obtained from write buffer: *IDN?

Raw data from write buffer: 0x2A 0x49 0x44 0x4E 0x3F 0x0D 0x0A
Number of bytes obtained from write buffer: 7
[5]·[20:16:42]·[33938]·[System]·[HasPermission]
authorization!
PreserveUSBDeviceLock.Unlock
** Activity (main) Pause, UserClosed = false **
thread2Start
sending message to waiting queue (testrunningtime_ended)
sending message to waiting queue (sleep)
sending message to waiting queue (testrunning_ended)
running waiting messages (3)
java.lang.reflect.InvocationTargetException
Exception : null----------TestRunningTime_Ended=false
java.lang.reflect.InvocationTargetException
Exception : null----------TestRunning_Ended=false
** Activity (main) Resume **
-1 received
writer error
java.lang.InterruptedException
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:1992)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2026)
    at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:373)
    at anywheresoftware.b4a.remotelogger.Connector$Writer.run(Connector.java:160)
    at java.lang.Thread.run(Thread.java:841)
Starting remote logger. Port: 35352
After accept
Uusbdev.IsInitialized
Not(isTesting)
Getusb=
Buffer size: 16384
 
Upvote 0

MomoWen

Member
Licensed User
This is my test of the problem
EN~I have solved the problem .
But I was curious, when I clicked on the USB permissions TAB, the screen turned black and quickly recovered.
Threads that call the thread.sleep() function will also close because of an exception
 
Upvote 0

MomoWen

Member
Licensed User

It seems to be related to an Android activity, ondestruction-onCreate
Activities were destroyed and rebuilt.(This is my guess, English is not my native language.)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…