Skip to content

Commit

Permalink
Remove MediaPlaybackService (#3324)
Browse files Browse the repository at this point in the history
b/342254474
b/282813379

Change-Id: I4ae8c67b51d3fb7ef1efc8dce8600af2300824d5

Co-authored-by: Colin Liang <[email protected]>
  • Loading branch information
zhongqiliang and Colin Liang authored May 29, 2024
1 parent 93959ea commit 05cfe09
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 229 deletions.
1 change: 0 additions & 1 deletion starboard/android/apk/apk_sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ apk_sources = [
"//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltTextToSpeechHelper.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CrashContextUpdateHandler.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/coat/ErrorDialog.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/coat/MediaPlaybackService.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/coat/NetworkStatus.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/coat/NullCobaltFactory.java",
"//starboard/android/apk/app/src/main/java/dev/cobalt/coat/PlatformError.java",
Expand Down
5 changes: 0 additions & 5 deletions starboard/android/apk/app/src/app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@
</intent-filter>
</activity>

<service android:name="dev.cobalt.coat.MediaPlaybackService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="mediaPlayback"/>

</application>

<queries>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import android.net.Network;
import android.net.NetworkCapabilities;
import android.os.Build;
import android.os.Build.VERSION;
import android.util.Pair;
import android.util.Size;
import android.util.SizeF;
Expand Down Expand Up @@ -184,48 +183,6 @@ protected void onServiceDestroy(Service service) {
}
}

@SuppressWarnings("unused")
@UsedByNative
protected void startMediaPlaybackService() {
if (cobaltMediaSession == null || !cobaltMediaSession.isActive()) {
Log.w(TAG, "Do not start a MediaPlaybackService when the MediSsession is null or inactive.");
return;
}

Service service = serviceHolder.get();
if (service == null) {
if (appContext == null) {
Log.w(TAG, "Activiy already destroyed.");
return;
}
Log.i(TAG, "Cold start - Instantiating a MediaPlaybackService.");
Intent intent = new Intent(appContext, MediaPlaybackService.class);
try {
if (VERSION.SDK_INT >= 26) {
appContext.startForegroundService(intent);
} else {
appContext.startService(intent);
}
} catch (SecurityException e) {
Log.e(TAG, "Failed to start MediaPlaybackService with intent.", e);
return;
}
} else {
Log.i(TAG, "Warm start - Restarting the MediaPlaybackService.");
((MediaPlaybackService) service).startService();
}
}

@SuppressWarnings("unused")
@UsedByNative
protected void stopMediaPlaybackService() {
Service service = serviceHolder.get();
if (service != null) {
Log.i(TAG, "Stopping the MediaPlaybackService.");
((MediaPlaybackService) service).stopService();
}
}

@SuppressWarnings("unused")
@UsedByNative
protected void beforeStartOrResume() {
Expand Down Expand Up @@ -253,9 +210,6 @@ protected void beforeSuspend() {
for (CobaltService service : cobaltServices.values()) {
service.beforeSuspend();
}
// We need to stop MediaPlaybackService before suspending so that this foreground service
// would not prevent releasing activity's memory consumption.
stopMediaPlaybackService();
} catch (Throwable e) {
Log.i(TAG, "Caught exception in beforeSuspend: " + e.getMessage());
}
Expand Down
8 changes: 0 additions & 8 deletions starboard/android/shared/android_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,20 +270,12 @@ void OnStart(GameActivity* activity) {

void OnResume(GameActivity* activity) {
if (g_app_running.load()) {
// Stop the MediaPlaybackService if activity state transits from background
// to foreground. Note that the MediaPlaybackService may already have
// been stopped before Cobalt's lifecycle state transits from Concealed
// to Frozen.
ApplicationAndroid::Get()->StopMediaPlaybackService();
ApplicationAndroid::Get()->SendAndroidCommand(AndroidCommand::kResume);
}
}

void OnPause(GameActivity* activity) {
if (g_app_running.load()) {
// Start the MediaPlaybackService before activity state transits from
// foreground to background.
ApplicationAndroid::Get()->StartMediaPlaybackService();
ApplicationAndroid::Get()->SendAndroidCommand(AndroidCommand::kPause);
}
}
Expand Down
10 changes: 0 additions & 10 deletions starboard/android/shared/application_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,6 @@ void ApplicationAndroid::OnSuspend() {
env->CallStarboardVoidMethodOrAbort("beforeSuspend", "()V");
}

void ApplicationAndroid::StartMediaPlaybackService() {
JniEnvExt* env = JniEnvExt::Get();
env->CallStarboardVoidMethodOrAbort("startMediaPlaybackService", "()V");
}

void ApplicationAndroid::StopMediaPlaybackService() {
JniEnvExt* env = JniEnvExt::Get();
env->CallStarboardVoidMethodOrAbort("stopMediaPlaybackService", "()V");
}

void ApplicationAndroid::ProcessAndroidCommand() {
JniEnvExt* env = JniEnvExt::Get();
AndroidCommand cmd;
Expand Down
4 changes: 0 additions & 4 deletions starboard/android/shared/application_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ class ApplicationAndroid
std::string GetOverlayedStringValue(const char* var_name);
bool GetOverlayedBoolValue(const char* var_name);

// Methods to start/stop Media playback service.
void StartMediaPlaybackService();
void StopMediaPlaybackService();

protected:
// --- Application overrides ---
void Initialize() override;
Expand Down

0 comments on commit 05cfe09

Please sign in to comment.