Apple (AAPL 0.19%) could face a big setback if the Department of Justice succeeds in its lawsuit against Alphabet (GOOG -1.05%) (GOOGL -1.09%).

The DOJ's trial against Google began last month. The Justice Department alleges Google engages in anticompetitive practices. In particular, the lawyers cite Google's agreements with browser and smartphone partners to make its internet search service part of the default software on their various products.

By some estimates, Google pays Apple $20 billion per year to be the default search engine on the Safari browser across Apple devices. If the DOJ deems those payments illegal, it could be a serious blow to Apple's bottom line.

A massive cash cow

Even for a company generating nearly $400 billion per year, $20 billion is a lot. But it's a lot more when you consider the impact on Apple's bottom line.

The profit margin on Google's traffic acquisition payments is about as high as possible. With a couple of lines of code, Apple can make the default search engine in Safari whatever it chooses. The cost is basically whatever it takes to pay someone to negotiate the deal. In other words, it's all profit.

Viewed that way, $20 billion is almost 18% of Apple's trailing 12-month operating profits.

It's an even bigger percentage of Apple's services segment, which is driving growth for the company. Gross profits for the segment over the last four quarters totaled $58 billion. That means Google's payments may have been more than one-third of the segment's profits.

There should be no doubt that a ruling against Google in the DOJ's case would be a major setback for Apple. But investors shouldn't worry too much.

Apple can protect itself from the negative consequences

Even in the worst-case scenario where the court rules against Google, Apple is well-positioned to withstand the negative consequences. In fact, it could emerge even better off over the long run.

First, investors shouldn't expect a ruling in the case until next year. Even then, there could be a lengthy appeals process. That's on top of the fact that the practice has been under regulatory scrutiny for some time, and the DOJ launched its case at the start of the year. That is to say, Apple has a long time to develop a contingency plan.

And it's been working on that plan for a while. It's made massive strides in its own ad business by improving ad technology and sales over the last few years. Apple could put that ad technology and sales team to work in its own search engine if it has to. In fact, it was revealed during the trial that Apple discussed buying Microsoft's Bing way back in 2018, so it's likely at least exploring the idea of running its own internet search engine.

Second, it's important to consider the court's ruling would only apply to the United States. And while the U.S. is by far the most lucrative digital advertising market, marketers outside the country still spend a large and growing amount of money. About 40% of search ad spend stems from outside the U.S. That said, Apple dominates the U.S. smartphone market, while its international market share is much smaller.

Finally, even if Apple can't accept payments from Google anymore, the ruling wouldn't necessarily disallow it from collecting payments from another search engine. And while Google is much better at converting internet searches into advertising dollars, Apple could still receive a significant sum from a competitor like Microsoft.

Apple has a massive competitive advantage

Apple's biggest competitive advantage is that it's the dominant platform provider. It's worked constantly over the past decade to leverage that position and push the economics in its favor. I have no doubt it can continue to do so, regardless of what the regulatory environment throws its way.

While Apple shares trade at a premium to the market and other big tech companies based on its forward PE ratio of 27, the shares may still be worth it. The share price is supported by its massive cash balance, as well as the $100 billion or so it spins off in free cash flow each year. Both give it room to continue buying back shares, which will make future earnings per share much higher.

Considering the massive competitive advantages Apple holds protecting itself against potential negative outcomes like the Google case, investors should consider buying shares of the company at today's price. And if the stock goes down in the future from a ruling against Google, it could present an even better buying opportunity. But there's no guarantee for how things will play out.