@@ -84,23 +84,37 @@ public static void ExecuteRemoteCommand(this IAdbClient client, string command,
8484 public static void Reboot ( this IAdbClient client , DeviceData device ) => client . Reboot ( string . Empty , device ) ;
8585
8686 /// <summary>
87- /// Connect to a device via TCP/IP.
87+ /// Pair with a device for secure TCP/IP communication
8888 /// </summary>
8989 /// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
9090 /// <param name="address">The IP address of the remote device.</param>
91+ /// <param name="code">The pairing code.</param>
9192 /// <returns>The results from adb.</returns>
92- public static string Connect ( this IAdbClient client , IPAddress address ) =>
93+ public static string Pair ( this IAdbClient client , IPAddress address , string code ) =>
9394 address == null
9495 ? throw new ArgumentNullException ( nameof ( address ) )
95- : client . Connect ( new IPEndPoint ( address , AdbClient . DefaultPort ) ) ;
96+ : client . Pair ( new IPEndPoint ( address , AdbClient . DefaultPort ) , code ) ;
9697
9798 /// <summary>
98- /// Connect to a device via TCP/IP.
99+ /// Pair with a device for secure TCP/IP communication
100+ /// </summary>
101+ /// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
102+ /// <param name="endpoint">The DNS endpoint at which the <c>adb</c> server on the device is running.</param>
103+ /// <param name="code">The pairing code.</param>
104+ /// <returns>The results from adb.</returns>
105+ public static string Pair ( this IAdbClient client , IPEndPoint endpoint , string code ) =>
106+ endpoint == null
107+ ? throw new ArgumentNullException ( nameof ( endpoint ) )
108+ : client . Pair ( new DnsEndPoint ( endpoint . Address . ToString ( ) , endpoint . Port ) , code ) ;
109+
110+ /// <summary>
111+ /// Pair with a device for secure TCP/IP communication
99112 /// </summary>
100113 /// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
101114 /// <param name="host">The host address of the remote device.</param>
115+ /// <param name="code">The pairing code.</param>
102116 /// <returns>The results from adb.</returns>
103- public static string Connect ( this IAdbClient client , string host )
117+ public static string Pair ( this IAdbClient client , string host , string code )
104118 {
105119 if ( string . IsNullOrEmpty ( host ) )
106120 {
@@ -111,40 +125,83 @@ public static string Connect(this IAdbClient client, string host)
111125
112126 return values . Length <= 0
113127 ? throw new ArgumentNullException ( nameof ( host ) )
114- : client . Connect ( new DnsEndPoint ( values [ 0 ] , values . Length == 1 ? AdbClient . DefaultPort : int . Parse ( values [ 1 ] ) ) ) ;
128+ : client . Pair ( new DnsEndPoint ( values [ 0 ] , values . Length == 1 ? AdbClient . DefaultPort : int . Parse ( values [ 1 ] ) ) , code ) ;
115129 }
116130
117131 /// <summary>
118- /// Connect to a device via TCP/IP.
132+ /// Pair with a device for secure TCP/IP communication
119133 /// </summary>
120134 /// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
121- /// <param name="endpoint">The IP endpoint at which the <c>adb</c> server on the device is running.</param>
135+ /// <param name="address">The IP address of the remote device.</param>
136+ /// <param name="code">The pairing code.</param>
122137 /// <returns>The results from adb.</returns>
123- public static string Connect ( this IAdbClient client , IPEndPoint endpoint ) =>
138+ public static Task < string > PairAsync ( this IAdbClient client , IPAddress address , string code ) =>
139+ address == null
140+ ? throw new ArgumentNullException ( nameof ( address ) )
141+ : client . PairAsync ( new IPEndPoint ( address , AdbClient . DefaultPort ) , code ) ;
142+
143+ /// <summary>
144+ /// Pair with a device for secure TCP/IP communication
145+ /// </summary>
146+ /// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
147+ /// <param name="endpoint">The DNS endpoint at which the <c>adb</c> server on the device is running.</param>
148+ /// <param name="code">The pairing code.</param>
149+ /// <returns>The results from adb.</returns>
150+ public static Task < string > PairAsync ( this IAdbClient client , IPEndPoint endpoint , string code ) =>
124151 endpoint == null
125152 ? throw new ArgumentNullException ( nameof ( endpoint ) )
126- : client . Connect ( new DnsEndPoint ( endpoint . Address . ToString ( ) , endpoint . Port ) ) ;
153+ : client . PairAsync ( new DnsEndPoint ( endpoint . Address . ToString ( ) , endpoint . Port ) , code ) ;
154+
155+ /// <summary>
156+ /// Pair with a device for secure TCP/IP communication
157+ /// </summary>
158+ /// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
159+ /// <param name="host">The host address of the remote device.</param>
160+ /// <param name="code">The pairing code.</param>
161+ /// <returns>The results from adb.</returns>
162+ public static Task < string > PairAsync ( this IAdbClient client , string host , string code )
163+ {
164+ if ( string . IsNullOrEmpty ( host ) )
165+ {
166+ throw new ArgumentNullException ( nameof ( host ) ) ;
167+ }
168+
169+ string [ ] values = host . Split ( ':' ) ;
170+
171+ return values . Length <= 0
172+ ? throw new ArgumentNullException ( nameof ( host ) )
173+ : client . PairAsync ( new DnsEndPoint ( values [ 0 ] , values . Length == 1 ? AdbClient . DefaultPort : int . Parse ( values [ 1 ] ) ) , code ) ;
174+ }
127175
128176 /// <summary>
129177 /// Connect to a device via TCP/IP.
130178 /// </summary>
131179 /// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
132180 /// <param name="address">The IP address of the remote device.</param>
133- /// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
134- /// <returns>An <see cref="Task"/> which return the results from adb.</returns>
135- public static Task < string > ConnectAsync ( this IAdbClient client , IPAddress address , CancellationToken cancellationToken = default ) =>
181+ /// <returns>The results from adb.</returns>
182+ public static string Connect ( this IAdbClient client , IPAddress address ) =>
136183 address == null
137184 ? throw new ArgumentNullException ( nameof ( address ) )
138- : client . ConnectAsync ( new IPEndPoint ( address , AdbClient . DefaultPort ) , cancellationToken ) ;
185+ : client . Connect ( new IPEndPoint ( address , AdbClient . DefaultPort ) ) ;
186+
187+ /// <summary>
188+ /// Connect to a device via TCP/IP.
189+ /// </summary>
190+ /// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
191+ /// <param name="endpoint">The IP endpoint at which the <c>adb</c> server on the device is running.</param>
192+ /// <returns>The results from adb.</returns>
193+ public static string Connect ( this IAdbClient client , IPEndPoint endpoint ) =>
194+ endpoint == null
195+ ? throw new ArgumentNullException ( nameof ( endpoint ) )
196+ : client . Connect ( new DnsEndPoint ( endpoint . Address . ToString ( ) , endpoint . Port ) ) ;
139197
140198 /// <summary>
141199 /// Connect to a device via TCP/IP.
142200 /// </summary>
143201 /// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
144202 /// <param name="host">The host address of the remote device.</param>
145- /// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
146- /// <returns>An <see cref="Task"/> which return the results from adb.</returns>
147- public static Task < string > ConnectAsync ( this IAdbClient client , string host , CancellationToken cancellationToken = default )
203+ /// <returns>The results from adb.</returns>
204+ public static string Connect ( this IAdbClient client , string host )
148205 {
149206 if ( string . IsNullOrEmpty ( host ) )
150207 {
@@ -155,9 +212,21 @@ public static Task<string> ConnectAsync(this IAdbClient client, string host, Can
155212
156213 return values . Length <= 0
157214 ? throw new ArgumentNullException ( nameof ( host ) )
158- : client . ConnectAsync ( new DnsEndPoint ( values [ 0 ] , values . Length == 1 ? AdbClient . DefaultPort : int . Parse ( values [ 1 ] ) ) , cancellationToken ) ;
215+ : client . Connect ( new DnsEndPoint ( values [ 0 ] , values . Length == 1 ? AdbClient . DefaultPort : int . Parse ( values [ 1 ] ) ) ) ;
159216 }
160217
218+ /// <summary>
219+ /// Connect to a device via TCP/IP.
220+ /// </summary>
221+ /// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
222+ /// <param name="address">The IP address of the remote device.</param>
223+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
224+ /// <returns>An <see cref="Task"/> which return the results from adb.</returns>
225+ public static Task < string > ConnectAsync ( this IAdbClient client , IPAddress address , CancellationToken cancellationToken = default ) =>
226+ address == null
227+ ? throw new ArgumentNullException ( nameof ( address ) )
228+ : client . ConnectAsync ( new IPEndPoint ( address , AdbClient . DefaultPort ) , cancellationToken ) ;
229+
161230 /// <summary>
162231 /// Connect to a device via TCP/IP.
163232 /// </summary>
@@ -169,5 +238,26 @@ public static Task<string> ConnectAsync(this IAdbClient client, IPEndPoint endpo
169238 endpoint == null
170239 ? throw new ArgumentNullException ( nameof ( endpoint ) )
171240 : client . ConnectAsync ( new DnsEndPoint ( endpoint . Address . ToString ( ) , endpoint . Port ) , cancellationToken ) ;
241+
242+ /// <summary>
243+ /// Connect to a device via TCP/IP.
244+ /// </summary>
245+ /// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
246+ /// <param name="host">The host address of the remote device.</param>
247+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
248+ /// <returns>An <see cref="Task"/> which return the results from adb.</returns>
249+ public static Task < string > ConnectAsync ( this IAdbClient client , string host , CancellationToken cancellationToken = default )
250+ {
251+ if ( string . IsNullOrEmpty ( host ) )
252+ {
253+ throw new ArgumentNullException ( nameof ( host ) ) ;
254+ }
255+
256+ string [ ] values = host . Split ( ':' ) ;
257+
258+ return values . Length <= 0
259+ ? throw new ArgumentNullException ( nameof ( host ) )
260+ : client . ConnectAsync ( new DnsEndPoint ( values [ 0 ] , values . Length == 1 ? AdbClient . DefaultPort : int . Parse ( values [ 1 ] ) ) , cancellationToken ) ;
261+ }
172262 }
173263}
0 commit comments