Skip to main content

fidl_fuchsia_recovery_android/
fidl_fuchsia_recovery_android.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_recovery_android_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct UpdaterUpdateRequest {
16    /// The URL of the update manifest.
17    pub manifest_url: String,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for UpdaterUpdateRequest {}
21
22#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
23pub struct UpdaterMarker;
24
25impl fidl::endpoints::ProtocolMarker for UpdaterMarker {
26    type Proxy = UpdaterProxy;
27    type RequestStream = UpdaterRequestStream;
28    #[cfg(target_os = "fuchsia")]
29    type SynchronousProxy = UpdaterSynchronousProxy;
30
31    const DEBUG_NAME: &'static str = "fuchsia.recovery.android.Updater";
32}
33impl fidl::endpoints::DiscoverableProtocolMarker for UpdaterMarker {}
34
35pub trait UpdaterProxyInterface: Send + Sync {
36    type UpdateResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
37    fn r#update(&self, manifest_url: &str) -> Self::UpdateResponseFut;
38}
39#[derive(Debug)]
40#[cfg(target_os = "fuchsia")]
41pub struct UpdaterSynchronousProxy {
42    client: fidl::client::sync::Client,
43}
44
45#[cfg(target_os = "fuchsia")]
46impl fidl::endpoints::SynchronousProxy for UpdaterSynchronousProxy {
47    type Proxy = UpdaterProxy;
48    type Protocol = UpdaterMarker;
49
50    fn from_channel(inner: fidl::Channel) -> Self {
51        Self::new(inner)
52    }
53
54    fn into_channel(self) -> fidl::Channel {
55        self.client.into_channel()
56    }
57
58    fn as_channel(&self) -> &fidl::Channel {
59        self.client.as_channel()
60    }
61}
62
63#[cfg(target_os = "fuchsia")]
64impl UpdaterSynchronousProxy {
65    pub fn new(channel: fidl::Channel) -> Self {
66        Self { client: fidl::client::sync::Client::new(channel) }
67    }
68
69    pub fn into_channel(self) -> fidl::Channel {
70        self.client.into_channel()
71    }
72
73    /// Waits until an event arrives and returns it. It is safe for other
74    /// threads to make concurrent requests while waiting for an event.
75    pub fn wait_for_event(
76        &self,
77        deadline: zx::MonotonicInstant,
78    ) -> Result<UpdaterEvent, fidl::Error> {
79        UpdaterEvent::decode(self.client.wait_for_event::<UpdaterMarker>(deadline)?)
80    }
81
82    /// Applies an update from the given manifest URL.
83    ///
84    /// Triggers an update and returns only after the update attempt has finished,
85    /// either by succeeding, failing, or being cancelled.
86    pub fn r#update(
87        &self,
88        mut manifest_url: &str,
89        ___deadline: zx::MonotonicInstant,
90    ) -> Result<(), fidl::Error> {
91        let _response = self
92            .client
93            .send_query::<UpdaterUpdateRequest, fidl::encoding::EmptyPayload, UpdaterMarker>(
94                (manifest_url,),
95                0x6e9c49ff8508aac7,
96                fidl::encoding::DynamicFlags::empty(),
97                ___deadline,
98            )?;
99        Ok(_response)
100    }
101}
102
103#[cfg(target_os = "fuchsia")]
104impl From<UpdaterSynchronousProxy> for zx::NullableHandle {
105    fn from(value: UpdaterSynchronousProxy) -> Self {
106        value.into_channel().into()
107    }
108}
109
110#[cfg(target_os = "fuchsia")]
111impl From<fidl::Channel> for UpdaterSynchronousProxy {
112    fn from(value: fidl::Channel) -> Self {
113        Self::new(value)
114    }
115}
116
117#[cfg(target_os = "fuchsia")]
118impl fidl::endpoints::FromClient for UpdaterSynchronousProxy {
119    type Protocol = UpdaterMarker;
120
121    fn from_client(value: fidl::endpoints::ClientEnd<UpdaterMarker>) -> Self {
122        Self::new(value.into_channel())
123    }
124}
125
126#[derive(Debug, Clone)]
127pub struct UpdaterProxy {
128    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
129}
130
131impl fidl::endpoints::Proxy for UpdaterProxy {
132    type Protocol = UpdaterMarker;
133
134    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
135        Self::new(inner)
136    }
137
138    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
139        self.client.into_channel().map_err(|client| Self { client })
140    }
141
142    fn as_channel(&self) -> &::fidl::AsyncChannel {
143        self.client.as_channel()
144    }
145}
146
147impl UpdaterProxy {
148    /// Create a new Proxy for fuchsia.recovery.android/Updater.
149    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
150        let protocol_name = <UpdaterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
151        Self { client: fidl::client::Client::new(channel, protocol_name) }
152    }
153
154    /// Get a Stream of events from the remote end of the protocol.
155    ///
156    /// # Panics
157    ///
158    /// Panics if the event stream was already taken.
159    pub fn take_event_stream(&self) -> UpdaterEventStream {
160        UpdaterEventStream { event_receiver: self.client.take_event_receiver() }
161    }
162
163    /// Applies an update from the given manifest URL.
164    ///
165    /// Triggers an update and returns only after the update attempt has finished,
166    /// either by succeeding, failing, or being cancelled.
167    pub fn r#update(
168        &self,
169        mut manifest_url: &str,
170    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
171        UpdaterProxyInterface::r#update(self, manifest_url)
172    }
173}
174
175impl UpdaterProxyInterface for UpdaterProxy {
176    type UpdateResponseFut =
177        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
178    fn r#update(&self, mut manifest_url: &str) -> Self::UpdateResponseFut {
179        fn _decode(
180            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
181        ) -> Result<(), fidl::Error> {
182            let _response = fidl::client::decode_transaction_body::<
183                fidl::encoding::EmptyPayload,
184                fidl::encoding::DefaultFuchsiaResourceDialect,
185                0x6e9c49ff8508aac7,
186            >(_buf?)?;
187            Ok(_response)
188        }
189        self.client.send_query_and_decode::<UpdaterUpdateRequest, ()>(
190            (manifest_url,),
191            0x6e9c49ff8508aac7,
192            fidl::encoding::DynamicFlags::empty(),
193            _decode,
194        )
195    }
196}
197
198pub struct UpdaterEventStream {
199    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
200}
201
202impl std::marker::Unpin for UpdaterEventStream {}
203
204impl futures::stream::FusedStream for UpdaterEventStream {
205    fn is_terminated(&self) -> bool {
206        self.event_receiver.is_terminated()
207    }
208}
209
210impl futures::Stream for UpdaterEventStream {
211    type Item = Result<UpdaterEvent, fidl::Error>;
212
213    fn poll_next(
214        mut self: std::pin::Pin<&mut Self>,
215        cx: &mut std::task::Context<'_>,
216    ) -> std::task::Poll<Option<Self::Item>> {
217        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
218            &mut self.event_receiver,
219            cx
220        )?) {
221            Some(buf) => std::task::Poll::Ready(Some(UpdaterEvent::decode(buf))),
222            None => std::task::Poll::Ready(None),
223        }
224    }
225}
226
227#[derive(Debug)]
228pub enum UpdaterEvent {}
229
230impl UpdaterEvent {
231    /// Decodes a message buffer as a [`UpdaterEvent`].
232    fn decode(
233        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
234    ) -> Result<UpdaterEvent, fidl::Error> {
235        let (bytes, _handles) = buf.split_mut();
236        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
237        debug_assert_eq!(tx_header.tx_id, 0);
238        match tx_header.ordinal {
239            _ => Err(fidl::Error::UnknownOrdinal {
240                ordinal: tx_header.ordinal,
241                protocol_name: <UpdaterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
242            }),
243        }
244    }
245}
246
247/// A Stream of incoming requests for fuchsia.recovery.android/Updater.
248pub struct UpdaterRequestStream {
249    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
250    is_terminated: bool,
251}
252
253impl std::marker::Unpin for UpdaterRequestStream {}
254
255impl futures::stream::FusedStream for UpdaterRequestStream {
256    fn is_terminated(&self) -> bool {
257        self.is_terminated
258    }
259}
260
261impl fidl::endpoints::RequestStream for UpdaterRequestStream {
262    type Protocol = UpdaterMarker;
263    type ControlHandle = UpdaterControlHandle;
264
265    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
266        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
267    }
268
269    fn control_handle(&self) -> Self::ControlHandle {
270        UpdaterControlHandle { inner: self.inner.clone() }
271    }
272
273    fn into_inner(
274        self,
275    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
276    {
277        (self.inner, self.is_terminated)
278    }
279
280    fn from_inner(
281        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
282        is_terminated: bool,
283    ) -> Self {
284        Self { inner, is_terminated }
285    }
286}
287
288impl futures::Stream for UpdaterRequestStream {
289    type Item = Result<UpdaterRequest, fidl::Error>;
290
291    fn poll_next(
292        mut self: std::pin::Pin<&mut Self>,
293        cx: &mut std::task::Context<'_>,
294    ) -> std::task::Poll<Option<Self::Item>> {
295        let this = &mut *self;
296        if this.inner.check_shutdown(cx) {
297            this.is_terminated = true;
298            return std::task::Poll::Ready(None);
299        }
300        if this.is_terminated {
301            panic!("polled UpdaterRequestStream after completion");
302        }
303        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
304            |bytes, handles| {
305                match this.inner.channel().read_etc(cx, bytes, handles) {
306                    std::task::Poll::Ready(Ok(())) => {}
307                    std::task::Poll::Pending => return std::task::Poll::Pending,
308                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
309                        this.is_terminated = true;
310                        return std::task::Poll::Ready(None);
311                    }
312                    std::task::Poll::Ready(Err(e)) => {
313                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
314                            e.into(),
315                        ))));
316                    }
317                }
318
319                // A message has been received from the channel
320                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
321
322                std::task::Poll::Ready(Some(match header.ordinal {
323                    0x6e9c49ff8508aac7 => {
324                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
325                        let mut req = fidl::new_empty!(
326                            UpdaterUpdateRequest,
327                            fidl::encoding::DefaultFuchsiaResourceDialect
328                        );
329                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<UpdaterUpdateRequest>(&header, _body_bytes, handles, &mut req)?;
330                        let control_handle = UpdaterControlHandle { inner: this.inner.clone() };
331                        Ok(UpdaterRequest::Update {
332                            manifest_url: req.manifest_url,
333
334                            responder: UpdaterUpdateResponder {
335                                control_handle: std::mem::ManuallyDrop::new(control_handle),
336                                tx_id: header.tx_id,
337                            },
338                        })
339                    }
340                    _ => Err(fidl::Error::UnknownOrdinal {
341                        ordinal: header.ordinal,
342                        protocol_name:
343                            <UpdaterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
344                    }),
345                }))
346            },
347        )
348    }
349}
350
351/// Provides a mechanism for adb sideload to provide the update url to recovery-android.
352#[derive(Debug)]
353pub enum UpdaterRequest {
354    /// Applies an update from the given manifest URL.
355    ///
356    /// Triggers an update and returns only after the update attempt has finished,
357    /// either by succeeding, failing, or being cancelled.
358    Update { manifest_url: String, responder: UpdaterUpdateResponder },
359}
360
361impl UpdaterRequest {
362    #[allow(irrefutable_let_patterns)]
363    pub fn into_update(self) -> Option<(String, UpdaterUpdateResponder)> {
364        if let UpdaterRequest::Update { manifest_url, responder } = self {
365            Some((manifest_url, responder))
366        } else {
367            None
368        }
369    }
370
371    /// Name of the method defined in FIDL
372    pub fn method_name(&self) -> &'static str {
373        match *self {
374            UpdaterRequest::Update { .. } => "update",
375        }
376    }
377}
378
379#[derive(Debug, Clone)]
380pub struct UpdaterControlHandle {
381    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
382}
383
384impl UpdaterControlHandle {
385    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
386        self.inner.shutdown_with_epitaph(status.into())
387    }
388}
389
390impl fidl::endpoints::ControlHandle for UpdaterControlHandle {
391    fn shutdown(&self) {
392        self.inner.shutdown()
393    }
394
395    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
396        self.inner.shutdown_with_epitaph(status)
397    }
398
399    fn is_closed(&self) -> bool {
400        self.inner.channel().is_closed()
401    }
402    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
403        self.inner.channel().on_closed()
404    }
405
406    #[cfg(target_os = "fuchsia")]
407    fn signal_peer(
408        &self,
409        clear_mask: zx::Signals,
410        set_mask: zx::Signals,
411    ) -> Result<(), zx_status::Status> {
412        use fidl::Peered;
413        self.inner.channel().signal_peer(clear_mask, set_mask)
414    }
415}
416
417impl UpdaterControlHandle {}
418
419#[must_use = "FIDL methods require a response to be sent"]
420#[derive(Debug)]
421pub struct UpdaterUpdateResponder {
422    control_handle: std::mem::ManuallyDrop<UpdaterControlHandle>,
423    tx_id: u32,
424}
425
426/// Set the the channel to be shutdown (see [`UpdaterControlHandle::shutdown`])
427/// if the responder is dropped without sending a response, so that the client
428/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
429impl std::ops::Drop for UpdaterUpdateResponder {
430    fn drop(&mut self) {
431        self.control_handle.shutdown();
432        // Safety: drops once, never accessed again
433        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
434    }
435}
436
437impl fidl::endpoints::Responder for UpdaterUpdateResponder {
438    type ControlHandle = UpdaterControlHandle;
439
440    fn control_handle(&self) -> &UpdaterControlHandle {
441        &self.control_handle
442    }
443
444    fn drop_without_shutdown(mut self) {
445        // Safety: drops once, never accessed again due to mem::forget
446        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
447        // Prevent Drop from running (which would shut down the channel)
448        std::mem::forget(self);
449    }
450}
451
452impl UpdaterUpdateResponder {
453    /// Sends a response to the FIDL transaction.
454    ///
455    /// Sets the channel to shutdown if an error occurs.
456    pub fn send(self) -> Result<(), fidl::Error> {
457        let _result = self.send_raw();
458        if _result.is_err() {
459            self.control_handle.shutdown();
460        }
461        self.drop_without_shutdown();
462        _result
463    }
464
465    /// Similar to "send" but does not shutdown the channel if an error occurs.
466    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
467        let _result = self.send_raw();
468        self.drop_without_shutdown();
469        _result
470    }
471
472    fn send_raw(&self) -> Result<(), fidl::Error> {
473        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
474            (),
475            self.tx_id,
476            0x6e9c49ff8508aac7,
477            fidl::encoding::DynamicFlags::empty(),
478        )
479    }
480}
481
482mod internal {
483    use super::*;
484
485    impl fidl::encoding::ResourceTypeMarker for UpdaterUpdateRequest {
486        type Borrowed<'a> = &'a mut Self;
487        fn take_or_borrow<'a>(
488            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
489        ) -> Self::Borrowed<'a> {
490            value
491        }
492    }
493
494    unsafe impl fidl::encoding::TypeMarker for UpdaterUpdateRequest {
495        type Owned = Self;
496
497        #[inline(always)]
498        fn inline_align(_context: fidl::encoding::Context) -> usize {
499            8
500        }
501
502        #[inline(always)]
503        fn inline_size(_context: fidl::encoding::Context) -> usize {
504            16
505        }
506    }
507
508    unsafe impl
509        fidl::encoding::Encode<UpdaterUpdateRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
510        for &mut UpdaterUpdateRequest
511    {
512        #[inline]
513        unsafe fn encode(
514            self,
515            encoder: &mut fidl::encoding::Encoder<
516                '_,
517                fidl::encoding::DefaultFuchsiaResourceDialect,
518            >,
519            offset: usize,
520            _depth: fidl::encoding::Depth,
521        ) -> fidl::Result<()> {
522            encoder.debug_check_bounds::<UpdaterUpdateRequest>(offset);
523            // Delegate to tuple encoding.
524            fidl::encoding::Encode::<
525                UpdaterUpdateRequest,
526                fidl::encoding::DefaultFuchsiaResourceDialect,
527            >::encode(
528                (<fidl::encoding::BoundedString<4096> as fidl::encoding::ValueTypeMarker>::borrow(
529                    &self.manifest_url,
530                ),),
531                encoder,
532                offset,
533                _depth,
534            )
535        }
536    }
537    unsafe impl<
538        T0: fidl::encoding::Encode<
539                fidl::encoding::BoundedString<4096>,
540                fidl::encoding::DefaultFuchsiaResourceDialect,
541            >,
542    >
543        fidl::encoding::Encode<UpdaterUpdateRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
544        for (T0,)
545    {
546        #[inline]
547        unsafe fn encode(
548            self,
549            encoder: &mut fidl::encoding::Encoder<
550                '_,
551                fidl::encoding::DefaultFuchsiaResourceDialect,
552            >,
553            offset: usize,
554            depth: fidl::encoding::Depth,
555        ) -> fidl::Result<()> {
556            encoder.debug_check_bounds::<UpdaterUpdateRequest>(offset);
557            // Zero out padding regions. There's no need to apply masks
558            // because the unmasked parts will be overwritten by fields.
559            // Write the fields.
560            self.0.encode(encoder, offset + 0, depth)?;
561            Ok(())
562        }
563    }
564
565    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
566        for UpdaterUpdateRequest
567    {
568        #[inline(always)]
569        fn new_empty() -> Self {
570            Self {
571                manifest_url: fidl::new_empty!(
572                    fidl::encoding::BoundedString<4096>,
573                    fidl::encoding::DefaultFuchsiaResourceDialect
574                ),
575            }
576        }
577
578        #[inline]
579        unsafe fn decode(
580            &mut self,
581            decoder: &mut fidl::encoding::Decoder<
582                '_,
583                fidl::encoding::DefaultFuchsiaResourceDialect,
584            >,
585            offset: usize,
586            _depth: fidl::encoding::Depth,
587        ) -> fidl::Result<()> {
588            decoder.debug_check_bounds::<Self>(offset);
589            // Verify that padding bytes are zero.
590            fidl::decode!(
591                fidl::encoding::BoundedString<4096>,
592                fidl::encoding::DefaultFuchsiaResourceDialect,
593                &mut self.manifest_url,
594                decoder,
595                offset + 0,
596                _depth
597            )?;
598            Ok(())
599        }
600    }
601}