How can a PostgreSQL standby decide whether its primary is still active or not
For streaming replication, you can check the pg_stat_wal_receiver view. There will be one line here when wal receiver is streaming.
Another question is why you need such information. For monitoring purposes, the amount of replication delay is much more important. Async replica may be significant lagged, but primary and wal receiver still alive (e.g. while reach the network bandwidth limit). Usually on hot standby:
select now() - pg_last_xact_replay_timestamp();

and pg_stat_replication on primary.