public static function set_user_device_type($newdevice) {
        $devicetype = self::get_device_type();
        if ($newdevice == $devicetype) {
            unset_user_preference('switchdevice'.$devicetype);
            return true;
        } else {
            $devicetypes = self::get_device_type_list();
            if (in_array($newdevice, $devicetypes)) {
                set_user_preference('switchdevice'.$devicetype, $newdevice);
                return true;
            }
        }
        throw new coding_exception('Invalid device type provided to set_user_device_type');
    }