I'm building an application for a COSU device. I based my code on the following example provided by Google:
Codelabs.developers.google.com/cosu
In the LockedActivity
there is the following piece of code:
private void setDefaultCosuPolicies(boolean active){
// Set user restrictions
setUserRestriction(UserManager.DISALLOW_SAFE_BOOT, active);
setUserRestriction(UserManager.DISALLOW_FACTORY_RESET, active);
setUserRestriction(UserManager.DISALLOW_ADD_USER, active);
setUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA, active);
setUserRestriction(UserManager.DISALLOW_ADJUST_VOLUME, active);
// remainder of this method is left out for simplicity
}
private void setUserRestriction(String restriction, boolean disallow){
if (disallow) {
mDevicePolicyManager.addUserRestriction(mAdminComponentName,
restriction);
} else {
mDevicePolicyManager.clearUserRestriction(mAdminComponentName,
restriction);
}
}
When active == true
in the above snippet, the volume buttons are disabled correctly as a consequence of setUserRestriction(UserManager.DISALLOW_ADJUST_VOLUME, true)
. However, this also mutes the master volume (which is documented here). That prevents my application from playing any sound. Personally, I think it would be better if the volume would simply be frozen at the level it was or if the volume were at least programmatically still configurable (which seems not to be the case).
I could programmatically override the volume up/down buttons, but that feels more like a workaround/hack (this is for instance done here).
So my question is: Is there a way to unmute the master volume while having the UserManager.DISALLOW_ADJUST_VOLUME
user permission set to true? Or are there any decent workarounds?