Search in sources :

Example 11 with WifiDisplay

use of android.hardware.display.WifiDisplay in project android_frameworks_base by ParanoidAndroid.

the class MediaRouter method selectRouteStatic.

static void selectRouteStatic(int types, RouteInfo route) {
    final RouteInfo oldRoute = sStatic.mSelectedRoute;
    if (oldRoute == route)
        return;
    if ((route.getSupportedTypes() & types) == 0) {
        Log.w(TAG, "selectRoute ignored; cannot select route with supported types " + typesToString(route.getSupportedTypes()) + " into route types " + typesToString(types));
        return;
    }
    final RouteInfo btRoute = sStatic.mBluetoothA2dpRoute;
    if (btRoute != null && (types & ROUTE_TYPE_LIVE_AUDIO) != 0 && (route == btRoute || route == sStatic.mDefaultAudioVideo)) {
        try {
            sStatic.mAudioService.setBluetoothA2dpOn(route == btRoute);
        } catch (RemoteException e) {
            Log.e(TAG, "Error changing Bluetooth A2DP state", e);
        }
    }
    final WifiDisplay activeDisplay = sStatic.mDisplayService.getWifiDisplayStatus().getActiveDisplay();
    final boolean oldRouteHasAddress = oldRoute != null && oldRoute.mDeviceAddress != null;
    final boolean newRouteHasAddress = route != null && route.mDeviceAddress != null;
    if (activeDisplay != null || oldRouteHasAddress || newRouteHasAddress) {
        if (newRouteHasAddress && !matchesDeviceAddress(activeDisplay, route)) {
            sStatic.mDisplayService.connectWifiDisplay(route.mDeviceAddress);
        } else if (activeDisplay != null && !newRouteHasAddress) {
            sStatic.mDisplayService.disconnectWifiDisplay();
        }
    }
    if (oldRoute != null) {
        dispatchRouteUnselected(types & oldRoute.getSupportedTypes(), oldRoute);
    }
    sStatic.mSelectedRoute = route;
    if (route != null) {
        dispatchRouteSelected(types & route.getSupportedTypes(), route);
    }
}
Also used : WifiDisplay(android.hardware.display.WifiDisplay) RemoteException(android.os.RemoteException)

Example 12 with WifiDisplay

use of android.hardware.display.WifiDisplay in project android_frameworks_base by ResurrectionRemix.

the class MediaRouter method selectRouteStatic.

static void selectRouteStatic(int types, @NonNull RouteInfo route, boolean explicit) {
    Log.v(TAG, "Selecting route: " + route);
    assert (route != null);
    final RouteInfo oldRoute = sStatic.mSelectedRoute;
    if (oldRoute == route)
        return;
    if (!route.matchesTypes(types)) {
        Log.w(TAG, "selectRoute ignored; cannot select route with supported types " + typesToString(route.getSupportedTypes()) + " into route types " + typesToString(types));
        return;
    }
    final RouteInfo btRoute = sStatic.mBluetoothA2dpRoute;
    if (btRoute != null && (types & ROUTE_TYPE_LIVE_AUDIO) != 0 && (route == btRoute || route == sStatic.mDefaultAudioVideo)) {
        try {
            sStatic.mAudioService.setBluetoothA2dpOn(route == btRoute);
        } catch (RemoteException e) {
            Log.e(TAG, "Error changing Bluetooth A2DP state", e);
        }
    }
    final WifiDisplay activeDisplay = sStatic.mDisplayService.getWifiDisplayStatus().getActiveDisplay();
    final boolean oldRouteHasAddress = oldRoute != null && oldRoute.mDeviceAddress != null;
    final boolean newRouteHasAddress = route.mDeviceAddress != null;
    if (activeDisplay != null || oldRouteHasAddress || newRouteHasAddress) {
        if (newRouteHasAddress && !matchesDeviceAddress(activeDisplay, route)) {
            if (sStatic.mCanConfigureWifiDisplays) {
                sStatic.mDisplayService.connectWifiDisplay(route.mDeviceAddress);
            } else {
                Log.e(TAG, "Cannot connect to wifi displays because this process " + "is not allowed to do so.");
            }
        } else if (activeDisplay != null && !newRouteHasAddress) {
            sStatic.mDisplayService.disconnectWifiDisplay();
        }
    }
    sStatic.setSelectedRoute(route, explicit);
    if (oldRoute != null) {
        dispatchRouteUnselected(types & oldRoute.getSupportedTypes(), oldRoute);
        if (oldRoute.resolveStatusCode()) {
            dispatchRouteChanged(oldRoute);
        }
    }
    if (route != null) {
        if (route.resolveStatusCode()) {
            dispatchRouteChanged(route);
        }
        dispatchRouteSelected(types & route.getSupportedTypes(), route);
    }
    // The behavior of active scans may depend on the currently selected route.
    sStatic.updateDiscoveryRequest();
}
Also used : WifiDisplay(android.hardware.display.WifiDisplay) RemoteException(android.os.RemoteException)

