Android Question Android Things USE_PERIPHERAL_IO permission problem

Tareq Khan

Member
Licensed User
Longtime User
I have installed Android Things 1.0.1 to Raspberry Pi 3. I am using B4A 8.3, Core (Version 8.3), Things (Version 1.10). Java: jdk1.8.0_172. Android jar path: C:\Android\platforms\android-24\android.jar

I have the following code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

#AdditionalJar: androidthings, ReferenceOnly
Sub Process_Globals
    Private pm As PeripheralManager
    Private pin4 As Gpio 'led
    Private pin17 As Gpio 'button
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        pm.Initialize
        Log(pm.GpioList)
        pin4 = pm.OpenGpio("BCM18")
        pin4.Direction = pin4.DIRECTION_OUT_INITIALLY_LOW
        pin17 = pm.OpenGpio("BCM17")
        pin17.Direction = pin17.DIRECTION_IN
        pin17.AddListener("pin17")
    End If
    Activity.LoadLayout("1")
End Sub

Sub Pin17_StateChanged (Value As Boolean)
    Dim clr As Int
    If Value Then clr = 0xFF54EF72 Else clr = 0xFFC52D56
    Activity.Color = clr
End Sub

Sub ToggleButton1_CheckedChange(Checked As Boolean)
    pin4.Value = Checked 'turn on or off the led
End Sub

The manifest editor contains:

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.

AddApplicationText(<uses-library android:name="com.google.android.things"/>)

'Launch activity automatically on boot (can remove if not needed)
AddActivityText(Main,
  <intent-filter>
  <action android:name="android.intent.action.MAIN"/>
  <category android:name="android.intent.category.IOT_LAUNCHER"/>
  <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>
)
AddPermission(com.google.android.things.permission.USE_PERIPHERAL_IO)


I am getting the "java.lang.SecurityException: Caller lacks required permission com.google.android.things.permission.USE_PERIPHERAL_IO" error as shown below:

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
(ArrayList) [BCM10, BCM11, BCM12, BCM13, BCM14, BCM15, BCM16, BCM17, BCM18, BCM19, BCM2, BCM20, BCM21, BCM22, BCM23, BCM24, BCM25, BCM26, BCM27, BCM3, BCM4, BCM5, BCM6, BCM7, BCM8, BCM9]
main_activity_create (java line: 350)
java.lang.SecurityException: Caller lacks required permission com.google.android.things.permission.USE_PERIPHERAL_IO
at android.os.Parcel.readException(Parcel.java:2005)
at android.os.Parcel.readException(Parcel.java:1951)
at com.google.android.things.pio.IPeripheralManagerClient$Stub$Proxy.GetGpioClient(IPeripheralManagerClient.java:759)
at com.google.android.things.pio.GpioImpl.<init>(GpioImpl.java:50)
at com.google.android.things.pio.PeripheralManager.openGpio(PeripheralManager.java:197)
at anywheresoftware.b4a.objects.PeripheralManagerWrapper.OpenGpio(PeripheralManagerWrapper.java:45)
at b4a.example.main._activity_create(main.java:350)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at b4a.example.main.afterFirstLayout(main.java:104)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

I tried to solve this by rebooting the RPi several times, but getting the same error message.

Can anyone pls help? Thanks!
 

Tareq Khan

Member
Licensed User
Longtime User
Upvote 0

Tareq Khan

Member
Licensed User
Longtime User
per.png
 
Upvote 0

Tareq Khan

Member
Licensed User
Longtime User
Hi, I rebooted the device several times as mentioned in the my first post, but I got the same error message. I found a way to solve this using the steps below:

1. In B4A, compile program in "Release" mode.

2. Go to folder /Object and copy the *.apk file to C:\Android\platform-tools

3. From cmd prompt of C:\Android\platform-tools.
>> adb uninstall <package name> [this is the package name such as b4a.example, check in B4A menu: Project-> Build configurations]

4. Install the APK manually using adb install -g <APK> the first time. This flag grants all requested permissions on install, so you can avoid the reboot.

>> adb install -g <*.apk>


5. From B4A, reinstall the program. It should work now.


To stop the program:

>> adb uninstall <package name>


Thanks for your help and comments!
 
Upvote 0

Homeless_John

New Member
Licensed User
Hi, i have the same probleme. But i can't solve it with your 5-step guide.

I get a syntax error when i try to install it (adb install -g <result.apk>). The file is in the platform-tools-folder, where also the adb.exe is found.

When i restart my device i can run the application without the "java.lang.SecurityException: Caller lacks required permission com.google.android.things.permission.USE_PERIPHERAL_IO"-error.
But i can't see the app-surface with a checkbox.
After a few seconds B4A tells me that an error has occured. The connection from the rapid debugger to the process failed.

If i try again, i get the PERIPHAL_IO-error again.


Does somebody has any idea?

Thank you for your help.
 
Upvote 0

Tareq Khan

Member
Licensed User
Longtime User
Hi, i have the same probleme. But i can't solve it with your 5-step guide.

I get a syntax error when i try to install it (adb install -g <result.apk>). The file is in the platform-tools-folder, where also the adb.exe is found.

When i restart my device i can run the application without the "java.lang.SecurityException: Caller lacks required permission com.google.android.things.permission.USE_PERIPHERAL_IO"-error.
But i can't see the app-surface with a checkbox.
After a few seconds B4A tells me that an error has occured. The connection from the rapid debugger to the process failed.

If i try again, i get the PERIPHAL_IO-error again.


Does somebody has any idea?

Thank you for your help.

in cmd prompt, write:
adb install -g result.apk

without the <>. This should solve the syntax error problem.
 
Upvote 0

Homeless_John

New Member
Licensed User
You are right. I had some problemes after that, so i decided to start from the beginning.
I flashed android things again.

After that i was able to install the app with these 5 steps.

Thank you!
 
Upvote 0
Top