| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.content.integrity; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.os.Parcel; |
| 21 |
import android.os.Parcelable; |
| 22 |
|
| 23 |
import java.util.Map; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public class InstallerAllowedByManifestFormula extends IntegrityFormula implements Parcelable { |
| 33 |
|
| 34 |
public static final String INSTALLER_CERTIFICATE_NOT_EVALUATED = ""; |
| 35 |
|
| 36 |
public InstallerAllowedByManifestFormula() { |
| 37 |
} |
| 38 |
|
| 39 |
private InstallerAllowedByManifestFormula(Parcel in) { |
| 40 |
} |
| 41 |
|
| 42 |
@NonNull |
| 43 |
public static final Creator<InstallerAllowedByManifestFormula> CREATOR = |
| 44 |
new Creator<InstallerAllowedByManifestFormula>() { |
| 45 |
@Override |
| 46 |
public InstallerAllowedByManifestFormula createFromParcel(Parcel in) { |
| 47 |
return new InstallerAllowedByManifestFormula(in); |
| 48 |
} |
| 49 |
|
| 50 |
@Override |
| 51 |
public InstallerAllowedByManifestFormula[] newArray(int size) { |
| 52 |
return new InstallerAllowedByManifestFormula[size]; |
| 53 |
} |
| 54 |
}; |
| 55 |
|
| 56 |
@Override |
| 57 |
public int getTag() { |
| 58 |
return IntegrityFormula.INSTALLER_ALLOWED_BY_MANIFEST_FORMULA_TAG; |
| 59 |
} |
| 60 |
|
| 61 |
@Override |
| 62 |
public boolean matches(AppInstallMetadata appInstallMetadata) { |
| 63 |
Map<String, String> allowedInstallersAndCertificates = |
| 64 |
appInstallMetadata.getAllowedInstallersAndCertificates(); |
| 65 |
return allowedInstallersAndCertificates.isEmpty() |
| 66 |
|| installerInAllowedInstallersFromManifest( |
| 67 |
appInstallMetadata, allowedInstallersAndCertificates); |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public boolean isAppCertificateFormula() { |
| 72 |
return false; |
| 73 |
} |
| 74 |
|
| 75 |
@Override |
| 76 |
public boolean isAppCertificateLineageFormula() { |
| 77 |
return false; |
| 78 |
} |
| 79 |
|
| 80 |
@Override |
| 81 |
public boolean isInstallerFormula() { |
| 82 |
return true; |
| 83 |
} |
| 84 |
|
| 85 |
private static boolean installerInAllowedInstallersFromManifest( |
| 86 |
AppInstallMetadata appInstallMetadata, |
| 87 |
Map<String, String> allowedInstallersAndCertificates) { |
| 88 |
String installerPackage = appInstallMetadata.getInstallerName(); |
| 89 |
|
| 90 |
if (!allowedInstallersAndCertificates.containsKey(installerPackage)) { |
| 91 |
return false; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
if (!allowedInstallersAndCertificates.get(installerPackage) |
| 96 |
.equals(INSTALLER_CERTIFICATE_NOT_EVALUATED)) { |
| 97 |
return appInstallMetadata.getInstallerCertificates() |
| 98 |
.contains( |
| 99 |
allowedInstallersAndCertificates |
| 100 |
.get(appInstallMetadata.getInstallerName())); |
| 101 |
} |
| 102 |
|
| 103 |
return true; |
| 104 |
} |
| 105 |
|
| 106 |
@Override |
| 107 |
public int describeContents() { |
| 108 |
return 0; |
| 109 |
} |
| 110 |
|
| 111 |
@Override |
| 112 |
public void writeToParcel(Parcel dest, int flags) { |
| 113 |
} |
| 114 |
} |