The misunderstanding of whether or not Sri Lanka is a safe country to visit still stays, and it is justified entirely due to the harsh civil war between 1983 and 2009. Most tourists indeed kept away during this phase, but after the end of the civil war, this is entirely a different phase altogether.
With friendliest people, Sri Lanka is a remarkably safe place to travel in, and violent crime against foreigners is almost unheard of. However, take the necessary measures to ensure safety by avoiding conversations that include topics like politics and religion, walking alone after dark, keeping your valuables like money and passport in a safe place, avoid rallies and substantial public gatherings, etc. It is also wise and cautious to avoid smoking and drinking in public places as it is against the law.
Side-step from taking any photos or filming around High-Security Zones like all military establishments and some government buildings, including official residences and also you are advised not to pose for a photograph next to a statue of Buddha. Make sure to keep updated about the weather or any natural disaster constantly. It will help you take any necessary action immediately. If you are going to the beach, make sure you are not alone and know how to swim.
Besides being cautious about the smallest details, it is also smart if you plan well, read travel advice from experts - you will find many on websites. And leave a detailed itinerary with someone at home and try and keep in regular contact with details. Paying attention to these smallest details will surely help you avoid getting into trouble and ensure a safe trip.