From ab12c47160591ff78a92da304e143b84865d6d99 Mon Sep 17 00:00:00 2001 From: henrika Date: Thu, 3 Mar 2016 16:59:50 +0100 Subject: [PATCH] Modifies SDK and iOS detection for helper method that needs iOS 9+ BUG=NONE R=tkchin@webrtc.org Review URL: https://codereview.webrtc.org/1746023002 . Cr-Commit-Position: refs/heads/master@{#11861} --- .../audio_device/ios/audio_device_ios.mm | 5 +++- webrtc/modules/utility/include/helpers_ios.h | 9 ++++--- webrtc/modules/utility/source/helpers_ios.mm | 27 +++++++++++++------ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/webrtc/modules/audio_device/ios/audio_device_ios.mm b/webrtc/modules/audio_device/ios/audio_device_ios.mm index 2551dad76d..4390f49258 100644 --- a/webrtc/modules/audio_device/ios/audio_device_ios.mm +++ b/webrtc/modules/audio_device/ios/audio_device_ios.mm @@ -262,14 +262,17 @@ static void LogDeviceInfo() { LOG(LS_INFO) << "LogDeviceInfo"; @autoreleasepool { LOG(LS_INFO) << " system name: " << ios::GetSystemName(); - LOG(LS_INFO) << " system version: " << ios::GetSystemVersion(); + LOG(LS_INFO) << " system version 1(2): " << ios::GetSystemVersionAsString(); + LOG(LS_INFO) << " system version 2(2): " << ios::GetSystemVersion(); LOG(LS_INFO) << " device type: " << ios::GetDeviceType(); LOG(LS_INFO) << " device name: " << ios::GetDeviceName(); LOG(LS_INFO) << " process name: " << ios::GetProcessName(); LOG(LS_INFO) << " process ID: " << ios::GetProcessID(); LOG(LS_INFO) << " OS version: " << ios::GetOSVersionString(); LOG(LS_INFO) << " processing cores: " << ios::GetProcessorCount(); +#if defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0 LOG(LS_INFO) << " low power mode: " << ios::GetLowPowerModeEnabled(); +#endif } } #endif // !defined(NDEBUG) diff --git a/webrtc/modules/utility/include/helpers_ios.h b/webrtc/modules/utility/include/helpers_ios.h index d3f788fec3..1b692f18c1 100644 --- a/webrtc/modules/utility/include/helpers_ios.h +++ b/webrtc/modules/utility/include/helpers_ios.h @@ -37,11 +37,12 @@ std::string GetAudioSessionCategory(); // Returns the current name of the operating system. std::string GetSystemName(); -// Returns the current version of the operating system. -std::string GetSystemVersion(); +// Returns the current version of the operating system as a string. +std::string GetSystemVersionAsString(); -// Returns the version of the operating system as a floating point value. -float GetSystemVersionAsFloat(); +// Returns the version of the operating system in double representation. +// Uses a cached value of the system version. +double GetSystemVersion(); // Returns the device type. // Examples: ”iPhone” and ”iPod touch”. diff --git a/webrtc/modules/utility/source/helpers_ios.mm b/webrtc/modules/utility/source/helpers_ios.mm index a312f032d1..3d7567b7f0 100644 --- a/webrtc/modules/utility/source/helpers_ios.mm +++ b/webrtc/modules/utility/source/helpers_ios.mm @@ -23,6 +23,10 @@ namespace webrtc { namespace ios { +bool isOperatingSystemAtLeastVersion(double version) { + return GetSystemVersion() >= version; +} + // Internal helper method used by GetDeviceName() to return device name. const char* LookUpRealName(const char* raw_name) { // Lookup table which maps raw device names to real (human readable) names. @@ -126,14 +130,18 @@ std::string GetSystemName() { return StdStringFromNSString(osName); } -std::string GetSystemVersion() { +std::string GetSystemVersionAsString() { NSString* osVersion = [[UIDevice currentDevice] systemVersion]; return StdStringFromNSString(osVersion); } -float GetSystemVersionAsFloat() { - NSString* osVersion = [[UIDevice currentDevice] systemVersion]; - return osVersion.floatValue; +double GetSystemVersion() { + static dispatch_once_t once_token; + static double system_version; + dispatch_once(&once_token, ^{ + system_version = [UIDevice currentDevice].systemVersion.doubleValue; + }); + return system_version; } std::string GetDeviceType() { @@ -169,14 +177,17 @@ int GetProcessorCount() { return [NSProcessInfo processInfo].processorCount; } +#if defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0 bool GetLowPowerModeEnabled() { - NSProcessInfo* info = [NSProcessInfo processInfo]; - // lowPoweredModeEnabled is only available on iOS9+. - if ([info respondsToSelector:@selector(lowPoweredModeEnabled)]) { - return info.lowPowerModeEnabled; + if (isOperatingSystemAtLeastVersion(9.0)) { + // lowPoweredModeEnabled is only available on iOS9+. + return [NSProcessInfo processInfo].lowPowerModeEnabled; } + LOG(LS_WARNING) << "webrtc::ios::GetLowPowerModeEnabled() is not " + "supported. Requires at least iOS 9.0"; return false; } +#endif } // namespace ios } // namespace webrtc