How battery-charger system in mobile phones and laptops works?
There's a charger controller IC inside the phone/laptop/whatever that regulates the charge current or voltage to ensure safe charging according to the battery's specs.

There are typically voltage and current control loops in the charger, and the mode is selected based on the state of charge of the battery, the temperature, etc.  They can be linear or switch mode power control schemes.

For example: bq24195 Charger IC

Here's a link to some information on how it all works: Charging and gauging