xref: /aosp_15_r20/external/webrtc/sdk/objc/helpers/UIDevice+RTCDevice.mm (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1/*
2 *  Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#import "UIDevice+RTCDevice.h"
12
13#import <sys/utsname.h>
14#include <memory>
15
16@implementation UIDevice (RTCDevice)
17
18+ (RTCDeviceType)deviceType {
19  NSDictionary *machineNameToType = @{
20    @"iPhone1,1" : @(RTCDeviceTypeIPhone1G),
21    @"iPhone1,2" : @(RTCDeviceTypeIPhone3G),
22    @"iPhone2,1" : @(RTCDeviceTypeIPhone3GS),
23    @"iPhone3,1" : @(RTCDeviceTypeIPhone4),
24    @"iPhone3,2" : @(RTCDeviceTypeIPhone4),
25    @"iPhone3,3" : @(RTCDeviceTypeIPhone4Verizon),
26    @"iPhone4,1" : @(RTCDeviceTypeIPhone4S),
27    @"iPhone5,1" : @(RTCDeviceTypeIPhone5GSM),
28    @"iPhone5,2" : @(RTCDeviceTypeIPhone5GSM_CDMA),
29    @"iPhone5,3" : @(RTCDeviceTypeIPhone5CGSM),
30    @"iPhone5,4" : @(RTCDeviceTypeIPhone5CGSM_CDMA),
31    @"iPhone6,1" : @(RTCDeviceTypeIPhone5SGSM),
32    @"iPhone6,2" : @(RTCDeviceTypeIPhone5SGSM_CDMA),
33    @"iPhone7,1" : @(RTCDeviceTypeIPhone6Plus),
34    @"iPhone7,2" : @(RTCDeviceTypeIPhone6),
35    @"iPhone8,1" : @(RTCDeviceTypeIPhone6S),
36    @"iPhone8,2" : @(RTCDeviceTypeIPhone6SPlus),
37    @"iPhone8,4" : @(RTCDeviceTypeIPhoneSE),
38    @"iPhone9,1" : @(RTCDeviceTypeIPhone7),
39    @"iPhone9,2" : @(RTCDeviceTypeIPhone7Plus),
40    @"iPhone9,3" : @(RTCDeviceTypeIPhone7),
41    @"iPhone9,4" : @(RTCDeviceTypeIPhone7Plus),
42    @"iPhone10,1" : @(RTCDeviceTypeIPhone8),
43    @"iPhone10,2" : @(RTCDeviceTypeIPhone8Plus),
44    @"iPhone10,3" : @(RTCDeviceTypeIPhoneX),
45    @"iPhone10,4" : @(RTCDeviceTypeIPhone8),
46    @"iPhone10,5" : @(RTCDeviceTypeIPhone8Plus),
47    @"iPhone10,6" : @(RTCDeviceTypeIPhoneX),
48    @"iPhone11,2" : @(RTCDeviceTypeIPhoneXS),
49    @"iPhone11,4" : @(RTCDeviceTypeIPhoneXSMax),
50    @"iPhone11,6" : @(RTCDeviceTypeIPhoneXSMax),
51    @"iPhone11,8" : @(RTCDeviceTypeIPhoneXR),
52    @"iPhone12,1" : @(RTCDeviceTypeIPhone11),
53    @"iPhone12,3" : @(RTCDeviceTypeIPhone11Pro),
54    @"iPhone12,5" : @(RTCDeviceTypeIPhone11ProMax),
55    @"iPhone12,8" : @(RTCDeviceTypeIPhoneSE2Gen),
56    @"iPhone13,1" : @(RTCDeviceTypeIPhone12Mini),
57    @"iPhone13,2" : @(RTCDeviceTypeIPhone12),
58    @"iPhone13,3" : @(RTCDeviceTypeIPhone12Pro),
59    @"iPhone13,4" : @(RTCDeviceTypeIPhone12ProMax),
60    @"iPhone14,5" : @(RTCDeviceTypeIPhone13),
61    @"iPhone14,4" : @(RTCDeviceTypeIPhone13Mini),
62    @"iPhone14,2" : @(RTCDeviceTypeIPhone13Pro),
63    @"iPhone14,3" : @(RTCDeviceTypeIPhone13ProMax),
64    @"iPod1,1" : @(RTCDeviceTypeIPodTouch1G),
65    @"iPod2,1" : @(RTCDeviceTypeIPodTouch2G),
66    @"iPod3,1" : @(RTCDeviceTypeIPodTouch3G),
67    @"iPod4,1" : @(RTCDeviceTypeIPodTouch4G),
68    @"iPod5,1" : @(RTCDeviceTypeIPodTouch5G),
69    @"iPod7,1" : @(RTCDeviceTypeIPodTouch6G),
70    @"iPod9,1" : @(RTCDeviceTypeIPodTouch7G),
71    @"iPad1,1" : @(RTCDeviceTypeIPad),
72    @"iPad2,1" : @(RTCDeviceTypeIPad2Wifi),
73    @"iPad2,2" : @(RTCDeviceTypeIPad2GSM),
74    @"iPad2,3" : @(RTCDeviceTypeIPad2CDMA),
75    @"iPad2,4" : @(RTCDeviceTypeIPad2Wifi2),
76    @"iPad2,5" : @(RTCDeviceTypeIPadMiniWifi),
77    @"iPad2,6" : @(RTCDeviceTypeIPadMiniGSM),
78    @"iPad2,7" : @(RTCDeviceTypeIPadMiniGSM_CDMA),
79    @"iPad3,1" : @(RTCDeviceTypeIPad3Wifi),
80    @"iPad3,2" : @(RTCDeviceTypeIPad3GSM_CDMA),
81    @"iPad3,3" : @(RTCDeviceTypeIPad3GSM),
82    @"iPad3,4" : @(RTCDeviceTypeIPad4Wifi),
83    @"iPad3,5" : @(RTCDeviceTypeIPad4GSM),
84    @"iPad3,6" : @(RTCDeviceTypeIPad4GSM_CDMA),
85    @"iPad4,1" : @(RTCDeviceTypeIPadAirWifi),
86    @"iPad4,2" : @(RTCDeviceTypeIPadAirCellular),
87    @"iPad4,3" : @(RTCDeviceTypeIPadAirWifiCellular),
88    @"iPad4,4" : @(RTCDeviceTypeIPadMini2GWifi),
89    @"iPad4,5" : @(RTCDeviceTypeIPadMini2GCellular),
90    @"iPad4,6" : @(RTCDeviceTypeIPadMini2GWifiCellular),
91    @"iPad4,7" : @(RTCDeviceTypeIPadMini3),
92    @"iPad4,8" : @(RTCDeviceTypeIPadMini3),
93    @"iPad4,9" : @(RTCDeviceTypeIPadMini3),
94    @"iPad5,1" : @(RTCDeviceTypeIPadMini4),
95    @"iPad5,2" : @(RTCDeviceTypeIPadMini4),
96    @"iPad5,3" : @(RTCDeviceTypeIPadAir2),
97    @"iPad5,4" : @(RTCDeviceTypeIPadAir2),
98    @"iPad6,3" : @(RTCDeviceTypeIPadPro9Inch),
99    @"iPad6,4" : @(RTCDeviceTypeIPadPro9Inch),
100    @"iPad6,7" : @(RTCDeviceTypeIPadPro12Inch),
101    @"iPad6,8" : @(RTCDeviceTypeIPadPro12Inch),
102    @"iPad6,11" : @(RTCDeviceTypeIPad5),
103    @"iPad6,12" : @(RTCDeviceTypeIPad5),
104    @"iPad7,1" : @(RTCDeviceTypeIPadPro12Inch2),
105    @"iPad7,2" : @(RTCDeviceTypeIPadPro12Inch2),
106    @"iPad7,3" : @(RTCDeviceTypeIPadPro10Inch),
107    @"iPad7,4" : @(RTCDeviceTypeIPadPro10Inch),
108    @"iPad7,5" : @(RTCDeviceTypeIPad6),
109    @"iPad7,6" : @(RTCDeviceTypeIPad6),
110    @"iPad7,11" : @(RTCDeviceTypeIPad7Gen10Inch),
111    @"iPad7,12" : @(RTCDeviceTypeIPad7Gen10Inch),
112    @"iPad8,1" : @(RTCDeviceTypeIPadPro3Gen11Inch),
113    @"iPad8,2" : @(RTCDeviceTypeIPadPro3Gen11Inch),
114    @"iPad8,3" : @(RTCDeviceTypeIPadPro3Gen11Inch),
115    @"iPad8,4" : @(RTCDeviceTypeIPadPro3Gen11Inch),
116    @"iPad8,5" : @(RTCDeviceTypeIPadPro3Gen12Inch),
117    @"iPad8,6" : @(RTCDeviceTypeIPadPro3Gen12Inch),
118    @"iPad8,7" : @(RTCDeviceTypeIPadPro3Gen12Inch),
119    @"iPad8,8" : @(RTCDeviceTypeIPadPro3Gen12Inch),
120    @"iPad8,9" : @(RTCDeviceTypeIPadPro4Gen11Inch),
121    @"iPad8,10" : @(RTCDeviceTypeIPadPro4Gen11Inch),
122    @"iPad8,11" : @(RTCDeviceTypeIPadPro4Gen12Inch),
123    @"iPad8,12" : @(RTCDeviceTypeIPadPro4Gen12Inch),
124    @"iPad11,1" : @(RTCDeviceTypeIPadMini5Gen),
125    @"iPad11,2" : @(RTCDeviceTypeIPadMini5Gen),
126    @"iPad11,3" : @(RTCDeviceTypeIPadAir3Gen),
127    @"iPad11,4" : @(RTCDeviceTypeIPadAir3Gen),
128    @"iPad11,6" : @(RTCDeviceTypeIPad8),
129    @"iPad11,7" : @(RTCDeviceTypeIPad8),
130    @"iPad12,1" : @(RTCDeviceTypeIPad9),
131    @"iPad12,2" : @(RTCDeviceTypeIPad9),
132    @"iPad13,1" : @(RTCDeviceTypeIPadAir4Gen),
133    @"iPad13,2" : @(RTCDeviceTypeIPadAir4Gen),
134    @"iPad13,4" : @(RTCDeviceTypeIPadPro5Gen11Inch),
135    @"iPad13,5" : @(RTCDeviceTypeIPadPro5Gen11Inch),
136    @"iPad13,6" : @(RTCDeviceTypeIPadPro5Gen11Inch),
137    @"iPad13,7" : @(RTCDeviceTypeIPadPro5Gen11Inch),
138    @"iPad13,8" : @(RTCDeviceTypeIPadPro5Gen12Inch),
139    @"iPad13,9" : @(RTCDeviceTypeIPadPro5Gen12Inch),
140    @"iPad13,10" : @(RTCDeviceTypeIPadPro5Gen12Inch),
141    @"iPad13,11" : @(RTCDeviceTypeIPadPro5Gen12Inch),
142    @"iPad14,1" : @(RTCDeviceTypeIPadMini6),
143    @"iPad14,2" : @(RTCDeviceTypeIPadMini6),
144    @"i386" : @(RTCDeviceTypeSimulatori386),
145    @"x86_64" : @(RTCDeviceTypeSimulatorx86_64),
146  };
147
148  RTCDeviceType deviceType = RTCDeviceTypeUnknown;
149  NSNumber *typeNumber = machineNameToType[[self machineName]];
150  if (typeNumber) {
151    deviceType = static_cast<RTCDeviceType>(typeNumber.integerValue);
152  }
153  return deviceType;
154}
155
156+ (NSString *)machineName {
157  struct utsname systemInfo;
158  uname(&systemInfo);
159  return [[NSString alloc] initWithCString:systemInfo.machine
160                                  encoding:NSUTF8StringEncoding];
161}
162
163+ (double)currentDeviceSystemVersion {
164  return [self currentDevice].systemVersion.doubleValue;
165}
166
167+ (BOOL)isIOS11OrLater {
168  return [self currentDeviceSystemVersion] >= 11.0;
169}
170
171@end
172