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

Side by Side Diff: telemetry/telemetry/internal/platform/win_platform_backend.py

Issue 1839713002: [Telemetry] Update the code that detect windows version to use CurrentMajorVersionNumber (Reland) (Closed) Base URL: https://github.com/catapult-project/catapult@master
Patch Set: Fix Created 4 years, 8 months 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 | « telemetry/telemetry/core/os_version.py ('k') | 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 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import atexit 5 import atexit
6 import collections 6 import collections
7 import contextlib 7 import contextlib
8 import ctypes 8 import ctypes
9 import logging 9 import logging
10 import os 10 import os
(...skipping 18 matching lines...) Expand all
29 try: 29 try:
30 import pywintypes # pylint: disable=import-error 30 import pywintypes # pylint: disable=import-error
31 import win32api # pylint: disable=import-error 31 import win32api # pylint: disable=import-error
32 from win32com.shell import shell # pylint: disable=no-name-in-module 32 from win32com.shell import shell # pylint: disable=no-name-in-module
33 from win32com.shell import shellcon # pylint: disable=no-name-in-module 33 from win32com.shell import shellcon # pylint: disable=no-name-in-module
34 import win32con # pylint: disable=import-error 34 import win32con # pylint: disable=import-error
35 import win32file # pylint: disable=import-error 35 import win32file # pylint: disable=import-error
36 import win32gui # pylint: disable=import-error 36 import win32gui # pylint: disable=import-error
37 import win32pipe # pylint: disable=import-error 37 import win32pipe # pylint: disable=import-error
38 import win32process # pylint: disable=import-error 38 import win32process # pylint: disable=import-error
39 try:
40 import winreg # pylint: disable=import-error
41 except ImportError:
42 import _winreg as winreg # pylint: disable=import-error
39 import win32security # pylint: disable=import-error 43 import win32security # pylint: disable=import-error
40 except ImportError: 44 except ImportError:
41 pywintypes = None 45 pywintypes = None
42 shell = None 46 shell = None
43 shellcon = None 47 shellcon = None
44 win32api = None 48 win32api = None
45 win32con = None 49 win32con = None
46 win32file = None 50 win32file = None
47 win32gui = None 51 win32gui = None
48 win32pipe = None 52 win32pipe = None
49 win32process = None 53 win32process = None
50 win32security = None 54 win32security = None
55 winreg = None
51 56
52 57
53 def _InstallWinRing0(): 58 def _InstallWinRing0():
54 """WinRing0 is used for reading MSRs.""" 59 """WinRing0 is used for reading MSRs."""
55 executable_dir = os.path.dirname(sys.executable) 60 executable_dir = os.path.dirname(sys.executable)
56 61
57 python_is_64_bit = sys.maxsize > 2 ** 32 62 python_is_64_bit = sys.maxsize > 2 ** 32
58 dll_file_name = 'WinRing0x64.dll' if python_is_64_bit else 'WinRing0.dll' 63 dll_file_name = 'WinRing0x64.dll' if python_is_64_bit else 'WinRing0.dll'
59 dll_path = os.path.join(executable_dir, dll_file_name) 64 dll_path = os.path.join(executable_dir, dll_file_name)
60 65
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 @decorators.Cache 236 @decorators.Cache
232 def GetOSVersionName(self): 237 def GetOSVersionName(self):
233 os_version = platform.uname()[3] 238 os_version = platform.uname()[3]
234 239
235 if os_version.startswith('5.1.'): 240 if os_version.startswith('5.1.'):
236 return os_version_module.XP 241 return os_version_module.XP
237 if os_version.startswith('6.0.'): 242 if os_version.startswith('6.0.'):
238 return os_version_module.VISTA 243 return os_version_module.VISTA
239 if os_version.startswith('6.1.'): 244 if os_version.startswith('6.1.'):
240 return os_version_module.WIN7 245 return os_version_module.WIN7
241 if os_version.startswith('6.2.'): 246 # The version of python.exe we commonly use (2.7) is only manifested as
247 # being compatible with Windows versions up to 8. Therefore Windows *lies*
248 # to python about the version number to keep it runnable on Windows 10.
249 key_name = r'Software\Microsoft\Windows NT\CurrentVersion'
250 key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_name)
251 try:
252 value, _ = winreg.QueryValueEx(key, 'CurrentMajorVersionNumber')
253 except WindowsErrror: # pylint: disable=undefined-variable
254 value = None
255 finally:
256 key.Close()
257 if value == 10:
258 return os_version_module.WIN10
259 elif os_version.startswith('6.2.'):
242 return os_version_module.WIN8 260 return os_version_module.WIN8
243 if os_version.startswith('10.'): 261 elif os_version.startswith('6.3.'):
244 return os_version_module.WIN10 262 return os_version_module.WIN81
245 263 raise NotImplementedError(
246 raise NotImplementedError('Unknown win version %s.' % os_version) 264 'Unknown win version: %s, CurrentMajorVersionNumber: %s' %
265 (os_version, value))
247 266
248 def CanFlushIndividualFilesFromSystemCache(self): 267 def CanFlushIndividualFilesFromSystemCache(self):
249 return True 268 return True
250 269
251 def _GetWin32ProcessInfo(self, func, pid): 270 def _GetWin32ProcessInfo(self, func, pid):
252 mask = (win32con.PROCESS_QUERY_INFORMATION | 271 mask = (win32con.PROCESS_QUERY_INFORMATION |
253 win32con.PROCESS_VM_READ) 272 win32con.PROCESS_VM_READ)
254 handle = None 273 handle = None
255 try: 274 try:
256 handle = win32api.OpenProcess(mask, False, pid) 275 handle = win32api.OpenProcess(mask, False, pid)
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 return True 430 return True
412 hwnds = [] 431 hwnds = []
413 win32gui.EnumWindows(find_chrome_windows, hwnds) 432 win32gui.EnumWindows(find_chrome_windows, hwnds)
414 if hwnds: 433 if hwnds:
415 for hwnd in hwnds: 434 for hwnd in hwnds:
416 win32gui.SendMessage(hwnd, win32con.WM_CLOSE, 0, 0) 435 win32gui.SendMessage(hwnd, win32con.WM_CLOSE, 0, 0)
417 return True 436 return True
418 else: 437 else:
419 logging.info('Did not find any windows owned by target process') 438 logging.info('Did not find any windows owned by target process')
420 return False 439 return False
OLDNEW
« no previous file with comments | « telemetry/telemetry/core/os_version.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698