1. Open phone’s settings
  2. open battery
  3. open menu and select “battery optimization”
  4. from the dropdown menu select “all apps”
  5. select the app you want to whitelist
  6. select “don’t optimize”

Now this app will show under not optimized apps.

An app can check whether it’s whitelisted by calling isIgnoringBatteryOptimizations()