Giter Club home page Giter Club logo

camalot / madb Goto Github PK

View Code? Open in Web Editor NEW
105.0 16.0 40.0 3.34 MB

The Original MADB Project. This is a Managed port of the Android Debug Bridge to allow communication from .NET applications to Android devices. This wraps the same methods that the ddms uses to directly communicate with ADB. This gives more flexibility to the developer than launching an adb process and executing one of its build in commands.

Home Page: http://madb.bit13.com

License: Other

C# 53.70% ASP 0.01% JavaScript 6.70% CSS 36.70% Batchfile 0.01% PowerShell 2.89%

madb's Introduction

MadBee

Build status Code Coverage by CodeCov

This is a Managed port of the Android Debug Bridge to allow communication from .NET applications to Android devices. This wraps the same methods that the ddms uses to directly communicate with ADB. This gives more flexibility to the developer than launching an adb process and executing one of its build in commands.

ohloh stats Donate

PushBullet Channels

Installation

To install madbee, run the following command in the Package Manager Console:


PM> Install-Package Managed.Adb 
PM> Install-Package Managed.Adb.x64

FileSystem Methods / Properties

  • Create
  • Move
  • Copy
  • MakeDirectory
  • Exists
  • Chmod
  • Delete
  • IsMountPointReadOnly
  • DeviceBlocks - Get a collection of the device blocks
  • Mount
  • Unmount
  • ResolveLink - Resolves a symbolic link to its full path

Busybox Methods / Properties

  • Available
  • Version
  • Commands
  • Supports ( command )
  • Install
  • ExecuteShellCommand
  • ExecuteRootCommand

Device Methods / Properties

  • CanSU
  • State
  • MountPoints
  • Properties
  • EnvironmentVariables
  • GetProperty
  • FileSystem
  • BusyBox
  • IsOnline
  • IsOffline
  • IsEmulator
  • IsBootLoader
  • IsRecovery
  • RemountMountPoint
  • Reboot
  • Reboot ( into )
  • SyncService
  • PackageManager
  • FileListingService
  • Screenshot
  • ExecuteShellCommand
  • ExecuteRootShellCommand
  • InstallPackage
  • SyncPackageToDevice
  • InstallRemotePackage
  • RemoveRemotePackage
  • UninstallPackage

FileEntry Methods / Properties

  • FindOrCreate *static
  • Find *static
  • Parent
  • Name
  • LinkName
  • Info
  • Permissions
  • Size
  • Date
  • Owner
  • Group
  • Type
  • IsApplicationPackage
  • IsRoot
  • IsExecutable
  • Children
  • IsLink
  • Exists
  • FindChild
  • IsDirectory
  • IsApplicationFileName
  • FullPath
  • FullResolvedPath
  • FullEscapedPath
  • PathSegments

PackageManager Methods / Properties

  • Packages
  • RefreshPackages
  • Exists
  • GetApkFileEntry
  • GetApkPath

SyncService

  • Pull
  • PullFile
  • Push
  • PushFile

Copyright

Copyright (c) 2010-2016 Ryan Conrad

Portions are:

Copyright (c) 2004-2008 Jon Skeet and Marc Gravell
Copyright (c) 2007 The Android Open Source Project

madb's People

Contributors

camalot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

madb's Issues

Device rejected command: unkown host service

Hello I have encountered a weird issue with adb using this repo

Start code

    '( GA_tools = C:\Users\(username)\AppData\Roaming\GeekAssistant\tools )
Public Sub madbCreateBridge(Optional forceNewBridge As Boolean = False)
    Dim madb = Adb.AndroidDebugBridge.CreateBridge($"{GA_tools}\adb.exe", forceNewBridge)
    madb.Start()
End Sub
Public Function madb_GetListOfDevice() As List(Of Adb.Device)
    madbCreateBridge() 'Failsafe  
'' vvv Exception thrown while running this: vvv
    Return Adb.AdbHelper.Instance.GetDevices(Adb.AndroidDebugBridge.SocketAddress)
End Function

Call stack

Managed.Adb.dll!Managed.Adb.AdbHelper.ExecuteRawSocketCommand(System.Net.IPEndPoint address, Managed.Adb.Device device, byte[] command) Line 1117 C#

Managed.Adb.dll!Managed.Adb.AdbHelper.ExecuteRawSocketCommand(System.Net.IPEndPoint address, byte[] command) Line 1079 C#

Managed.Adb.dll!Managed.Adb.AdbHelper.ExecuteRawSocketCommand(System.Net.IPEndPoint address, string command) Line 1069 C#

Managed.Adb.dll!Managed.Adb.AdbHelper.GetDevices(System.Net.IPEndPoint address) Line 667 C#

