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

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/helpers.mm

Issue 2581153002: Remove device HW id -> marketing name mapping table for iOS devices. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 10 matching lines...) Expand all
21 #include "webrtc/base/logging.h" 21 #include "webrtc/base/logging.h"
22 #include "webrtc/sdk/objc/Framework/Classes/helpers.h" 22 #include "webrtc/sdk/objc/Framework/Classes/helpers.h"
23 23
24 namespace webrtc { 24 namespace webrtc {
25 namespace ios { 25 namespace ios {
26 26
27 bool isOperatingSystemAtLeastVersion(double version) { 27 bool isOperatingSystemAtLeastVersion(double version) {
28 return GetSystemVersion() >= version; 28 return GetSystemVersion() >= version;
29 } 29 }
30 30
31 // Internal helper method used by GetDeviceName() to return device name.
32 const char* LookUpRealName(const char* raw_name) {
33 // Lookup table which maps raw device names to real (human readable) names.
34 struct {
35 const char* raw_name;
36 const char* real_name;
37 } device_names[] = {
38 {"iPhone1,1", "iPhone 1G"},
39 {"iPhone1,2", "iPhone 3G"},
40 {"iPhone2,1", "iPhone 3GS"},
41 {"iPhone3,1", "iPhone 4"},
42 {"iPhone3,3", "Verizon iPhone 4"},
43 {"iPhone4,1", "iPhone 4S"},
44 {"iPhone5,1", "iPhone 5 (GSM)"},
45 {"iPhone5,2", "iPhone 5 (GSM+CDMA)"},
46 {"iPhone5,3", "iPhone 5c (GSM)"},
47 {"iPhone5,4", "iPhone 5c (GSM+CDMA)"},
48 {"iPhone6,1", "iPhone 5s (GSM)"},
49 {"iPhone6,2", "iPhone 5s (GSM+CDMA)"},
50 {"iPhone7,1", "iPhone 6 Plus"},
51 {"iPhone7,2", "iPhone 6"},
52 {"iPhone8,1", "iPhone 6s"},
53 {"iPhone8,2", "iPhone 6s Plus"},
54 {"iPod1,1", "iPod Touch 1G"},
55 {"iPod2,1", "iPod Touch 2G"},
56 {"iPod3,1", "iPod Touch 3G"},
57 {"iPod4,1", "iPod Touch 4G"},
58 {"iPod5,1", "iPod Touch 5G"},
59 {"iPad1,1", "iPad"},
60 {"iPad2,1", "iPad 2 (WiFi)"},
61 {"iPad2,2", "iPad 2 (GSM)"},
62 {"iPad2,3", "iPad 2 (CDMA)"},
63 {"iPad2,4", "iPad 2 (WiFi)"},
64 {"iPad2,5", "iPad Mini (WiFi)"},
65 {"iPad2,6", "iPad Mini (GSM)"},
66 {"iPad2,7", "iPad Mini (GSM+CDMA)"},
67 {"iPad3,1", "iPad 3 (WiFi)"},
68 {"iPad3,2", "iPad 3 (GSM+CDMA)"},
69 {"iPad3,3", "iPad 3 (GSM)"},
70 {"iPad3,4", "iPad 4 (WiFi)"},
71 {"iPad3,5", "iPad 4 (GSM)"},
72 {"iPad3,6", "iPad 4 (GSM+CDMA)"},
73 {"iPad4,1", "iPad Air (WiFi)"},
74 {"iPad4,2", "iPad Air (Cellular)"},
75 {"iPad4,4", "iPad mini 2G (WiFi)"},
76 {"iPad4,5", "iPad mini 2G (Cellular)"},
77 {"i386", "Simulator"},
78 {"x86_64", "Simulator"},
79 };
80
81 for (auto& d : device_names) {
82 if (strcmp(d.raw_name, raw_name) == 0)
83 return d.real_name;
84 }
85 LOG(LS_WARNING) << "Failed to find device name (" << raw_name << ")";
86 return "";
87 }
88
89 NSString* NSStringFromStdString(const std::string& stdString) { 31 NSString* NSStringFromStdString(const std::string& stdString) {
90 // std::string may contain null termination character so we construct 32 // std::string may contain null termination character so we construct
91 // using length. 33 // using length.
92 return [[NSString alloc] initWithBytes:stdString.data() 34 return [[NSString alloc] initWithBytes:stdString.data()
93 length:stdString.length() 35 length:stdString.length()
94 encoding:NSUTF8StringEncoding]; 36 encoding:NSUTF8StringEncoding];
95 } 37 }
96 38
97 std::string StdStringFromNSString(NSString* nsString) { 39 std::string StdStringFromNSString(NSString* nsString) {
98 NSData* charData = [nsString dataUsingEncoding:NSUTF8StringEncoding]; 40 NSData* charData = [nsString dataUsingEncoding:NSUTF8StringEncoding];
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 NSString* deviceModel = [[UIDevice currentDevice] model]; 89 NSString* deviceModel = [[UIDevice currentDevice] model];
148 return StdStringFromNSString(deviceModel); 90 return StdStringFromNSString(deviceModel);
149 } 91 }
150 92
151 std::string GetDeviceName() { 93 std::string GetDeviceName() {
152 size_t size; 94 size_t size;
153 sysctlbyname("hw.machine", NULL, &size, NULL, 0); 95 sysctlbyname("hw.machine", NULL, &size, NULL, 0);
154 std::unique_ptr<char[]> machine; 96 std::unique_ptr<char[]> machine;
155 machine.reset(new char[size]); 97 machine.reset(new char[size]);
156 sysctlbyname("hw.machine", machine.get(), &size, NULL, 0); 98 sysctlbyname("hw.machine", machine.get(), &size, NULL, 0);
157 return std::string(LookUpRealName(machine.get())); 99 return std::string(machine.get());
158 } 100 }
159 101
160 std::string GetProcessName() { 102 std::string GetProcessName() {
161 NSString* processName = [NSProcessInfo processInfo].processName; 103 NSString* processName = [NSProcessInfo processInfo].processName;
162 return StdStringFromNSString(processName); 104 return StdStringFromNSString(processName);
163 } 105 }
164 106
165 int GetProcessID() { 107 int GetProcessID() {
166 return [NSProcessInfo processInfo].processIdentifier; 108 return [NSProcessInfo processInfo].processIdentifier;
167 } 109 }
(...skipping 18 matching lines...) Expand all
186 LOG(LS_WARNING) << "webrtc::ios::GetLowPowerModeEnabled() is not " 128 LOG(LS_WARNING) << "webrtc::ios::GetLowPowerModeEnabled() is not "
187 "supported. Requires at least iOS 9.0"; 129 "supported. Requires at least iOS 9.0";
188 return false; 130 return false;
189 } 131 }
190 #endif 132 #endif
191 133
192 } // namespace ios 134 } // namespace ios
193 } // namespace webrtc 135 } // namespace webrtc
194 136
195 #endif // defined(WEBRTC_IOS) 137 #endif // defined(WEBRTC_IOS)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698