Search in sources :

Example 1 with AppDetailsItem

use of io.github.muntashirakon.AppManager.details.struct.AppDetailsItem in project AppManager by MuntashirAkon.

the class AppDetailsViewModel method loadSignatures.

@SuppressWarnings("deprecation")
@WorkerThread
private void loadSignatures() {
    List<AppDetailsItem<X509Certificate>> appDetailsItems = new ArrayList<>();
    if (mApkFile == null) {
        mSignatures.postValue(appDetailsItems);
        return;
    }
    try {
        File idsigFile = mApkFile.getIdsigFile();
        ApkVerifier.Builder builder = new ApkVerifier.Builder(mApkFile.getBaseEntry().getRealCachedFile());
        if (idsigFile != null) {
            builder.setV4SignatureFile(idsigFile);
        }
        ApkVerifier apkVerifier = builder.build();
        mApkVerifierResult = apkVerifier.verify();
        // Get signer certificates
        List<X509Certificate> certificates = mApkVerifierResult.getSignerCertificates();
        if (certificates != null && certificates.size() > 0) {
            for (X509Certificate certificate : certificates) {
                AppDetailsItem<X509Certificate> item = new AppDetailsItem<>(certificate);
                item.name = "Signer Certificate";
                appDetailsItems.add(item);
            }
            if (mIsExternalApk && mPackageInfo.signatures == null) {
                List<Signature> signatures = new ArrayList<>(certificates.size());
                for (X509Certificate certificate : certificates) {
                    try {
                        signatures.add(new Signature(certificate.getEncoded()));
                    } catch (CertificateEncodingException ignore) {
                    }
                }
                mPackageInfo.signatures = signatures.toArray(new Signature[0]);
            }
        } else {
            // noinspection ConstantConditions Null is deliberately set here to get at least one row
            appDetailsItems.add(new AppDetailsItem<>(null));
        }
        // Get source stamp certificate
        if (mApkVerifierResult.isSourceStampVerified()) {
            ApkVerifier.Result.SourceStampInfo sourceStampInfo = mApkVerifierResult.getSourceStampInfo();
            X509Certificate certificate = sourceStampInfo.getCertificate();
            if (certificate != null) {
                AppDetailsItem<X509Certificate> item = new AppDetailsItem<>(certificate);
                item.name = "SourceStamp Certificate";
                appDetailsItems.add(item);
            }
        }
        SigningCertificateLineage lineage = mApkVerifierResult.getSigningCertificateLineage();
        if (lineage != null) {
            certificates = lineage.getCertificatesInLineage();
            if (certificates != null && certificates.size() > 0) {
                for (X509Certificate certificate : certificates) {
                    AppDetailsItem<X509Certificate> item = new AppDetailsItem<>(certificate);
                    item.name = "Certificate for Lineage";
                    appDetailsItems.add(item);
                }
            }
        }
    } catch (IOException | ApkFormatException | NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    mSignatures.postValue(appDetailsItems);
}
Also used : ArrayList(java.util.ArrayList) CertificateEncodingException(java.security.cert.CertificateEncodingException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AppDetailsItem(io.github.muntashirakon.AppManager.details.struct.AppDetailsItem) X509Certificate(java.security.cert.X509Certificate) SigningCertificateLineage(com.android.apksig.SigningCertificateLineage) ApkVerifier(com.android.apksig.ApkVerifier) ApkFormatException(com.android.apksig.apk.ApkFormatException) Signature(android.content.pm.Signature) ApkFile(io.github.muntashirakon.AppManager.apk.ApkFile) File(java.io.File) WorkerThread(androidx.annotation.WorkerThread)

Example 2 with AppDetailsItem

use of io.github.muntashirakon.AppManager.details.struct.AppDetailsItem in project AppManager by MuntashirAkon.

the class AppDetailsViewModel method loadPermissions.

@WorkerThread
private void loadPermissions() {
    synchronized (mPermissionItems) {
        mPermissionItems.clear();
        if (getPackageInfoInternal() == null || mPackageInfo.permissions == null) {
            // No custom permissions
            mPermissions.postValue(mPermissionItems);
            return;
        }
        for (PermissionInfo permissionInfo : mPackageInfo.permissions) {
            AppDetailsItem<PermissionInfo> appDetailsItem = new AppDetailsItem<>(permissionInfo);
            appDetailsItem.name = permissionInfo.name;
            mPermissionItems.add(appDetailsItem);
        }
        mPermissions.postValue(filterAndSortPermissions(mPermissionItems));
    }
}
Also used : PermissionInfo(android.content.pm.PermissionInfo) AppDetailsItem(io.github.muntashirakon.AppManager.details.struct.AppDetailsItem) WorkerThread(androidx.annotation.WorkerThread)

Example 3 with AppDetailsItem

use of io.github.muntashirakon.AppManager.details.struct.AppDetailsItem in project AppManager by MuntashirAkon.

the class AppDetailsViewModel method loadConfigurations.

@WorkerThread
private void loadConfigurations() {
    List<AppDetailsItem<ConfigurationInfo>> appDetailsItems = new ArrayList<>();
    if (getPackageInfoInternal() == null || mPackageInfo.configPreferences != null) {
        for (ConfigurationInfo configurationInfo : mPackageInfo.configPreferences) {
            AppDetailsItem<ConfigurationInfo> appDetailsItem = new AppDetailsItem<>(configurationInfo);
            appDetailsItems.add(appDetailsItem);
        }
    }
    mConfigurations.postValue(appDetailsItems);
}
Also used : ArrayList(java.util.ArrayList) AppDetailsItem(io.github.muntashirakon.AppManager.details.struct.AppDetailsItem) ConfigurationInfo(android.content.pm.ConfigurationInfo) WorkerThread(androidx.annotation.WorkerThread)

Example 4 with AppDetailsItem

use of io.github.muntashirakon.AppManager.details.struct.AppDetailsItem in project AppManager by MuntashirAkon.

the class AppDetailsViewModel method loadSharedLibraries.

@WorkerThread
private void loadSharedLibraries() {
    List<AppDetailsItem<?>> appDetailsItems = new ArrayList<>();
    if (getPackageInfoInternal() == null) {
        mSharedLibraries.postValue(appDetailsItems);
        return;
    }
    ApplicationInfo info = mPackageInfo.applicationInfo;
    if (info.sharedLibraryFiles != null) {
        for (String sharedLibrary : info.sharedLibraryFiles) {
            File sharedLib = new File(sharedLibrary);
            AppDetailsItem<?> appDetailsItem = new AppDetailsItem<>(sharedLib);
            appDetailsItem.name = sharedLib.getName();
            appDetailsItems.add(appDetailsItem);
        }
    }
    List<ApkFile.Entry> entries = mApkFile.getEntries();
    for (ApkFile.Entry entry : entries) {
        if (entry.type == ApkFile.APK_BASE || entry.type == ApkFile.APK_SPLIT_FEATURE || entry.type == ApkFile.APK_SPLIT_ABI || entry.type == ApkFile.APK_SPLIT_UNKNOWN) {
            // Scan for .so files
            NativeLibraries nativeLibraries;
            try (InputStream is = entry.getRealInputStream()) {
                try {
                    nativeLibraries = new NativeLibraries(is);
                } catch (IOException e) {
                    // Maybe zip error, Try without InputStream
                    nativeLibraries = new NativeLibraries(entry.getRealCachedFile());
                }
                for (NativeLibraries.NativeLib nativeLib : nativeLibraries.getLibs()) {
                    AppDetailsItem<?> appDetailsItem = new AppDetailsItem<>(nativeLib);
                    appDetailsItem.name = nativeLib.getName();
                    appDetailsItems.add(appDetailsItem);
                }
            } catch (Throwable th) {
                Log.e(TAG, th);
            }
        }
    }
    Collections.sort(appDetailsItems, (o1, o2) -> o1.name.compareToIgnoreCase(o2.name));
    mSharedLibraries.postValue(appDetailsItems);
}
Also used : ApkFile(io.github.muntashirakon.AppManager.apk.ApkFile) NativeLibraries(io.github.muntashirakon.AppManager.scanner.NativeLibraries) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) IOException(java.io.IOException) AppDetailsItem(io.github.muntashirakon.AppManager.details.struct.AppDetailsItem) OpEntry(io.github.muntashirakon.AppManager.appops.OpEntry) RuleEntry(io.github.muntashirakon.AppManager.rules.struct.RuleEntry) ApkFile(io.github.muntashirakon.AppManager.apk.ApkFile) File(java.io.File) WorkerThread(androidx.annotation.WorkerThread)

Example 5 with AppDetailsItem

use of io.github.muntashirakon.AppManager.details.struct.AppDetailsItem in project AppManager by MuntashirAkon.

the class AppDetailsViewModel method loadFeatures.

@WorkerThread
private void loadFeatures() {
    List<AppDetailsItem<FeatureInfo>> appDetailsItems = new ArrayList<>();
    if (getPackageInfoInternal() == null || mPackageInfo.reqFeatures == null) {
        // No required features
        mFeatures.postValue(appDetailsItems);
        return;
    }
    for (FeatureInfo fi : mPackageInfo.reqFeatures) {
        if (fi.name == null)
            fi.name = OPEN_GL_ES;
    }
    Arrays.sort(mPackageInfo.reqFeatures, (o1, o2) -> o1.name.compareToIgnoreCase(o2.name));
    for (FeatureInfo featureInfo : mPackageInfo.reqFeatures) {
        AppDetailsItem<FeatureInfo> appDetailsItem = new AppDetailsItem<>(featureInfo);
        appDetailsItem.name = featureInfo.name;
        appDetailsItems.add(appDetailsItem);
    }
    mFeatures.postValue(appDetailsItems);
}
Also used : ArrayList(java.util.ArrayList) FeatureInfo(android.content.pm.FeatureInfo) AppDetailsItem(io.github.muntashirakon.AppManager.details.struct.AppDetailsItem) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

WorkerThread (androidx.annotation.WorkerThread)5 AppDetailsItem (io.github.muntashirakon.AppManager.details.struct.AppDetailsItem)5 ArrayList (java.util.ArrayList)4 ApkFile (io.github.muntashirakon.AppManager.apk.ApkFile)2 File (java.io.File)2 IOException (java.io.IOException)2 ApplicationInfo (android.content.pm.ApplicationInfo)1 ConfigurationInfo (android.content.pm.ConfigurationInfo)1 FeatureInfo (android.content.pm.FeatureInfo)1 PermissionInfo (android.content.pm.PermissionInfo)1 Signature (android.content.pm.Signature)1 ApkVerifier (com.android.apksig.ApkVerifier)1 SigningCertificateLineage (com.android.apksig.SigningCertificateLineage)1 ApkFormatException (com.android.apksig.apk.ApkFormatException)1 OpEntry (io.github.muntashirakon.AppManager.appops.OpEntry)1 RuleEntry (io.github.muntashirakon.AppManager.rules.struct.RuleEntry)1 NativeLibraries (io.github.muntashirakon.AppManager.scanner.NativeLibraries)1 InputStream (java.io.InputStream)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1