Geek Assistant (Android AIO).exe!GeekAssistant.madb_Functions.madb_GetListOfDevice() Line 38 Basic

...

Exception thrown at AdbHelper.cs Line 1117

1116 |    if ( !resp.IOSuccess || !resp.Okay ) {
1117 |	    throw new AdbException ( "Device rejected command: {0}".With ( resp.Message ) );
1118 |    }

Debug information:

resp.IOSuccess = true
resp.Message = "unkown host service"
resp.Okay = false
(IPEndPoint) address = {127.0.0.1:5037}
(Device) device = null
(byte[]) command = byte[19]

Version information:

  • Visual Studio: v16.9.2
  • Managed.Adb: v2.0.131.13916
  • Newtonsoft.Json: v8.0.3
  • morelinq: v1.4.0

Meanwhile outside of madb (using the same adb.exe used above in madb):

PS C:\Users\(username)\AppData\Roaming\GeekAssistant\tools> adb devices
List of devices attached
09...(Serial Number)        device

Get MAC Address

Please help me to find the way to get the MAC Address of the Android device/Tab which is connected to system.

Creating bridge is impossible without path

It should be possible to create AndroidDebugBridge expecting that it is already running. In this case disconnecting from the bridge should not cause kill-server message to be sent.

getevent never returns

Device.ExecuteShellCommand("getevent -l", ConsoleOutputReceiver.Instance);

I would expect this to start streaming messages to the console however it just simply hangs. Defining a timeout doesn't seem to work either.

Invalid device list data when getting devices

Attempting to connect to an oculus go. Using straight adb commands works completely fine through command prompt just not through the plugin.

Adb Devices return through cmd :
[serialNumber] device

Stacktrace :
at Managed.Adb.Device.CreateFromAdbData(String data) in C:\projects\madb\Managed.AndroidDebugBridge\Device.cs:line 210
at Managed.Adb.AdbHelper.<>c__DisplayClass28_0.b__0(String item) in C:\projects\madb\Managed.AndroidDebugBridge\AdbHelper.cs:line 686
at MoreLinq.MoreEnumerable.ForEach[T](IEnumerable1 source, Action1 action)
at Managed.Adb.AdbHelper.GetDevices(IPEndPoint address) in C:\projects\madb\Managed.AndroidDebugBridge\AdbHelper.cs:line 685

Permission Denied. Pull and Push, FileSystem.Exists functions were called

Hi,
When I performed "device.FileSystem.Exists("/sdcard/testfolder")" from my wpf application , following error were shown.

Managed.Adb.Exceptions.PermissionDeniedException: 'The remote execution returned: 'lstat '//pds' failed: Permission denied''.

Please give some suggestions for getting the permission.
device used is Moto G
were used.

PackageManager.PackageManager.GetApkFileEntry fail on resolve debugged apk's

I try many time for PackageManager.Exist("mypackage"). Exit method crash.
because it use PackageManager.GetApkFileEntry. but GetApkPath more stable and find my apk's path.

I think. PackageManager.Exist method edit like as following

public bool Exists ( String package ) {
try {
return GetApkPath ( package ) != null;
} catch ( FileNotFoundException) {
return false;
}
}

Device, bridge and client listeners should be static

In Java version of the lib they're static. Is there a reason these event listeners are not static?
When they're not static it can lead to a data race when bridge is created because we cannot set any listeners until we have an instance of it. And we cannot populate a device list outside of the lib before we have an instance either.

InstallPackage faild

use InstallPackage faild,but use SyncPackageToDevice and ExecuteShellCommand("pm install -r " + path, result); success
That's why
I was in accordance with the order of the source, separate command can

Device monitor event incorrectly states device is online when it is not.

Original Bug on CodePlex

the device monitor connection event always states the device is online even if the state of the device is not online.

current code has a line that switches the newdevice state to online even though adb is not reporting it online. A device coming this way via the event will be listed as online but will be offline if you find the same device via the AndroidDebugBridge Devices Propety which uses AdbHelper.Instance.GetDevices

// at this point we should still have some new devices in newList, so we
// process them.
foreach ( Device newDevice in list ) {
  // add them to the list
  Devices.Add ( newDevice );
  if ( Server != null ) {
    newDevice.State = DeviceState.Online;
    newDevice.OnStateChanged ( EventArgs.Empty );
    Server.OnDeviceConnected ( new DeviceEventArgs ( newDevice ) );
  }
  // start monitoring them.
  if ( AndroidDebugBridge.ClientSupport ) {
    if ( newDevice.IsOnline ) {
      StartMonitoringDevice ( newDevice );
    }
  }
  // look for their build info.
  if ( newDevice.IsOnline ) {
    QueryNewDeviceForInfo ( newDevice );
  }
}

