sl4f_lib/location/
regulatory_region_facade.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use anyhow::Error;
use fidl_fuchsia_location_namedplace::{
    RegulatoryRegionConfiguratorMarker, RegulatoryRegionConfiguratorProxy,
};
use fuchsia_component::client::connect_to_protocol;

#[derive(Debug)]
pub struct RegulatoryRegionFacade {
    configurator: RegulatoryRegionConfiguratorProxy,
}

impl RegulatoryRegionFacade {
    pub fn new() -> Result<RegulatoryRegionFacade, Error> {
        Ok(RegulatoryRegionFacade {
            configurator: connect_to_protocol::<RegulatoryRegionConfiguratorMarker>()?,
        })
    }

    /// Informs the RegulatoryRegionService of the new `region_code`.
    pub fn set_region(&self, region_code: &str) -> Result<(), Error> {
        self.configurator.set_region(region_code)?;
        Ok(())
    }
}