fidl_fuchsia_recovery_policy/
fidl_fuchsia_recovery_policy.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 _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
14pub struct DeviceSetIsLocalResetAllowedRequest {
15    pub allowed: bool,
16}
17
18impl fidl::Persistable for DeviceSetIsLocalResetAllowedRequest {}
19
20#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
21pub struct FactoryResetGetEnabledResponse {
22    pub fdr_enabled: bool,
23}
24
25impl fidl::Persistable for FactoryResetGetEnabledResponse {}
26
27#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
28pub struct DeviceMarker;
29
30impl fidl::endpoints::ProtocolMarker for DeviceMarker {
31    type Proxy = DeviceProxy;
32    type RequestStream = DeviceRequestStream;
33    #[cfg(target_os = "fuchsia")]
34    type SynchronousProxy = DeviceSynchronousProxy;
35
36    const DEBUG_NAME: &'static str = "fuchsia.recovery.policy.Device";
37}
38impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
39
40pub trait DeviceProxyInterface: Send + Sync {
41    fn r#set_is_local_reset_allowed(&self, allowed: bool) -> Result<(), fidl::Error>;
42}
43#[derive(Debug)]
44#[cfg(target_os = "fuchsia")]
45pub struct DeviceSynchronousProxy {
46    client: fidl::client::sync::Client,
47}
48
49#[cfg(target_os = "fuchsia")]
50impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
51    type Proxy = DeviceProxy;
52    type Protocol = DeviceMarker;
53
54    fn from_channel(inner: fidl::Channel) -> Self {
55        Self::new(inner)
56    }
57
58    fn into_channel(self) -> fidl::Channel {
59        self.client.into_channel()
60    }
61
62    fn as_channel(&self) -> &fidl::Channel {
63        self.client.as_channel()
64    }
65}
66
67#[cfg(target_os = "fuchsia")]
68impl DeviceSynchronousProxy {
69    pub fn new(channel: fidl::Channel) -> Self {
70        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
71        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
72    }
73
74    pub fn into_channel(self) -> fidl::Channel {
75        self.client.into_channel()
76    }
77
78    /// Waits until an event arrives and returns it. It is safe for other
79    /// threads to make concurrent requests while waiting for an event.
80    pub fn wait_for_event(
81        &self,
82        deadline: zx::MonotonicInstant,
83    ) -> Result<DeviceEvent, fidl::Error> {
84        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
85    }
86
87    /// Sets whether local factory reset is enabled, and persists the setting
88    /// after reboot.
89    /// If this function has never been called on this device, then local
90    /// factory reset is allowed by default.
91    pub fn r#set_is_local_reset_allowed(&self, mut allowed: bool) -> Result<(), fidl::Error> {
92        self.client.send::<DeviceSetIsLocalResetAllowedRequest>(
93            (allowed,),
94            0x7a0343d0fccb7ac7,
95            fidl::encoding::DynamicFlags::empty(),
96        )
97    }
98}
99
100#[derive(Debug, Clone)]
101pub struct DeviceProxy {
102    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
103}
104
105impl fidl::endpoints::Proxy for DeviceProxy {
106    type Protocol = DeviceMarker;
107
108    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
109        Self::new(inner)
110    }
111
112    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
113        self.client.into_channel().map_err(|client| Self { client })
114    }
115
116    fn as_channel(&self) -> &::fidl::AsyncChannel {
117        self.client.as_channel()
118    }
119}
120
121impl DeviceProxy {
122    /// Create a new Proxy for fuchsia.recovery.policy/Device.
123    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
124        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
125        Self { client: fidl::client::Client::new(channel, protocol_name) }
126    }
127
128    /// Get a Stream of events from the remote end of the protocol.
129    ///
130    /// # Panics
131    ///
132    /// Panics if the event stream was already taken.
133    pub fn take_event_stream(&self) -> DeviceEventStream {
134        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
135    }
136
137    /// Sets whether local factory reset is enabled, and persists the setting
138    /// after reboot.
139    /// If this function has never been called on this device, then local
140    /// factory reset is allowed by default.
141    pub fn r#set_is_local_reset_allowed(&self, mut allowed: bool) -> Result<(), fidl::Error> {
142        DeviceProxyInterface::r#set_is_local_reset_allowed(self, allowed)
143    }
144}
145
146impl DeviceProxyInterface for DeviceProxy {
147    fn r#set_is_local_reset_allowed(&self, mut allowed: bool) -> Result<(), fidl::Error> {
148        self.client.send::<DeviceSetIsLocalResetAllowedRequest>(
149            (allowed,),
150            0x7a0343d0fccb7ac7,
151            fidl::encoding::DynamicFlags::empty(),
152        )
153    }
154}
155
156pub struct DeviceEventStream {
157    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
158}
159
160impl std::marker::Unpin for DeviceEventStream {}
161
162impl futures::stream::FusedStream for DeviceEventStream {
163    fn is_terminated(&self) -> bool {
164        self.event_receiver.is_terminated()
165    }
166}
167
168impl futures::Stream for DeviceEventStream {
169    type Item = Result<DeviceEvent, fidl::Error>;
170
171    fn poll_next(
172        mut self: std::pin::Pin<&mut Self>,
173        cx: &mut std::task::Context<'_>,
174    ) -> std::task::Poll<Option<Self::Item>> {
175        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
176            &mut self.event_receiver,
177            cx
178        )?) {
179            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
180            None => std::task::Poll::Ready(None),
181        }
182    }
183}
184
185#[derive(Debug)]
186pub enum DeviceEvent {}
187
188impl DeviceEvent {
189    /// Decodes a message buffer as a [`DeviceEvent`].
190    fn decode(
191        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
192    ) -> Result<DeviceEvent, fidl::Error> {
193        let (bytes, _handles) = buf.split_mut();
194        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
195        debug_assert_eq!(tx_header.tx_id, 0);
196        match tx_header.ordinal {
197            _ => Err(fidl::Error::UnknownOrdinal {
198                ordinal: tx_header.ordinal,
199                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
200            }),
201        }
202    }
203}
204
205/// A Stream of incoming requests for fuchsia.recovery.policy/Device.
206pub struct DeviceRequestStream {
207    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
208    is_terminated: bool,
209}
210
211impl std::marker::Unpin for DeviceRequestStream {}
212
213impl futures::stream::FusedStream for DeviceRequestStream {
214    fn is_terminated(&self) -> bool {
215        self.is_terminated
216    }
217}
218
219impl fidl::endpoints::RequestStream for DeviceRequestStream {
220    type Protocol = DeviceMarker;
221    type ControlHandle = DeviceControlHandle;
222
223    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
224        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
225    }
226
227    fn control_handle(&self) -> Self::ControlHandle {
228        DeviceControlHandle { inner: self.inner.clone() }
229    }
230
231    fn into_inner(
232        self,
233    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
234    {
235        (self.inner, self.is_terminated)
236    }
237
238    fn from_inner(
239        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
240        is_terminated: bool,
241    ) -> Self {
242        Self { inner, is_terminated }
243    }
244}
245
246impl futures::Stream for DeviceRequestStream {
247    type Item = Result<DeviceRequest, fidl::Error>;
248
249    fn poll_next(
250        mut self: std::pin::Pin<&mut Self>,
251        cx: &mut std::task::Context<'_>,
252    ) -> std::task::Poll<Option<Self::Item>> {
253        let this = &mut *self;
254        if this.inner.check_shutdown(cx) {
255            this.is_terminated = true;
256            return std::task::Poll::Ready(None);
257        }
258        if this.is_terminated {
259            panic!("polled DeviceRequestStream after completion");
260        }
261        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
262            |bytes, handles| {
263                match this.inner.channel().read_etc(cx, bytes, handles) {
264                    std::task::Poll::Ready(Ok(())) => {}
265                    std::task::Poll::Pending => return std::task::Poll::Pending,
266                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
267                        this.is_terminated = true;
268                        return std::task::Poll::Ready(None);
269                    }
270                    std::task::Poll::Ready(Err(e)) => {
271                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
272                            e.into(),
273                        ))))
274                    }
275                }
276
277                // A message has been received from the channel
278                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
279
280                std::task::Poll::Ready(Some(match header.ordinal {
281                    0x7a0343d0fccb7ac7 => {
282                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
283                        let mut req = fidl::new_empty!(
284                            DeviceSetIsLocalResetAllowedRequest,
285                            fidl::encoding::DefaultFuchsiaResourceDialect
286                        );
287                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSetIsLocalResetAllowedRequest>(&header, _body_bytes, handles, &mut req)?;
288                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
289                        Ok(DeviceRequest::SetIsLocalResetAllowed {
290                            allowed: req.allowed,
291
292                            control_handle,
293                        })
294                    }
295                    _ => Err(fidl::Error::UnknownOrdinal {
296                        ordinal: header.ordinal,
297                        protocol_name:
298                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
299                    }),
300                }))
301            },
302        )
303    }
304}
305
306/// A protocol for controlling whether factory reset can be triggered by holding
307/// the physical button.
308/// This protocol will be used by Settings service to make root_presenter aware
309/// of a new FactoryReset policy.
310#[derive(Debug)]
311pub enum DeviceRequest {
312    /// Sets whether local factory reset is enabled, and persists the setting
313    /// after reboot.
314    /// If this function has never been called on this device, then local
315    /// factory reset is allowed by default.
316    SetIsLocalResetAllowed { allowed: bool, control_handle: DeviceControlHandle },
317}
318
319impl DeviceRequest {
320    #[allow(irrefutable_let_patterns)]
321    pub fn into_set_is_local_reset_allowed(self) -> Option<(bool, DeviceControlHandle)> {
322        if let DeviceRequest::SetIsLocalResetAllowed { allowed, control_handle } = self {
323            Some((allowed, control_handle))
324        } else {
325            None
326        }
327    }
328
329    /// Name of the method defined in FIDL
330    pub fn method_name(&self) -> &'static str {
331        match *self {
332            DeviceRequest::SetIsLocalResetAllowed { .. } => "set_is_local_reset_allowed",
333        }
334    }
335}
336
337#[derive(Debug, Clone)]
338pub struct DeviceControlHandle {
339    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
340}
341
342impl fidl::endpoints::ControlHandle for DeviceControlHandle {
343    fn shutdown(&self) {
344        self.inner.shutdown()
345    }
346    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
347        self.inner.shutdown_with_epitaph(status)
348    }
349
350    fn is_closed(&self) -> bool {
351        self.inner.channel().is_closed()
352    }
353    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
354        self.inner.channel().on_closed()
355    }
356
357    #[cfg(target_os = "fuchsia")]
358    fn signal_peer(
359        &self,
360        clear_mask: zx::Signals,
361        set_mask: zx::Signals,
362    ) -> Result<(), zx_status::Status> {
363        use fidl::Peered;
364        self.inner.channel().signal_peer(clear_mask, set_mask)
365    }
366}
367
368impl DeviceControlHandle {}
369
370#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
371pub struct FactoryResetMarker;
372
373impl fidl::endpoints::ProtocolMarker for FactoryResetMarker {
374    type Proxy = FactoryResetProxy;
375    type RequestStream = FactoryResetRequestStream;
376    #[cfg(target_os = "fuchsia")]
377    type SynchronousProxy = FactoryResetSynchronousProxy;
378
379    const DEBUG_NAME: &'static str = "fuchsia.recovery.policy.FactoryReset";
380}
381impl fidl::endpoints::DiscoverableProtocolMarker for FactoryResetMarker {}
382
383pub trait FactoryResetProxyInterface: Send + Sync {
384    type GetEnabledResponseFut: std::future::Future<Output = Result<bool, fidl::Error>> + Send;
385    fn r#get_enabled(&self) -> Self::GetEnabledResponseFut;
386}
387#[derive(Debug)]
388#[cfg(target_os = "fuchsia")]
389pub struct FactoryResetSynchronousProxy {
390    client: fidl::client::sync::Client,
391}
392
393#[cfg(target_os = "fuchsia")]
394impl fidl::endpoints::SynchronousProxy for FactoryResetSynchronousProxy {
395    type Proxy = FactoryResetProxy;
396    type Protocol = FactoryResetMarker;
397
398    fn from_channel(inner: fidl::Channel) -> Self {
399        Self::new(inner)
400    }
401
402    fn into_channel(self) -> fidl::Channel {
403        self.client.into_channel()
404    }
405
406    fn as_channel(&self) -> &fidl::Channel {
407        self.client.as_channel()
408    }
409}
410
411#[cfg(target_os = "fuchsia")]
412impl FactoryResetSynchronousProxy {
413    pub fn new(channel: fidl::Channel) -> Self {
414        let protocol_name = <FactoryResetMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
415        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
416    }
417
418    pub fn into_channel(self) -> fidl::Channel {
419        self.client.into_channel()
420    }
421
422    /// Waits until an event arrives and returns it. It is safe for other
423    /// threads to make concurrent requests while waiting for an event.
424    pub fn wait_for_event(
425        &self,
426        deadline: zx::MonotonicInstant,
427    ) -> Result<FactoryResetEvent, fidl::Error> {
428        FactoryResetEvent::decode(self.client.wait_for_event(deadline)?)
429    }
430
431    /// A hanging-get style api that returns whether local factory reset is
432    /// enabled.
433    pub fn r#get_enabled(&self, ___deadline: zx::MonotonicInstant) -> Result<bool, fidl::Error> {
434        let _response = self
435            .client
436            .send_query::<fidl::encoding::EmptyPayload, FactoryResetGetEnabledResponse>(
437                (),
438                0x46b4c73b3d6be123,
439                fidl::encoding::DynamicFlags::empty(),
440                ___deadline,
441            )?;
442        Ok(_response.fdr_enabled)
443    }
444}
445
446#[derive(Debug, Clone)]
447pub struct FactoryResetProxy {
448    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
449}
450
451impl fidl::endpoints::Proxy for FactoryResetProxy {
452    type Protocol = FactoryResetMarker;
453
454    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
455        Self::new(inner)
456    }
457
458    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
459        self.client.into_channel().map_err(|client| Self { client })
460    }
461
462    fn as_channel(&self) -> &::fidl::AsyncChannel {
463        self.client.as_channel()
464    }
465}
466
467impl FactoryResetProxy {
468    /// Create a new Proxy for fuchsia.recovery.policy/FactoryReset.
469    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
470        let protocol_name = <FactoryResetMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
471        Self { client: fidl::client::Client::new(channel, protocol_name) }
472    }
473
474    /// Get a Stream of events from the remote end of the protocol.
475    ///
476    /// # Panics
477    ///
478    /// Panics if the event stream was already taken.
479    pub fn take_event_stream(&self) -> FactoryResetEventStream {
480        FactoryResetEventStream { event_receiver: self.client.take_event_receiver() }
481    }
482
483    /// A hanging-get style api that returns whether local factory reset is
484    /// enabled.
485    pub fn r#get_enabled(
486        &self,
487    ) -> fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect> {
488        FactoryResetProxyInterface::r#get_enabled(self)
489    }
490}
491
492impl FactoryResetProxyInterface for FactoryResetProxy {
493    type GetEnabledResponseFut =
494        fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect>;
495    fn r#get_enabled(&self) -> Self::GetEnabledResponseFut {
496        fn _decode(
497            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
498        ) -> Result<bool, fidl::Error> {
499            let _response = fidl::client::decode_transaction_body::<
500                FactoryResetGetEnabledResponse,
501                fidl::encoding::DefaultFuchsiaResourceDialect,
502                0x46b4c73b3d6be123,
503            >(_buf?)?;
504            Ok(_response.fdr_enabled)
505        }
506        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, bool>(
507            (),
508            0x46b4c73b3d6be123,
509            fidl::encoding::DynamicFlags::empty(),
510            _decode,
511        )
512    }
513}
514
515pub struct FactoryResetEventStream {
516    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
517}
518
519impl std::marker::Unpin for FactoryResetEventStream {}
520
521impl futures::stream::FusedStream for FactoryResetEventStream {
522    fn is_terminated(&self) -> bool {
523        self.event_receiver.is_terminated()
524    }
525}
526
527impl futures::Stream for FactoryResetEventStream {
528    type Item = Result<FactoryResetEvent, fidl::Error>;
529
530    fn poll_next(
531        mut self: std::pin::Pin<&mut Self>,
532        cx: &mut std::task::Context<'_>,
533    ) -> std::task::Poll<Option<Self::Item>> {
534        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
535            &mut self.event_receiver,
536            cx
537        )?) {
538            Some(buf) => std::task::Poll::Ready(Some(FactoryResetEvent::decode(buf))),
539            None => std::task::Poll::Ready(None),
540        }
541    }
542}
543
544#[derive(Debug)]
545pub enum FactoryResetEvent {}
546
547impl FactoryResetEvent {
548    /// Decodes a message buffer as a [`FactoryResetEvent`].
549    fn decode(
550        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
551    ) -> Result<FactoryResetEvent, fidl::Error> {
552        let (bytes, _handles) = buf.split_mut();
553        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
554        debug_assert_eq!(tx_header.tx_id, 0);
555        match tx_header.ordinal {
556            _ => Err(fidl::Error::UnknownOrdinal {
557                ordinal: tx_header.ordinal,
558                protocol_name: <FactoryResetMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
559            }),
560        }
561    }
562}
563
564/// A Stream of incoming requests for fuchsia.recovery.policy/FactoryReset.
565pub struct FactoryResetRequestStream {
566    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
567    is_terminated: bool,
568}
569
570impl std::marker::Unpin for FactoryResetRequestStream {}
571
572impl futures::stream::FusedStream for FactoryResetRequestStream {
573    fn is_terminated(&self) -> bool {
574        self.is_terminated
575    }
576}
577
578impl fidl::endpoints::RequestStream for FactoryResetRequestStream {
579    type Protocol = FactoryResetMarker;
580    type ControlHandle = FactoryResetControlHandle;
581
582    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
583        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
584    }
585
586    fn control_handle(&self) -> Self::ControlHandle {
587        FactoryResetControlHandle { inner: self.inner.clone() }
588    }
589
590    fn into_inner(
591        self,
592    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
593    {
594        (self.inner, self.is_terminated)
595    }
596
597    fn from_inner(
598        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
599        is_terminated: bool,
600    ) -> Self {
601        Self { inner, is_terminated }
602    }
603}
604
605impl futures::Stream for FactoryResetRequestStream {
606    type Item = Result<FactoryResetRequest, fidl::Error>;
607
608    fn poll_next(
609        mut self: std::pin::Pin<&mut Self>,
610        cx: &mut std::task::Context<'_>,
611    ) -> std::task::Poll<Option<Self::Item>> {
612        let this = &mut *self;
613        if this.inner.check_shutdown(cx) {
614            this.is_terminated = true;
615            return std::task::Poll::Ready(None);
616        }
617        if this.is_terminated {
618            panic!("polled FactoryResetRequestStream after completion");
619        }
620        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
621            |bytes, handles| {
622                match this.inner.channel().read_etc(cx, bytes, handles) {
623                    std::task::Poll::Ready(Ok(())) => {}
624                    std::task::Poll::Pending => return std::task::Poll::Pending,
625                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
626                        this.is_terminated = true;
627                        return std::task::Poll::Ready(None);
628                    }
629                    std::task::Poll::Ready(Err(e)) => {
630                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
631                            e.into(),
632                        ))))
633                    }
634                }
635
636                // A message has been received from the channel
637                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
638
639                std::task::Poll::Ready(Some(match header.ordinal {
640                    0x46b4c73b3d6be123 => {
641                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
642                        let mut req = fidl::new_empty!(
643                            fidl::encoding::EmptyPayload,
644                            fidl::encoding::DefaultFuchsiaResourceDialect
645                        );
646                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
647                        let control_handle =
648                            FactoryResetControlHandle { inner: this.inner.clone() };
649                        Ok(FactoryResetRequest::GetEnabled {
650                            responder: FactoryResetGetEnabledResponder {
651                                control_handle: std::mem::ManuallyDrop::new(control_handle),
652                                tx_id: header.tx_id,
653                            },
654                        })
655                    }
656                    _ => Err(fidl::Error::UnknownOrdinal {
657                        ordinal: header.ordinal,
658                        protocol_name:
659                            <FactoryResetMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
660                    }),
661                }))
662            },
663        )
664    }
665}
666
667/// A protocol for determining whether factory reset can be triggered.
668#[derive(Debug)]
669pub enum FactoryResetRequest {
670    /// A hanging-get style api that returns whether local factory reset is
671    /// enabled.
672    GetEnabled { responder: FactoryResetGetEnabledResponder },
673}
674
675impl FactoryResetRequest {
676    #[allow(irrefutable_let_patterns)]
677    pub fn into_get_enabled(self) -> Option<(FactoryResetGetEnabledResponder)> {
678        if let FactoryResetRequest::GetEnabled { responder } = self {
679            Some((responder))
680        } else {
681            None
682        }
683    }
684
685    /// Name of the method defined in FIDL
686    pub fn method_name(&self) -> &'static str {
687        match *self {
688            FactoryResetRequest::GetEnabled { .. } => "get_enabled",
689        }
690    }
691}
692
693#[derive(Debug, Clone)]
694pub struct FactoryResetControlHandle {
695    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
696}
697
698impl fidl::endpoints::ControlHandle for FactoryResetControlHandle {
699    fn shutdown(&self) {
700        self.inner.shutdown()
701    }
702    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
703        self.inner.shutdown_with_epitaph(status)
704    }
705
706    fn is_closed(&self) -> bool {
707        self.inner.channel().is_closed()
708    }
709    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
710        self.inner.channel().on_closed()
711    }
712
713    #[cfg(target_os = "fuchsia")]
714    fn signal_peer(
715        &self,
716        clear_mask: zx::Signals,
717        set_mask: zx::Signals,
718    ) -> Result<(), zx_status::Status> {
719        use fidl::Peered;
720        self.inner.channel().signal_peer(clear_mask, set_mask)
721    }
722}
723
724impl FactoryResetControlHandle {}
725
726#[must_use = "FIDL methods require a response to be sent"]
727#[derive(Debug)]
728pub struct FactoryResetGetEnabledResponder {
729    control_handle: std::mem::ManuallyDrop<FactoryResetControlHandle>,
730    tx_id: u32,
731}
732
733/// Set the the channel to be shutdown (see [`FactoryResetControlHandle::shutdown`])
734/// if the responder is dropped without sending a response, so that the client
735/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
736impl std::ops::Drop for FactoryResetGetEnabledResponder {
737    fn drop(&mut self) {
738        self.control_handle.shutdown();
739        // Safety: drops once, never accessed again
740        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
741    }
742}
743
744impl fidl::endpoints::Responder for FactoryResetGetEnabledResponder {
745    type ControlHandle = FactoryResetControlHandle;
746
747    fn control_handle(&self) -> &FactoryResetControlHandle {
748        &self.control_handle
749    }
750
751    fn drop_without_shutdown(mut self) {
752        // Safety: drops once, never accessed again due to mem::forget
753        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
754        // Prevent Drop from running (which would shut down the channel)
755        std::mem::forget(self);
756    }
757}
758
759impl FactoryResetGetEnabledResponder {
760    /// Sends a response to the FIDL transaction.
761    ///
762    /// Sets the channel to shutdown if an error occurs.
763    pub fn send(self, mut fdr_enabled: bool) -> Result<(), fidl::Error> {
764        let _result = self.send_raw(fdr_enabled);
765        if _result.is_err() {
766            self.control_handle.shutdown();
767        }
768        self.drop_without_shutdown();
769        _result
770    }
771
772    /// Similar to "send" but does not shutdown the channel if an error occurs.
773    pub fn send_no_shutdown_on_err(self, mut fdr_enabled: bool) -> Result<(), fidl::Error> {
774        let _result = self.send_raw(fdr_enabled);
775        self.drop_without_shutdown();
776        _result
777    }
778
779    fn send_raw(&self, mut fdr_enabled: bool) -> Result<(), fidl::Error> {
780        self.control_handle.inner.send::<FactoryResetGetEnabledResponse>(
781            (fdr_enabled,),
782            self.tx_id,
783            0x46b4c73b3d6be123,
784            fidl::encoding::DynamicFlags::empty(),
785        )
786    }
787}
788
789mod internal {
790    use super::*;
791
792    impl fidl::encoding::ValueTypeMarker for DeviceSetIsLocalResetAllowedRequest {
793        type Borrowed<'a> = &'a Self;
794        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
795            value
796        }
797    }
798
799    unsafe impl fidl::encoding::TypeMarker for DeviceSetIsLocalResetAllowedRequest {
800        type Owned = Self;
801
802        #[inline(always)]
803        fn inline_align(_context: fidl::encoding::Context) -> usize {
804            1
805        }
806
807        #[inline(always)]
808        fn inline_size(_context: fidl::encoding::Context) -> usize {
809            1
810        }
811    }
812
813    unsafe impl<D: fidl::encoding::ResourceDialect>
814        fidl::encoding::Encode<DeviceSetIsLocalResetAllowedRequest, D>
815        for &DeviceSetIsLocalResetAllowedRequest
816    {
817        #[inline]
818        unsafe fn encode(
819            self,
820            encoder: &mut fidl::encoding::Encoder<'_, D>,
821            offset: usize,
822            _depth: fidl::encoding::Depth,
823        ) -> fidl::Result<()> {
824            encoder.debug_check_bounds::<DeviceSetIsLocalResetAllowedRequest>(offset);
825            // Delegate to tuple encoding.
826            fidl::encoding::Encode::<DeviceSetIsLocalResetAllowedRequest, D>::encode(
827                (<bool as fidl::encoding::ValueTypeMarker>::borrow(&self.allowed),),
828                encoder,
829                offset,
830                _depth,
831            )
832        }
833    }
834    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<bool, D>>
835        fidl::encoding::Encode<DeviceSetIsLocalResetAllowedRequest, D> for (T0,)
836    {
837        #[inline]
838        unsafe fn encode(
839            self,
840            encoder: &mut fidl::encoding::Encoder<'_, D>,
841            offset: usize,
842            depth: fidl::encoding::Depth,
843        ) -> fidl::Result<()> {
844            encoder.debug_check_bounds::<DeviceSetIsLocalResetAllowedRequest>(offset);
845            // Zero out padding regions. There's no need to apply masks
846            // because the unmasked parts will be overwritten by fields.
847            // Write the fields.
848            self.0.encode(encoder, offset + 0, depth)?;
849            Ok(())
850        }
851    }
852
853    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
854        for DeviceSetIsLocalResetAllowedRequest
855    {
856        #[inline(always)]
857        fn new_empty() -> Self {
858            Self { allowed: fidl::new_empty!(bool, D) }
859        }
860
861        #[inline]
862        unsafe fn decode(
863            &mut self,
864            decoder: &mut fidl::encoding::Decoder<'_, D>,
865            offset: usize,
866            _depth: fidl::encoding::Depth,
867        ) -> fidl::Result<()> {
868            decoder.debug_check_bounds::<Self>(offset);
869            // Verify that padding bytes are zero.
870            fidl::decode!(bool, D, &mut self.allowed, decoder, offset + 0, _depth)?;
871            Ok(())
872        }
873    }
874
875    impl fidl::encoding::ValueTypeMarker for FactoryResetGetEnabledResponse {
876        type Borrowed<'a> = &'a Self;
877        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
878            value
879        }
880    }
881
882    unsafe impl fidl::encoding::TypeMarker for FactoryResetGetEnabledResponse {
883        type Owned = Self;
884
885        #[inline(always)]
886        fn inline_align(_context: fidl::encoding::Context) -> usize {
887            1
888        }
889
890        #[inline(always)]
891        fn inline_size(_context: fidl::encoding::Context) -> usize {
892            1
893        }
894    }
895
896    unsafe impl<D: fidl::encoding::ResourceDialect>
897        fidl::encoding::Encode<FactoryResetGetEnabledResponse, D>
898        for &FactoryResetGetEnabledResponse
899    {
900        #[inline]
901        unsafe fn encode(
902            self,
903            encoder: &mut fidl::encoding::Encoder<'_, D>,
904            offset: usize,
905            _depth: fidl::encoding::Depth,
906        ) -> fidl::Result<()> {
907            encoder.debug_check_bounds::<FactoryResetGetEnabledResponse>(offset);
908            // Delegate to tuple encoding.
909            fidl::encoding::Encode::<FactoryResetGetEnabledResponse, D>::encode(
910                (<bool as fidl::encoding::ValueTypeMarker>::borrow(&self.fdr_enabled),),
911                encoder,
912                offset,
913                _depth,
914            )
915        }
916    }
917    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<bool, D>>
918        fidl::encoding::Encode<FactoryResetGetEnabledResponse, D> for (T0,)
919    {
920        #[inline]
921        unsafe fn encode(
922            self,
923            encoder: &mut fidl::encoding::Encoder<'_, D>,
924            offset: usize,
925            depth: fidl::encoding::Depth,
926        ) -> fidl::Result<()> {
927            encoder.debug_check_bounds::<FactoryResetGetEnabledResponse>(offset);
928            // Zero out padding regions. There's no need to apply masks
929            // because the unmasked parts will be overwritten by fields.
930            // Write the fields.
931            self.0.encode(encoder, offset + 0, depth)?;
932            Ok(())
933        }
934    }
935
936    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
937        for FactoryResetGetEnabledResponse
938    {
939        #[inline(always)]
940        fn new_empty() -> Self {
941            Self { fdr_enabled: fidl::new_empty!(bool, D) }
942        }
943
944        #[inline]
945        unsafe fn decode(
946            &mut self,
947            decoder: &mut fidl::encoding::Decoder<'_, D>,
948            offset: usize,
949            _depth: fidl::encoding::Depth,
950        ) -> fidl::Result<()> {
951            decoder.debug_check_bounds::<Self>(offset);
952            // Verify that padding bytes are zero.
953            fidl::decode!(bool, D, &mut self.fdr_enabled, decoder, offset + 0, _depth)?;
954            Ok(())
955        }
956    }
957}