Example 13 with WifiDisplay

use of android.hardware.display.WifiDisplay in project android_frameworks_base by ResurrectionRemix.

the class MediaRouter method updateWifiDisplayStatus.

static void updateWifiDisplayStatus(WifiDisplayStatus status) {
    WifiDisplay[] displays;
    WifiDisplay activeDisplay;
    if (status.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_ON) {
        displays = status.getDisplays();
        activeDisplay = status.getActiveDisplay();
        // Filter the list down to just the active display.
        if (!sStatic.mCanConfigureWifiDisplays) {
            if (activeDisplay != null) {
                displays = new WifiDisplay[] { activeDisplay };
            } else {
                displays = WifiDisplay.EMPTY_ARRAY;
            }
        }
    } else {
        displays = WifiDisplay.EMPTY_ARRAY;
        activeDisplay = null;
    }
    String activeDisplayAddress = activeDisplay != null ? activeDisplay.getDeviceAddress() : null;
    // Add or update routes.
    for (int i = 0; i < displays.length; i++) {
        final WifiDisplay d = displays[i];
        if (shouldShowWifiDisplay(d, activeDisplay)) {
            RouteInfo route = findWifiDisplayRoute(d);
            if (route == null) {
                route = makeWifiDisplayRoute(d, status);
                addRouteStatic(route);
            } else {
                String address = d.getDeviceAddress();
                boolean disconnected = !address.equals(activeDisplayAddress) && address.equals(sStatic.mPreviousActiveWifiDisplayAddress);
                updateWifiDisplayRoute(route, d, status, disconnected);
            }
            if (d.equals(activeDisplay)) {
                selectRouteStatic(route.getSupportedTypes(), route, false);
            }
        }
    }
    // Remove stale routes.
    for (int i = sStatic.mRoutes.size(); i-- > 0; ) {
        RouteInfo route = sStatic.mRoutes.get(i);
        if (route.mDeviceAddress != null) {
            WifiDisplay d = findWifiDisplay(displays, route.mDeviceAddress);
            if (d == null || !shouldShowWifiDisplay(d, activeDisplay)) {
                removeRouteStatic(route);
            }
        }
    }
    // Remember the current active wifi display address so that we can infer disconnections.
    // TODO: This hack will go away once all of this is moved into the media router service.
    sStatic.mPreviousActiveWifiDisplayAddress = activeDisplayAddress;
}
Also used : WifiDisplay(android.hardware.display.WifiDisplay)

Example 14 with WifiDisplay

use of android.hardware.display.WifiDisplay in project android_frameworks_base by ResurrectionRemix.

the class WifiDisplayAdapter method requestRenameLocked.

