~eliasnaur/gio-patches

app/permission: add documentation and storage permissions v1 PROPOSED

Greg Pomerantz
Greg Pomerantz: 1
 app/permission: add documentation and storage permissions

 6 files changed, 107 insertions(+), 30 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/9149/mbox | git am -3
Learn more about email & git

[PATCH] app/permission: add documentation and storage permissions Export this patch

Greg Pomerantz
Storage permissions enables the Android permissions
READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE.
---
 app/doc.go                          | 32 ++------------------------------
 app/permission/bluetooth/main.go    | 23 +++++++++++++++++++++++
 app/permission/bluetooth_le/main.go | 23 +++++++++++++++++++++++
 app/permission/doc.go               | 37 +++++++++++++++++++++++++++++++++++++
 app/permission/storage/main.go      | 18 ++++++++++++++++++
 cmd/gogio/permission.go             |  4 ++++
 6 files changed, 107 insertions(+), 30 deletions(-)
 create mode 100644 app/permission/doc.go
 create mode 100644 app/permission/storage/main.go

diff --git a/app/doc.go b/app/doc.go
index fc034b8..7dc6a26 100644
--- a/app/doc.go
+++ b/app/doc.go
@@ -67,35 +67,7 @@ Permissions
 
 The packages under gioui.org/app/permission should be imported
 by a Gio program or by one of its dependencies to indicate that specific
-operating-system permissions are required. For example, if a Gio
-program requires access to a device's Bluetooth interface, it
-should import "gioui.org/app/permission/bluetooth" as follows:
-
-	package main
-
-	import (
-		"gioui.org/app"
-		_ "gioui.org/app/permission/bluetooth"
-	)
-
-	func main() {
-		...
-	}
-
-Since there are no exported identifiers in the app/permission/bluetooth
-package, the import uses the anonymous identifier (_) as the imported
-package name.
-
-As a special case, the gogio tool detects when a program directly or
-indirectly depends on the "net" package from the Go standard library as an
-indication that the program requires network access permissions. If a program
-requires network permissions but does not directly or indirectly import
-"net", it will be necessary to add the following code somewhere in the
-program's source code:
-
-	import (
-		...
-		_ "net"
-	)
+operating-system permissions are required. Please see documentation under
+gioui.org/app/permission for more information.
 */
 package app
diff --git a/app/permission/bluetooth/main.go b/app/permission/bluetooth/main.go
index b3b971b..adbe7b9 100644
--- a/app/permission/bluetooth/main.go
+++ b/app/permission/bluetooth/main.go
@@ -1 +1,24 @@
+// SPDX-License-Identifier: Unlicense OR MIT
+
+/*
+Package bluetooth provides access to Bluetooth hardware,
+including the ability to discover and pair devices.
+
+On Android, this causes the following entries to be added to
+AndroidManifest.xml:
+
+    <uses-permission android:name="android.permission.BLUETOOTH"/>
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+    <uses-feature android:name="android.hardware.bluetooth" android:required="false"/>
+
+Note that ACCESS_FINE_LOCATION is required on Android before the Bluetooth
+device may be used.
+See https://developer.android.com/guide/topics/connectivity/bluetooth.
+
+Since ACCESS_FINE_LOCATION has a protection level of "dangerous",
+your app will need to prompt the user to request access. This can be
+done with a java Fragment, installed using (*app.Window).RegisterFragment().
+For more information on dangerous permissions, see: https://developer.android.com/guide/topics/permissions/overview#dangerous_permissions
+*/
 package bluetooth
diff --git a/app/permission/bluetooth_le/main.go b/app/permission/bluetooth_le/main.go
index 6fcf968..a677bd9 100644
--- a/app/permission/bluetooth_le/main.go
+++ b/app/permission/bluetooth_le/main.go
@@ -1 +1,24 @@
+// SPDX-License-Identifier: Unlicense OR MIT
+
+/*
+Package bluetooth_le provides access to Bluetooth Low Energy hardware,
+including the ability to discover and pair devices.
+
+On Android, this causes the following entries to be added to
+AndroidManifest.xml:
+
+    <uses-permission android:name="android.permission.BLUETOOTH"/>
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+    <uses-feature android:name="android.hardware.bluetooth_le" android:required="false"/>
+
+Note that ACCESS_FINE_LOCATION is required on Android before the Bluetooth
+device may be used.
+See https://developer.android.com/guide/topics/connectivity/bluetooth.
+
+Since ACCESS_FINE_LOCATION has a protection level of "dangerous",
+your app will need to prompt the user to request access. This can be
+done with a java Fragment, installed using (*app.Window).RegisterFragment().
+For more information on dangerous permissions, see: https://developer.android.com/guide/topics/permissions/overview#dangerous_permissions
+*/
 package bluetooth_le
