Basically what you would want to do in this case is use the Firebase Subscriptions.
Firebase Subscriptions allows you to subscribe or unsubscribe to a particular topic and that allows for a behaviour like only the users which are subscribed to a particular topic will receive the push notifications
You can subscribe or unsubscribe a user from the topic or in simple words stop or enable notifications based on a toggle in the settings say for example
To see a sample as to how to subscribe to a topic you can do something like
FirebaseMessaging.getInstanceId().subscribeToTopic("topic")
More details here
And then to unsubscribe you can check this example
For more info about subscriptions you can refer to official Firebase Docs