public void requestRenameLocked(String address, String alias) {
    if (DEBUG) {
        Slog.d(TAG, "requestRenameLocked: address=" + address + ", alias=" + alias);
    }
    if (alias != null) {
        alias = alias.trim();
        if (alias.isEmpty() || alias.equals(address)) {
            alias = null;
        }
    }
    WifiDisplay display = mPersistentDataStore.getRememberedWifiDisplay(address);
    if (display != null && !Objects.equal(display.getDeviceAlias(), alias)) {
        display = new WifiDisplay(address, display.getDeviceName(), alias, false, false, false);
        if (mPersistentDataStore.rememberWifiDisplay(display)) {
            mPersistentDataStore.saveIfNeeded();
            updateRememberedDisplaysLocked();
            scheduleStatusChangedBroadcastLocked();
        }
    }
    if (mActiveDisplay != null && mActiveDisplay.getDeviceAddress().equals(address)) {
        renameDisplayDeviceLocked(mActiveDisplay.getFriendlyDisplayName());
    }
}
Also used : WifiDisplay(android.hardware.display.WifiDisplay)

Example 15 with WifiDisplay

use of android.hardware.display.WifiDisplay in project android_frameworks_base by ResurrectionRemix.

the class WifiDisplayController method advertiseDisplay.

private void advertiseDisplay(final WifiDisplay display, final Surface surface, final int width, final int height, final int flags) {
    if (!Objects.equal(mAdvertisedDisplay, display) || mAdvertisedDisplaySurface != surface || mAdvertisedDisplayWidth != width || mAdvertisedDisplayHeight != height || mAdvertisedDisplayFlags != flags) {
        final WifiDisplay oldDisplay = mAdvertisedDisplay;
        final Surface oldSurface = mAdvertisedDisplaySurface;
        mAdvertisedDisplay = display;
        mAdvertisedDisplaySurface = surface;
        mAdvertisedDisplayWidth = width;
        mAdvertisedDisplayHeight = height;
        mAdvertisedDisplayFlags = flags;
        mHandler.post(new Runnable() {

            @Override
            public void run() {
                if (oldSurface != null && surface != oldSurface) {
                    mListener.onDisplayDisconnected();
                } else if (oldDisplay != null && !oldDisplay.hasSameAddress(display)) {
                    mListener.onDisplayConnectionFailed();
                }
                if (display != null) {
                    if (!display.hasSameAddress(oldDisplay)) {
                        mListener.onDisplayConnecting(display);
                    } else if (!display.equals(oldDisplay)) {
                        // The address is the same but some other property such as the
                        // name must have changed.
                        mListener.onDisplayChanged(display);
                    }
                    if (surface != null && surface != oldSurface) {
                        mListener.onDisplayConnected(display, surface, width, height, flags);
                    }
                }
            }
        });
    }
}
Also used : WifiDisplay(android.hardware.display.WifiDisplay) Surface(android.view.Surface)

Aggregations

WifiDisplay (android.hardware.display.WifiDisplay)77 WifiP2pDevice (android.net.wifi.p2p.WifiP2pDevice)12 Surface (android.view.Surface)12 HashMap (java.util.HashMap)10 Map (java.util.Map)10 WpsInfo (android.net.wifi.WpsInfo)6 WifiP2pConfig (android.net.wifi.p2p.WifiP2pConfig)6 ActionListener (android.net.wifi.p2p.WifiP2pManager.ActionListener)6 GroupInfoListener (android.net.wifi.p2p.WifiP2pManager.GroupInfoListener)6 PeerListListener (android.net.wifi.p2p.WifiP2pManager.PeerListListener)6 RemoteException (android.os.RemoteException)6 Inet4Address (java.net.Inet4Address)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 ArrayList (java.util.ArrayList)5 RemoteDisplay (android.media.RemoteDisplay)3 StackTraceElement (java.lang.StackTraceElement)3 WifiDisplayStatus (android.hardware.display.WifiDisplayStatus)1 MediaRouter (android.media.MediaRouter)1 RouteInfo (android.media.MediaRouter.RouteInfo)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1