-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows to use a microphone for Brave Talk in the background on Android
- Loading branch information
1 parent
5d7fb2b
commit 42c5569
Showing
20 changed files
with
356 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...d/java/org/chromium/chrome/browser/media/ui/BraveMediaNotificationControllerDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.chromium.chrome.browser.media.ui; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.IntentFilter; | ||
import android.media.AudioManager; | ||
|
||
import org.chromium.base.ContextUtils; | ||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.notifications.NotificationConstants; | ||
|
||
public class BraveMediaNotificationControllerDelegate | ||
extends ChromeMediaNotificationControllerDelegate { | ||
BraveMediaNotificationControllerDelegate(int id) { | ||
super(id); | ||
ChromeMediaNotificationControllerDelegate.sMapNotificationIdToOptions.put( | ||
PlaybackListenerMicServiceImpl.NOTIFICATION_ID, | ||
new NotificationOptions( | ||
BraveMediaNotificationControllerServices.PlaybackListenerMicService.class, | ||
NotificationConstants.GROUP_MEDIA_PLAYBACK)); | ||
} | ||
|
||
private static Context getContext() { | ||
assert false; | ||
return null; | ||
} | ||
|
||
/** Service used to run Brave Talk session */ | ||
public static final class PlaybackListenerMicServiceImpl extends ListenerServiceImpl { | ||
static final int NOTIFICATION_ID = R.id.media_playback_mic_notification; | ||
|
||
public PlaybackListenerMicServiceImpl() { | ||
super(NOTIFICATION_ID); | ||
} | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
IntentFilter filter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY); | ||
ContextUtils.registerProtectedBroadcastReceiver( | ||
getService(), mAudioBecomingNoisyReceiver, filter); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
getService().unregisterReceiver(mAudioBecomingNoisyReceiver); | ||
super.onDestroy(); | ||
} | ||
|
||
private BroadcastReceiver mAudioBecomingNoisyReceiver = | ||
new BroadcastReceiver() { | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
if (!AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) { | ||
return; | ||
} | ||
|
||
Intent i = | ||
new Intent( | ||
getContext(), | ||
BraveMediaNotificationControllerServices | ||
.PlaybackListenerMicService.class); | ||
i.setAction(intent.getAction()); | ||
try { | ||
getContext().startService(i); | ||
} catch (RuntimeException e) { | ||
} | ||
} | ||
}; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...d/java/org/chromium/chrome/browser/media/ui/BraveMediaNotificationControllerServices.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.chromium.chrome.browser.media.ui; | ||
|
||
import org.chromium.build.annotations.IdentifierNameString; | ||
import org.chromium.chrome.browser.base.SplitCompatService; | ||
|
||
public class BraveMediaNotificationControllerServices { | ||
public static class PlaybackListenerMicService extends SplitCompatService { | ||
private static @IdentifierNameString String sImplClassName = | ||
"org.chromium.chrome.browser.media.ui." | ||
+ "BraveMediaNotificationControllerDelegate$PlaybackListenerMicServiceImpl"; | ||
|
||
public PlaybackListenerMicService() { | ||
super(sImplClassName); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
android/java/org/chromium/chrome/browser/media/ui/BraveMediaSessionTabHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.chromium.chrome.browser.media.ui; | ||
|
||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.tab.Tab; | ||
import org.chromium.components.browser_ui.media.BraveMediaSessionHelper; | ||
import org.chromium.components.browser_ui.media.MediaNotificationInfo; | ||
import org.chromium.components.browser_ui.media.MediaNotificationManager; | ||
|
||
public class BraveMediaSessionTabHelper extends MediaSessionTabHelper { | ||
/** Will be deleted in bytecode, value from the parent class will be used instead. */ | ||
private Tab mTab; | ||
|
||
BraveMediaSessionTabHelper(Tab tab) { | ||
super(tab); | ||
} | ||
|
||
@Override | ||
public MediaNotificationInfo.Builder createMediaNotificationInfoBuilder() { | ||
if (!BraveMediaSessionHelper.isBraveTalk(mTab.getWebContents())) { | ||
return super.createMediaNotificationInfoBuilder(); | ||
} | ||
|
||
return new MediaNotificationInfo.Builder() | ||
.setInstanceId(mTab.getId()) | ||
.setId(R.id.media_playback_mic_notification); | ||
} | ||
|
||
@Override | ||
public void hideMediaNotification() { | ||
if (!BraveMediaSessionHelper.isBraveTalk(mTab.getWebContents())) { | ||
super.hideMediaNotification(); | ||
return; | ||
} | ||
MediaNotificationManager.hide(mTab.getId(), R.id.media_playback_mic_notification); | ||
} | ||
|
||
@Override | ||
public void activateAndroidMediaSession() { | ||
if (!BraveMediaSessionHelper.isBraveTalk(mTab.getWebContents())) { | ||
super.activateAndroidMediaSession(); | ||
return; | ||
} | ||
MediaNotificationManager.activateAndroidMediaSession( | ||
mTab.getId(), R.id.media_playback_mic_notification); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
build/android/bytecode/java/org/brave/bytecode/BraveForegroundServiceUtilsClassAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.brave.bytecode; | ||
|
||
import org.objectweb.asm.ClassVisitor; | ||
|
||
public class BraveForegroundServiceUtilsClassAdapter extends BraveClassVisitor { | ||
static String sForegroundServiceUtilsClassName = | ||
"org/chromium/components/browser_ui/notifications/ForegroundServiceUtils"; | ||
|
||
static String sBraveForegroundServiceUtilsClassName = | ||
"org/chromium/components/browser_ui/notifications/BraveForegroundServiceUtils"; | ||
|
||
public BraveForegroundServiceUtilsClassAdapter(ClassVisitor visitor) { | ||
super(visitor); | ||
|
||
redirectConstructor( | ||
sForegroundServiceUtilsClassName, sBraveForegroundServiceUtilsClassName); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...oid/bytecode/java/org/brave/bytecode/BraveMediaNotificationControllerDelegateAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.brave.bytecode; | ||
|
||
import org.objectweb.asm.ClassVisitor; | ||
|
||
public class BraveMediaNotificationControllerDelegateAdapter extends BraveClassVisitor { | ||
static String sChromeMediaNotificationControllerDelegate = | ||
"org/chromium/chrome/browser/media/ui/ChromeMediaNotificationControllerDelegate"; | ||
static String sBraveMediaNotificationControllerDelegate = | ||
"org/chromium/chrome/browser/media/ui/BraveMediaNotificationControllerDelegate"; | ||
|
||
public BraveMediaNotificationControllerDelegateAdapter(ClassVisitor visitor) { | ||
super(visitor); | ||
|
||
redirectConstructor( | ||
sChromeMediaNotificationControllerDelegate, | ||
sBraveMediaNotificationControllerDelegate); | ||
deleteMethod(sBraveMediaNotificationControllerDelegate, "getContext"); | ||
makePublicMethod(sChromeMediaNotificationControllerDelegate, "getContext"); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
build/android/bytecode/java/org/brave/bytecode/BraveMediaSessionTabHelperClassAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.brave.bytecode; | ||
|
||
import org.objectweb.asm.ClassVisitor; | ||
|
||
public class BraveMediaSessionTabHelperClassAdapter extends BraveClassVisitor { | ||
static String sMediaSessionTabHelper = | ||
"org/chromium/chrome/browser/media/ui/MediaSessionTabHelper"; | ||
static String sBraveMediaSessionTabHelper = | ||
"org/chromium/chrome/browser/media/ui/BraveMediaSessionTabHelper"; | ||
|
||
public BraveMediaSessionTabHelperClassAdapter(ClassVisitor visitor) { | ||
super(visitor); | ||
|
||
redirectConstructor(sMediaSessionTabHelper, sBraveMediaSessionTabHelper); | ||
deleteField(sBraveMediaSessionTabHelper, "mTab"); | ||
makeProtectedField(sMediaSessionTabHelper, "mTab"); | ||
} | ||
} |
Oops, something went wrong.