SystemInformationService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. namespace SRDebugger.Services.Implementation
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using SRF;
  7. using SRF.Service;
  8. using UnityEngine;
  9. /// <summary>
  10. /// Reports system specifications and environment information. Information that can
  11. /// be used to identify a user is marked as private, and won't be included in any generated
  12. /// reports.
  13. /// </summary>
  14. [Service(typeof(ISystemInformationService))]
  15. public class StandardSystemInformationService : ISystemInformationService
  16. {
  17. private readonly Dictionary<string, IList<InfoEntry>> _info = new Dictionary<string, IList<InfoEntry>>();
  18. public StandardSystemInformationService()
  19. {
  20. CreateDefaultSet();
  21. }
  22. public IEnumerable<string> GetCategories()
  23. {
  24. return _info.Keys;
  25. }
  26. public IList<InfoEntry> GetInfo(string category)
  27. {
  28. IList<InfoEntry> list;
  29. if (!_info.TryGetValue(category, out list))
  30. {
  31. Debug.LogError("[SystemInformationService] Category not found: {0}".Fmt(category));
  32. return new InfoEntry[0];
  33. }
  34. return list;
  35. }
  36. public void Add(InfoEntry info, string category = "Default")
  37. {
  38. IList<InfoEntry> list;
  39. if (!_info.TryGetValue(category, out list))
  40. {
  41. list = new List<InfoEntry>();
  42. _info.Add(category, list);
  43. }
  44. if (list.Any(p => p.Title == info.Title))
  45. {
  46. throw new ArgumentException("An InfoEntry object with the same title already exists in that category.", "info");
  47. }
  48. list.Add(info);
  49. }
  50. public Dictionary<string, Dictionary<string, object>> CreateReport(bool includePrivate = false)
  51. {
  52. var dict = new Dictionary<string, Dictionary<string, object>>(_info.Count);
  53. foreach (var keyValuePair in _info)
  54. {
  55. var category = new Dictionary<string, object>(keyValuePair.Value.Count);
  56. foreach (var systemInfo in keyValuePair.Value)
  57. {
  58. if (systemInfo.IsPrivate && !includePrivate)
  59. {
  60. continue;
  61. }
  62. category.Add(systemInfo.Title, systemInfo.Value);
  63. }
  64. dict.Add(keyValuePair.Key, category);
  65. }
  66. return dict;
  67. }
  68. private void CreateDefaultSet()
  69. {
  70. _info.Add("System", new[]
  71. {
  72. InfoEntry.Create("Operating System", UnityEngine.SystemInfo.operatingSystem),
  73. InfoEntry.Create("Device Name", UnityEngine.SystemInfo.deviceName, true),
  74. InfoEntry.Create("Device Type", UnityEngine.SystemInfo.deviceType),
  75. InfoEntry.Create("Device Model", UnityEngine.SystemInfo.deviceModel),
  76. InfoEntry.Create("CPU Type", UnityEngine.SystemInfo.processorType),
  77. InfoEntry.Create("CPU Count", UnityEngine.SystemInfo.processorCount),
  78. InfoEntry.Create("System Memory", SRFileUtil.GetBytesReadable(((long) UnityEngine.SystemInfo.systemMemorySize)*1024*1024))
  79. //Info.Create("Process Name", () => Process.GetCurrentProcess().ProcessName)
  80. });
  81. if (SystemInfo.batteryStatus != BatteryStatus.Unknown)
  82. {
  83. _info.Add("Battery", new[]
  84. {
  85. InfoEntry.Create("Status", UnityEngine.SystemInfo.batteryStatus),
  86. InfoEntry.Create("Battery Level", UnityEngine.SystemInfo.batteryLevel)
  87. });
  88. }
  89. #if ENABLE_IL2CPP
  90. const string IL2CPP = "Yes";
  91. #else
  92. const string IL2CPP = "No";
  93. #endif
  94. _info.Add("Unity", new[]
  95. {
  96. InfoEntry.Create("Version", Application.unityVersion),
  97. InfoEntry.Create("Debug", Debug.isDebugBuild),
  98. InfoEntry.Create("Unity Pro", Application.HasProLicense()),
  99. InfoEntry.Create("Genuine",
  100. "{0} ({1})".Fmt(Application.genuine ? "Yes" : "No",
  101. Application.genuineCheckAvailable ? "Trusted" : "Untrusted")),
  102. InfoEntry.Create("System Language", Application.systemLanguage),
  103. InfoEntry.Create("Platform", Application.platform),
  104. InfoEntry.Create("Install Mode", Application.installMode),
  105. InfoEntry.Create("Sandbox", Application.sandboxType),
  106. InfoEntry.Create("IL2CPP", IL2CPP),
  107. InfoEntry.Create("Application Version", Application.version),
  108. InfoEntry.Create("Application Id", Application.identifier),
  109. InfoEntry.Create("SRDebugger Version", SRDebug.Version),
  110. });
  111. _info.Add("Display", new[]
  112. {
  113. InfoEntry.Create("Resolution", () => Screen.width + "x" + Screen.height),
  114. InfoEntry.Create("DPI", () => Screen.dpi),
  115. InfoEntry.Create("Fullscreen", () => Screen.fullScreen),
  116. InfoEntry.Create("Fullscreen Mode", () => Screen.fullScreenMode),
  117. InfoEntry.Create("Orientation", () => Screen.orientation),
  118. });
  119. _info.Add("Runtime", new[]
  120. {
  121. InfoEntry.Create("Play Time", () => Time.unscaledTime),
  122. InfoEntry.Create("Level Play Time", () => Time.timeSinceLevelLoad),
  123. #if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2
  124. InfoEntry.Create("Current Level", () => Application.loadedLevelName),
  125. #else
  126. InfoEntry.Create("Current Level", () =>
  127. {
  128. var activeScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
  129. return "{0} (Index: {1})".Fmt(activeScene.name, activeScene.buildIndex);
  130. }),
  131. #endif
  132. InfoEntry.Create("Quality Level",
  133. () =>
  134. QualitySettings.names[QualitySettings.GetQualityLevel()] + " (" +
  135. QualitySettings.GetQualityLevel() + ")")
  136. });
  137. // Check for cloud build manifest
  138. var cloudBuildManifest = (TextAsset)Resources.Load("UnityCloudBuildManifest.json");
  139. var manifestDict = cloudBuildManifest != null
  140. ? Json.Deserialize(cloudBuildManifest.text) as Dictionary<string, object>
  141. : null;
  142. if (manifestDict != null)
  143. {
  144. var manifestList = new List<InfoEntry>(manifestDict.Count);
  145. foreach (var kvp in manifestDict)
  146. {
  147. if (kvp.Value == null)
  148. {
  149. continue;
  150. }
  151. var value = kvp.Value.ToString();
  152. manifestList.Add(InfoEntry.Create(GetCloudManifestPrettyName(kvp.Key), value));
  153. }
  154. _info.Add("Build", manifestList);
  155. }
  156. _info.Add("Features", new[]
  157. {
  158. InfoEntry.Create("Location", UnityEngine.SystemInfo.supportsLocationService),
  159. InfoEntry.Create("Accelerometer", UnityEngine.SystemInfo.supportsAccelerometer),
  160. InfoEntry.Create("Gyroscope", UnityEngine.SystemInfo.supportsGyroscope),
  161. InfoEntry.Create("Vibration", UnityEngine.SystemInfo.supportsVibration),
  162. InfoEntry.Create("Audio", UnityEngine.SystemInfo.supportsAudio)
  163. });
  164. #if UNITY_IOS
  165. _info.Add("iOS", new[] {
  166. #if UNITY_5 || UNITY_5_3_OR_NEWER
  167. InfoEntry.Create("Generation", UnityEngine.iOS.Device.generation),
  168. InfoEntry.Create("Ad Tracking", UnityEngine.iOS.Device.advertisingTrackingEnabled),
  169. #else
  170. InfoEntry.Create("Generation", iPhone.generation),
  171. InfoEntry.Create("Ad Tracking", iPhone.advertisingTrackingEnabled),
  172. #endif
  173. });
  174. #endif
  175. #pragma warning disable 618
  176. _info.Add("Graphics - Device", new[]
  177. {
  178. InfoEntry.Create("Device Name", UnityEngine.SystemInfo.graphicsDeviceName),
  179. InfoEntry.Create("Device Vendor", UnityEngine.SystemInfo.graphicsDeviceVendor),
  180. InfoEntry.Create("Device Version", UnityEngine.SystemInfo.graphicsDeviceVersion),
  181. InfoEntry.Create("Graphics Memory", SRFileUtil.GetBytesReadable(((long) UnityEngine.SystemInfo.graphicsMemorySize)*1024*1024)),
  182. InfoEntry.Create("Max Tex Size", UnityEngine.SystemInfo.maxTextureSize),
  183. });
  184. _info.Add("Graphics - Features", new[]
  185. {
  186. InfoEntry.Create("UV Starts at top", UnityEngine.SystemInfo.graphicsUVStartsAtTop),
  187. InfoEntry.Create("Shader Level", UnityEngine.SystemInfo.graphicsShaderLevel),
  188. InfoEntry.Create("Multi Threaded", UnityEngine.SystemInfo.graphicsMultiThreaded),
  189. InfoEntry.Create("Hidden Service Removal (GPU)", UnityEngine.SystemInfo.hasHiddenSurfaceRemovalOnGPU),
  190. InfoEntry.Create("Uniform Array Indexing (Fragment Shaders)", UnityEngine.SystemInfo.hasDynamicUniformArrayIndexingInFragmentShaders),
  191. InfoEntry.Create("Shadows", UnityEngine.SystemInfo.supportsShadows),
  192. InfoEntry.Create("Raw Depth Sampling (Shadows)", UnityEngine.SystemInfo.supportsRawShadowDepthSampling),
  193. InfoEntry.Create("Motion Vectors", UnityEngine.SystemInfo.supportsMotionVectors),
  194. InfoEntry.Create("Cubemaps", UnityEngine.SystemInfo.supportsRenderToCubemap),
  195. InfoEntry.Create("Image Effects", UnityEngine.SystemInfo.supportsImageEffects),
  196. InfoEntry.Create("3D Textures", UnityEngine.SystemInfo.supports3DTextures),
  197. InfoEntry.Create("2D Array Textures", UnityEngine.SystemInfo.supports2DArrayTextures),
  198. InfoEntry.Create("3D Render Textures", UnityEngine.SystemInfo.supports3DRenderTextures),
  199. InfoEntry.Create("Cubemap Array Textures", UnityEngine.SystemInfo.supportsCubemapArrayTextures),
  200. InfoEntry.Create("Copy Texture Support", UnityEngine.SystemInfo.copyTextureSupport),
  201. InfoEntry.Create("Compute Shaders", UnityEngine.SystemInfo.supportsComputeShaders),
  202. InfoEntry.Create("Instancing", UnityEngine.SystemInfo.supportsInstancing),
  203. InfoEntry.Create("Hardware Quad Topology", UnityEngine.SystemInfo.supportsHardwareQuadTopology),
  204. InfoEntry.Create("32-bit index buffer", UnityEngine.SystemInfo.supports32bitsIndexBuffer),
  205. InfoEntry.Create("Sparse Textures", UnityEngine.SystemInfo.supportsSparseTextures),
  206. InfoEntry.Create("Render Target Count", UnityEngine.SystemInfo.supportedRenderTargetCount),
  207. InfoEntry.Create("Separated Render Targets Blend", UnityEngine.SystemInfo.supportsSeparatedRenderTargetsBlend),
  208. InfoEntry.Create("Multisampled Textures", UnityEngine.SystemInfo.supportsMultisampledTextures),
  209. InfoEntry.Create("Texture Wrap Mirror Once", UnityEngine.SystemInfo.supportsTextureWrapMirrorOnce),
  210. InfoEntry.Create("Reversed Z Buffer", UnityEngine.SystemInfo.usesReversedZBuffer)
  211. });
  212. #pragma warning restore 618
  213. }
  214. private static string GetCloudManifestPrettyName(string name)
  215. {
  216. switch (name)
  217. {
  218. case "scmCommitId":
  219. return "Commit";
  220. case "scmBranch":
  221. return "Branch";
  222. case "cloudBuildTargetName":
  223. return "Build Target";
  224. case "buildStartTime":
  225. return "Build Date";
  226. }
  227. // Return name with first letter capitalised
  228. return name.Substring(0, 1).ToUpper() + name.Substring(1);
  229. }
  230. }
  231. }