Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AndroidDeviceEnumerator.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Collections.Generic;
4 
5 namespace SiliconStudio
6 {
8  {
9  /// <summary>
10  /// Lists all the Android devices accessible from the computer.
11  /// </summary>
12  /// <returns>The list of all the available Android devices.</returns>
14  {
15  var devices = new List<AndroidDeviceDescription>();
16 
17  var devicesOutputs = ShellHelper.RunProcessAndGetOutput(@"adb", @"devices");
18  var whitespace = new[] { ' ', '\t' };
19  for (var i = 1; i < devicesOutputs.OutputLines.Count; ++i) // from the second line
20  {
21  var line = devicesOutputs.OutputLines[i];
22  if (line != null)
23  {
24  var res = line.Split(whitespace);
25  if (res.Length == 2)
26  {
28  device.Serial = res[0];
29  device.Name = res[1];
30  devices.Add(device);
31  }
32  }
33  }
34 
35  // Set the real name of the Android device.
36  for (var i = 0; i < devices.Count; ++i)
37  {
38  var device = devices[i];
39  //TODO: doing a grep instead will be better
40  var deviceNameOutputs = ShellHelper.RunProcessAndGetOutput(@"adb", string.Format(@"-s {0} shell cat /system/build.prop", device.Serial));
41  foreach (var line in deviceNameOutputs.OutputLines)
42  {
43  if (line != null && line.StartsWith(@"ro.product.model")) // correct line
44  {
45  var parts = line.Split('=');
46 
47  if (parts.Length > 1)
48  {
49  device.Name = parts[1];
50  devices[i] = device;
51  }
52 
53  break; // no need to search further
54  }
55  }
56  }
57 
58  return devices.ToArray();
59  }
60 
62  {
63  public string Serial;
64  public string Name;
65  }
66  }
67 }
static AndroidDeviceDescription[] ListAndroidDevices()
Lists all the Android devices accessible from the computer.