Fixing tests failure due to unhandled exceptions

Bug: b/270035611, b/270097730
Test: CtsAppEnumerationTestCases, ContactsProviderTests
Change-Id: I32fad70110477fc2376eb15d4843b86a2245edd4
This commit is contained in:
Ashish Kumar
2023-02-21 13:58:42 +00:00
committed by Ashish Kumar Gaurav
parent b62d832a20
commit 22047a39a5
2 changed files with 16 additions and 10 deletions

View File

@@ -342,15 +342,16 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall
final int enumCheckUriPermission =
GET_TYPE_ACCESSED_WITHOUT_PERMISSION__LOCATION__PROVIDER_CHECK_URI_PERMISSION;
if (permissionCheckPassed) {
// Just for logging for mediaProvider cases
final ProviderInfo cpi = mContext.getPackageManager()
.resolveContentProvider(uri.getAuthority(),
PackageManager.ComponentInfoFlags.of(PackageManager.GET_META_DATA));
final int callingUserId = UserHandle.getUserId(callingUid);
final Uri userUri = (mSingleUser
&& !UserHandle.isSameUser(mMyUid, callingUid))
? maybeAddUserId(uri, callingUserId) : uri;
try {
// Just for logging for mediaProvider cases
final ProviderInfo cpi = mContext.getPackageManager()
.resolveContentProvider(uri.getAuthority(),
PackageManager.ComponentInfoFlags.of(
PackageManager.GET_META_DATA));
final int callingUserId = UserHandle.getUserId(callingUid);
final Uri userUri = (mSingleUser
&& !UserHandle.isSameUser(mMyUid, callingUid))
? maybeAddUserId(uri, callingUserId) : uri;
if (cpi.forceUriPermissions
&& mInterface.checkUriPermission(uri,
callingUid, Intent.FLAG_GRANT_READ_URI_PERMISSION)

View File

@@ -930,7 +930,8 @@ public abstract class ContentResolver implements ContentInterface {
if (provider != null) {
try {
final StringResultListener resultListener = new StringResultListener();
provider.getTypeAsync(url, new RemoteCallback(resultListener));
provider.getTypeAsync(mContext.getAttributionSource(),
url, new RemoteCallback(resultListener));
resultListener.waitForResult(CONTENT_PROVIDER_TIMEOUT_MILLIS);
if (resultListener.exception != null) {
throw resultListener.exception;
@@ -944,7 +945,11 @@ public abstract class ContentResolver implements ContentInterface {
Log.w(TAG, "Failed to get type for: " + url + " (" + e.getMessage() + ")");
return null;
} finally {
releaseProvider(provider);
try {
releaseProvider(provider);
} catch (java.lang.NullPointerException e) {
// does nothing, Binder connection already null
}
}
}