blob: 9a662284959137a92c028d3c77df43176dfb2bd3 [file] [log] [blame]
Jooyung Hanc221c052022-02-22 05:20:15 +09001// Copyright 2022, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Command to create or update an idsig for APK
16
17use android_system_virtualizationservice::aidl::android::system::virtualizationservice::IVirtualizationService::IVirtualizationService;
Alan Stokes0e82b502022-08-08 14:44:48 +010018use binder::ParcelFileDescriptor;
Jooyung Hanc221c052022-02-22 05:20:15 +090019use anyhow::{Context, Error};
20use std::fs::{File, OpenOptions};
21use std::path::Path;
22
23/// Creates or update the idsig file by digesting the input APK file.
24pub fn command_create_idsig(
Andrew Walbran616d13f2022-05-12 18:35:55 +000025 service: &dyn IVirtualizationService,
Jooyung Hanc221c052022-02-22 05:20:15 +090026 apk: &Path,
27 idsig: &Path,
28) -> Result<(), Error> {
29 let apk_file = File::open(apk).with_context(|| format!("Failed to open {:?}", apk))?;
30 let idsig_file = OpenOptions::new()
31 .create(true)
32 .truncate(true)
33 .read(true)
34 .write(true)
35 .open(idsig)
36 .with_context(|| format!("Failed to create/open {:?}", idsig))?;
37 service
38 .createOrUpdateIdsigFile(
39 &ParcelFileDescriptor::new(apk_file),
40 &ParcelFileDescriptor::new(idsig_file),
41 )
42 .with_context(|| format!("Failed to create/update idsig for {:?}", apk))?;
43 Ok(())
44}