Samsung's Galaxy Note 7 has been recalled and discontinued. Image source: Samsung.

Shares of Apple (NASDAQ:AAPL) are on a tremendous run. Over the last three months, shares of the consumer electronics company are up approximately 21% versus the S&P 500's gain of 2%. Even with the recent outperformance, Apple still trades at a price-to-earnings ratio of 13.5, approximately half the valuation of the greater S&P 500's P/E ratio of 25.

In the last month, Apple's returns have been turbocharged due to Samsung's (NASDAQOTH: SSNLF) struggles. In September, Samsung issued a voluntary recall for 2.5 million Galaxy Note 7 smartphones due to a "minor flaw in the battery manufacturing process" that led to phones exploding. Samsung's situation took a turn for the worse when the company recently announced it would cease Galaxy Note 7 production after replacement units proved no safer than the initial models.

Conventional wisdom states any loss for Samsung is Apple's gain, and that's most-likely true in some aspect. In the end, however, the biggest beneficiary of Samsung's struggles may be the company that provides Samsung's ecosystem: Alphabet (NASDAQ:GOOG) (NASDAQ:GOOGL).

Ecosystem is important as device and switching costs are increasing

A base analysis of smartphones typically compares on-device features and specifications. While things like processing clock speed, camera megapixels, and design are important, in many cases the differences between premium smartphones are so minuscule they're unlikely to drive the buying decision on their own.

What does drive the buying decision is the ability to quickly access photos, emails, and purchased content and to understand the device layout. The simple truth is the ecosystem -- the seamless experience between hardware, operating system, and content -- is becoming the true differentiator between smartphones more so than device specifications. And when it comes to ecosystem, the operating system is the key differentiator.

While both Apple and Android-powered phones have taken steps to encourage cross-OS switchers, it's increasingly difficult for an Android user to become an iOS user, and vice versa, due to the increasing switching costs from cloud storage, purchased content (music, movies, and TV shows), and other OS-specific applications. Ecosystems have become so key to the buying decision that many smartphone users refer to themselves as "iOS-only" or "Android-only." Against that backdrop, it's likely Samsung's stumbles benefits other high-end Android smartphone vendors.

Alphabet's new Google Pixel smartphone. Image Source: Alphabet

Samsung's Note 7 disaster is good news for Alphabet

Samsung's stumbles could not have occurred at a better time for Alphabet. The company's recently announced Google Pixel smartphone is a major step in Apple's direction. The company always had control over the operating system, but took a page from Apple by essentially taking control of the Pixel's hardware and software design to control the user experience.

Why analysts have typically compared Samsung and Alphabet to Apple, the bigger risk for these Android partners is internal. A few years ago The Wall Street Journal [subscription required] reported Alphabet (then Google) was so scared of Samsung's Android dominance it actively encouraged other hardware partners to manufacture Android devices. On the other hand, Samsung is actively involved with its Tizen OS and even runs the company's smartwatches off of the Android competitor.

More recently, apprehension between the two has ameliorated as a combination of Samsung market share losses (particularly at the low end) and Tizen's inability to gain a large following has resolved earlier concerns. Alphabet's Pixel smartphone appears to be a strong offering and should win over Samsung smartphone users that are looking to upgrade to an Android-powered smartphone. It's likely Apple will benefit from Samsung's struggles, but Alphabet's smaller-scale smartphone business will most likely get a larger boost. 

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.