what-the-bank/sources/com/huawei/hms/framework/common/check/ProviderCheckUtil.java

47 lines
1.9 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.huawei.hms.framework.common.check;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.net.Uri;
import com.huawei.hms.framework.common.ContextHolder;
import com.huawei.hms.framework.common.Logger;
import com.huawei.hms.support.api.entity.common.CommonConstant;
/* loaded from: classes2.dex */
public class ProviderCheckUtil {
private static final String TAG = "ProviderCheckUtil";
public static boolean isValid(Uri uri) {
if (uri == null) {
return false;
}
PackageManager packageManager = ContextHolder.getAppContext().getPackageManager();
ProviderInfo resolveContentProvider = packageManager.resolveContentProvider(uri.getAuthority(), 0);
if (resolveContentProvider == null || ComponentInfo.class.getField("applicationInfo").get(resolveContentProvider) == null) {
Logger.w(TAG, "Invalid param");
return false;
}
String str = (String) PackageItemInfo.class.getField(CommonConstant.ReqAccessTokenParam.PACKAGE_NAME).get(ComponentInfo.class.getField("applicationInfo").get(resolveContentProvider));
Logger.v(TAG, "Target provider service's package name is : ".concat(String.valueOf(str)));
if (str == null) {
Logger.w(TAG, "Invalid packageName");
return false;
}
return checkSignaturesMatch(packageManager, str);
}
private static boolean checkSignaturesMatch(PackageManager packageManager, String str) {
if (packageManager.checkSignatures("com.huawei.hwid", str) == 0) {
Logger.v(TAG, "Valid Provider");
return true;
}
if (packageManager.checkSignatures("com.huawei.hwid.tv", str) != 0) {
return false;
}
Logger.v(TAG, "Valid Provider in tv");
return true;
}
}