I tried a lot of different methods,This can be done by notifying a dummy modify to keymap with such an operator.
I don’t think it’s a good way, but is there any other good way?
class SAMPLE_OT_DirtyKeymap(bpy.types.Operator) :
bl_idname = "addon.sample_dirty_keymap"
bl_label = "Save Keymap"
def execute(self, context):
km = context.window_manager.keyconfigs.user.keymaps["MyAddon"] :
km.show_expanded_items = km.show_expanded_items
for kmi in km.keymap_items :
kmi.active = kmi.active
context.preferences.is_dirty = True
return {'FINISHED'}