Fix ClassCastException in WatchedIntentResolver
Bug: 187691893 IntentResolver.sortResults() is a generic method that assumes its argument is a List<IntentFilter>, although this is not explicit in the data types. The assumption fails in WatchedIntentResolver, which is actually holding List<WatchedIntentFilter>. The change follows the same path as server/firewall/IntentFirewall: sortResults() is overridden in WatchedIntentResolver to accept the proper type. While we are at it, we force the class parameters in WatchedIntentResolver to be WatchedIntentFilter (because that is always true). This means no casting is required to support sortResults(). Finally, WatchedIntentResolver is moved into the server.pm package, where it is actually used. Should the need arise, it can be elevated back to the server package. Test: atest * CtsContentTestCases:IntentFilterTest * CtsDynamicMimeHostTestCases * FrameworksServicesTests:AppsFilterTest Change-Id: Id1546c6711f95e0970c018b0e54cad7f3a8ac4b7
This commit is contained in:
@@ -19,7 +19,6 @@ package com.android.server.pm;
|
||||
import android.annotation.NonNull;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import com.android.server.WatchedIntentResolver;
|
||||
import com.android.server.utils.Snappable;
|
||||
import com.android.server.utils.SnapshotCache;
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.android.server.pm;
|
||||
import android.annotation.NonNull;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import com.android.server.WatchedIntentResolver;
|
||||
import com.android.server.utils.Snappable;
|
||||
import com.android.server.utils.SnapshotCache;
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.android.server.pm;
|
||||
import android.annotation.NonNull;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import com.android.server.WatchedIntentResolver;
|
||||
import com.android.server.utils.Snappable;
|
||||
import com.android.server.utils.SnapshotCache;
|
||||
|
||||
|
||||
@@ -14,18 +14,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server;
|
||||
package com.android.server.pm;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
|
||||
import com.android.server.pm.WatchedIntentFilter;
|
||||
import com.android.server.IntentResolver;
|
||||
import com.android.server.utils.Snappable;
|
||||
import com.android.server.utils.Watchable;
|
||||
import com.android.server.utils.WatchableImpl;
|
||||
import com.android.server.utils.Watcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -34,7 +36,8 @@ import java.util.List;
|
||||
* @param <R> The resolver type.
|
||||
* {@hide}
|
||||
*/
|
||||
public abstract class WatchedIntentResolver<F extends Watchable, R extends Object>
|
||||
public abstract class WatchedIntentResolver<F extends WatchedIntentFilter,
|
||||
R extends WatchedIntentFilter>
|
||||
extends IntentResolver<F, R>
|
||||
implements Watchable, Snappable {
|
||||
|
||||
@@ -116,11 +119,21 @@ public abstract class WatchedIntentResolver<F extends Watchable, R extends Objec
|
||||
onChanged();
|
||||
}
|
||||
|
||||
// Sorts a List of IntentFilter objects into descending priority order.
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Comparator<WatchedIntentFilter> sResolvePrioritySorter =
|
||||
new Comparator<>() {
|
||||
public int compare(WatchedIntentFilter o1, WatchedIntentFilter o2) {
|
||||
final int q1 = o1.getPriority();
|
||||
final int q2 = o2.getPriority();
|
||||
return (q1 > q2) ? -1 : ((q1 < q2) ? 1 : 0);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void sortResults(List<R> results) {
|
||||
super.sortResults(results);
|
||||
onChanged();
|
||||
Collections.sort(results, sResolvePrioritySorter);
|
||||
}
|
||||
|
||||
/**
|
||||
Reference in New Issue
Block a user