settings/privacy/
privacy_controller.rs
1use crate::base::SettingInfo;
6use crate::handler::base::Request;
7use crate::handler::setting_handler::persist::{controller as data_controller, ClientProxy};
8use crate::handler::setting_handler::{
9 controller, ControllerError, IntoHandlerResult, SettingHandlerResult,
10};
11use crate::privacy::types::PrivacyInfo;
12use async_trait::async_trait;
13use settings_storage::device_storage::{DeviceStorage, DeviceStorageCompatible};
14use settings_storage::storage_factory::{NoneT, StorageAccess};
15
16impl DeviceStorageCompatible for PrivacyInfo {
17 type Loader = NoneT;
18 const KEY: &'static str = "privacy_info";
19}
20
21impl From<PrivacyInfo> for SettingInfo {
22 fn from(info: PrivacyInfo) -> SettingInfo {
23 SettingInfo::Privacy(info)
24 }
25}
26
27pub struct PrivacyController {
28 client: ClientProxy,
29}
30
31impl StorageAccess for PrivacyController {
32 type Storage = DeviceStorage;
33 type Data = PrivacyInfo;
34 const STORAGE_KEY: &'static str = PrivacyInfo::KEY;
35}
36
37#[async_trait(?Send)]
38impl data_controller::Create for PrivacyController {
39 async fn create(client: ClientProxy) -> Result<Self, ControllerError> {
40 Ok(PrivacyController { client })
41 }
42}
43
44#[async_trait(?Send)]
45impl controller::Handle for PrivacyController {
46 async fn handle(&self, request: Request) -> Option<SettingHandlerResult> {
47 match request {
48 Request::SetUserDataSharingConsent(user_data_sharing_consent) => {
49 let id = fuchsia_trace::Id::new();
50 let mut current = self.client.read_setting::<PrivacyInfo>(id).await;
51
52 current.user_data_sharing_consent = user_data_sharing_consent;
54 Some(self.client.write_setting(current.into(), id).await.into_handler_result())
55 }
56 Request::Get => Some(
57 self.client
58 .read_setting_info::<PrivacyInfo>(fuchsia_trace::Id::new())
59 .await
60 .into_handler_result(),
61 ),
62 _ => None,
63 }
64 }
65}