Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: webrtc/modules/utility/source/helpers_ios.mm

Issue 1746023002: Modifies SDK and iOS detection for helper method that needs iOS 9+ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Improvements proposed by tkchin@ Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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) 11 #if defined(WEBRTC_IOS)
12 12
13 #import <AVFoundation/AVFoundation.h> 13 #import <AVFoundation/AVFoundation.h>
14 #import <Foundation/Foundation.h> 14 #import <Foundation/Foundation.h>
15 #import <sys/sysctl.h> 15 #import <sys/sysctl.h>
16 #import <UIKit/UIKit.h> 16 #import <UIKit/UIKit.h>
17 17
18 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
20 #include "webrtc/base/scoped_ptr.h" 20 #include "webrtc/base/scoped_ptr.h"
21 #include "webrtc/modules/utility/include/helpers_ios.h" 21 #include "webrtc/modules/utility/include/helpers_ios.h"
22 22
23 namespace webrtc { 23 namespace webrtc {
24 namespace ios { 24 namespace ios {
25 25
26 bool isOperatingSystemAtLeastVersion(double version) {
27 return GetSystemVersion() >= version;
28 }
29
26 // Internal helper method used by GetDeviceName() to return device name. 30 // Internal helper method used by GetDeviceName() to return device name.
27 const char* LookUpRealName(const char* raw_name) { 31 const char* LookUpRealName(const char* raw_name) {
28 // Lookup table which maps raw device names to real (human readable) names. 32 // Lookup table which maps raw device names to real (human readable) names.
29 struct { 33 struct {
30 const char* raw_name; 34 const char* raw_name;
31 const char* real_name; 35 const char* real_name;
32 } device_names[] = { 36 } device_names[] = {
33 {"iPhone1,1", "iPhone 1G"}, 37 {"iPhone1,1", "iPhone 1G"},
34 {"iPhone1,2", "iPhone 3G"}, 38 {"iPhone1,2", "iPhone 3G"},
35 {"iPhone2,1", "iPhone 3GS"}, 39 {"iPhone2,1", "iPhone 3GS"},
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 std::string GetAudioSessionCategory() { 123 std::string GetAudioSessionCategory() {
120 NSString* category = [[AVAudioSession sharedInstance] category]; 124 NSString* category = [[AVAudioSession sharedInstance] category];
121 return StdStringFromNSString(category); 125 return StdStringFromNSString(category);
122 } 126 }
123 127
124 std::string GetSystemName() { 128 std::string GetSystemName() {
125 NSString* osName = [[UIDevice currentDevice] systemName]; 129 NSString* osName = [[UIDevice currentDevice] systemName];
126 return StdStringFromNSString(osName); 130 return StdStringFromNSString(osName);
127 } 131 }
128 132
129 std::string GetSystemVersion() { 133 std::string GetSystemVersionAsString() {
130 NSString* osVersion = [[UIDevice currentDevice] systemVersion]; 134 NSString* osVersion = [[UIDevice currentDevice] systemVersion];
131 return StdStringFromNSString(osVersion); 135 return StdStringFromNSString(osVersion);
132 } 136 }
133 137
134 float GetSystemVersionAsFloat() { 138 double GetSystemVersion() {
135 NSString* osVersion = [[UIDevice currentDevice] systemVersion]; 139 static dispatch_once_t once_token;
136 return osVersion.floatValue; 140 static double system_version;
141 dispatch_once(&once_token, ^{
142 system_version = [UIDevice currentDevice].systemVersion.doubleValue;
143 });
144 return system_version;
137 } 145 }
138 146
139 std::string GetDeviceType() { 147 std::string GetDeviceType() {
140 NSString* deviceModel = [[UIDevice currentDevice] model]; 148 NSString* deviceModel = [[UIDevice currentDevice] model];
141 return StdStringFromNSString(deviceModel); 149 return StdStringFromNSString(deviceModel);
142 } 150 }
143 151
144 std::string GetDeviceName() { 152 std::string GetDeviceName() {
145 size_t size; 153 size_t size;
146 sysctlbyname("hw.machine", NULL, &size, NULL, 0); 154 sysctlbyname("hw.machine", NULL, &size, NULL, 0);
(...skipping 15 matching lines...) Expand all
162 std::string GetOSVersionString() { 170 std::string GetOSVersionString() {
163 NSString* osVersion = 171 NSString* osVersion =
164 [NSProcessInfo processInfo].operatingSystemVersionString; 172 [NSProcessInfo processInfo].operatingSystemVersionString;
165 return StdStringFromNSString(osVersion); 173 return StdStringFromNSString(osVersion);
166 } 174 }
167 175
168 int GetProcessorCount() { 176 int GetProcessorCount() {
169 return [NSProcessInfo processInfo].processorCount; 177 return [NSProcessInfo processInfo].processorCount;
170 } 178 }
171 179
180 #if defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0
172 bool GetLowPowerModeEnabled() { 181 bool GetLowPowerModeEnabled() {
173 NSProcessInfo* info = [NSProcessInfo processInfo]; 182 if (isOperatingSystemAtLeastVersion(9.0)) {
174 // lowPoweredModeEnabled is only available on iOS9+. 183 // lowPoweredModeEnabled is only available on iOS9+.
175 if ([info respondsToSelector:@selector(lowPoweredModeEnabled)]) { 184 return [NSProcessInfo processInfo].lowPowerModeEnabled;
176 return info.lowPowerModeEnabled;
177 } 185 }
186 LOG(LS_WARNING) << "webrtc::ios::GetLowPowerModeEnabled() is not "
187 "supported. Requires at least iOS 9.0";
178 return false; 188 return false;
179 } 189 }
190 #endif
180 191
181 } // namespace ios 192 } // namespace ios
182 } // namespace webrtc 193 } // namespace webrtc
183 194
184 #endif // defined(WEBRTC_IOS) 195 #endif // defined(WEBRTC_IOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698