Apple Inc. has spent decades tending to and building a “walled garden” around its technology, allowing the most valuable company in the U.S. to maintain control over what software can land on its iPhones and Macs and what that software can do.