Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cdab35b8 authored by Varun Shah's avatar Varun Shah
Browse files

Throw an ANR if ContentProvider#getType takes too long.

If the transaction between the system server and the content provider
takes longer than the specified timeout, an ANR will be thrown to avoid
blocking.

Bug: 122243546
Test: atest AppSecurityTests
Change-Id: I5146938b07364cc0f5b703e18ab7cb2961946bf5
parent 4fc0de74
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -7569,7 +7569,25 @@ public class ActivityManagerService extends IActivityManager.Stub
            holder = getContentProviderExternalUnchecked(name, null, callingUid,
                    "*getmimetype*", userId);
            if (holder != null) {
                final IBinder providerConnection = holder.connection;
                final ComponentName providerName = holder.info.getComponentName();
                // Note: creating a new Runnable instead of using a lambda here since lambdas in
                // java provide no guarantee that there will be a new instance returned every call.
                // Hence, it's possible that a cached copy is returned and the ANR is executed on
                // the incorrect provider.
                final Runnable providerNotResponding = new Runnable() {
                    @Override
                    public void run() {
                        Log.w(TAG, "Provider " + providerName + " didn't return from getType().");
                        appNotRespondingViaProvider(providerConnection);
                    }
                };
                mHandler.postDelayed(providerNotResponding, 1000);
                try {
                    return holder.provider.getType(uri);
                } finally {
                    mHandler.removeCallbacks(providerNotResponding);
                }
            }
        } catch (RemoteException e) {
            Log.w(TAG, "Content provider dead retrieving " + uri, e);