blob: 2402d30ab06a89542c67b1c9e03149b4bb54e6ae [file] [log] [blame]
[email protected]aebcd0dd2012-10-05 17:48:581// Copyright 2012 The Chromium Authors. All rights reserved.
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
marqf51b0032015-08-10 08:55:177#import <Foundation/Foundation.h>
avi9b6f42932015-12-26 22:15:148#include <stddef.h>
marqf51b0032015-08-10 08:55:179
avi9b6f42932015-12-26 22:15:1410#include "base/macros.h"
[email protected]aebcd0dd2012-10-05 17:48:5811#include "base/sys_info.h"
12
13namespace {
justincohenb83910d2016-01-08 23:49:4314
[email protected]aebcd0dd2012-10-05 17:48:5815// Return a 3 elements array containing the major, minor and bug fix version of
16// the OS.
avi9b6f42932015-12-26 22:15:1417const int32_t* OSVersionAsArray() {
18 int32_t* digits = new int32_t[3];
[email protected]aebcd0dd2012-10-05 17:48:5819 base::SysInfo::OperatingSystemVersionNumbers(
20 &digits[0], &digits[1], &digits[2]);
21 return digits;
22}
justincohenb83910d2016-01-08 23:49:4323
24std::string* g_icudtl_path_override = nullptr;
25
[email protected]aebcd0dd2012-10-05 17:48:5826} // namespace
27
28namespace base {
29namespace ios {
30
michaeldo19e74eb2016-06-16 23:58:1031bool IsRunningOnIOS10OrLater() {
kapishnikov71f40c3b2017-06-15 14:10:3932 static const bool is_running_on_or_later = IsRunningOnOrLater(10, 0, 0);
33 return is_running_on_or_later;
michaeldo19e74eb2016-06-16 23:58:1034}
35
rohitraode9bce72017-06-14 15:37:3036bool IsRunningOnIOS11OrLater() {
kapishnikov71f40c3b2017-06-15 14:10:3937 static const bool is_running_on_or_later = IsRunningOnOrLater(11, 0, 0);
38 return is_running_on_or_later;
rohitraode9bce72017-06-14 15:37:3039}
40
avi9b6f42932015-12-26 22:15:1441bool IsRunningOnOrLater(int32_t major, int32_t minor, int32_t bug_fix) {
42 static const int32_t* current_version = OSVersionAsArray();
43 int32_t version[] = {major, minor, bug_fix};
[email protected]aebcd0dd2012-10-05 17:48:5844 for (size_t i = 0; i < arraysize(version); i++) {
45 if (current_version[i] != version[i])
46 return current_version[i] > version[i];
47 }
48 return true;
49}
50
marqf51b0032015-08-10 08:55:1751bool IsInForcedRTL() {
52 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
marqb2238de2015-09-21 17:06:2153 return [defaults boolForKey:@"NSForceRightToLeftWritingDirection"];
marqf51b0032015-08-10 08:55:1754}
55
justincohenb83910d2016-01-08 23:49:4356void OverridePathOfEmbeddedICU(const char* path) {
57 DCHECK(!g_icudtl_path_override);
58 g_icudtl_path_override = new std::string(path);
59}
60
61FilePath FilePathOfEmbeddedICU() {
62 if (g_icudtl_path_override) {
63 return FilePath(*g_icudtl_path_override);
64 }
65 return FilePath();
66}
67
[email protected]aebcd0dd2012-10-05 17:48:5868} // namespace ios
69} // namespace base