diff --git a/app/permission/doc.go b/app/permission/doc.go
new file mode 100644
index 0000000..1a703cf
--- /dev/null
+++ b/app/permission/doc.go
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: Unlicense OR MIT
+
+/*
+Package permission includes sub-packages that should be imported
+by a Gio program or by one of its dependencies to indicate that specific
+operating-system permissions are required. For example, if a Gio
+program requires access to a device's Bluetooth interface, it
+should import "gioui.org/app/permission/bluetooth" as follows:
+
+	package main
+
+	import (
+		"gioui.org/app"
+		_ "gioui.org/app/permission/bluetooth"
+	)
+
+	func main() {
+		...
+	}
+
+Since there are no exported identifiers in the app/permission/bluetooth
+package, the import uses the anonymous identifier (_) as the imported
+package name.
+
+As a special case, the gogio tool detects when a program directly or
+indirectly depends on the "net" package from the Go standard library as an
+indication that the program requires network access permissions. If a program
+requires network permissions but does not directly or indirectly import
+"net", it will be necessary to add the following code somewhere in the
+program's source code:
+
+	import (
+		...
+		_ "net"
+	)
+*/
+package permission
diff --git a/app/permission/storage/main.go b/app/permission/storage/main.go
new file mode 100644
index 0000000..f50ba7e
--- /dev/null
+++ b/app/permission/storage/main.go
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: Unlicense OR MIT
+
+/*
+Package storage provides access to read and write storage on mobile devices.
+
+On Android, this causes the following entries to be added to
+AndroidManifest.xml:
+
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+
+Because READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE have a protection
+level of "dangerous", your app will need to prompt the user to request access.
+This can be done with a java Fragment, installed using
+(*app.Window).RegisterFragment().
+For more information on dangerous permissions, see: https://developer.android.com/guide/topics/permissions/overview#dangerous_permissions
+*/
+package storage
diff --git a/cmd/gogio/permission.go b/cmd/gogio/permission.go
index eabbb91..a39f1b8 100644
--- a/cmd/gogio/permission.go
+++ b/cmd/gogio/permission.go
@@ -14,6 +14,10 @@ var AndroidPermissions = map[string][]string{
 		"android.permission.BLUETOOTH_ADMIN",
 		"android.permission.ACCESS_FINE_LOCATION",
 	},
+	"storage": {
+		"android.permission.READ_EXTERNAL_STORAGE",
+		"android.permission.WRITE_EXTERNAL_STORAGE",
+	},
 }
 
 var AndroidFeatures = map[string][]string{
-- 
2.16.2
Nice!

On Mon Nov 25, 2019 at 11:40 AM Greg Pomerantz wrote:
> diff --git a/app/doc.go b/app/doc.go
> index fc034b8..7dc6a26 100644
> --- a/app/doc.go
> +++ b/app/doc.go
> @@ -67,35 +67,7 @@ Permissions
> 
> The packages under gioui.org/app/permission should be imported
> by a Gio program or by one of its dependencies to indicate that specific
> -operating-system permissions are required. For example, if a Gio
> -program requires access to a device's Bluetooth interface, it
> -should import "gioui.org/app/permission/bluetooth" as follows:
> -
> -	package main
> -
> -	import (
> -		"gioui.org/app"
> -		_ "gioui.org/app/permission/bluetooth"
> -	)
> -
> -	func main() {
> -		...
> -	}
> -
> -Since there are no exported identifiers in the app/permission/bluetooth
> -package, the import uses the anonymous identifier (_) as the imported
> -package name.
> -
> -As a special case, the gogio tool detects when a program directly or
> -indirectly depends on the "net" package from the Go standard library as an
> -indication that the program requires network access permissions. If a program
> -requires network permissions but does not directly or indirectly import
> -"net", it will be necessary to add the following code somewhere in the
> -program's source code:
> -
> -	import (
> -		...
> -		_ "net"
> -	)
> +operating-system permissions are required.
View this thread in the archives