Improve argument validation in frame:expandTemplate()

Just like the other methods, e shouldn't be allowing passing of things
that aren't numbers or strings here.

For that matter, we should just abstract out the whole "arg key and
value validation" into a separate function instead of repeating it in
four places.

Bug: T76609
Change-Id: Id7e512a988ef9b7a5c5a110c8992dd5d649dcbf9
Merge "Improve argument validation in frame:expandTemplate()"