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