• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2012 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/ios/ios_util.h"
6
7#import <Foundation/Foundation.h>
8#import <UIKit/UIKit.h>
9#include <stddef.h>
10
11#include "base/apple/foundation_util.h"
12#import "base/ios/device_util.h"
13#include "base/system/sys_info.h"
14
15namespace {
16
17std::string* g_icudtl_path_override = nullptr;
18
19}  // namespace
20
21namespace base::ios {
22
23bool IsRunningOnIOS12OrLater() {
24  static const bool is_running_on_or_later = IsRunningOnOrLater(12, 0, 0);
25  return is_running_on_or_later;
26}
27
28bool IsRunningOnIOS13OrLater() {
29  static const bool is_running_on_or_later = IsRunningOnOrLater(13, 0, 0);
30  return is_running_on_or_later;
31}
32
33bool IsRunningOnIOS14OrLater() {
34  static const bool is_running_on_or_later = IsRunningOnOrLater(14, 0, 0);
35  return is_running_on_or_later;
36}
37
38bool IsRunningOnIOS15OrLater() {
39  static const bool is_running_on_or_later = IsRunningOnOrLater(15, 0, 0);
40  return is_running_on_or_later;
41}
42
43bool IsRunningOnIOS16OrLater() {
44  static const bool is_running_on_or_later = IsRunningOnOrLater(16, 0, 0);
45  return is_running_on_or_later;
46}
47
48bool IsRunningOnIOS17OrLater() {
49  static const bool is_running_on_or_later = IsRunningOnOrLater(17, 0, 0);
50  return is_running_on_or_later;
51}
52
53bool IsRunningOnOrLater(int32_t major, int32_t minor, int32_t bug_fix) {
54  static const class OSVersion {
55   public:
56    OSVersion() {
57      SysInfo::OperatingSystemVersionNumbers(
58          &current_version_[0], &current_version_[1], &current_version_[2]);
59    }
60
61    bool IsRunningOnOrLater(int32_t version[3]) const {
62      for (size_t i = 0; i < std::size(current_version_); ++i) {
63        if (current_version_[i] != version[i])
64          return current_version_[i] > version[i];
65      }
66      return true;
67    }
68
69   private:
70    int32_t current_version_[3];
71  } kOSVersion;
72
73  int32_t version[3] = {major, minor, bug_fix};
74  return kOSVersion.IsRunningOnOrLater(version);
75}
76
77bool IsInForcedRTL() {
78  NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
79  return [defaults boolForKey:@"NSForceRightToLeftWritingDirection"];
80}
81
82void OverridePathOfEmbeddedICU(const char* path) {
83  DCHECK(!g_icudtl_path_override);
84  g_icudtl_path_override = new std::string(path);
85}
86
87FilePath FilePathOfEmbeddedICU() {
88  if (g_icudtl_path_override) {
89    return FilePath(*g_icudtl_path_override);
90  }
91  return FilePath();
92}
93
94bool IsMultipleScenesSupported() {
95  if (@available(iOS 13, *)) {
96    return UIApplication.sharedApplication.supportsMultipleScenes;
97  }
98  return false;
99}
100
101bool IsApplicationPreWarmed() {
102  return [NSProcessInfo.processInfo.environment objectForKey:@"ActivePrewarm"];
103}
104
105bool HasDynamicIsland() {
106  std::string hardware_model = ::ios::device_util::GetPlatform();
107  static bool is_dynamic_island_model =
108      (hardware_model == "iPhone15,2" || hardware_model == "iPhone15,3");
109  return is_dynamic_island_model;
110}
111
112}  // namespace base::ios
113