Skip to content

Commit 2199deb

Browse files
authored
feat: get information about sdk version and native codes (#7)
* add get_compile_sdk_version and get_compile_sdk_version_codename * add get_native_codes * fix the comments in get_native_codes func
1 parent c8b8147 commit 2199deb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

core/src/apk.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! The main structure that represents the `apk` file.
22
3+
use std::collections::HashSet;
34
use std::fs::File;
45
use std::io::{self, BufReader, Read};
56
use std::path::Path;
@@ -312,6 +313,20 @@ impl Apk {
312313
.get_attribute_value("manifest", "platformBuildVersionName", self.arsc.as_ref())
313314
}
314315

316+
/// Retrieves the `compileSdkVersion` from the `<manifest>` element.
317+
#[inline]
318+
pub fn get_compile_sdk_version(&self) -> Option<String> {
319+
self.axml
320+
.get_attribute_value("manifest", "compileSdkVersion", self.arsc.as_ref())
321+
}
322+
323+
/// Retrieves the `compileSdkVersionCodename` from the `<manifest>` element.
324+
#[inline]
325+
pub fn get_compile_sdk_version_codename(&self) -> Option<String> {
326+
self.axml
327+
.get_attribute_value("manifest", "compileSdkVersionCodename", self.arsc.as_ref())
328+
}
329+
315330
/// Extracts the `android:allowTaskReparenting` attribute from `<application>`.
316331
///
317332
/// See: <https://developer.android.com/guide/topics/manifest/application-element#reparent>
@@ -697,4 +712,22 @@ impl Apk {
697712

698713
Ok(signatures)
699714
}
715+
716+
// Information about the native code (.so libraries) of the APK file
717+
pub fn get_native_codes(&self) -> Vec<String> {
718+
let mut native_codes_set = HashSet::new();
719+
for filename in self.zip.namelist() {
720+
if filename.starts_with("lib/") && filename.ends_with(".so") {
721+
let parts: Vec<&str> = filename.split('/').collect();
722+
// The structure is usually lib/<abi>/<libname>.so
723+
if parts.len() == 3 {
724+
let abi: String = parts[1].to_string();
725+
native_codes_set.insert(abi);
726+
}
727+
}
728+
}
729+
let mut native_codes: Vec<String> = native_codes_set.into_iter().collect();
730+
native_codes.sort();
731+
native_codes
732+
}
700733
}

0 commit comments

Comments
 (0)