What is Kodi restricted mode? (New bug in my addon)
#1
There is a new bug that some users of my addon are experiencing.
When using ElementTree to parse the settings.xml file, in the log the exception reads:

Code:
IOError: file() constructor not accessible in restricted mode

Looking through the documentation, I can't find what restricted mode is, how it is invoked and what is actually restricted in restricted mode.

The background is that I need to set the allowable values (via type='labelenum') for multiple settings on the addon's Settings page at runtime. This is for a service addon, so this process is invoked at startup.
To do this, I have been loading the settings.xml file from the addon directory (Note: not the addon_data version) via xml.etree.ElementTree.parse().
I then make the changes and write settings.xml back out.

For example:
Code:
<setting default="Default" id="default_profile" label="32012" subsetting="true" type="labelenum" values="None|Default" visible="eq(-1,true)" />
is changed at runtime so that the values="..." is changed to reflect what is actually on the user's system (details not important except that these values are arbitrary and different on each system).


Some users are getting the above error during the initial parse() call. I cannot recreate this on my own system.

I have tried to think of other ways to dynamically change these values, but have not come up with a good solution. I thought of trying to use the type="fileenum" (see: http://kodi.wiki/view/Add-on_settings#ty...ileenum.22) and creating a directory with empty files named for the allowed selections. However, the starting directory in "values" does not accept the "special://" format and it seems that the only directories allowed are subdirectories of the actual addon. So I would possibly end up in the same boat. If restricted mode does not allow read/write in the addon's directory (which is where the settings.xml file is) then I wouldn't be able to create and change this directory from within the addon's code.

Anyone have any ideas on this one?
Reply
#2
Best I know the addon directory is read-only under some linux/android systems. Not a good idea to screw with settings.xml there. You can modify it in the userdata copy - which is what the addon actually looks at in the get/set settings calls.
Reply
#3
(2015-09-16, 22:14)learningit Wrote: Best I know the addon directory is read-only under some linux/android systems. Not a good idea to screw with settings.xml there. You can modify it in the userdata copy - which is what the addon actually looks at in the get/set settings calls.

But you can't edit what the choices are that are provided in a type=labelenum in the userdata copy. That copy only stores what has actually been chosen.
Reply
#4
You could try using a select type, not quite as neat as a enum (it gives a select dialog to choose from), eg

Code:
<setting id="default_profile" label="32012" type="select" source="../../userdata/addon_data/YOURADDON/enumValues/" default="Default"/>

Then you just need to make sure the correct files (if you want to use folders add a mask="/") are created in the enumValues folder, see this thread for more info:

http://forum.kodi.tv/showthread.php?tid=...pid1241581

I guess you could also try using the relative path in a fileenum, it might also work, in fact I'm sure that would work, the ../../ will put you in the Kodi home folder (since it starts in the resources folder where the settings.xml file is located), you can then just go back up the tree to the user_data folder (which is always read/write)

I actually like the select dialog form as it shows you all the available options.

Edit
Just tried the fileenum combined with values="../../userdata/addon_data/YOURADDON/enumValues/ and that definitely works.
Reply
#5
(2015-09-16, 23:42)spoyser Wrote: You could try using a select type, not quite as neat as a enum (it gives a select dialog to choose from), eg

Code:
<setting id="default_profile" label="32012" type="select" source="../../userdata/addon_data/YOURADDON/enumValues/" default="Default"/>

Then you just need to make sure the correct files (if you want to use folders add a mask="/") are created in the enumValues folder, see this thread for more info:

http://forum.kodi.tv/showthread.php?tid=...pid1241581

I guess you could also try using the relative path in a fileenum, it might also work, in fact I'm sure that would work, the ../../ will put you in the Kodi home folder (since it starts in the resources folder where the settings.xml file is located), you can then just go back up the tree to the user_data folder (which is always read/write)

I actually like the select dialog form as it shows you all the available options.

Edit
Just tried the fileenum combined with values="../../userdata/addon_data/YOURADDON/enumValues/ and that definitely works.

Great hint, I like that idea. The only question I have is: will that mapping work even if the user is installed in portable mode? That was why I was trying to use 'special://userdata'...

As an aside - the option="hideext" doesn't seem to work on either the fileenum or select types for me. Ugh.

EDIT:
The one other drawback of doing it this way is I can't set the default to a known value since I don't know what the values might be ahead of time.
Reply
#6
To answer one of my own questions:
Yes, using spoyser's "../../userdata/addon_data/" mapping does work in both normal mode and portable mode.

My main thread question remains: What is restricted mode?
On windows my log on line 9 shows 'Running with restricted rights' when I run it as default and 'Running with administrator rights' if I run as an administrator.
It is not clear that this is related to 'restricted mode'.

There is no documentation that I can find. Searching the github xbmc/xbmc repo for 'restricted' or 'restricted mode' does not turn up anything useful in the source code.
Perhaps I am going about figuring this out the wrong way. I would think that if that message is generated in the log that that text would have to turn up in the source code somewhere...
Reply

Logout Mark Read Team Forum Stats Members Help
What is Kodi restricted mode? (New bug in my addon)0