use of android.content.pm.EphemeralResolveInfo.EphemeralDigest in project platform_frameworks_base by android.
the class PackageManagerService method getEphemeralResolveInfo.
private static EphemeralResolveInfo getEphemeralResolveInfo(Context context, EphemeralResolverConnection resolverConnection, Intent intent, String resolvedType, int userId, String packageName) {
final int ephemeralPrefixMask = Global.getInt(context.getContentResolver(), Global.EPHEMERAL_HASH_PREFIX_MASK, DEFAULT_EPHEMERAL_HASH_PREFIX_MASK);
final int ephemeralPrefixCount = Global.getInt(context.getContentResolver(), Global.EPHEMERAL_HASH_PREFIX_COUNT, DEFAULT_EPHEMERAL_HASH_PREFIX_COUNT);
final EphemeralDigest digest = new EphemeralDigest(intent.getData(), ephemeralPrefixMask, ephemeralPrefixCount);
final int[] shaPrefix = digest.getDigestPrefix();
final byte[][] digestBytes = digest.getDigestBytes();
final List<EphemeralResolveInfo> ephemeralResolveInfoList = resolverConnection.getEphemeralResolveInfoList(shaPrefix, ephemeralPrefixMask);
if (ephemeralResolveInfoList == null || ephemeralResolveInfoList.size() == 0) {
// No hash prefix match; there are no ephemeral apps for this domain.
return null;
}
// Go in reverse order so we match the narrowest scope first.
for (int i = shaPrefix.length - 1; i >= 0; --i) {
for (EphemeralResolveInfo ephemeralApplication : ephemeralResolveInfoList) {
if (!Arrays.equals(digestBytes[i], ephemeralApplication.getDigestBytes())) {
continue;
}
final List<IntentFilter> filters = ephemeralApplication.getFilters();
// No filters; this should never happen.
if (filters.isEmpty()) {
continue;
}
if (packageName != null && !packageName.equals(ephemeralApplication.getPackageName())) {
continue;
}
// We have a domain match; resolve the filters to see if anything matches.
final EphemeralIntentResolver ephemeralResolver = new EphemeralIntentResolver();
for (int j = filters.size() - 1; j >= 0; --j) {
final EphemeralResolveIntentInfo intentInfo = new EphemeralResolveIntentInfo(filters.get(j), ephemeralApplication);
ephemeralResolver.addFilter(intentInfo);
}
List<EphemeralResolveInfo> matchedResolveInfoList = ephemeralResolver.queryIntent(intent, resolvedType, false, /*defaultOnly*/
userId);
if (!matchedResolveInfoList.isEmpty()) {
return matchedResolveInfoList.get(0);
}
}
}
// Hash or filter mis-match; no ephemeral apps for this domain.
return null;
}
use of android.content.pm.EphemeralResolveInfo.EphemeralDigest in project android_frameworks_base by DirtyUnicorns.
the class PackageManagerService method getEphemeralResolveInfo.
private static EphemeralResolveInfo getEphemeralResolveInfo(Context context, EphemeralResolverConnection resolverConnection, Intent intent, String resolvedType, int userId, String packageName) {
final int ephemeralPrefixMask = Global.getInt(context.getContentResolver(), Global.EPHEMERAL_HASH_PREFIX_MASK, DEFAULT_EPHEMERAL_HASH_PREFIX_MASK);
final int ephemeralPrefixCount = Global.getInt(context.getContentResolver(), Global.EPHEMERAL_HASH_PREFIX_COUNT, DEFAULT_EPHEMERAL_HASH_PREFIX_COUNT);
final EphemeralDigest digest = new EphemeralDigest(intent.getData(), ephemeralPrefixMask, ephemeralPrefixCount);
final int[] shaPrefix = digest.getDigestPrefix();
final byte[][] digestBytes = digest.getDigestBytes();
final List<EphemeralResolveInfo> ephemeralResolveInfoList = resolverConnection.getEphemeralResolveInfoList(shaPrefix, ephemeralPrefixMask);
if (ephemeralResolveInfoList == null || ephemeralResolveInfoList.size() == 0) {
// No hash prefix match; there are no ephemeral apps for this domain.
return null;
}
// Go in reverse order so we match the narrowest scope first.
for (int i = shaPrefix.length - 1; i >= 0; --i) {
for (EphemeralResolveInfo ephemeralApplication : ephemeralResolveInfoList) {
if (!Arrays.equals(digestBytes[i], ephemeralApplication.getDigestBytes())) {
continue;
}
final List<IntentFilter> filters = ephemeralApplication.getFilters();
// No filters; this should never happen.
if (filters.isEmpty()) {
continue;
}
if (packageName != null && !packageName.equals(ephemeralApplication.getPackageName())) {
continue;
}
// We have a domain match; resolve the filters to see if anything matches.
final EphemeralIntentResolver ephemeralResolver = new EphemeralIntentResolver();
for (int j = filters.size() - 1; j >= 0; --j) {
final EphemeralResolveIntentInfo intentInfo = new EphemeralResolveIntentInfo(filters.get(j), ephemeralApplication);
ephemeralResolver.addFilter(intentInfo);
}
List<EphemeralResolveInfo> matchedResolveInfoList = ephemeralResolver.queryIntent(intent, resolvedType, false, /*defaultOnly*/
userId);
if (!matchedResolveInfoList.isEmpty()) {
return matchedResolveInfoList.get(0);
}
}
}
// Hash or filter mis-match; no ephemeral apps for this domain.
return null;
}
Aggregations