alexandroid/decompiled/jadx/sources/com/google/firebase/components/ComponentDiscovery.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

137 lines
6 KiB
Java

package com.google.firebase.components;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.firebase.inject.Provider;
import defpackage.a$$ExternalSyntheticOutline0;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes8.dex */
public final class ComponentDiscovery<T> {
private static final String COMPONENT_KEY_PREFIX = "com.google.firebase.components:";
private static final String COMPONENT_SENTINEL_VALUE = "com.google.firebase.components.ComponentRegistrar";
static final String TAG = "ComponentDiscovery";
private final T context;
private final RegistrarNameRetriever<T> retriever;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static class MetadataRegistrarNameRetriever implements RegistrarNameRetriever<Context> {
private final Class<? extends Service> discoveryService;
private MetadataRegistrarNameRetriever(Class<? extends Service> cls) {
this.discoveryService = cls;
}
private Bundle getMetadata(Context context) {
try {
PackageManager packageManager = context.getPackageManager();
if (packageManager == null) {
Log.w(ComponentDiscovery.TAG, "Context has no PackageManager.");
return null;
}
ServiceInfo serviceInfo = packageManager.getServiceInfo(new ComponentName(context, this.discoveryService), 128);
if (serviceInfo != null) {
return serviceInfo.metaData;
}
Log.w(ComponentDiscovery.TAG, this.discoveryService + " has no service info.");
return null;
} catch (PackageManager.NameNotFoundException unused) {
Log.w(ComponentDiscovery.TAG, "Application info not found.");
return null;
}
}
@Override // com.google.firebase.components.ComponentDiscovery.RegistrarNameRetriever
public List<String> retrieve(Context context) {
Bundle metadata = getMetadata(context);
if (metadata == null) {
Log.w(ComponentDiscovery.TAG, "Could not retrieve metadata, returning empty list of registrars.");
return Collections.EMPTY_LIST;
}
ArrayList arrayList = new ArrayList();
for (String str : metadata.keySet()) {
if (ComponentDiscovery.COMPONENT_SENTINEL_VALUE.equals(metadata.get(str)) && str.startsWith(ComponentDiscovery.COMPONENT_KEY_PREFIX)) {
arrayList.add(str.substring(31));
}
}
return arrayList;
}
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@VisibleForTesting
public interface RegistrarNameRetriever<T> {
List<String> retrieve(T t);
}
@VisibleForTesting
public ComponentDiscovery(T t, RegistrarNameRetriever<T> registrarNameRetriever) {
this.context = t;
this.retriever = registrarNameRetriever;
}
public static ComponentDiscovery<Context> forContext(Context context, Class<? extends Service> cls) {
return new ComponentDiscovery<>(context, new MetadataRegistrarNameRetriever(cls));
}
/* JADX INFO: Access modifiers changed from: private */
@Nullable
public static ComponentRegistrar instantiate(String str) {
try {
Class<?> cls = Class.forName(str);
if (ComponentRegistrar.class.isAssignableFrom(cls)) {
return (ComponentRegistrar) cls.getDeclaredConstructor(null).newInstance(null);
}
throw new InvalidRegistrarException("Class " + str + " is not an instance of com.google.firebase.components.ComponentRegistrar");
} catch (ClassNotFoundException unused) {
Log.w(TAG, "Class " + str + " is not an found.");
return null;
} catch (IllegalAccessException e) {
throw new InvalidRegistrarException(a$$ExternalSyntheticOutline0.m("Could not instantiate ", str, "."), e);
} catch (InstantiationException e2) {
throw new InvalidRegistrarException(a$$ExternalSyntheticOutline0.m("Could not instantiate ", str, "."), e2);
} catch (NoSuchMethodException e3) {
throw new InvalidRegistrarException(a$$ExternalSyntheticOutline0.m("Could not instantiate ", str), e3);
} catch (InvocationTargetException e4) {
throw new InvalidRegistrarException(a$$ExternalSyntheticOutline0.m("Could not instantiate ", str), e4);
}
}
@Deprecated
public List<ComponentRegistrar> discover() {
ArrayList arrayList = new ArrayList();
Iterator<String> it2 = this.retriever.retrieve(this.context).iterator();
while (it2.hasNext()) {
try {
ComponentRegistrar instantiate = instantiate(it2.next());
if (instantiate != null) {
arrayList.add(instantiate);
}
} catch (InvalidRegistrarException e) {
Log.w(TAG, "Invalid component registrar.", e);
}
}
return arrayList;
}
public List<Provider<ComponentRegistrar>> discoverLazy() {
ArrayList arrayList = new ArrayList();
Iterator<String> it2 = this.retriever.retrieve(this.context).iterator();
while (it2.hasNext()) {
arrayList.add(new ComponentDiscovery$$ExternalSyntheticLambda0(it2.next(), 0));
}
return arrayList;
}
}