When writing a book, can you use well known brand names?

Without getting sued or needing permission I mean?
Like if I say my character wanted to eat a Hershey s bar, they drive a Ford, or they went to Walmart, is it legal for me to do so, or can I get in trouble?

I've read a lot of books with real brands in them but have never seen anything about copyright. Look into each brand to see if you need permission to use it.

Its assumed adwertising. And if something evil happens about those its considered propaganda. Ie a ford car failed. You are black adwertising it.
ie a mcdonalds used by fat ngga. You are doing black ads about mcdonalds and make its profits drop down etc. Is not allowed.

It seems to me that they would appreciate the endorsement. Businesses actually pay to have their product shown in movies and TV shows.

Yes, that's fine. Copyright does not mean you are forbidden from uttering a brand's name or admitting that it exists. There's no law against that. Intellectual property law only stops you from selling something that someone else owns, or claiming something is yours, etc. Mentioning it in a story is absolutely fine. Your characters can drive fords, go to McDonald's, or do anything else real they want.

That being said, sometimes it is a good idea to use fictional companies and brands as substitutes, mostly if they play a major part of the story. There are two reasons why:

1- Big companies might not like it if you portray them as the main antagonists of the story. Whether or not you're actually at any legal risk is another story, but many publishers don't like to tangle with them if they don't have to (it could affect future deals, endorsement and so forth as well as legal action), so they may prefer a fictional company is used.

2- It gives you a bit more leeway in terms of how those companies are organized, who works there and what they did/didn't do, without people cross-referencing to see how accurate is- people sometimes will try and criticize work based on accuracy, so if you use fictional names, places and so forth, you are safe.

As such, if a major brand or company was also a major part of your story's plot, it is often a good idea to invent a fictional one instead. For instance, I remember a police procedural show years ago had an evil company called "Dusanto", which was a stand-in for the real company "Monsanto". However again, they were a big part of the story. Minor details in the background don't need this.

That is not copyright infringement and you do not need permission to use those brand names.