[SPARK-3543] Write TaskContext in Java and expose it through a static accessor.

It doesn't, because java is too strict about package private. The package name should be exact same does not expose it even in sub-packages.