Suffix upper case lead to upload failed

var pushPaths = new string[] {@“c:\123.JPG” };
SyncResult rust =drivce.SyncService.Push(pushPaths, remote, new NullSyncProgressMonitor());

rust.Code=0
But the phone can not find the file
123.JPG Modify as: 123.jpg success

Incorrect raw-image width returned from screenshot

The screenshot property was working perfectly for me returning the physical size as the height and width of the raw-image on my moto 5Gs plus devices running on Android 7.1.1.
However I recently upgraded one of the device to Android 8.1 Oreo and since then I have been having an issue where the screenshot width returns the number "8294400" as the width instead of the actual physical size of 1080.
Any ideas why this might be the case?

Wrong split strings in PackageManager

Hi! Sorry for my English, I was bad at school.
Function ProcessNewLines() in class PackageManagerReceiver receive wrong parameters, when i use Samsung Galaxy S7 and Xiaomi Redmi Note 4. With Xiaomi MI2S that's OK. Array lines(ProcessNewLines( string[] lines )) contains only one element with all string: see screenshot
I can't fix this on my own, please, help.

AdbHelper.GetDevices fails if device name contains a white space

Original Bug on CodePlex

The Visual Studio emulator registers as a device with a space in its device name; the following data is passed to CreateDeviceFromAdbData:

169.254.138.177:5555   device product:VS Emulator Android Device - 480 x 800 model:Android_Device___480_x_800 device:donatello

The current regex doesn't allow white space and throws an ArgumentException with message Invalid device list data.

The fix appears to be to update the RE_DEVICELIST_INFO to allow for whitespaces but not for the colon : in the product name section of the device list.

    private const String RE_DEVICELIST_INFO = @"^([a-z0-9_-]+(?:\s?[\.a-z0-9_-]+)?(?:\:\d{1,})?)\s+(device|offline|unknown|bootloader|recovery|download)(?:\s+product:([^:]+)\s+model\:([\S]+)\s+device\:([\S]+))?$";

Implementing adb connect

Original Bug on CodePlex

This is a patch which adds support for adb connect to madbee.

Although not listed in https://android.googlesource.com/platform/system/core/+/master/adb/SERVICES.TXT, it is a valid adb command. The implementation can be seen in https://android.googlesource.com/platform/system/core/+/master/adb/commandline.c at around line 1328.

The code below adds support for adb connect to madbee. It was implemented as an extension method to AdbHelper, which explains the various this AdbHelper helper statements. They are probably not needed if you decide to integrate this code into madbee.

public static class AdbHelperExtensions
    {
        /// <summary>
        /// The default port to use when connecting to a device over TCP/IP.
        /// </summary>
        private const int DEFAULT_PORT = 5555;

        /// <summary>
        /// Connect to a device via TCP/IP.
        /// </summary>
        /// <param name="helper">
        /// An instance of the <see cref="AdbHelper"/> class.
        /// </param>
        /// <param name="adbEndpoint">
        /// The socket where the <c>adb</c> server is listening.
        /// </param>
        /// <param name="address">
        /// The IP address of the remote device.
        /// </param>
        /// <returns>
        /// <c>0</c> if the operation completed successfully; otherwise,
        /// <c>-1</c>.
        /// </returns>
        public static int Connect(this AdbHelper helper, IPEndPoint adbEndpoint, IPAddress address)
        {
            if(address == null)
            {
                throw new ArgumentNullException("address");
            }

            return helper.Connect(adbEndpoint, new IPEndPoint(address, DEFAULT_PORT));
        }

        /// <summary>
        /// Connect to a device via TCP/IP.
        /// </summary>
        /// <param name="helper">
        /// An instance of the <see cref="AdbHelper"/> class.
        /// </param>
        /// <param name="adbEndpoint">
        /// The socket where the <c>adb</c> server is listening.
        /// </param>
        /// <param name="host">
        /// The host address of the remote device.
        /// </param>
        /// <returns>
        /// <c>0</c> if the operation completed successfully; otherwise,
        /// <c>-1</c>.
        /// </returns>
        public static int Connect(this AdbHelper helper, IPEndPoint adbEndpoint, string host)
        {
            if(string.IsNullOrEmpty(host))
            {
                throw new ArgumentNullException("host");
            }

            return helper.Connect(adbEndpoint, new DnsEndPoint(host, DEFAULT_PORT));
        }

        /// <summary>
        /// Connect to a device via TCP/IP.
        /// </summary>
        /// <param name="helper">
        /// An instance of the <see cref="AdbHelper"/> class.
        /// </param>
        /// <param name="adbEndpoint">
        /// The socket where the <c>adb</c> server is listening.
        /// </param>
        /// <param name="endpoint">
        /// The IP endpoint at which the <c>adb</c> server on the device is running.
        /// </param>
        /// <returns>
        /// <c>0</c> if the operation completed successfully; otherwise,
        /// <c>-1</c>.
        /// </returns>
        public static int Connect(this AdbHelper helper, IPEndPoint adbEndpoint, IPEndPoint endpoint)
        {
            if(endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            return helper.Connect(adbEndpoint, new DnsEndPoint(endpoint.Address.ToString(), endpoint.Port));
        }

        /// <summary>
        /// Connect to a device via TCP/IP.
        /// </summary>
        /// <param name="helper">
        /// An instance of the <see cref="AdbHelper"/> class.
        /// </param>
        /// <param name="adbEndpoint">
        /// The socket where the <c>adb</c> server is listening.
        /// </param>
        /// <param name="endpoint">
        /// The DNS endpoint at which the <c>adb</c> server on the device is running.
        /// </param>
        /// <returns>
        /// <c>0</c> if the operation completed successfully; otherwise,
        /// <c>-1</c>.
        /// </returns>
        public static int Connect(this AdbHelper helper, IPEndPoint adbEndpoint, DnsEndPoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            byte[] request = helper.FormAdbRequest(string.Format("host:connect:{0}:{1}", endpoint.Host, endpoint.Port));

            using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                socket.Connect(adbEndpoint);
                socket.Blocking = true;
                if (!helper.Write(socket, request))
                {
                    throw new IOException("failed submitting request to  adb");
                }
                var resp = helper.ReadAdbResponse(socket, false);
                if (!resp.IOSuccess || !resp.Okay)
                {
                    Log.e(TAG, "Got timeout or unhappy response from ADB req: " + resp.Message);
                    socket.Close();
                    return -1;
                }
                return 0;
            }
        }
    }

