• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 //! run count example
15 use ipc::parcel::MsgParcel;
16 use ipc::remote::{RemoteObj, RemoteStub};
17 use samgr::definition::DOWNLOAD_SERVICE_ID;
18 use samgr::manage::SystemAbilityManager;
19 
20 struct RunCount;
21 const SERVICE_TOKEN: &str = "OHOS.Download.RequestServiceInterface";
22 impl RemoteStub for RunCount {
on_remote_request( &self, _code: u32, data: &mut ipc::parcel::MsgParcel, _reply: &mut ipc::parcel::MsgParcel, ) -> i3223     fn on_remote_request(
24         &self,
25         _code: u32,
26         data: &mut ipc::parcel::MsgParcel,
27         _reply: &mut ipc::parcel::MsgParcel,
28     ) -> i32 {
29         let token = data.read_interface_token().unwrap();
30         assert_eq!(token, "OHOS.Download.NotifyInterface");
31         let run_count: i64 = data.read().unwrap();
32         println!("Run count: {}", run_count);
33         0
34     }
35 }
36 
main()37 fn main() {
38     let download_server = loop {
39         if let Some(download_server) =
40             SystemAbilityManager::check_system_ability(DOWNLOAD_SERVICE_ID)
41         {
42             break download_server;
43         }
44         SystemAbilityManager::load_system_ability(DOWNLOAD_SERVICE_ID, 15000).unwrap();
45         std::thread::sleep(std::time::Duration::from_secs(1));
46     };
47     let mut data = MsgParcel::new();
48     data.write_interface_token(SERVICE_TOKEN).unwrap();
49     data.write_remote(RemoteObj::from_stub(RunCount).unwrap())
50         .unwrap();
51     download_server.send_request(16, &mut data).unwrap();
52     std::thread::sleep(std::time::Duration::from_secs(30000));
53 }
54