This app shows to use the permissions API to request optional permissions. It can list the attached serial ports, but only if the "serial" permission is granted. The app shows how to check if the permission is granted and how to request it if it is not.