How does focusing work on mobile phone cameras?
Tiny AF motor, in the case of iPhone. Probably the same for other phones with adjustable focus cameras. I've read about the possibility of using liquid lenses and other whizzy technology, but I'm not aware of any devices on the market that use them.
Aren't their optics simple enough to not have any moving parts whatsoever?
Many phones do have cameras with such tiny apertures that they have nearly infinite depth of field, so focusing isn't necessary. But starting with the iPhone 4, iPhones and iPads have had adjustable focus. Same for other brands.
If so, how come most smartphones have an auto-focus, and with various
Android releases it always wastes huge amount of time and causes huge
shutter lags, plus sometimes you end up with pictures of objects at
focal infinity that clearly appear out-of-focus?
Tradeoffs, limitations of current technology, and user error:
Tradeoffs: it'd probably be possible to design a phone with a really fast and accurate AF system and no shutter lag, but it might not be a very good phone (or game machine, surrogate for your computer, etc.)
Limitations: part of the lag in both AF and shutter may be due to the capabilities of the cameras built into these devices. The distance that the lens can move to focus must be very small -- perhaps that necessitates slower movements to find focus.
User error: there's no reason that a distant object should be in focus if you're telling the camera to focus on something close. Like any camera, you've got to learn to control the one in your phone appropriately. Many smartphones use taps on the screen to choose the area to focus on and adjust exposure for. Learn when the shutter fires -- is it when you touch the button, or when you lift your finger?