Repo Created
This commit is contained in:
parent
eb305e2886
commit
a8c22c65db
4784 changed files with 329907 additions and 2 deletions
56
play-services-cast-framework/core/build.gradle
Normal file
56
play-services-cast-framework/core/build.gradle
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
|
||||
dependencies {
|
||||
implementation project(':play-services-cast-framework')
|
||||
implementation project(':play-services-base-core')
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutineVersion"
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "org.microg.gms.cast.framework.core"
|
||||
|
||||
compileSdkVersion androidCompileSdk
|
||||
buildToolsVersion "$androidBuildVersionTools"
|
||||
|
||||
defaultConfig {
|
||||
versionName version
|
||||
minSdkVersion androidMinSdk
|
||||
targetSdkVersion androidTargetSdk
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
dataBinding = true
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
disable 'MissingTranslation'
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = 1.8
|
||||
}
|
||||
}
|
||||
|
||||
apply from: '../../gradle/publish-android.gradle'
|
||||
|
||||
description = 'microG service implementation for play-services-cast-framework'
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ SPDX-FileCopyrightText: 2022 microG Project Team
|
||||
~ SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Copyright (C) 2013-2017 microG Project Team
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.cast.framework.internal;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.mediarouter.media.MediaControlIntent;
|
||||
import androidx.mediarouter.media.MediaRouteSelector;
|
||||
|
||||
import com.google.android.gms.cast.CastMediaControlIntent;
|
||||
import com.google.android.gms.cast.framework.CastOptions;
|
||||
import com.google.android.gms.cast.framework.IAppVisibilityListener;
|
||||
import com.google.android.gms.cast.framework.ICastContext;
|
||||
import com.google.android.gms.cast.framework.IDiscoveryManager;
|
||||
import com.google.android.gms.cast.framework.ISessionManager;
|
||||
import com.google.android.gms.cast.framework.ISessionProvider;
|
||||
import com.google.android.gms.dynamic.IObjectWrapper;
|
||||
import com.google.android.gms.dynamic.ObjectWrapper;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CastContextImpl extends ICastContext.Stub {
|
||||
private static final String TAG = CastContextImpl.class.getSimpleName();
|
||||
|
||||
private SessionManagerImpl sessionManager;
|
||||
private DiscoveryManagerImpl discoveryManager;
|
||||
|
||||
private Context context;
|
||||
private CastOptions options;
|
||||
private IMediaRouter router;
|
||||
private Map<String, ISessionProvider> sessionProviders = new HashMap<String, ISessionProvider>();
|
||||
public ISessionProvider defaultSessionProvider;
|
||||
|
||||
private MediaRouteSelector mergedSelector;
|
||||
|
||||
public CastContextImpl(IObjectWrapper context, CastOptions options, IMediaRouter router, Map<String, IBinder> sessionProviders) throws RemoteException {
|
||||
this.context = (Context) ObjectWrapper.unwrap(context);
|
||||
this.options = options;
|
||||
this.router = router;
|
||||
for (Map.Entry<String, IBinder> entry : sessionProviders.entrySet()) {
|
||||
this.sessionProviders.put(entry.getKey(), ISessionProvider.Stub.asInterface(entry.getValue()));
|
||||
}
|
||||
|
||||
String receiverApplicationId = options.getReceiverApplicationId();
|
||||
String defaultCategory = CastMediaControlIntent.categoryForCast(receiverApplicationId);
|
||||
|
||||
this.defaultSessionProvider = this.sessionProviders.get(defaultCategory);
|
||||
|
||||
// TODO: This should incorporate passed options
|
||||
this.mergedSelector = new MediaRouteSelector.Builder()
|
||||
.addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
|
||||
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
|
||||
.addControlCategory(defaultCategory)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle getMergedSelectorAsBundle() throws RemoteException {
|
||||
return this.mergedSelector.asBundle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVisibilityChangeListener(IAppVisibilityListener listener) {
|
||||
Log.d(TAG, "unimplemented Method: addVisibilityChangeListener");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeVisibilityChangeListener(IAppVisibilityListener listener) {
|
||||
Log.d(TAG, "unimplemented Method: removeVisibilityChangeListener");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicationVisible() throws RemoteException {
|
||||
Log.d(TAG, "unimplemented Method: isApplicationVisible");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionManagerImpl getSessionManagerImpl() {
|
||||
if (this.sessionManager == null) {
|
||||
this.sessionManager = new SessionManagerImpl(this);
|
||||
}
|
||||
return this.sessionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDiscoveryManager getDiscoveryManagerImpl() throws RemoteException {
|
||||
if (this.discoveryManager == null) {
|
||||
this.discoveryManager = new DiscoveryManagerImpl(this);
|
||||
}
|
||||
return this.discoveryManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws RemoteException {
|
||||
Log.d(TAG, "unimplemented Method: destroy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(IObjectWrapper activity) throws RemoteException {
|
||||
Log.d(TAG, "unimplemented Method: onActivityResumed");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(IObjectWrapper activity) throws RemoteException {
|
||||
Log.d(TAG, "unimplemented Method: onActivityPaused");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReceiverApplicationId(String receiverApplicationId, Map sessionProvidersByCategory) throws RemoteException {
|
||||
Log.d(TAG, "unimplemented Method: setReceiverApplicationId");
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return this.context;
|
||||
}
|
||||
|
||||
public IMediaRouter getRouter() {
|
||||
return this.router;
|
||||
}
|
||||
|
||||
public MediaRouteSelector getMergedSelector() {
|
||||
return this.mergedSelector;
|
||||
}
|
||||
|
||||
public CastOptions getOptions() {
|
||||
return this.options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectWrapper getWrappedThis() throws RemoteException {
|
||||
return ObjectWrapper.wrap(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (C) 2013-2017 microG Project Team
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.cast.framework.internal;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.cast.framework.CastOptions;
|
||||
import com.google.android.gms.cast.framework.ICastConnectionController;
|
||||
import com.google.android.gms.cast.framework.ICastContext;
|
||||
import com.google.android.gms.cast.framework.ICastSession;
|
||||
import com.google.android.gms.cast.framework.IReconnectionService;
|
||||
import com.google.android.gms.cast.framework.ISession;
|
||||
import com.google.android.gms.cast.framework.ISessionProxy;
|
||||
import com.google.android.gms.cast.framework.media.CastMediaOptions;
|
||||
import com.google.android.gms.cast.framework.internal.CastContextImpl;
|
||||
import com.google.android.gms.cast.framework.internal.CastSessionImpl;
|
||||
import com.google.android.gms.cast.framework.internal.MediaRouterCallbackImpl;
|
||||
import com.google.android.gms.cast.framework.internal.SessionImpl;
|
||||
import com.google.android.gms.cast.framework.media.IMediaNotificationService;
|
||||
import com.google.android.gms.cast.framework.media.internal.IFetchBitmapTask;
|
||||
import com.google.android.gms.cast.framework.media.internal.IFetchBitmapTaskProgressPublisher;
|
||||
import com.google.android.gms.dynamic.IObjectWrapper;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CastDynamiteModuleImpl extends ICastDynamiteModule.Stub {
|
||||
private static final String TAG = CastDynamiteModuleImpl.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public ICastContext newCastContextImpl(IObjectWrapper context, CastOptions options, IMediaRouter router, Map sessionProviders) throws RemoteException {
|
||||
return new CastContextImpl(context, options, router, sessionProviders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISession newSessionImpl(String category, String sessionId, ISessionProxy proxy) throws RemoteException {
|
||||
return new SessionImpl(category, sessionId, proxy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICastSession newCastSessionImpl(CastOptions options, IObjectWrapper session, ICastConnectionController controller) throws RemoteException {
|
||||
return new CastSessionImpl(options, session, controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMediaNotificationService newMediaNotificationServiceImpl(IObjectWrapper service, IObjectWrapper castContext, IObjectWrapper resources, CastMediaOptions options) throws RemoteException {
|
||||
Log.d(TAG, "unimplemented Method: newMediaNotificationServiceImpl");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IReconnectionService newReconnectionServiceImpl(IObjectWrapper service, IObjectWrapper sessionManager, IObjectWrapper discoveryManager) throws RemoteException {
|
||||
Log.d(TAG, "unimplemented Method: newReconnectionServiceImpl");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFetchBitmapTask newFetchBitmapTaskImpl(IObjectWrapper asyncTask, IFetchBitmapTaskProgressPublisher progressPublisher, int i1, int i2, boolean b1, long l1, int i3, int i4, int i5) throws RemoteException {
|
||||
Log.d(TAG, "unimplemented Method: newFetchBitmapTaskImpl");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (C) 2013-2017 microG Project Team
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.cast.framework.internal;
|
||||
|
||||
import com.google.android.gms.cast.framework.ICastSession;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.cast.ApplicationMetadata;
|
||||
import com.google.android.gms.cast.framework.CastOptions;
|
||||
import com.google.android.gms.cast.framework.ICastConnectionController;
|
||||
import com.google.android.gms.common.api.Status;
|
||||
import com.google.android.gms.dynamic.IObjectWrapper;
|
||||
import com.google.android.gms.dynamic.ObjectWrapper;
|
||||
|
||||
public class CastSessionImpl extends ICastSession.Stub {
|
||||
private static final String TAG = CastSessionImpl.class.getSimpleName();
|
||||
private CastOptions options;
|
||||
private SessionImpl session;
|
||||
private ICastConnectionController controller;
|
||||
|
||||
public CastSessionImpl(CastOptions options, IObjectWrapper session, ICastConnectionController controller) throws RemoteException {
|
||||
this.options = options;
|
||||
this.session = (SessionImpl) ObjectWrapper.unwrap(session);
|
||||
this.controller = controller;
|
||||
|
||||
this.session.setCastSession(this);
|
||||
}
|
||||
|
||||
public void launchApplication() throws RemoteException {
|
||||
this.controller.launchApplication(this.options.getReceiverApplicationId(), this.options.getLaunchOptions());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(Bundle routeInfoExtra) throws RemoteException {
|
||||
this.controller.launchApplication(this.options.getReceiverApplicationId(), this.options.getLaunchOptions());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionSuspended(int reason) {
|
||||
Log.d(TAG, "unimplemented Method: onConnectionSuspended");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionFailed(Status status) {
|
||||
Log.d(TAG, "unimplemented Method: onConnectionFailed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationConnectionSuccess(ApplicationMetadata applicationMetadata, String applicationStatus, String sessionId, boolean wasLaunched) {
|
||||
this.session.onApplicationConnectionSuccess(applicationMetadata, applicationStatus, sessionId, wasLaunched);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationConnectionFailure(int statusCode) {
|
||||
this.session.onApplicationConnectionFailure(statusCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnectFromDevice(boolean boolean1, int int1) {
|
||||
Log.d(TAG, "unimplemented Method: disconnectFromDevice");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (C) 2013-2017 microG Project Team
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.cast.framework.internal;
|
||||
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.cast.framework.IDiscoveryManager;
|
||||
import com.google.android.gms.cast.framework.IDiscoveryManagerListener;
|
||||
import com.google.android.gms.cast.framework.internal.CastContextImpl;
|
||||
import com.google.android.gms.dynamic.IObjectWrapper;
|
||||
import com.google.android.gms.dynamic.ObjectWrapper;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class DiscoveryManagerImpl extends IDiscoveryManager.Stub {
|
||||
private static final String TAG = DiscoveryManagerImpl.class.getSimpleName();
|
||||
|
||||
private CastContextImpl castContextImpl;
|
||||
|
||||
private Set discoveryManagerListeners = new HashSet();
|
||||
|
||||
public DiscoveryManagerImpl(CastContextImpl castContextImpl) {
|
||||
this.castContextImpl = castContextImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDiscovery() {
|
||||
Log.d(TAG, "unimplemented Method: startDiscovery");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopDiscovery() {
|
||||
Log.d(TAG, "unimplemented Method: stopDiscovery");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDiscoveryManagerListener(IDiscoveryManagerListener listener) {
|
||||
Log.d(TAG, "unimplemented Method: addDiscoveryManagerListener");
|
||||
this.discoveryManagerListeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDiscoveryManagerListener(IDiscoveryManagerListener listener) {
|
||||
Log.d(TAG, "unimplemented Method: removeDiscoveryManagerListener");
|
||||
this.discoveryManagerListeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectWrapper getWrappedThis() throws RemoteException {
|
||||
return ObjectWrapper.wrap(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (C) 2013-2017 microG Project Team
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.cast.framework.internal;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.cast.CastDevice;
|
||||
import com.google.android.gms.cast.framework.ISession;
|
||||
import com.google.android.gms.dynamic.IObjectWrapper;
|
||||
import com.google.android.gms.dynamic.ObjectWrapper;
|
||||
|
||||
public class MediaRouterCallbackImpl extends IMediaRouterCallback.Stub {
|
||||
private static final String TAG = MediaRouterCallbackImpl.class.getSimpleName();
|
||||
|
||||
private CastContextImpl castContext;
|
||||
|
||||
public MediaRouterCallbackImpl(CastContextImpl castContext) {
|
||||
this.castContext = castContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRouteAdded(String routeId, Bundle extras) {
|
||||
Log.d(TAG, "unimplemented Method: onRouteAdded");
|
||||
}
|
||||
@Override
|
||||
public void onRouteChanged(String routeId, Bundle extras) {
|
||||
Log.d(TAG, "unimplemented Method: onRouteChanged");
|
||||
}
|
||||
@Override
|
||||
public void onRouteRemoved(String routeId, Bundle extras) {
|
||||
Log.d(TAG, "unimplemented Method: onRouteRemoved");
|
||||
}
|
||||
@Override
|
||||
public void onRouteSelected(String routeId, Bundle extras) throws RemoteException {
|
||||
CastDevice castDevice = CastDevice.getFromBundle(extras);
|
||||
|
||||
SessionImpl session = (SessionImpl) ObjectWrapper.unwrap(this.castContext.defaultSessionProvider.getSession(null));
|
||||
Bundle routeInfoExtras = this.castContext.getRouter().getRouteInfoExtrasById(routeId);
|
||||
if (routeInfoExtras != null) {
|
||||
session.start(this.castContext, castDevice, routeId, routeInfoExtras);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void unknown(String routeId, Bundle extras) {
|
||||
Log.d(TAG, "unimplemented Method: unknown");
|
||||
}
|
||||
@Override
|
||||
public void onRouteUnselected(String routeId, Bundle extras, int reason) {
|
||||
Log.d(TAG, "unimplemented Method: onRouteUnselected");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
* Copyright (C) 2013-2017 microG Project Team
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.cast.framework.internal;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import com.google.android.gms.cast.ApplicationMetadata;
|
||||
import com.google.android.gms.cast.CastDevice;
|
||||
import com.google.android.gms.cast.framework.ISession;
|
||||
import com.google.android.gms.cast.framework.ISessionProxy;
|
||||
import com.google.android.gms.dynamic.IObjectWrapper;
|
||||
import com.google.android.gms.dynamic.ObjectWrapper;
|
||||
|
||||
public class SessionImpl extends ISession.Stub {
|
||||
private static final String TAG = SessionImpl.class.getSimpleName();
|
||||
|
||||
private String category;
|
||||
private String sessionId;
|
||||
private ISessionProxy proxy;
|
||||
|
||||
private CastSessionImpl castSession;
|
||||
|
||||
private CastContextImpl castContext;
|
||||
private CastDevice castDevice;
|
||||
private Bundle routeInfoExtra;
|
||||
|
||||
private boolean mIsConnecting = false;
|
||||
private boolean mIsConnected = false;
|
||||
private String routeId = null;
|
||||
|
||||
public SessionImpl(String category, String sessionId, ISessionProxy proxy) {
|
||||
this.category = category;
|
||||
this.sessionId = sessionId;
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
public void start(CastContextImpl castContext, CastDevice castDevice, String routeId, Bundle routeInfoExtra) throws RemoteException {
|
||||
this.castContext = castContext;
|
||||
this.castDevice = castDevice;
|
||||
this.routeInfoExtra = routeInfoExtra;
|
||||
this.routeId = routeId;
|
||||
|
||||
this.mIsConnecting = true;
|
||||
this.mIsConnected = false;
|
||||
this.castContext.getSessionManagerImpl().onSessionStarting(this);
|
||||
this.proxy.start(routeInfoExtra);
|
||||
}
|
||||
|
||||
public void onApplicationConnectionSuccess(ApplicationMetadata applicationMetadata, String applicationStatus, String sessionId, boolean wasLaunched) {
|
||||
this.mIsConnecting = false;
|
||||
this.mIsConnected = true;
|
||||
this.castContext.getSessionManagerImpl().onSessionStarted(this, sessionId);
|
||||
try {
|
||||
this.castContext.getRouter().selectRouteById(this.getRouteId());
|
||||
} catch (RemoteException ex) {
|
||||
Log.e(TAG, "Error calling selectRouteById: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void onApplicationConnectionFailure(int statusCode) {
|
||||
this.mIsConnecting = false;
|
||||
this.mIsConnected = false;
|
||||
this.routeId = null;
|
||||
this.castContext = null;
|
||||
this.castDevice = null;
|
||||
this.routeInfoExtra = null;
|
||||
this.castContext.getSessionManagerImpl().onSessionStartFailed(this, statusCode);
|
||||
try {
|
||||
this.castContext.getRouter().selectDefaultRoute();
|
||||
} catch (RemoteException ex) {
|
||||
Log.e(TAG, "Error calling selectDefaultRoute: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void onRouteSelected(Bundle extras) {
|
||||
}
|
||||
|
||||
public CastSessionImpl getCastSession() {
|
||||
return this.castSession;
|
||||
}
|
||||
|
||||
public void setCastSession(CastSessionImpl castSession) {
|
||||
this.castSession = castSession;
|
||||
}
|
||||
|
||||
public ISessionProxy getSessionProxy() {
|
||||
return this.proxy;
|
||||
}
|
||||
|
||||
public IObjectWrapper getWrappedSession() throws RemoteException {
|
||||
if (this.proxy == null) {
|
||||
return ObjectWrapper.wrap(null);
|
||||
}
|
||||
return this.proxy.getWrappedSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSessionId() {
|
||||
return this.sessionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRouteId() {
|
||||
return this.routeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return this.mIsConnected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnecting() {
|
||||
return this.mIsConnecting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisconnecting() {
|
||||
Log.d(TAG, "unimplemented Method: isDisconnecting");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisconnected() {
|
||||
Log.d(TAG, "unimplemented Method: isDisconnected");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isResuming() {
|
||||
Log.d(TAG, "unimplemented Method: isResuming");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuspended() {
|
||||
Log.d(TAG, "unimplemented Method: isSuspended");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifySessionStarted(String sessionId) {
|
||||
Log.d(TAG, "unimplemented Method: notifySessionStarted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyFailedToStartSession(int error) {
|
||||
Log.d(TAG, "unimplemented Method: notifyFailedToStartSession");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifySessionEnded(int error) {
|
||||
Log.d(TAG, "unimplemented Method: notifySessionEnded");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifySessionResumed(boolean wasSuspended) {
|
||||
Log.d(TAG, "unimplemented Method: notifySessionResumed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyFailedToResumeSession(int error) {
|
||||
Log.d(TAG, "unimplemented Method: notifyFailedToResumeSession");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifySessionSuspended(int reason) {
|
||||
Log.d(TAG, "unimplemented Method: notifySessionSuspended");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectWrapper getWrappedObject() {
|
||||
return ObjectWrapper.wrap(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,230 @@
|
|||
/*
|
||||
* Copyright (C) 2013-2017 microG Project Team
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.android.gms.cast.framework.internal;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.gms.cast.framework.CastState;
|
||||
import com.google.android.gms.cast.framework.ICastStateListener;
|
||||
import com.google.android.gms.cast.framework.ISession;
|
||||
import com.google.android.gms.cast.framework.ISessionManager;
|
||||
import com.google.android.gms.cast.framework.ISessionManagerListener;
|
||||
import com.google.android.gms.cast.framework.internal.CastContextImpl;
|
||||
import com.google.android.gms.cast.framework.internal.SessionImpl;
|
||||
import com.google.android.gms.dynamic.IObjectWrapper;
|
||||
import com.google.android.gms.dynamic.ObjectWrapper;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SessionManagerImpl extends ISessionManager.Stub {
|
||||
private static final String TAG = SessionManagerImpl.class.getSimpleName();
|
||||
|
||||
private CastContextImpl castContext;
|
||||
|
||||
private Set<ISessionManagerListener> sessionManagerListeners = new HashSet<ISessionManagerListener>();
|
||||
private Set<ICastStateListener> castStateListeners = new HashSet<ICastStateListener>();
|
||||
|
||||
private Map<String, SessionImpl> routeSessions = new HashMap<String, SessionImpl>();
|
||||
|
||||
private SessionImpl currentSession;
|
||||
|
||||
private int castState = CastState.NO_DEVICES_AVAILABLE;
|
||||
|
||||
public SessionManagerImpl(CastContextImpl castContext) {
|
||||
this.castContext = castContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectWrapper getWrappedCurrentSession() throws RemoteException {
|
||||
if (this.currentSession == null) {
|
||||
return ObjectWrapper.wrap(null);
|
||||
}
|
||||
return this.currentSession.getWrappedSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endCurrentSession(boolean b, boolean stopCasting) throws RemoteException {
|
||||
Log.d(TAG, "unimplemented Method: endCurrentSession");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSessionManagerListener(ISessionManagerListener listener) {
|
||||
Log.d(TAG, "unimplemented Method: addSessionManagerListener");
|
||||
this.sessionManagerListeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSessionManagerListener(ISessionManagerListener listener) {
|
||||
Log.d(TAG, "unimplemented Method: removeSessionManagerListener");
|
||||
this.sessionManagerListeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCastStateListener(ICastStateListener listener) {
|
||||
Log.d(TAG, "unimplemented Method: addCastStateListener");
|
||||
this.castStateListeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCastStateListener(ICastStateListener listener) {
|
||||
Log.d(TAG, "unimplemented Method: removeCastStateListener");
|
||||
this.castStateListeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IObjectWrapper getWrappedThis() throws RemoteException {
|
||||
return ObjectWrapper.wrap(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCastState() {
|
||||
return this.castState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startSession(Bundle params) {
|
||||
Log.d(TAG, "unimplemented Method: startSession");
|
||||
String routeId = params.getString("CAST_INTENT_TO_CAST_ROUTE_ID_KEY");
|
||||
String sessionId = params.getString("CAST_INTENT_TO_CAST_SESSION_ID_KEY");
|
||||
}
|
||||
|
||||
public void onRouteSelected(String routeId, Bundle extras) {
|
||||
Log.d(TAG, "unimplemented Method: onRouteSelected: " + routeId);
|
||||
}
|
||||
|
||||
private void setCastState(int castState) {
|
||||
this.castState = castState;
|
||||
this.onCastStateChanged();
|
||||
}
|
||||
|
||||
public void onCastStateChanged() {
|
||||
for (ICastStateListener listener : this.castStateListeners) {
|
||||
try {
|
||||
listener.onCastStateChanged(this.castState);
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Remote exception calling onCastStateChanged: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSessionStarting(SessionImpl session) {
|
||||
this.setCastState(CastState.CONNECTING);
|
||||
for (ISessionManagerListener listener : this.sessionManagerListeners) {
|
||||
try {
|
||||
listener.onSessionStarting(session.getSessionProxy().getWrappedSession());
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Remote exception calling onSessionStarting: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSessionStartFailed(SessionImpl session, int error) {
|
||||
this.currentSession = null;
|
||||
this.setCastState(CastState.NOT_CONNECTED);
|
||||
for (ISessionManagerListener listener : this.sessionManagerListeners) {
|
||||
try {
|
||||
listener.onSessionStartFailed(session.getSessionProxy().getWrappedSession(), error);
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Remote exception calling onSessionStartFailed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSessionStarted(SessionImpl session, String sessionId) {
|
||||
this.currentSession = session;
|
||||
this.setCastState(CastState.CONNECTED);
|
||||
for (ISessionManagerListener listener : this.sessionManagerListeners) {
|
||||
try {
|
||||
listener.onSessionStarted(session.getSessionProxy().getWrappedSession(), sessionId);
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Remote exception calling onSessionStarted: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSessionResumed(SessionImpl session, boolean wasSuspended) {
|
||||
this.setCastState(CastState.CONNECTED);
|
||||
for (ISessionManagerListener listener : this.sessionManagerListeners) {
|
||||
try {
|
||||
listener.onSessionResumed(session.getSessionProxy().getWrappedSession(), wasSuspended);
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Remote exception calling onSessionResumed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSessionEnding(SessionImpl session) {
|
||||
for (ISessionManagerListener listener : this.sessionManagerListeners) {
|
||||
try {
|
||||
listener.onSessionEnding(session.getSessionProxy().getWrappedSession());
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Remote exception calling onSessionEnding: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSessionEnded(SessionImpl session, int error) {
|
||||
this.currentSession = null;
|
||||
this.setCastState(CastState.NOT_CONNECTED);
|
||||
for (ISessionManagerListener listener : this.sessionManagerListeners) {
|
||||
try {
|
||||
listener.onSessionEnded(session.getSessionProxy().getWrappedSession(), error);
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Remote exception calling onSessionEnded: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSessionResuming(SessionImpl session, String sessionId) {
|
||||
for (ISessionManagerListener listener : this.sessionManagerListeners) {
|
||||
try {
|
||||
listener.onSessionResuming(session.getSessionProxy().getWrappedSession(), sessionId);
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Remote exception calling onSessionResuming: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSessionResumeFailed(SessionImpl session, int error) {
|
||||
this.currentSession = null;
|
||||
this.setCastState(CastState.NOT_CONNECTED);
|
||||
for (ISessionManagerListener listener : this.sessionManagerListeners) {
|
||||
try {
|
||||
listener.onSessionResumeFailed(session.getSessionProxy().getWrappedSession(), error);
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Remote exception calling onSessionResumeFailed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSessionSuspended(SessionImpl session, int reason) {
|
||||
this.setCastState(CastState.NOT_CONNECTED);
|
||||
for (ISessionManagerListener listener : this.sessionManagerListeners) {
|
||||
try {
|
||||
listener.onSessionSuspended(session.getSessionProxy().getWrappedSession(), reason);
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Remote exception calling onSessionSuspended: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue