2015-07-14 17:04:08 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
|
|
2015-10-21 04:11:53 -07:00
|
|
|
#import <AVFoundation/AVFoundation.h>
|
2015-07-14 17:04:08 +02:00
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
#import <sys/sysctl.h>
|
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
|
|
|
|
|
#include "webrtc/base/checks.h"
|
|
|
|
|
#include "webrtc/base/logging.h"
|
|
|
|
|
#include "webrtc/base/scoped_ptr.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/utility/include/helpers_ios.h"
|
2015-07-14 17:04:08 +02:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace ios {
|
|
|
|
|
|
2016-02-24 14:27:09 +01:00
|
|
|
// 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.
|
|
|
|
|
struct {
|
|
|
|
|
const char* raw_name;
|
|
|
|
|
const char* real_name;
|
|
|
|
|
} device_names[] = {
|
|
|
|
|
{"iPhone1,1", "iPhone 1G"},
|
|
|
|
|
{"iPhone1,2", "iPhone 3G"},
|
|
|
|
|
{"iPhone2,1", "iPhone 3GS"},
|
|
|
|
|
{"iPhone3,1", "iPhone 4"},
|
|
|
|
|
{"iPhone3,3", "Verizon iPhone 4"},
|
|
|
|
|
{"iPhone4,1", "iPhone 4S"},
|
|
|
|
|
{"iPhone5,1", "iPhone 5 (GSM)"},
|
|
|
|
|
{"iPhone5,2", "iPhone 5 (GSM+CDMA)"},
|
|
|
|
|
{"iPhone5,3", "iPhone 5c (GSM)"},
|
|
|
|
|
{"iPhone5,4", "iPhone 5c (GSM+CDMA)"},
|
|
|
|
|
{"iPhone6,1", "iPhone 5s (GSM)"},
|
|
|
|
|
{"iPhone6,2", "iPhone 5s (GSM+CDMA)"},
|
|
|
|
|
{"iPhone7,1", "iPhone 6 Plus"},
|
|
|
|
|
{"iPhone7,2", "iPhone 6"},
|
|
|
|
|
{"iPhone8,1", "iPhone 6s"},
|
|
|
|
|
{"iPhone8,2", "iPhone 6s Plus"},
|
|
|
|
|
{"iPod1,1", "iPod Touch 1G"},
|
|
|
|
|
{"iPod2,1", "iPod Touch 2G"},
|
|
|
|
|
{"iPod3,1", "iPod Touch 3G"},
|
|
|
|
|
{"iPod4,1", "iPod Touch 4G"},
|
|
|
|
|
{"iPod5,1", "iPod Touch 5G"},
|
|
|
|
|
{"iPad1,1", "iPad"},
|
|
|
|
|
{"iPad2,1", "iPad 2 (WiFi)"},
|
|
|
|
|
{"iPad2,2", "iPad 2 (GSM)"},
|
|
|
|
|
{"iPad2,3", "iPad 2 (CDMA)"},
|
|
|
|
|
{"iPad2,4", "iPad 2 (WiFi)"},
|
|
|
|
|
{"iPad2,5", "iPad Mini (WiFi)"},
|
|
|
|
|
{"iPad2,6", "iPad Mini (GSM)"},
|
|
|
|
|
{"iPad2,7", "iPad Mini (GSM+CDMA)"},
|
|
|
|
|
{"iPad3,1", "iPad 3 (WiFi)"},
|
|
|
|
|
{"iPad3,2", "iPad 3 (GSM+CDMA)"},
|
|
|
|
|
{"iPad3,3", "iPad 3 (GSM)"},
|
|
|
|
|
{"iPad3,4", "iPad 4 (WiFi)"},
|
|
|
|
|
{"iPad3,5", "iPad 4 (GSM)"},
|
|
|
|
|
{"iPad3,6", "iPad 4 (GSM+CDMA)"},
|
|
|
|
|
{"iPad4,1", "iPad Air (WiFi)"},
|
|
|
|
|
{"iPad4,2", "iPad Air (Cellular)"},
|
|
|
|
|
{"iPad4,4", "iPad mini 2G (WiFi)"},
|
|
|
|
|
{"iPad4,5", "iPad mini 2G (Cellular)"},
|
|
|
|
|
{"i386", "Simulator"},
|
|
|
|
|
{"x86_64", "Simulator"},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (auto& d : device_names) {
|
|
|
|
|
if (strcmp(d.raw_name, raw_name) == 0)
|
|
|
|
|
return d.real_name;
|
|
|
|
|
}
|
|
|
|
|
LOG(LS_WARNING) << "Failed to find device name (" << raw_name << ")";
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 17:04:08 +02:00
|
|
|
// TODO(henrika): move to shared location.
|
|
|
|
|
// See https://code.google.com/p/webrtc/issues/detail?id=4773 for details.
|
|
|
|
|
NSString* NSStringFromStdString(const std::string& stdString) {
|
|
|
|
|
// std::string may contain null termination character so we construct
|
|
|
|
|
// using length.
|
|
|
|
|
return [[NSString alloc] initWithBytes:stdString.data()
|
|
|
|
|
length:stdString.length()
|
|
|
|
|
encoding:NSUTF8StringEncoding];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string StdStringFromNSString(NSString* nsString) {
|
|
|
|
|
NSData* charData = [nsString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
|
return std::string(reinterpret_cast<const char*>([charData bytes]),
|
|
|
|
|
[charData length]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CheckAndLogError(BOOL success, NSError* error) {
|
|
|
|
|
if (!success) {
|
|
|
|
|
NSString* msg =
|
|
|
|
|
[NSString stringWithFormat:@"Error: %ld, %@, %@", (long)error.code,
|
|
|
|
|
error.localizedDescription,
|
|
|
|
|
error.localizedFailureReason];
|
|
|
|
|
LOG(LS_ERROR) << StdStringFromNSString(msg);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(henrika): see if it is possible to move to GetThreadName in
|
|
|
|
|
// platform_thread.h and base it on pthread methods instead.
|
|
|
|
|
std::string GetCurrentThreadDescription() {
|
|
|
|
|
NSString* name = [NSString stringWithFormat:@"%@", [NSThread currentThread]];
|
|
|
|
|
return StdStringFromNSString(name);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 04:11:53 -07:00
|
|
|
std::string GetAudioSessionCategory() {
|
|
|
|
|
NSString* category = [[AVAudioSession sharedInstance] category];
|
|
|
|
|
return StdStringFromNSString(category);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 17:04:08 +02:00
|
|
|
std::string GetSystemName() {
|
|
|
|
|
NSString* osName = [[UIDevice currentDevice] systemName];
|
|
|
|
|
return StdStringFromNSString(osName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string GetSystemVersion() {
|
|
|
|
|
NSString* osVersion = [[UIDevice currentDevice] systemVersion];
|
|
|
|
|
return StdStringFromNSString(osVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float GetSystemVersionAsFloat() {
|
|
|
|
|
NSString* osVersion = [[UIDevice currentDevice] systemVersion];
|
|
|
|
|
return osVersion.floatValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string GetDeviceType() {
|
|
|
|
|
NSString* deviceModel = [[UIDevice currentDevice] model];
|
|
|
|
|
return StdStringFromNSString(deviceModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string GetDeviceName() {
|
|
|
|
|
size_t size;
|
|
|
|
|
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
|
|
|
|
|
rtc::scoped_ptr<char[]> machine;
|
|
|
|
|
machine.reset(new char[size]);
|
|
|
|
|
sysctlbyname("hw.machine", machine.get(), &size, NULL, 0);
|
2016-02-24 14:27:09 +01:00
|
|
|
return std::string(LookUpRealName(machine.get()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string GetProcessName() {
|
|
|
|
|
NSString* processName = [NSProcessInfo processInfo].processName;
|
|
|
|
|
return StdStringFromNSString(processName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GetProcessID() {
|
|
|
|
|
return [NSProcessInfo processInfo].processIdentifier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string GetOSVersionString() {
|
|
|
|
|
NSString* osVersion =
|
|
|
|
|
[NSProcessInfo processInfo].operatingSystemVersionString;
|
|
|
|
|
return StdStringFromNSString(osVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GetProcessorCount() {
|
|
|
|
|
return [NSProcessInfo processInfo].processorCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GetLowPowerModeEnabled() {
|
|
|
|
|
return [NSProcessInfo processInfo].lowPowerModeEnabled;
|
2015-07-14 17:04:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ios
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // defined(WEBRTC_IOS)
|