OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #if defined(WEBRTC_IOS) | |
12 | 11 |
13 #import <AVFoundation/AVFoundation.h> | 12 #import <AVFoundation/AVFoundation.h> |
14 #import <Foundation/Foundation.h> | 13 #import <Foundation/Foundation.h> |
15 #import <sys/sysctl.h> | 14 #import <sys/sysctl.h> |
| 15 #if defined(WEBRTC_IOS) |
16 #import <UIKit/UIKit.h> | 16 #import <UIKit/UIKit.h> |
| 17 #endif |
17 | 18 |
18 #include <memory> | 19 #include <memory> |
19 | 20 |
20 #include "webrtc/base/checks.h" | 21 #include "webrtc/base/checks.h" |
21 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
22 #include "webrtc/sdk/objc/Framework/Classes/helpers.h" | 23 #include "webrtc/sdk/objc/Framework/Classes/helpers.h" |
23 | 24 |
24 namespace webrtc { | 25 namespace webrtc { |
25 namespace ios { | 26 namespace ios { |
26 | 27 |
| 28 #if defined(WEBRTC_IOS) |
27 bool isOperatingSystemAtLeastVersion(double version) { | 29 bool isOperatingSystemAtLeastVersion(double version) { |
28 return GetSystemVersion() >= version; | 30 return GetSystemVersion() >= version; |
29 } | 31 } |
| 32 #endif |
30 | 33 |
31 NSString* NSStringFromStdString(const std::string& stdString) { | 34 NSString* NSStringFromStdString(const std::string& stdString) { |
32 // std::string may contain null termination character so we construct | 35 // std::string may contain null termination character so we construct |
33 // using length. | 36 // using length. |
34 return [[NSString alloc] initWithBytes:stdString.data() | 37 return [[NSString alloc] initWithBytes:stdString.data() |
35 length:stdString.length() | 38 length:stdString.length() |
36 encoding:NSUTF8StringEncoding]; | 39 encoding:NSUTF8StringEncoding]; |
37 } | 40 } |
38 | 41 |
39 std::string StdStringFromNSString(NSString* nsString) { | 42 std::string StdStringFromNSString(NSString* nsString) { |
(...skipping 14 matching lines...) Expand all Loading... |
54 return true; | 57 return true; |
55 } | 58 } |
56 | 59 |
57 // TODO(henrika): see if it is possible to move to GetThreadName in | 60 // TODO(henrika): see if it is possible to move to GetThreadName in |
58 // platform_thread.h and base it on pthread methods instead. | 61 // platform_thread.h and base it on pthread methods instead. |
59 std::string GetCurrentThreadDescription() { | 62 std::string GetCurrentThreadDescription() { |
60 NSString* name = [NSString stringWithFormat:@"%@", [NSThread currentThread]]; | 63 NSString* name = [NSString stringWithFormat:@"%@", [NSThread currentThread]]; |
61 return StdStringFromNSString(name); | 64 return StdStringFromNSString(name); |
62 } | 65 } |
63 | 66 |
| 67 #if defined(WEBRTC_IOS) |
64 std::string GetAudioSessionCategory() { | 68 std::string GetAudioSessionCategory() { |
65 NSString* category = [[AVAudioSession sharedInstance] category]; | 69 NSString* category = [[AVAudioSession sharedInstance] category]; |
66 return StdStringFromNSString(category); | 70 return StdStringFromNSString(category); |
67 } | 71 } |
68 | 72 |
69 std::string GetSystemName() { | 73 std::string GetSystemName() { |
70 NSString* osName = [[UIDevice currentDevice] systemName]; | 74 NSString* osName = [[UIDevice currentDevice] systemName]; |
71 return StdStringFromNSString(osName); | 75 return StdStringFromNSString(osName); |
72 } | 76 } |
73 | 77 |
74 std::string GetSystemVersionAsString() { | 78 std::string GetSystemVersionAsString() { |
75 NSString* osVersion = [[UIDevice currentDevice] systemVersion]; | 79 NSString* osVersion = [[UIDevice currentDevice] systemVersion]; |
76 return StdStringFromNSString(osVersion); | 80 return StdStringFromNSString(osVersion); |
77 } | 81 } |
78 | 82 |
79 double GetSystemVersion() { | 83 double GetSystemVersion() { |
80 static dispatch_once_t once_token; | 84 static dispatch_once_t once_token; |
81 static double system_version; | 85 static double system_version; |
82 dispatch_once(&once_token, ^{ | 86 dispatch_once(&once_token, ^{ |
83 system_version = [UIDevice currentDevice].systemVersion.doubleValue; | 87 system_version = [UIDevice currentDevice].systemVersion.doubleValue; |
84 }); | 88 }); |
85 return system_version; | 89 return system_version; |
86 } | 90 } |
87 | 91 |
88 std::string GetDeviceType() { | 92 std::string GetDeviceType() { |
89 NSString* deviceModel = [[UIDevice currentDevice] model]; | 93 NSString* deviceModel = [[UIDevice currentDevice] model]; |
90 return StdStringFromNSString(deviceModel); | 94 return StdStringFromNSString(deviceModel); |
91 } | 95 } |
| 96 #endif |
92 | 97 |
93 std::string GetDeviceName() { | 98 std::string GetDeviceName() { |
94 size_t size; | 99 size_t size; |
95 sysctlbyname("hw.machine", NULL, &size, NULL, 0); | 100 sysctlbyname("hw.machine", NULL, &size, NULL, 0); |
96 std::unique_ptr<char[]> machine; | 101 std::unique_ptr<char[]> machine; |
97 machine.reset(new char[size]); | 102 machine.reset(new char[size]); |
98 sysctlbyname("hw.machine", machine.get(), &size, NULL, 0); | 103 sysctlbyname("hw.machine", machine.get(), &size, NULL, 0); |
99 return std::string(machine.get()); | 104 return std::string(machine.get()); |
100 } | 105 } |
101 | 106 |
(...skipping 25 matching lines...) Expand all Loading... |
127 } | 132 } |
128 LOG(LS_WARNING) << "webrtc::ios::GetLowPowerModeEnabled() is not " | 133 LOG(LS_WARNING) << "webrtc::ios::GetLowPowerModeEnabled() is not " |
129 "supported. Requires at least iOS 9.0"; | 134 "supported. Requires at least iOS 9.0"; |
130 return false; | 135 return false; |
131 } | 136 } |
132 #endif | 137 #endif |
133 | 138 |
134 } // namespace ios | 139 } // namespace ios |
135 } // namespace webrtc | 140 } // namespace webrtc |
136 | 141 |
137 #endif // defined(WEBRTC_IOS) | |
OLD | NEW |