There should be an extra option on groups_get_activity_group so that you can specify if your activity wants a specific group always (and only 0 if the user is not permitted to view any groups).
This is for things like our wiki where you can only view one wiki at a time, and the 'All groups' option doesn't make sense. Note that it is possible to implement this using the existing functions but I think it would be better done in the library as it should be the same everywhere and you can make mistakes...
Same thing applies to groups_print_activity_menu.
1) Add function groups_get_allowed_groups which abstracts out the logic already in a couple places (get groupmode, get accessallgroups, return appropriate list of groups).
2) Change groups_get_activity_group($cm, $update=false) to add extra parameter at end, $requiregroup=false
If $requiregroup is false then behaviour as at present. If $requiregroup is true then get list of allowed groups. Return first [i.e. arbitrary] from this list, or 0 if user is not allowed any groups.
3) Change groups_print_activity_menu to add $requiregroup=false
If $requiregroup is false then behaviour as at present. If it is true then do not display the 'all participants' option.