Support for additional PixelFormats in RawImage.ToImage

Original Bug on CodePlex

In RawImage.ToImage (RawImage.cs:257), two pixel formats are hard coded. If the screen buffer is 32-bit, ARGB is always assumed; if the screen buffer is 16-bit, RGB565 is always assumed.

The Microsoft Visual Studio Android emulator uses a RGB format, so the colors are off.

The following code reads the ARGB offsets and determines the pixel format based on these values:

if(this.Bpp == 32) {
    if(this.Alpha.Offset == 0 && this.Red.Offset == 8 && this.Green.Offset == 16 && this.Blue.Offset == 24) {
        format = PixelFormat.Format32bppArgb;
    } else if(this.Red.Offset == 0 && this.Green.Offset == 8 && this.Blue.Offset == 16 && this.Alpha.Offset == 24) {
        format = PixelFormat.Format32bppRgb;
    }
} else if(this.Bpp == 16) {
    if (this.Red.Offset == 0 && Green.Offset == 5 && Red.Offset == 11) {
        format = PixelFormat.Format16bppRgb565;
    } else if(this.Red.Offset == 0 && Green.Offset == 5 && Red.Offset == 10) {
        format = PixelFormat.Format16bppRgb555;
    }
}

return ToImage ( format );

Device.RefreshProperties fails with ArgumentException

Original Bug Filed on CodePlex

If you call Device.RefreshProperties, the code fails with an ArgumentException.

The GetPropReceiver attempts to add the properties to the Device.Properties dictionary. But if a property was already present previously, this will result the .Add operation to fail with an ArgumentException.

The best solution probably is to clear the dictionary before refreshing it. That way, stale properties are removed and the GetPropReciever will never encounter this situation.

Screenshot is too slow

It's taking 8 seconds to take a screen shot with a screen resolution of 2560 x 1440.
It would be useful to be able to get the color of a single pixel without having to take a screen shot.
Can this be done?

NewtonSoft Version

Is it possible to have a madb version compatible with NewtonSoft>10.0 . the current maximum version (<8.1) conflicts with SQLight Extension?

Invalid device list data

Hi, I just found an issue in CreateFromAdbData, I have a Nexus5x which device model has been modified to AOSP on hammerhead. the data passed to this function is "09a7cc5c02ba0415 device product:aosp_hammerhead model:AOSP_on_HammerHead device:hammerhead transport_id:2", then the regex failed to match.

Error with GetDevices

Get an error with GetDevices()

var device = AdbClient.Instance.GetDevices().First();

An unhandled exception of type 'System.ArgumentException' occurred in SharpAdbClient.dll

Additional information: Invalid device list data '01f15dd79990d792 device product:g2_vzw model:VS980_4G device:g2 transport_id:3'

A bug?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.