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

Commit a83d26df authored by Narayan Kamath's avatar Narayan Kamath Committed by Android (Google) Code Review
Browse files

Merge "CastTile: stop active projection (if any) on tile clicks"

parents 36437d7d f60a6271
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.media.MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.media.projection.MediaProjectionInfo;
import android.provider.Settings;
import android.service.quicksettings.Tile;
import android.util.Log;
@@ -125,7 +126,30 @@ public class CastTile extends QSTileImpl<BooleanState> {
            });
            return;
        }

        CastDevice activeProjection = getActiveDeviceMediaProjection();
        if (activeProjection == null) {
            showDetail(true);
        } else {
            mController.stopCasting(activeProjection);
        }
    }

    private CastDevice getActiveDeviceMediaProjection() {
        CastDevice activeDevice = null;
        for (CastDevice device : mController.getCastDevices()) {
            if (device.state == CastDevice.STATE_CONNECTED
                    || device.state == CastDevice.STATE_CONNECTING) {
                activeDevice = device;
                break;
            }
        }

        if (activeDevice != null && activeDevice.tag instanceof MediaProjectionInfo) {
            return activeDevice;
        }

        return null;
    }

    @Override