  Given the algebraic data characterizing any (2+1)D bosonic or fermionic
topological order with a global symmetry group $G = \mathrm{U}(1) \rtimes H$,
we construct a (3+1)D topologically invariant path integral in the presence of
a curved background $G$ gauge field, as an exact combinatorial state sum.
Specifically, the $\mathrm{U}(1)$ component of the $G$ gauge field can have a
non-trivial second Chern class, extending previous work that was restricted to
flat $G$ bundles. Our construction expresses the $\mathrm{U}(1)$ gauge field in
terms of a Villain formulation on the triangulation, which includes a 1-form
$\mathbb{R}$ gauge field and 2-form $\mathbb{Z}$ gauge field. We develop a new
graphical calculus for anyons interacting with "Villain symmetry defects",
associated with the 1-form and 2-form background gauge fields. This graphical
calculus is used to define the (3+1)D path integral, which can describe either
a bosonic or fermionic symmetry-protected topological (SPT) phase. For example,
we can construct the topological path integral on curved $\mathrm{U}(1)$
bundles for the (3+1)D fermionic topological insulator in class AII and
topological superconductor in class AIII given appropriate (2+1)D fermionic
symmetry fractionalization data; these then give invariants of 4-manifolds with
Spin$^c$ or Pin$^c$ structures and their generalizations. The (3+1)D path
integrals define anomaly indicators for the (2+1)D topological orders; in the
case of Abelian (2+1)D topological orders, we derive by explicit computation
all of the mixed $\mathrm{U}(1)$ anomaly indicator formulas proposed by Lapa
and Levin. We also propose a Spin$^c$ generalization of the Gauss-Milgram sum,
valid for super-modular categories.
