Skip to content

Commit b679274

Browse files
committed
interfaces/builtin/opengl: Add support for libhybris setups
For libhybris/Halium distributions to support graphics acceleration we need to allow loading a huge set of Android libraries which, due to their proprietary nature, we don't know the exact dependency chain of beforehand. Luckily we have the OnTouch property to only allow these permissions to be applied on Ubuntu Touch systems where this might be needed. snap-confine already prepares the environment appropriately for us, we just need to punch holes into the security policy of the OpenGL-consuming Snap. This allows loading proprietary Android OpenGL ES drivers on Ubuntu Touch.
1 parent 748d063 commit b679274

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

interfaces/builtin/opengl.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/snapcore/snapd/interfaces/apparmor"
2828
"github.com/snapcore/snapd/interfaces/mount"
2929
"github.com/snapcore/snapd/osutil"
30+
"github.com/snapcore/snapd/release"
3031
)
3132

3233
const openglSummary = `allows access to OpenGL stack`
@@ -217,6 +218,33 @@ unix (send, receive) type=dgram peer=(addr="@var/run/nvidia-xdriver-*"),
217218
/run/nvidia-persistenced/socket rw,
218219
`
219220

221+
const openglHybrisConnectedPlugAppArmor = `
222+
# Hybris support
223+
/android{,/**} r,
224+
/{,android/}system/build.prop r,
225+
/{,android/}vendor/lib{,64}/** r,
226+
/{,android/}vendor/lib{,64}/**.so m,
227+
/{,android/}system/lib{,64}/** r,
228+
/{,android/}system/lib{,64}/**.so m,
229+
/{,android/}system/vendor/lib{,64}/** r,
230+
/{,android/}system/vendor/lib{,64}/**.so m,
231+
/{,android/}odm/lib{,64}/** r,
232+
/{,android/}odm/lib{,64}/**.so m,
233+
/{,android/}apex/com.android.*/lib{,64}/** r,
234+
/{,android/}apex/com.android.*/lib{,64}/**.so m,
235+
/{,dev/}socket/property_service rw, # attach_disconnected path
236+
/{,dev/}socket/logdw rw, # attach_disconnected path
237+
/{,dev/}__properties__/** r, # attach_disconnected path
238+
/dev/{,binderfs/}binder rw,
239+
/dev/{,binderfs/}hwbinder rw,
240+
/dev/ashmem rw,
241+
/dev/ion rw,
242+
/dev/kgsl-3d0 rw,
243+
/sys/devices/platform/soc/**/kgsl/kgsl-3d0/gpu_model rw,
244+
`
245+
246+
247+
220248
type openglInterface struct {
221249
commonInterface
222250
}
@@ -251,6 +279,14 @@ var openglConnectedPlugUDev = []string{
251279
`SUBSYSTEM=="kfd", KERNEL=="kfd"`,
252280
}
253281

282+
// Set up hybris/Halium device access for GLES to work on Touch
283+
var openglHybrisConnectedPlugUDev = []string{
284+
`KERNEL=="kgsl-3d0"`,
285+
`KERNEL=="ion"`,
286+
`KERNEL=="binder"`,
287+
`KERNEL=="hwbinder"`,
288+
}
289+
254290
// Those two are the same, but in theory they are separate and can move (or
255291
// could move) dependently. The first path is as seen on the initial mount
256292
// namespace of the host. The second path is as seen inside the per-snap mount
@@ -263,6 +299,10 @@ const (
263299
func (iface *openglInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error {
264300
spec.AddSnippet(openglConnectedPlugAppArmor)
265301

302+
if release.OnTouch {
303+
spec.AddSnippet(openglHybrisConnectedPlugAppArmor)
304+
}
305+
266306
// Allow mounting the Nvidia driver profiles directory
267307
hostNvProfilesDir := filepath.Join(dirs.GlobalRootDir, nvProfilesDirInHostNs)
268308
if !osutil.IsDirectory(hostNvProfilesDir) {
@@ -301,14 +341,18 @@ func (iface *openglInterface) MountConnectedPlug(spec *mount.Specification, plug
301341
}
302342

303343
func init() {
344+
connectedPlugUDev := openglConnectedPlugUDev
345+
if release.OnTouch {
346+
connectedPlugUDev = append(openglConnectedPlugUDev, openglHybrisConnectedPlugUDev...)
347+
}
304348
registerIface(&openglInterface{
305349
commonInterface: commonInterface{
306350
name: "opengl",
307351
summary: openglSummary,
308352
implicitOnCore: true,
309353
implicitOnClassic: true,
310354
baseDeclarationSlots: openglBaseDeclarationSlots,
311-
connectedPlugUDev: openglConnectedPlugUDev,
355+
connectedPlugUDev: connectedPlugUDev,
312356
},
313357
})
314358
}

0 commit comments

Comments
 (0)