Fix unintended preferred activity reset

When the preferred handler of an action is saved with "always", the set
of components displayed as options to the user are saved with it. On
subsequent queries, if that set of components change, the preference is
cleared to allow the user to consider the new set. With the introduction
of app visibility filtering in R (and to a lesser extent, Instant Apps
in O), the set of apps that an app can see may be less than the set that
the system can. As a result, if the caller calls resolveIntent and
cannot see all of the apps the system can, it may reset the user
preference unexpectedly.

This change ensures that before we clear the user preference that we're
comparing against the full set of apps. As such, if we encounter a call
to the method from an app that cannot see all apps, we avoid any
mutations and instead just return the set of apps that the user can see
or the preferred app if it's part of the set they can see. If the system
calls or if the call is part of an activity start, we'll allow reset of
the preference.

Test: Manual - Install 3 cameras, verify preference only reset on start
Fixes: 157548344
Change-Id: Icb50a66500edba26c4c6c3e80a6a9c544d4d63d6
1 file changed