Update Intent#resolveTypeIfNeeded() for intent filter matching

With the change ag/15315839, explicit intents also have to match the
declared intent filters. The existing implementation of
resolveTypeIfNeeded() assumes all explicit intents will always be
delivered and will skip resolving types for content:// uris. Update the
implementation to only skip resolution if the intent is bound to the
same app it was created, or the caller is either root or the system.

Bug: 196573010
Test: atest CtsContentTestCases:PackageManagerTest
Change-Id: Ic3b51c68fd971422242db42af35e13f691d65c07
This commit is contained in:
John Wu
2021-08-24 16:01:42 -07:00
parent 80908af683
commit 19da953ee1

View File

@@ -30,6 +30,7 @@ import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.app.ActivityThread;
import android.app.AppGlobals;
import android.bluetooth.BluetoothDevice;
import android.compat.annotation.UnsupportedAppUsage;
@@ -8281,7 +8282,10 @@ public class Intent implements Parcelable, Cloneable {
* needed.
*/
public @Nullable String resolveTypeIfNeeded(@NonNull ContentResolver resolver) {
if (mComponent != null) {
// Match logic in PackageManagerService#applyEnforceIntentFilterMatching(...)
if (mComponent != null && (Process.myUid() == Process.ROOT_UID
|| Process.myUid() == Process.SYSTEM_UID
|| mComponent.getPackageName().equals(ActivityThread.currentPackageName()))) {
return mType;
}
return resolveType(resolver);