• 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#import "base/ios/device_util.h"
12#include "base/mac/foundation_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 {
22namespace ios {
23
24bool IsRunningOnIOS12OrLater() {
25  static const bool is_running_on_or_later = IsRunningOnOrLater(12, 0, 0);
26  return is_running_on_or_later;
27}
28
29bool IsRunningOnIOS13OrLater() {
30  static const bool is_running_on_or_later = IsRunningOnOrLater(13, 0, 0);
31  return is_running_on_or_later;
32}
33
34bool IsRunningOnIOS14OrLater() {
35  static const bool is_running_on_or_later = IsRunningOnOrLater(14, 0, 0);
36  return is_running_on_or_later;
37}
38
39bool IsRunningOnIOS15OrLater() {
40  static const bool is_running_on_or_later = IsRunningOnOrLater(15, 0, 0);
41  return is_running_on_or_later;
42}
43
44bool IsRunningOnIOS16OrLater() {
45  static const bool is_running_on_or_later = IsRunningOnOrLater(16, 0, 0);
46  return is_running_on_or_later;
47}
48
49bool IsRunningOnOrLater(int32_t major, int32_t minor, int32_t bug_fix) {
50  static const class OSVersion {
51   public:
52    OSVersion() {
53      SysInfo::OperatingSystemVersionNumbers(
54          &current_version_[0], &current_version_[1], &current_version_[2]);
55    }
56
57    bool IsRunningOnOrLater(int32_t version[3]) const {
58      for (size_t i = 0; i < std::size(current_version_); ++i) {
59        if (current_version_[i] != version[i])
60          return current_version_[i] > version[i];
61      }
62      return true;
63    }
64
65   private:
66    int32_t current_version_[3];
67  } kOSVersion;
68
69  int32_t version[3] = {major, minor, bug_fix};
70  return kOSVersion.IsRunningOnOrLater(version);
71}
72
73bool IsInForcedRTL() {
74  NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
75  return [defaults boolForKey:@"NSForceRightToLeftWritingDirection"];
76}
77
78void OverridePathOfEmbeddedICU(const char* path) {
79  DCHECK(!g_icudtl_path_override);
80  g_icudtl_path_override = new std::string(path);
81}
82
83FilePath FilePathOfEmbeddedICU() {
84  if (g_icudtl_path_override) {
85    return FilePath(*g_icudtl_path_override);
86  }
87  return FilePath();
88}
89
90bool IsMultipleScenesSupported() {
91  if (@available(iOS 13, *)) {
92    return UIApplication.sharedApplication.supportsMultipleScenes;
93  }
94  return false;
95}
96
97bool IsApplicationPreWarmed() {
98  return [NSProcessInfo.processInfo.environment objectForKey:@"ActivePrewarm"];
99}
100
101bool HasDynamicIsland() {
102  std::string hardware_model = ::ios::device_util::GetPlatform();
103  static bool is_dynamic_island_model =
104      (hardware_model == "iPhone15,2" || hardware_model == "iPhone15,3");
105  return is_dynamic_island_model;
106}
107
108}  // namespace ios
109}  // namespace base
110