Media: Implement Seamless Transfer with a single provider.

Seamless transfer for a single provider case and two providers case
should be dealt with in different ways.

For a single provider case, the provider can handle transfer and returns
the result of transfer.

For multiple providers case, the media app handles the transfer.

This CL covers seamless transfer within a single provider.

If a user requests semless transfer in System UI, MR2Manager.selectRoute
should be called and this request is sent to MediaRoute2ProviderService
that can handle seamless transfer internally.

The new test, testSingleProviderSelect() in MediaRouterManagerTest tests the path for
seamless transfer and ensure transfer request is handled by a provider.

From this CL, we use packagename instead of uid to select app for seamless transfer.
This is required to handle unlaunched apps that don't have uid.
It would prevent to use media router 2 in a multi-user case, that will
be supported by another CL.

I also added onUnselectRoute in MediaRoute2ProviderService, which is
essential to notify a provider that a media app stopped casting.

Bug: 136775407
Test: atest mediaroutertest

Change-Id: Ie3d0e988a72eedea6036f465454e661c424a0495
diff --git a/media/tests/MediaRouteProvider/src/com/android/mediarouteprovider/example/SampleMediaRoute2ProviderService.java b/media/tests/MediaRouteProvider/src/com/android/mediarouteprovider/example/SampleMediaRoute2ProviderService.java
index 21cb93d..2cdc6a8 100644
--- a/media/tests/MediaRouteProvider/src/com/android/mediarouteprovider/example/SampleMediaRoute2ProviderService.java
+++ b/media/tests/MediaRouteProvider/src/com/android/mediarouteprovider/example/SampleMediaRoute2ProviderService.java
@@ -59,8 +59,26 @@
     }
 
     @Override
-    public void onSelect(int uid, String routeId) {
-        updateProvider(uid, routeId);
+    public void onSelectRoute(String packageName, String routeId) {
+        MediaRoute2Info route = mRoutes.get(routeId);
+        if (route == null) {
+            return;
+        }
+        mRoutes.put(routeId, new MediaRoute2Info.Builder(route)
+                .setClientPackageName(packageName)
+                .build());
+        publishRoutes();
+    }
+
+    @Override
+    public void onUnselectRoute(String packageName, String routeId) {
+        MediaRoute2Info route = mRoutes.get(routeId);
+        if (route == null) {
+            return;
+        }
+        mRoutes.put(routeId, new MediaRoute2Info.Builder(route)
+                .setClientPackageName(null)
+                .build());
         publishRoutes();
     }