This isn't exactly what you're asking for but on Android: Settings > Sound > Do Not Disturb > Allowed in Priority Only > Calls From Contacts Only (or Calls from Starred Contacts Only if you really want to lock it down).
Optionally enable: If the same person calls a second time within a 15 minute period, allow it (might allow someone really trying to reach you to get through, might also allow a spam caller through).