Merge pull request #4284 from deltachat/adb/format-code6

format code with spotless (part 6)
This commit is contained in:
adb
2026-03-17 18:19:47 +01:00
committed by GitHub
32 changed files with 4150 additions and 3700 deletions
File diff suppressed because it is too large Load Diff
@@ -9,7 +9,6 @@ import android.net.LinkProperties;
import android.net.NetworkCapabilities;
import android.os.Build;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.app.NotificationManagerCompat;
@@ -19,14 +18,16 @@ import androidx.work.ExistingPeriodicWorkPolicy;
import androidx.work.NetworkType;
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;
import chat.delta.rpc.Rpc;
import chat.delta.rpc.RpcException;
import com.b44t.messenger.DcAccounts;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.DcEvent;
import com.b44t.messenger.DcEventChannel;
import com.b44t.messenger.DcEventEmitter;
import com.b44t.messenger.FFITransport;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.thoughtcrime.securesms.calls.CallCoordinator;
import org.thoughtcrime.securesms.connect.AccountManager;
import org.thoughtcrime.securesms.connect.DcEventCenter;
@@ -49,33 +50,27 @@ import org.thoughtcrime.securesms.util.SignalProtocolLoggerProvider;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.webxdc.WebxdcGarbageCollectionWorker;
import java.io.File;
import java.util.concurrent.TimeUnit;
import chat.delta.rpc.Rpc;
import chat.delta.rpc.RpcException;
public class ApplicationContext extends MultiDexApplication {
private static final String TAG = ApplicationContext.class.getSimpleName();
private static final Object initLock = new Object();
private static volatile boolean isInitialized = false;
private static DcAccounts dcAccounts;
private Rpc rpc;
private DcContext dcContext;
private static DcAccounts dcAccounts;
private Rpc rpc;
private DcContext dcContext;
private DcLocationManager dcLocationManager;
private DcEventCenter eventCenter;
private NotificationCenter notificationCenter;
private JobManager jobManager;
private DcLocationManager dcLocationManager;
private DcEventCenter eventCenter;
private NotificationCenter notificationCenter;
private JobManager jobManager;
private int debugOnAvailableCount;
private int debugOnBlockedStatusChangedCount;
private int debugOnCapabilitiesChangedCount;
private int debugOnLinkPropertiesChangedCount;
private int debugOnAvailableCount;
private int debugOnBlockedStatusChangedCount;
private int debugOnCapabilitiesChangedCount;
private int debugOnLinkPropertiesChangedCount;
public static ApplicationContext getInstance(@NonNull Context context) {
return (ApplicationContext)context.getApplicationContext();
return (ApplicationContext) context.getApplicationContext();
}
private static void ensureInitialized() {
@@ -92,8 +87,8 @@ public class ApplicationContext extends MultiDexApplication {
}
/**
* Get DcAccounts instance, waiting for initialization if necessary.
* This method is thread-safe and will block until initialization is complete.
* Get DcAccounts instance, waiting for initialization if necessary. This method is thread-safe
* and will block until initialization is complete.
*/
public static DcAccounts getDcAccounts() {
ensureInitialized();
@@ -101,8 +96,8 @@ public class ApplicationContext extends MultiDexApplication {
}
/**
* Get Rpc instance, waiting for initialization if necessary.
* This method is thread-safe and will block until initialization is complete.
* Get Rpc instance, waiting for initialization if necessary. This method is thread-safe and will
* block until initialization is complete.
*/
public Rpc getRpc() {
ensureInitialized();
@@ -110,8 +105,8 @@ public class ApplicationContext extends MultiDexApplication {
}
/**
* Get DcContext instance, waiting for initialization if necessary.
* This method is thread-safe and will block until initialization is complete.
* Get DcContext instance, waiting for initialization if necessary. This method is thread-safe and
* will block until initialization is complete.
*/
public DcContext getDcContext() {
ensureInitialized();
@@ -120,8 +115,8 @@ public class ApplicationContext extends MultiDexApplication {
/**
* Set DcContext instance. This should only be called by AccountManager when switching accounts,
* which only happens after initial initialization is complete.
* This method is thread-safe but does NOT trigger initialization or notify waiting threads.
* which only happens after initial initialization is complete. This method is thread-safe but
* does NOT trigger initialization or notify waiting threads.
*/
public void setDcContext(DcContext dcContext) {
synchronized (initLock) {
@@ -130,8 +125,8 @@ public class ApplicationContext extends MultiDexApplication {
}
/**
* Get DcLocationManager instance, waiting for initialization if necessary.
* This method is thread-safe and will block until initialization is complete.
* Get DcLocationManager instance, waiting for initialization if necessary. This method is
* thread-safe and will block until initialization is complete.
*/
public DcLocationManager getLocationManager() {
ensureInitialized();
@@ -139,8 +134,8 @@ public class ApplicationContext extends MultiDexApplication {
}
/**
* Get DcEventCenter instance, waiting for initialization if necessary.
* This method is thread-safe and will block until initialization is complete.
* Get DcEventCenter instance, waiting for initialization if necessary. This method is thread-safe
* and will block until initialization is complete.
*/
public DcEventCenter getEventCenter() {
ensureInitialized();
@@ -148,8 +143,8 @@ public class ApplicationContext extends MultiDexApplication {
}
/**
* Get NotificationCenter instance, waiting for initialization if necessary.
* This method is thread-safe and will block until initialization is complete.
* Get NotificationCenter instance, waiting for initialization if necessary. This method is
* thread-safe and will block until initialization is complete.
*/
public NotificationCenter getNotificationCenter() {
ensureInitialized();
@@ -172,90 +167,114 @@ public class ApplicationContext extends MultiDexApplication {
System.loadLibrary("native-utils");
// Initialize DcAccounts in background to avoid ANR during SQL migrations
Util.runOnBackground(() -> {
synchronized (initLock) {
try {
DcEventChannel eventChannel = new DcEventChannel();
DcEventEmitter emitter = eventChannel.getEventEmitter();
eventCenter = new DcEventCenter(this);
new Thread(() -> {
Log.i(TAG, "Starting event loop");
while (true) {
DcEvent event = emitter.getNextEvent();
if (event == null) {
break;
}
if (isInitialized) {
eventCenter.handleEvent(event);
} else {
// not fully initialized, only handle logging events,
// ex. account migrations during DcAccounts initialization
eventCenter.handleLogging(event);
}
}
Log.i("DeltaChat", "shutting down event handler");
}, "eventThread").start();
dcAccounts = new DcAccounts(new File(getFilesDir(), "accounts").getAbsolutePath(), eventChannel);
Log.i(TAG, "DcAccounts created");
rpc = new Rpc(new FFITransport(dcAccounts.getJsonrpcInstance()));
Log.i(TAG, "Rpc created");
AccountManager.getInstance().migrateToDcAccounts(this);
int[] allAccounts = dcAccounts.getAll();
Log.i(TAG, "Number of profiles: " + allAccounts.length);
for (int accountId : allAccounts) {
DcContext ac = dcAccounts.getAccount(accountId);
if (!ac.isOpen()) {
try {
DatabaseSecret secret = DatabaseSecretProvider.getOrCreateDatabaseSecret(this, accountId);
boolean res = ac.open(secret.asString());
if (res) Log.i(TAG, "Successfully opened account " + accountId + ", path: " + ac.getBlobdir());
else Log.e(TAG, "Error opening account " + accountId + ", path: " + ac.getBlobdir());
} catch (Exception e) {
Log.e(TAG, "Failed to open account " + accountId + ", path: " + ac.getBlobdir() + ": " + e);
e.printStackTrace();
}
}
// 2025-12-16: The setting was removed.
// Revert it to the default if it was changed in the past.
ac.setConfigInt("webxdc_realtime_enabled", 1);
// 2025-11-12: this is needed until core starts ignoring "delete_server_after" for chatmail
if (ac.isChatmail()) {
ac.setConfig("delete_server_after", null); // reset
}
}
if (allAccounts.length == 0) {
Util.runOnBackground(
() -> {
synchronized (initLock) {
try {
rpc.addAccount();
} catch (RpcException e) {
e.printStackTrace();
DcEventChannel eventChannel = new DcEventChannel();
DcEventEmitter emitter = eventChannel.getEventEmitter();
eventCenter = new DcEventCenter(this);
new Thread(
() -> {
Log.i(TAG, "Starting event loop");
while (true) {
DcEvent event = emitter.getNextEvent();
if (event == null) {
break;
}
if (isInitialized) {
eventCenter.handleEvent(event);
} else {
// not fully initialized, only handle logging events,
// ex. account migrations during DcAccounts initialization
eventCenter.handleLogging(event);
}
}
Log.i("DeltaChat", "shutting down event handler");
},
"eventThread")
.start();
dcAccounts =
new DcAccounts(
new File(getFilesDir(), "accounts").getAbsolutePath(), eventChannel);
Log.i(TAG, "DcAccounts created");
rpc = new Rpc(new FFITransport(dcAccounts.getJsonrpcInstance()));
Log.i(TAG, "Rpc created");
AccountManager.getInstance().migrateToDcAccounts(this);
int[] allAccounts = dcAccounts.getAll();
Log.i(TAG, "Number of profiles: " + allAccounts.length);
for (int accountId : allAccounts) {
DcContext ac = dcAccounts.getAccount(accountId);
if (!ac.isOpen()) {
try {
DatabaseSecret secret =
DatabaseSecretProvider.getOrCreateDatabaseSecret(this, accountId);
boolean res = ac.open(secret.asString());
if (res)
Log.i(
TAG,
"Successfully opened account "
+ accountId
+ ", path: "
+ ac.getBlobdir());
else
Log.e(
TAG, "Error opening account " + accountId + ", path: " + ac.getBlobdir());
} catch (Exception e) {
Log.e(
TAG,
"Failed to open account "
+ accountId
+ ", path: "
+ ac.getBlobdir()
+ ": "
+ e);
e.printStackTrace();
}
}
// 2025-12-16: The setting was removed.
// Revert it to the default if it was changed in the past.
ac.setConfigInt("webxdc_realtime_enabled", 1);
// 2025-11-12: this is needed until core starts ignoring "delete_server_after" for
// chatmail
if (ac.isChatmail()) {
ac.setConfig("delete_server_after", null); // reset
}
}
if (allAccounts.length == 0) {
try {
rpc.addAccount();
} catch (RpcException e) {
e.printStackTrace();
}
}
dcContext = dcAccounts.getSelectedAccount();
notificationCenter = new NotificationCenter(this);
dcLocationManager = new DcLocationManager(this, dcContext);
isInitialized = true;
initLock.notifyAll();
Log.i(TAG, "DcAccounts initialization complete");
// set translations before starting I/O to avoid sending untranslated MDNs (issue
// #2288)
DcHelper.setStockTranslations(this);
dcAccounts.startIo();
} catch (Exception e) {
Log.e(TAG, "Fatal error during DcAccounts initialization", e);
// Mark as initialized even on error to avoid deadlock
isInitialized = true;
initLock.notifyAll();
throw new RuntimeException("Failed to initialize DcAccounts", e);
}
}
dcContext = dcAccounts.getSelectedAccount();
notificationCenter = new NotificationCenter(this);
dcLocationManager = new DcLocationManager(this, dcContext);
isInitialized = true;
initLock.notifyAll();
Log.i(TAG, "DcAccounts initialization complete");
// set translations before starting I/O to avoid sending untranslated MDNs (issue #2288)
DcHelper.setStockTranslations(this);
dcAccounts.startIo();
} catch (Exception e) {
Log.e(TAG, "Fatal error during DcAccounts initialization", e);
// Mark as initialized even on error to avoid deadlock
isInitialized = true;
initLock.notifyAll();
throw new RuntimeException("Failed to initialize DcAccounts", e);
}
}
});
});
// October-2025 migration: delete deprecated "permanent channel" id
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
@@ -266,33 +285,50 @@ public class ApplicationContext extends MultiDexApplication {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
ConnectivityManager connectivityManager =
(ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
connectivityManager.registerDefaultNetworkCallback(new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(@NonNull android.net.Network network) {
Log.i("DeltaChat", "++++++++++++++++++ NetworkCallback.onAvailable() #" + debugOnAvailableCount++);
getDcAccounts().maybeNetwork();
}
(ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
connectivityManager.registerDefaultNetworkCallback(
new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(@NonNull android.net.Network network) {
Log.i(
"DeltaChat",
"++++++++++++++++++ NetworkCallback.onAvailable() #" + debugOnAvailableCount++);
getDcAccounts().maybeNetwork();
}
@Override
public void onBlockedStatusChanged(@NonNull android.net.Network network, boolean blocked) {
Log.i("DeltaChat", "++++++++++++++++++ NetworkCallback.onBlockedStatusChanged() #" + debugOnBlockedStatusChangedCount++);
}
@Override
public void onBlockedStatusChanged(
@NonNull android.net.Network network, boolean blocked) {
Log.i(
"DeltaChat",
"++++++++++++++++++ NetworkCallback.onBlockedStatusChanged() #"
+ debugOnBlockedStatusChangedCount++);
}
@Override
public void onCapabilitiesChanged(@NonNull android.net.Network network, NetworkCapabilities networkCapabilities) {
// usually called after onAvailable(), so a maybeNetwork seems contraproductive
Log.i("DeltaChat", "++++++++++++++++++ NetworkCallback.onCapabilitiesChanged() #" + debugOnCapabilitiesChangedCount++);
}
@Override
public void onCapabilitiesChanged(
@NonNull android.net.Network network, NetworkCapabilities networkCapabilities) {
// usually called after onAvailable(), so a maybeNetwork seems contraproductive
Log.i(
"DeltaChat",
"++++++++++++++++++ NetworkCallback.onCapabilitiesChanged() #"
+ debugOnCapabilitiesChangedCount++);
}
@Override
public void onLinkPropertiesChanged(@NonNull android.net.Network network, LinkProperties linkProperties) {
Log.i("DeltaChat", "++++++++++++++++++ NetworkCallback.onLinkPropertiesChanged() #" + debugOnLinkPropertiesChangedCount++);
}
});
@Override
public void onLinkPropertiesChanged(
@NonNull android.net.Network network, LinkProperties linkProperties) {
Log.i(
"DeltaChat",
"++++++++++++++++++ NetworkCallback.onLinkPropertiesChanged() #"
+ debugOnLinkPropertiesChangedCount++);
}
});
} // no else: use old method for debugging
BroadcastReceiver networkStateReceiver = new NetworkStateReceiver();
registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
registerReceiver(
networkStateReceiver,
new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
KeepAliveService.maybeStartSelf(this);
@@ -308,13 +344,15 @@ public class ApplicationContext extends MultiDexApplication {
DynamicTheme.setDefaultDayNightMode(this);
IntentFilter filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
registerReceiver(
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Util.localeChanged();
DcHelper.setStockTranslations(context);
}
}, filter);
}
},
filter);
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
@@ -325,31 +363,34 @@ public class ApplicationContext extends MultiDexApplication {
// MAYBE TODO: i think the ApplicationContext is also created
// when the app is stated by FetchWorker timeouts.
// in this case, the normal threads shall not be started.
Constraints constraints = new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build();
PeriodicWorkRequest fetchWorkRequest = new PeriodicWorkRequest.Builder(
FetchWorker.class,
PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS, // usually 15 minutes
TimeUnit.MILLISECONDS,
PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS, // the start may be preferred by up to 5 minutes, so we run every 10-15 minutes
TimeUnit.MILLISECONDS)
Constraints constraints =
new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();
PeriodicWorkRequest fetchWorkRequest =
new PeriodicWorkRequest.Builder(
FetchWorker.class,
PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS, // usually 15 minutes
TimeUnit.MILLISECONDS,
PeriodicWorkRequest
.MIN_PERIODIC_FLEX_MILLIS, // the start may be preferred by up to 5 minutes,
// so we run every 10-15 minutes
TimeUnit.MILLISECONDS)
.setConstraints(constraints)
.build();
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
"FetchWorker",
ExistingPeriodicWorkPolicy.KEEP,
fetchWorkRequest);
WorkManager.getInstance(this)
.enqueueUniquePeriodicWork(
"FetchWorker", ExistingPeriodicWorkPolicy.KEEP, fetchWorkRequest);
}
PeriodicWorkRequest webxdcGarbageCollectionRequest = new PeriodicWorkRequest.Builder(
WebxdcGarbageCollectionWorker.class,
PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS,
TimeUnit.MILLISECONDS,
PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS,
TimeUnit.MILLISECONDS)
PeriodicWorkRequest webxdcGarbageCollectionRequest =
new PeriodicWorkRequest.Builder(
WebxdcGarbageCollectionWorker.class,
PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS,
TimeUnit.MILLISECONDS,
PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS,
TimeUnit.MILLISECONDS)
.build();
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
WorkManager.getInstance(this)
.enqueueUniquePeriodicWork(
"WebxdcGarbageCollectionWorker",
ExistingPeriodicWorkPolicy.KEEP,
webxdcGarbageCollectionRequest);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,9 +1,7 @@
package org.thoughtcrime.securesms;
import android.os.Build;
import androidx.annotation.RequiresApi;
import org.webrtc.EglBase;
@RequiresApi(Build.VERSION_CODES.M)
@@ -8,22 +8,16 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.telecom.CallEndpointCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import java.util.List;
import org.thoughtcrime.securesms.R;
import java.util.List;
/**
* Bottom sheet dialog for selecting audio output device
*/
/** Bottom sheet dialog for selecting audio output device */
@RequiresApi(Build.VERSION_CODES.O)
public class AudioDevicePickerDialog extends BottomSheetDialog {
private static final String TAG = AudioDevicePickerDialog.class.getSimpleName();
@@ -32,10 +26,11 @@ public class AudioDevicePickerDialog extends BottomSheetDialog {
void onDeviceSelected(CallEndpointCompat endpoint);
}
public AudioDevicePickerDialog(@NonNull Context context,
@NonNull List<CallEndpointCompat> endpoints,
CallEndpointCompat currentEndpoint,
@NonNull OnDeviceSelectedListener listener) {
public AudioDevicePickerDialog(
@NonNull Context context,
@NonNull List<CallEndpointCompat> endpoints,
CallEndpointCompat currentEndpoint,
@NonNull OnDeviceSelectedListener listener) {
super(context);
setContentView(R.layout.dialog_audio_device_picker);
@@ -48,30 +43,30 @@ public class AudioDevicePickerDialog extends BottomSheetDialog {
recyclerView.setLayoutManager(new LinearLayoutManager(context));
AudioDeviceAdapter adapter = new AudioDeviceAdapter(
endpoints,
currentEndpoint,
endpoint -> {
listener.onDeviceSelected(endpoint);
dismiss();
}
);
AudioDeviceAdapter adapter =
new AudioDeviceAdapter(
endpoints,
currentEndpoint,
endpoint -> {
listener.onDeviceSelected(endpoint);
dismiss();
});
recyclerView.setAdapter(adapter);
}
/**
* RecyclerView adapter for audio devices
*/
private static class AudioDeviceAdapter extends RecyclerView.Adapter<AudioDeviceAdapter.ViewHolder> {
/** RecyclerView adapter for audio devices */
private static class AudioDeviceAdapter
extends RecyclerView.Adapter<AudioDeviceAdapter.ViewHolder> {
private final List<CallEndpointCompat> endpoints;
private final CallEndpointCompat currentEndpoint;
private final OnDeviceSelectedListener listener;
AudioDeviceAdapter(List<CallEndpointCompat> endpoints,
CallEndpointCompat currentEndpoint,
OnDeviceSelectedListener listener) {
AudioDeviceAdapter(
List<CallEndpointCompat> endpoints,
CallEndpointCompat currentEndpoint,
OnDeviceSelectedListener listener) {
this.endpoints = endpoints;
this.currentEndpoint = currentEndpoint;
this.listener = listener;
@@ -80,19 +75,18 @@ public class AudioDevicePickerDialog extends BottomSheetDialog {
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(
R.layout.item_audio_device,
parent,
false
);
View view =
LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_audio_device, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
CallEndpointCompat endpoint = endpoints.get(position);
boolean isCurrent = currentEndpoint != null &&
endpoint.getIdentifier().equals(currentEndpoint.getIdentifier());
boolean isCurrent =
currentEndpoint != null
&& endpoint.getIdentifier().equals(currentEndpoint.getIdentifier());
holder.bind(endpoint, isCurrent, listener);
}
@@ -20,7 +20,6 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
@@ -37,10 +36,10 @@ import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.button.MaterialButtonToggleGroup;
import java.util.ArrayList;
import java.util.List;
import org.thoughtcrime.securesms.BuildConfig;
import org.thoughtcrime.securesms.EglUtils;
import org.thoughtcrime.securesms.R;
@@ -48,12 +47,7 @@ import org.webrtc.RendererCommon;
import org.webrtc.SurfaceViewRenderer;
import org.webrtc.VideoTrack;
import java.util.ArrayList;
import java.util.List;
/**
* Full-screen call activity for VoIP calls
*/
/** Full-screen call activity for VoIP calls */
@RequiresApi(api = Build.VERSION_CODES.O)
public class CallActivity extends AppCompatActivity {
@@ -120,28 +114,29 @@ public class CallActivity extends AppCompatActivity {
}
// PiP listener
addOnPictureInPictureModeChangedListener(pipModeInfo -> {
boolean isInPipMode = pipModeInfo.isInPictureInPictureMode();
addOnPictureInPictureModeChangedListener(
pipModeInfo -> {
boolean isInPipMode = pipModeInfo.isInPictureInPictureMode();
if (isInPipMode) {
topBar.setVisibility(View.GONE);
bottomLayoutContainer.setVisibility(View.GONE);
localVideoContainer.setVisibility(View.GONE);
incomingCallPrompt.setVisibility(View.GONE);
} else {
topBar.setVisibility(View.VISIBLE);
bottomLayoutContainer.setVisibility(View.VISIBLE);
if (viewModel != null) {
CallViewModel.CallState state = viewModel.getCallState().getValue();
if (state != null) {
updateUIForState(state);
if (isInPipMode) {
topBar.setVisibility(View.GONE);
bottomLayoutContainer.setVisibility(View.GONE);
localVideoContainer.setVisibility(View.GONE);
incomingCallPrompt.setVisibility(View.GONE);
} else {
topBar.setVisibility(View.VISIBLE);
bottomLayoutContainer.setVisibility(View.VISIBLE);
if (viewModel != null) {
CallViewModel.CallState state = viewModel.getCallState().getValue();
if (state != null) {
updateUIForState(state);
}
}
layoutVideos();
}
}
layoutVideos();
}
updateProximityWakeLock();
});
updateProximityWakeLock();
});
initializeViewModel();
@@ -197,20 +192,15 @@ public class CallActivity extends AppCompatActivity {
private void setupInsets() {
View rootView = findViewById(R.id.call_root_view);
ViewCompat.setOnApplyWindowInsetsListener(rootView, (v, windowInsets) -> {
Insets systemBars = windowInsets.getInsets(
WindowInsetsCompat.Type.systemBars()
);
ViewCompat.setOnApplyWindowInsetsListener(
rootView,
(v, windowInsets) -> {
Insets systemBars = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(
systemBars.left,
systemBars.top,
systemBars.right,
systemBars.bottom
);
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return windowInsets;
});
return windowInsets;
});
}
private void setupWindowFlags() {
@@ -221,23 +211,24 @@ public class CallActivity extends AppCompatActivity {
setShowWhenLocked(true);
setTurnScreenOn(true);
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager keyguardManager =
(KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
if (keyguardManager != null) {
keyguardManager.requestDismissKeyguard(this, null);
}
} else {
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
);
getWindow()
.addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// Control status bar icon colors
WindowInsetsControllerCompat controller =
WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());
WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());
controller.setAppearanceLightStatusBars(false);
controller.setAppearanceLightNavigationBars(false);
}
@@ -251,10 +242,9 @@ public class CallActivity extends AppCompatActivity {
}
if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
proximityWakeLock = powerManager.newWakeLock(
PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
"DeltaChat:ProximityLock"
);
proximityWakeLock =
powerManager.newWakeLock(
PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "DeltaChat:ProximityLock");
proximityWakeLock.setReferenceCounted(false);
Log.d(TAG, "Proximity wake lock initialized");
} else {
@@ -309,78 +299,88 @@ public class CallActivity extends AppCompatActivity {
}
private void setupButtonListeners() {
answerButton.setOnClickListener(v -> {
if (viewModel != null) {
viewModel.answerCall();
}
});
answerButton.setOnClickListener(
v -> {
if (viewModel != null) {
viewModel.answerCall();
}
});
declineButton.setOnClickListener(v -> {
if (viewModel != null) {
viewModel.declineCall();
}
finish();
});
endCallButton.setOnClickListener(v -> {
if (viewModel != null) {
viewModel.hangUp();
}
finish();
});
muteButton.setOnClickListener(v -> {
if (viewModel != null) {
viewModel.toggleAudio();
}
});
videoButton.setOnClickListener(v -> {
if (viewModel != null) {
viewModel.toggleVideo();
}
});
speakerButton.setOnClickListener(v -> {
if (viewModel != null) {
showAudioDevicePicker();
}
});
switchCameraButton.setOnClickListener(v -> {
if (viewModel != null) {
viewModel.switchCamera();
}
});
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
CallViewModel.CallState state = viewModel.getCallState().getValue();
if (isDeviceLocked() || state == null) {
declineButton.setOnClickListener(
v -> {
if (viewModel != null) {
viewModel.declineCall();
}
finish();
return;
}
});
switch (state) {
case RINGING:
case CONNECTING:
case CONNECTED:
case RECONNECTING:
enterPictureInPictureMode(createPipParams());
break;
endCallButton.setOnClickListener(
v -> {
if (viewModel != null) {
viewModel.hangUp();
}
finish();
});
case INITIALIZING:
case PROMPTING_USER_ACCEPT:
case ENDED:
case ERROR:
default:
finish();
break;
}
}
});
muteButton.setOnClickListener(
v -> {
if (viewModel != null) {
viewModel.toggleAudio();
}
});
videoButton.setOnClickListener(
v -> {
if (viewModel != null) {
viewModel.toggleVideo();
}
});
speakerButton.setOnClickListener(
v -> {
if (viewModel != null) {
showAudioDevicePicker();
}
});
switchCameraButton.setOnClickListener(
v -> {
if (viewModel != null) {
viewModel.switchCamera();
}
});
getOnBackPressedDispatcher()
.addCallback(
this,
new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
CallViewModel.CallState state = viewModel.getCallState().getValue();
if (isDeviceLocked() || state == null) {
finish();
return;
}
switch (state) {
case RINGING:
case CONNECTING:
case CONNECTED:
case RECONNECTING:
enterPictureInPictureMode(createPipParams());
break;
case INITIALIZING:
case PROMPTING_USER_ACCEPT:
case ENDED:
case ERROR:
default:
finish();
break;
}
}
});
}
private void initializeViewModel() {
@@ -398,79 +398,118 @@ public class CallActivity extends AppCompatActivity {
viewModel.getCallState().observe(this, this::updateUIForState);
// Display info
viewModel.getDisplayName().observe(this, name -> {
displayNameText.setText(name != null ? name : "Unknown");
});
viewModel
.getDisplayName()
.observe(
this,
name -> {
displayNameText.setText(name != null ? name : "Unknown");
});
viewModel.getDisplayIcon().observe(this, icon -> {
if (callerIconView != null) {
if (icon != null) {
callerIconView.setImageIcon(icon);
} else {
callerIconView.setImageResource(R.drawable.ic_person);
}
}
viewModel
.getDisplayIcon()
.observe(
this,
icon -> {
if (callerIconView != null) {
if (icon != null) {
callerIconView.setImageIcon(icon);
} else {
callerIconView.setImageResource(R.drawable.ic_person);
}
}
if (remoteAvatarView != null) {
if (icon != null) {
remoteAvatarView.setImageIcon(icon);
} else {
remoteAvatarView.setImageResource(R.drawable.ic_person);
}
}
});
if (remoteAvatarView != null) {
if (icon != null) {
remoteAvatarView.setImageIcon(icon);
} else {
remoteAvatarView.setImageResource(R.drawable.ic_person);
}
}
});
// Audio/video state
viewModel.getAudioEnabled().observe(this, enabled -> {
muteButton.setSelected(!enabled);
muteButton.setImageResource(enabled ?
R.drawable.ic_mic_on : R.drawable.ic_mic_off);
});
viewModel
.getAudioEnabled()
.observe(
this,
enabled -> {
muteButton.setSelected(!enabled);
muteButton.setImageResource(enabled ? R.drawable.ic_mic_on : R.drawable.ic_mic_off);
});
viewModel.getVideoEnabled().observe(this, enabled -> {
videoButton.setSelected(!enabled);
videoButton.setImageResource(enabled ?
R.drawable.ic_videocam_on : R.drawable.ic_videocam_off);
});
viewModel
.getVideoEnabled()
.observe(
this,
enabled -> {
videoButton.setSelected(!enabled);
videoButton.setImageResource(
enabled ? R.drawable.ic_videocam_on : R.drawable.ic_videocam_off);
});
viewModel.getCurrentAudioEndpoint().observe(this, endpoint -> {
updateSpeakerButton(endpoint);
updateProximityWakeLock();
});
viewModel
.getCurrentAudioEndpoint()
.observe(
this,
endpoint -> {
updateSpeakerButton(endpoint);
updateProximityWakeLock();
});
viewModel.getAvailableAudioEndpoints().observe(this, endpoints -> {
// Need observe to trigger flow emit
Log.d(TAG, "Available endpoints updated, count: " +
(endpoints != null ? endpoints.size() : 0));
});
viewModel
.getAvailableAudioEndpoints()
.observe(
this,
endpoints -> {
// Need observe to trigger flow emit
Log.d(
TAG,
"Available endpoints updated, count: "
+ (endpoints != null ? endpoints.size() : 0));
});
// Errors
viewModel.getErrorMessage().observe(this, error -> {
if (error != null && !error.isEmpty()) {
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
}
});
viewModel
.getErrorMessage()
.observe(
this,
error -> {
if (error != null && !error.isEmpty()) {
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
}
});
// Relay usage
viewModel.getIsRelayUsed().observe(this, isRelayUsed -> {
if (isRelayUsed != null) {
Log.d(TAG, "TURN relay is " + (isRelayUsed ? "being used" : "NOT being used"));
}
});
viewModel
.getIsRelayUsed()
.observe(
this,
isRelayUsed -> {
if (isRelayUsed != null) {
Log.d(TAG, "TURN relay is " + (isRelayUsed ? "being used" : "NOT being used"));
}
});
// Set up LiveData sources
videoConfigChanged.addSource(viewModel.getCallState(), v -> videoConfigChanged.setValue(true));
videoConfigChanged.addSource(viewModel.getLocalVideoTrack(), v -> videoConfigChanged.setValue(true));
videoConfigChanged.addSource(viewModel.getRemoteVideoTrack(), v -> videoConfigChanged.setValue(true));
videoConfigChanged.addSource(viewModel.getVideoEnabled(), v -> videoConfigChanged.setValue(true));
videoConfigChanged.addSource(viewModel.getRemoteVideoEnabled(), v -> videoConfigChanged.setValue(true));
videoConfigChanged.addSource(
viewModel.getLocalVideoTrack(), v -> videoConfigChanged.setValue(true));
videoConfigChanged.addSource(
viewModel.getRemoteVideoTrack(), v -> videoConfigChanged.setValue(true));
videoConfigChanged.addSource(
viewModel.getVideoEnabled(), v -> videoConfigChanged.setValue(true));
videoConfigChanged.addSource(
viewModel.getRemoteVideoEnabled(), v -> videoConfigChanged.setValue(true));
// Video layout
videoConfigChanged.observe(this, changed -> {
if (!isFinishing() && !isDestroyed()) {
layoutVideos();
}
});
videoConfigChanged.observe(
this,
changed -> {
if (!isFinishing() && !isDestroyed()) {
layoutVideos();
}
});
}
@Override
@@ -485,9 +524,9 @@ public class CallActivity extends AppCompatActivity {
private void updateUIForState(CallViewModel.CallState state) {
Log.d(TAG, "Call state: " + state);
if (isInPictureInPictureMode() &&
state != CallViewModel.CallState.ENDED &&
state != CallViewModel.CallState.ERROR) {
if (isInPictureInPictureMode()
&& state != CallViewModel.CallState.ENDED
&& state != CallViewModel.CallState.ERROR) {
return;
}
@@ -556,11 +595,14 @@ public class CallActivity extends AppCompatActivity {
answerModeSelector.setVisibility(View.GONE);
remoteAvatarView.setVisibility(View.VISIBLE);
new Handler(Looper.getMainLooper()).postDelayed(() -> {
if (!isFinishing()) {
finish();
}
}, 2500);
new Handler(Looper.getMainLooper())
.postDelayed(
() -> {
if (!isFinishing()) {
finish();
}
},
2500);
break;
}
@@ -590,14 +632,14 @@ public class CallActivity extends AppCompatActivity {
}
// Create and show BottomSheetDialog
AudioDevicePickerDialog dialog = new AudioDevicePickerDialog(
this,
endpoints,
currentEndpoint,
selectedEndpoint -> {
viewModel.selectAudioDevice(selectedEndpoint);
}
);
AudioDevicePickerDialog dialog =
new AudioDevicePickerDialog(
this,
endpoints,
currentEndpoint,
selectedEndpoint -> {
viewModel.selectAudioDevice(selectedEndpoint);
});
dialog.show();
}
@@ -624,13 +666,13 @@ public class CallActivity extends AppCompatActivity {
CallViewModel.CallState state = viewModel.getCallState().getValue();
CallEndpointCompat endpoint = viewModel.getCurrentAudioEndpoint().getValue();
return (state == CallViewModel.CallState.CONNECTED ||
state == CallViewModel.CallState.RINGING ||
state == CallViewModel.CallState.CONNECTING ||
state == CallViewModel.CallState.RECONNECTING) &&
endpoint != null &&
endpoint.getType() == CallEndpointCompat.TYPE_EARPIECE &&
!isInPictureInPictureMode();
return (state == CallViewModel.CallState.CONNECTED
|| state == CallViewModel.CallState.RINGING
|| state == CallViewModel.CallState.CONNECTING
|| state == CallViewModel.CallState.RECONNECTING)
&& endpoint != null
&& endpoint.getType() == CallEndpointCompat.TYPE_EARPIECE
&& !isInPictureInPictureMode();
}
private void initializeAnswerModeSelector() {
@@ -638,18 +680,19 @@ public class CallActivity extends AppCompatActivity {
// Set initial selection without triggering listener
answerModeSelector.clearOnButtonCheckedListeners();
answerModeSelector.check(coordinator.isStartsWithVideo() ?
R.id.answer_video_button : R.id.answer_audio_only_button);
answerModeSelector.check(
coordinator.isStartsWithVideo() ? R.id.answer_video_button : R.id.answer_audio_only_button);
// Set listener
answerModeSelector.addOnButtonCheckedListener((group, checkedId, isChecked) -> {
if (isChecked && viewModel != null) {
boolean startsWithVideo = (checkedId == R.id.answer_video_button);
viewModel.setStartsWithVideo(startsWithVideo);
viewModel.switchToEarpiece(!startsWithVideo);
Log.d(TAG, "Answer mode changed to: " + (startsWithVideo ? "Video" : "Audio"));
}
});
answerModeSelector.addOnButtonCheckedListener(
(group, checkedId, isChecked) -> {
if (isChecked && viewModel != null) {
boolean startsWithVideo = (checkedId == R.id.answer_video_button);
viewModel.setStartsWithVideo(startsWithVideo);
viewModel.switchToEarpiece(!startsWithVideo);
Log.d(TAG, "Answer mode changed to: " + (startsWithVideo ? "Video" : "Audio"));
}
});
}
private void layoutVideos() {
@@ -657,8 +700,7 @@ public class CallActivity extends AppCompatActivity {
if (viewModel == null) return;
CallViewModel.CallState state = viewModel.getCallState().getValue();
if (state == CallViewModel.CallState.ENDED ||
state == CallViewModel.CallState.ERROR) return;
if (state == CallViewModel.CallState.ENDED || state == CallViewModel.CallState.ERROR) return;
detachAllTracks();
@@ -687,19 +729,19 @@ public class CallActivity extends AppCompatActivity {
Log.d(TAG, "Video layout: Connected (local corner, remote full-screen)");
} else if (!coordinator.isIncomingCall() &&
(state == CallViewModel.CallState.RINGING ||
state == CallViewModel.CallState.CONNECTING)) {
if (localTrack != null && Boolean.TRUE.equals(videoEnabled)) {
// Outgoing call before connected: local preview in center, hide corner
localTrack.addSink(remoteVideoView);
shouldShowRemoteVideoView = true;
localVideoContainer.setVisibility(View.GONE);
Log.d(TAG, "Video layout: Outgoing preview (local full-screen)");
} else {
localVideoContainer.setVisibility(View.GONE);
Log.d(TAG, "Video layout: Outgoing audio-only");
}
} else if (!coordinator.isIncomingCall()
&& (state == CallViewModel.CallState.RINGING
|| state == CallViewModel.CallState.CONNECTING)) {
if (localTrack != null && Boolean.TRUE.equals(videoEnabled)) {
// Outgoing call before connected: local preview in center, hide corner
localTrack.addSink(remoteVideoView);
shouldShowRemoteVideoView = true;
localVideoContainer.setVisibility(View.GONE);
Log.d(TAG, "Video layout: Outgoing preview (local full-screen)");
} else {
localVideoContainer.setVisibility(View.GONE);
Log.d(TAG, "Video layout: Outgoing audio-only");
}
} else {
// All other cases: just show avatar
@@ -728,25 +770,21 @@ public class CallActivity extends AppCompatActivity {
private boolean hasRequiredPermissions() {
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)
== PackageManager.PERMISSION_GRANTED;
== PackageManager.PERMISSION_GRANTED
&& ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)
== PackageManager.PERMISSION_GRANTED;
}
private void requestRequiredPermissions() {
ActivityCompat.requestPermissions(
this,
new String[] {
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO
},
PERMISSION_REQUEST_CODE
);
this,
new String[] {Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO},
PERMISSION_REQUEST_CODE);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
public void onRequestPermissionsResult(
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_REQUEST_CODE) {
@@ -762,9 +800,8 @@ public class CallActivity extends AppCompatActivity {
}
if (!microphoneGranted) {
Toast.makeText(this,
"Microphone permission is required for calls",
Toast.LENGTH_LONG).show();
Toast.makeText(this, "Microphone permission is required for calls", Toast.LENGTH_LONG)
.show();
finish();
return;
}
@@ -773,9 +810,9 @@ public class CallActivity extends AppCompatActivity {
if (!cameraGranted && coordinator.isStartsWithVideo()) {
Log.w(TAG, "Camera permission denied, switching to audio-only");
Toast.makeText(this,
"Starting audio-only call (camera permission denied)",
Toast.LENGTH_SHORT).show();
Toast.makeText(
this, "Starting audio-only call (camera permission denied)", Toast.LENGTH_SHORT)
.show();
coordinator.setStartsWithVideo(false);
}
@@ -817,17 +854,18 @@ public class CallActivity extends AppCompatActivity {
}
}
private PictureInPictureParams createPipParams() {
Rational aspectRatio = new Rational(9, 16);
PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder()
.setAspectRatio(aspectRatio)
.setActions(new ArrayList<>());
private PictureInPictureParams createPipParams() {
Rational aspectRatio = new Rational(9, 16);
PictureInPictureParams.Builder builder =
new PictureInPictureParams.Builder()
.setAspectRatio(aspectRatio)
.setActions(new ArrayList<>());
// FIXME: PiP currently shows media controls.
// Will fix later: to fix this, we may need changes to audio playback implementation.
// FIXME: PiP currently shows media controls.
// Will fix later: to fix this, we may need changes to audio playback implementation.
return builder.build();
}
return builder.build();
}
// Helper
@@ -849,7 +887,6 @@ public class CallActivity extends AppCompatActivity {
proximityWakeLock.release();
Log.d(TAG, "Proximity wake lock released in onDestroy");
}
}
@Override
File diff suppressed because it is too large Load Diff
@@ -15,22 +15,18 @@ import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import chat.delta.rpc.RpcException;
import org.thoughtcrime.securesms.webrtc.WebRTCClient;
import org.webrtc.AudioTrack;
import org.webrtc.MediaStream;
import org.webrtc.PeerConnection;
import org.webrtc.VideoTrack;
import chat.delta.rpc.RpcException;
/**
* Foreground service for VoIP calls
* Required to post CallStyle notifications on Android 12+
* Owns WebRTC resources and keeps call alive
* Foreground service for VoIP calls Required to post CallStyle notifications on Android 12+ Owns
* WebRTC resources and keeps call alive
*/
@RequiresApi(api = Build.VERSION_CODES.O)
public class CallService extends Service implements WebRTCClient.Callbacks {
@@ -84,10 +80,7 @@ public class CallService extends Service implements WebRTCClient.Callbacks {
// Initialization
/**
* Initialize call infrastructure
* Does NOT start camera/microphone
*/
/** Initialize call infrastructure Does NOT start camera/microphone */
public void initializeCall() {
Log.d(TAG, "initializeCall (Infrastructure only)");
@@ -98,35 +91,34 @@ public class CallService extends Service implements WebRTCClient.Callbacks {
webRTCClient = new WebRTCClient(getApplicationContext(), this);
mediaStreamManager = new MediaStreamManager(
getApplicationContext(),
webRTCClient.getPeerConnectionFactory()
);
mediaStreamManager =
new MediaStreamManager(getApplicationContext(), webRTCClient.getPeerConnectionFactory());
fetchIceServersAndSetup();
}
private void fetchIceServersAndSetup() {
new Thread(() -> {
try {
String iceServersJson = callCoordinator.fetchIceServers();
Log.d(TAG, "ICE servers fetched: " + iceServersJson);
new Thread(
() -> {
try {
String iceServersJson = callCoordinator.fetchIceServers();
Log.d(TAG, "ICE servers fetched: " + iceServersJson);
webRTCClient.configure(iceServersJson);
webRTCClient.configure(iceServersJson);
Log.d(TAG, "Infrastructure initialized, waiting for media capture");
Log.d(TAG, "Infrastructure initialized, waiting for media capture");
} catch (RpcException e) {
Log.e(TAG, "Failed to fetch ICE servers", e);
callCoordinator.reportError("Failed to connect: " + e.getMessage());
}
}).start();
} catch (RpcException e) {
Log.e(TAG, "Failed to fetch ICE servers", e);
callCoordinator.reportError("Failed to connect: " + e.getMessage());
}
})
.start();
}
/**
* Start camera/microphone capture
* Must be called when app is in foreground
* Called by coordinator when ViewModel/Activity is ready
* Start camera/microphone capture Must be called when app is in foreground Called by coordinator
* when ViewModel/Activity is ready
*/
public void startMediaCapture() {
Log.d(TAG, "startMediaCapture (Camera/Microphone)");
@@ -156,35 +148,35 @@ public class CallService extends Service implements WebRTCClient.Callbacks {
Log.d(TAG, "Creating media stream with video: " + startsWithVideo);
mediaStreamManager.createMediaStream(new MediaStreamManager.Callback() {
@Override
public void onMediaStreamReady(MediaStream stream) {
Log.d(TAG, "Media stream ready");
mediaStreamManager.createMediaStream(
new MediaStreamManager.Callback() {
@Override
public void onMediaStreamReady(MediaStream stream) {
Log.d(TAG, "Media stream ready");
webRTCClient.setLocalMediaStream(stream);
webRTCClient.setLocalMediaStream(stream);
callCoordinator.setVideoEnabled(startsWithVideo);
callCoordinator.setVideoEnabled(startsWithVideo);
if (!stream.videoTracks.isEmpty()) {
VideoTrack localTrack = stream.videoTracks.get(0);
callCoordinator.updateLocalVideoTrack(localTrack);
} else {
Log.w(TAG, "Camera unavailable, call will be audio-only");
callCoordinator.reportError("Camera unavailable, using audio only");
callCoordinator.setVideoEnabled(false);
}
if (!stream.videoTracks.isEmpty()) {
VideoTrack localTrack = stream.videoTracks.get(0);
callCoordinator.updateLocalVideoTrack(localTrack);
} else {
Log.w(TAG, "Camera unavailable, call will be audio-only");
callCoordinator.reportError("Camera unavailable, using audio only");
callCoordinator.setVideoEnabled(false);
}
Log.d(TAG, "Media capture complete, ready for call");
Log.d(TAG, "Media capture complete, ready for call");
}
}
@Override
public void onError(String error) {
Log.e(TAG, "Failed to setup media: " + error);
callCoordinator.reportError("Camera/microphone error: " + error);
callCoordinator.setVideoEnabled(false);
}
});
@Override
public void onError(String error) {
Log.e(TAG, "Failed to setup media: " + error);
callCoordinator.reportError("Camera/microphone error: " + error);
callCoordinator.setVideoEnabled(false);
}
});
}
// Ringtone Management
@@ -213,21 +205,21 @@ public class CallService extends Service implements WebRTCClient.Callbacks {
return;
}
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
.setLegacyStreamType(AudioManager.STREAM_RING)
.build();
AudioAttributes audioAttributes =
new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
.setLegacyStreamType(AudioManager.STREAM_RING)
.build();
ringtone.setAudioAttributes(audioAttributes);
// Request audio focus
audioFocusRequest = new AudioFocusRequest.Builder(
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT
)
.setAudioAttributes(audioAttributes)
.setWillPauseWhenDucked(false)
.build();
audioFocusRequest =
new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT)
.setAudioAttributes(audioAttributes)
.setWillPauseWhenDucked(false)
.build();
int result = audioManager.requestAudioFocus(audioFocusRequest);
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
@@ -253,18 +245,18 @@ public class CallService extends Service implements WebRTCClient.Callbacks {
}
try {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
.setLegacyStreamType(AudioManager.STREAM_VOICE_CALL)
.build();
AudioAttributes audioAttributes =
new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
.setLegacyStreamType(AudioManager.STREAM_VOICE_CALL)
.build();
audioFocusRequest = new AudioFocusRequest.Builder(
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
)
.setAudioAttributes(audioAttributes)
.setWillPauseWhenDucked(false)
.build();
audioFocusRequest =
new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK)
.setAudioAttributes(audioAttributes)
.setWillPauseWhenDucked(false)
.build();
int result = audioManager.requestAudioFocus(audioFocusRequest);
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
@@ -289,9 +281,7 @@ public class CallService extends Service implements WebRTCClient.Callbacks {
}
}
/**
* Stop playing ringtone
*/
/** Stop playing ringtone */
public void stopRingtone() {
Log.d(TAG, "stopRingtone");
@@ -6,14 +6,11 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.telecom.CallEndpointCompat;
import com.b44t.messenger.DcChat;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
@@ -58,27 +55,37 @@ public class CallUtil {
Recipient recipient = new Recipient(context, dcChat);
ContactPhoto contactPhoto = recipient.getContactPhoto(context);
int wh = context.getResources()
.getDimensionPixelSize(R.dimen.contact_photo_target_size);
int wh = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
Bitmap bitmap;
if (contactPhoto != null) {
bitmap = GlideApp.with(context)
.asBitmap()
.load(contactPhoto)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.circleCrop()
.submit(wh, wh)
.get();
bitmap =
GlideApp.with(context)
.asBitmap()
.load(contactPhoto)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.circleCrop()
.submit(wh, wh)
.get();
} else {
Drawable drawable = recipient.getFallbackContactPhoto()
.asDrawable(context, recipient.getFallbackAvatarColor());
Drawable drawable =
recipient
.getFallbackContactPhoto()
.asDrawable(context, recipient.getFallbackAvatarColor());
bitmap = BitmapUtil.createFromDrawable(drawable, wh, wh);
}
if (bitmap != null) {
Log.d(TAG, "Bitmap loaded: " + bitmap.getWidth() + "x" + bitmap.getHeight()
+ ", config=" + bitmap.getConfig() + ", recycled=" + bitmap.isRecycled());
Log.d(
TAG,
"Bitmap loaded: "
+ bitmap.getWidth()
+ "x"
+ bitmap.getHeight()
+ ", config="
+ bitmap.getConfig()
+ ", recycled="
+ bitmap.isRecycled());
Icon icon = Icon.createWithBitmap(bitmap);
Log.d(TAG, "Icon created successfully");
return icon;
@@ -5,7 +5,6 @@ import android.graphics.drawable.Icon;
import android.os.Build;
import android.telecom.DisconnectCause;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.telecom.CallEndpointCompat;
@@ -13,12 +12,10 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.Observer;
import java.util.List;
import org.webrtc.PeerConnection;
import org.webrtc.VideoTrack;
import java.util.List;
@RequiresApi(api = Build.VERSION_CODES.O)
public class CallViewModel extends AndroidViewModel {
@@ -103,20 +100,22 @@ public class CallViewModel extends AndroidViewModel {
}
private void setupConnectionStateObserver() {
callState.addSource(callCoordinator.getConnectionState(), state -> {
CallState newState = translateConnectionState(state);
callState.addSource(
callCoordinator.getConnectionState(),
state -> {
CallState newState = translateConnectionState(state);
if (callState.getValue() != newState) {
callState.setValue(newState);
}
if (callState.getValue() != newState) {
callState.setValue(newState);
}
if (state == PeerConnection.PeerConnectionState.FAILED ||
state == PeerConnection.PeerConnectionState.CLOSED) {
if (!hasCallEnded) {
hasCallEnded = true;
}
}
});
if (state == PeerConnection.PeerConnectionState.FAILED
|| state == PeerConnection.PeerConnectionState.CLOSED) {
if (!hasCallEnded) {
hasCallEnded = true;
}
}
});
}
private CallState translateConnectionState(PeerConnection.PeerConnectionState state) {
@@ -132,7 +131,7 @@ public class CallViewModel extends AndroidViewModel {
if (callCoordinator.isIncomingCall()) {
return CallState.CONNECTING;
} else {
return CallState.RINGING; // Mirror TypeScript
return CallState.RINGING; // Mirror TypeScript
}
case CONNECTED:
@@ -168,10 +167,7 @@ public class CallViewModel extends AndroidViewModel {
answerCallWhenReady();
}
/**
* Answer incoming call (WebRTC only)
* Used when system answer already happened
*/
/** Answer incoming call (WebRTC only) Used when system answer already happened */
public void answerCallWhenReady() {
Log.d(TAG, "answerCallWhenReady");
@@ -186,28 +182,26 @@ public class CallViewModel extends AndroidViewModel {
// Create one-time observer
LiveData<VideoTrack> localTrack = callCoordinator.getLocalVideoTrack();
answerCallObserver = new Observer<VideoTrack>() {
@Override
public void onChanged(VideoTrack videoTrack) {
if (videoTrack != null) {
// Media is ready, remove observer
localTrack.removeObserver(this);
answerCallObserver = null;
answerCallObserver =
new Observer<VideoTrack>() {
@Override
public void onChanged(VideoTrack videoTrack) {
if (videoTrack != null) {
// Media is ready, remove observer
localTrack.removeObserver(this);
answerCallObserver = null;
Log.d(TAG, "Local video ready, answering call (WebRTC)");
Log.d(TAG, "Local video ready, answering call (WebRTC)");
callCoordinator.answerWebRTC();
}
}
};
callCoordinator.answerWebRTC();
}
}
};
localTrack.observeForever(answerCallObserver);
}
/**
* Start outgoing call with media capture
* Called by Activity for outgoing calls
*/
/** Start outgoing call with media capture Called by Activity for outgoing calls */
public void startOutgoingCallWhenReady() {
Log.d(TAG, "startOutgoingCallWhenReady");
@@ -226,20 +220,21 @@ public class CallViewModel extends AndroidViewModel {
Log.d(TAG, "Media already ready, starting call immediately");
callCoordinator.startOutgoingCall();
} else {
startOutgoingCallObserver = new Observer<VideoTrack>() {
@Override
public void onChanged(VideoTrack videoTrack) {
if (videoTrack != null) {
// Media is ready, remove observer
localTrack.removeObserver(this);
startOutgoingCallObserver = null;
startOutgoingCallObserver =
new Observer<VideoTrack>() {
@Override
public void onChanged(VideoTrack videoTrack) {
if (videoTrack != null) {
// Media is ready, remove observer
localTrack.removeObserver(this);
startOutgoingCallObserver = null;
Log.d(TAG, "Local video ready, starting outgoing call");
Log.d(TAG, "Local video ready, starting outgoing call");
callCoordinator.startOutgoingCall();
}
}
};
callCoordinator.startOutgoingCall();
}
}
};
localTrack.observeForever(startOutgoingCallObserver);
}
@@ -405,7 +400,6 @@ public class CallViewModel extends AndroidViewModel {
return availableAudioEndpoints;
}
// Notification Action Handlers
public void handleNotificationAnswer() {
@@ -2,10 +2,8 @@ package org.thoughtcrime.securesms.calls;
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.EglUtils;
import org.webrtc.AudioSource;
import org.webrtc.AudioTrack;
@@ -19,7 +17,6 @@ import org.webrtc.VideoCapturer;
import org.webrtc.VideoSource;
import org.webrtc.VideoTrack;
public class MediaStreamManager {
private static final String TAG = CallUtil.class.getSimpleName();
@@ -37,6 +34,7 @@ public class MediaStreamManager {
public interface Callback {
void onMediaStreamReady(MediaStream stream);
void onError(String error);
}
@@ -46,9 +44,7 @@ public class MediaStreamManager {
this.peerConnectionFactory = peerConnectionFactory;
}
/**
* Create media stream with audio and optionally video
*/
/** Create media stream with audio and optionally video */
public void createMediaStream(Callback callback) {
try {
MediaStream mediaStream = peerConnectionFactory.createLocalMediaStream(STREAM_ID);
@@ -72,10 +68,8 @@ public class MediaStreamManager {
mediaStream.addTrack(videoTrack);
// Start capturing
surfaceTextureHelper = SurfaceTextureHelper.create(
"CaptureThread",
EglUtils.getEglBase().getEglBaseContext()
);
surfaceTextureHelper =
SurfaceTextureHelper.create("CaptureThread", EglUtils.getEglBase().getEglBaseContext());
videoCapturer.initialize(surfaceTextureHelper, context, videoSource.getCapturerObserver());
videoCapturer.startCapture(1280, 720, 30);
@@ -121,9 +115,7 @@ public class MediaStreamManager {
}
}
/**
* Cleanup resources
*/
/** Cleanup resources */
public void dispose() {
if (videoCapturer != null) {
try {
@@ -3,125 +3,128 @@ package org.thoughtcrime.securesms.connect;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.DcEvent;
import java.util.ArrayList;
import java.util.Hashtable;
import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.service.FetchForegroundService;
import org.thoughtcrime.securesms.util.Util;
import java.util.ArrayList;
import java.util.Hashtable;
public class DcEventCenter {
private static final String TAG = DcEventCenter.class.getSimpleName();
private @NonNull final Hashtable<Integer, ArrayList<DcEventDelegate>> currentAccountObservers = new Hashtable<>();
private @NonNull final Hashtable<Integer, ArrayList<DcEventDelegate>> multiAccountObservers = new Hashtable<>();
private final Object LOCK = new Object();
private final @NonNull ApplicationContext context;
private static final String TAG = DcEventCenter.class.getSimpleName();
private @NonNull final Hashtable<Integer, ArrayList<DcEventDelegate>> currentAccountObservers =
new Hashtable<>();
private @NonNull final Hashtable<Integer, ArrayList<DcEventDelegate>> multiAccountObservers =
new Hashtable<>();
private final Object LOCK = new Object();
private final @NonNull ApplicationContext context;
public interface DcEventDelegate {
void handleEvent(@NonNull DcEvent event);
default boolean runOnMain() {
return true;
public interface DcEventDelegate {
void handleEvent(@NonNull DcEvent event);
default boolean runOnMain() {
return true;
}
}
public DcEventCenter(@NonNull Context context) {
this.context = ApplicationContext.getInstance(context);
}
public void addObserver(int eventId, @NonNull DcEventDelegate observer) {
addObserver(currentAccountObservers, eventId, observer);
}
public void addMultiAccountObserver(int eventId, @NonNull DcEventDelegate observer) {
addObserver(multiAccountObservers, eventId, observer);
}
private void addObserver(
Hashtable<Integer, ArrayList<DcEventDelegate>> observers,
int eventId,
@NonNull DcEventDelegate observer) {
synchronized (LOCK) {
ArrayList<DcEventDelegate> idObservers = observers.get(eventId);
if (idObservers == null) {
observers.put(eventId, (idObservers = new ArrayList<>()));
}
idObservers.add(observer);
}
}
public void removeObserver(int eventId, DcEventDelegate observer) {
synchronized (LOCK) {
ArrayList<DcEventDelegate> idObservers = currentAccountObservers.get(eventId);
if (idObservers != null) {
idObservers.remove(observer);
}
idObservers = multiAccountObservers.get(eventId);
if (idObservers != null) {
idObservers.remove(observer);
}
}
}
public void removeObservers(DcEventDelegate observer) {
synchronized (LOCK) {
for (Integer eventId : currentAccountObservers.keySet()) {
ArrayList<DcEventDelegate> idObservers = currentAccountObservers.get(eventId);
if (idObservers != null) {
idObservers.remove(observer);
}
}
public DcEventCenter(@NonNull Context context) {
this.context = ApplicationContext.getInstance(context);
}
public void addObserver(int eventId, @NonNull DcEventDelegate observer) {
addObserver(currentAccountObservers, eventId, observer);
}
public void addMultiAccountObserver(int eventId, @NonNull DcEventDelegate observer) {
addObserver(multiAccountObservers, eventId, observer);
}
private void addObserver(Hashtable<Integer, ArrayList<DcEventDelegate>> observers, int eventId, @NonNull DcEventDelegate observer) {
synchronized (LOCK) {
ArrayList<DcEventDelegate> idObservers = observers.get(eventId);
if (idObservers == null) {
observers.put(eventId, (idObservers = new ArrayList<>()));
}
idObservers.add(observer);
}
for (Integer eventId : multiAccountObservers.keySet()) {
ArrayList<DcEventDelegate> idObservers = multiAccountObservers.get(eventId);
if (idObservers != null) {
idObservers.remove(observer);
}
}
}
}
public void removeObserver(int eventId, DcEventDelegate observer) {
synchronized (LOCK) {
ArrayList<DcEventDelegate> idObservers = currentAccountObservers.get(eventId);
if (idObservers != null) {
idObservers.remove(observer);
}
idObservers = multiAccountObservers.get(eventId);
if (idObservers != null) {
idObservers.remove(observer);
}
}
}
public void removeObservers(DcEventDelegate observer) {
synchronized (LOCK) {
for(Integer eventId : currentAccountObservers.keySet()) {
ArrayList<DcEventDelegate> idObservers = currentAccountObservers.get(eventId);
if (idObservers != null) {
idObservers.remove(observer);
}
}
for(Integer eventId : multiAccountObservers.keySet()) {
ArrayList<DcEventDelegate> idObservers = multiAccountObservers.get(eventId);
if (idObservers != null) {
idObservers.remove(observer);
}
}
}
}
private void sendToMultiAccountObservers(@NonNull DcEvent event) {
sendToObservers(multiAccountObservers, event);
}
private void sendToCurrentAccountObservers(@NonNull DcEvent event) {
sendToObservers(currentAccountObservers, event);
}
private void sendToObservers(Hashtable<Integer, ArrayList<DcEventDelegate>> observers, @NonNull DcEvent event) {
synchronized (LOCK) {
ArrayList<DcEventDelegate> idObservers = observers.get(event.getId());
if (idObservers != null) {
for (DcEventDelegate observer : idObservers) {
// using try/catch blocks as under some circumstances eg. getContext() may return NULL -
// and as this function is used virtually everywhere, also in libs,
// it's not feasible to check all single occurrences.
if(observer.runOnMain()) {
Util.runOnMain(() -> {
try {
observer.handleEvent(event);
}
catch(Exception e) {
Log.e(TAG, "Error calling observer.handleEvent()", e);
}
});
} else {
Util.runOnBackground(() -> {
try {
observer.handleEvent(event);
}
catch (Exception e) {
Log.e(TAG, "Error calling observer.handleEvent()", e);
}
});
}
}
}
private void sendToMultiAccountObservers(@NonNull DcEvent event) {
sendToObservers(multiAccountObservers, event);
}
private void sendToCurrentAccountObservers(@NonNull DcEvent event) {
sendToObservers(currentAccountObservers, event);
}
private void sendToObservers(
Hashtable<Integer, ArrayList<DcEventDelegate>> observers, @NonNull DcEvent event) {
synchronized (LOCK) {
ArrayList<DcEventDelegate> idObservers = observers.get(event.getId());
if (idObservers != null) {
for (DcEventDelegate observer : idObservers) {
// using try/catch blocks as under some circumstances eg. getContext() may return NULL -
// and as this function is used virtually everywhere, also in libs,
// it's not feasible to check all single occurrences.
if (observer.runOnMain()) {
Util.runOnMain(
() -> {
try {
observer.handleEvent(event);
} catch (Exception e) {
Log.e(TAG, "Error calling observer.handleEvent()", e);
}
});
} else {
Util.runOnBackground(
() -> {
try {
observer.handleEvent(event);
} catch (Exception e) {
Log.e(TAG, "Error calling observer.handleEvent()", e);
}
});
}
}
}
}
}
private final Object lastErrorLock = new Object();
private boolean showNextErrorAsToast = true;
@@ -148,24 +151,26 @@ public class DcEventCenter {
}
// show error to user
Util.runOnMain(() -> {
if (showAsToast) {
String toastString = null;
Util.runOnMain(
() -> {
if (showAsToast) {
String toastString = null;
if (event == DcContext.DC_EVENT_ERROR_SELF_NOT_IN_GROUP) {
toastString = context.getString(R.string.group_self_not_in_group);
}
if (event == DcContext.DC_EVENT_ERROR_SELF_NOT_IN_GROUP) {
toastString = context.getString(R.string.group_self_not_in_group);
}
ForegroundDetector foregroundDetector = ForegroundDetector.getInstance();
if (toastString != null && (foregroundDetector == null || foregroundDetector.isForeground())) {
Toast.makeText(context, toastString, Toast.LENGTH_LONG).show();
}
}
});
ForegroundDetector foregroundDetector = ForegroundDetector.getInstance();
if (toastString != null
&& (foregroundDetector == null || foregroundDetector.isForeground())) {
Toast.makeText(context, toastString, Toast.LENGTH_LONG).show();
}
}
});
}
public void handleLogging(@NonNull DcEvent event) {
final String logPrefix = "[accId="+event.getAccountId()+ "] ";
final String logPrefix = "[accId=" + event.getAccountId() + "] ";
switch (event.getId()) {
case DcContext.DC_EVENT_INFO:
Log.i("DeltaChat", logPrefix + event.getData2Str());
@@ -189,15 +194,19 @@ public class DcEventCenter {
switch (id) {
case DcContext.DC_EVENT_INCOMING_MSG:
DcHelper.getNotificationCenter(context).notifyMessage(accountId, event.getData1Int(), event.getData2Int());
DcHelper.getNotificationCenter(context)
.notifyMessage(accountId, event.getData1Int(), event.getData2Int());
break;
case DcContext.DC_EVENT_INCOMING_REACTION:
DcHelper.getNotificationCenter(context).notifyReaction(accountId, event.getData1Int(), event.getData2Int(), event.getData2Str());
DcHelper.getNotificationCenter(context)
.notifyReaction(
accountId, event.getData1Int(), event.getData2Int(), event.getData2Str());
break;
case DcContext.DC_EVENT_INCOMING_WEBXDC_NOTIFY:
DcHelper.getNotificationCenter(context).notifyWebxdc(accountId, event.getData1Int(), event.getData2Int(), event.getData2Str());
DcHelper.getNotificationCenter(context)
.notifyWebxdc(accountId, event.getData1Int(), event.getData2Int(), event.getData2Str());
break;
case DcContext.DC_EVENT_MSGS_NOTICED:
@@ -205,7 +214,8 @@ public class DcEventCenter {
break;
case DcContext.DC_EVENT_MSG_DELETED:
DcHelper.getNotificationCenter(context).removeNotification(accountId, event.getData1Int(), event.getData2Int());
DcHelper.getNotificationCenter(context)
.removeNotification(accountId, event.getData1Int(), event.getData2Int());
break;
case DcContext.DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE:
File diff suppressed because it is too large Load Diff
@@ -5,10 +5,16 @@ import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -33,19 +39,7 @@ import org.webrtc.VideoDecoderFactory;
import org.webrtc.VideoEncoderFactory;
import org.webrtc.VideoTrack;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
* Manages WebRTC PeerConnection.
* Mirrors TypeScript CallsManager.
*/
/** Manages WebRTC PeerConnection. Mirrors TypeScript CallsManager. */
@RequiresApi(Build.VERSION_CODES.M)
public class WebRTCClient {
@@ -95,17 +89,22 @@ public class WebRTCClient {
// Callbacks to ViewModel
private final Callbacks callbacks;
/**
* Callbacks to ViewModel of connection events
*/
/** Callbacks to ViewModel of connection events */
public interface Callbacks {
void onOfferReady(String offerSdp);
void onAnswerReady(String answerSdp);
void onRemoteVideoTrack(VideoTrack videoTrack);
void onRemoteAudioTrack(AudioTrack audioTrack);
void onConnectionStateChanged(PeerConnection.PeerConnectionState state);
void onRemoteMutedStateChanged(boolean audioEnabled, boolean videoEnabled);
void onRelayUsageChanged(Boolean isRelayUsed);
void onError(String error);
}
@@ -124,20 +123,21 @@ public class WebRTCClient {
private void initializePeerConnectionFactory() {
PeerConnectionFactory.InitializationOptions initOptions =
PeerConnectionFactory.InitializationOptions.builder(context)
.setEnableInternalTracer(false)
.setFieldTrials("")
.createInitializationOptions();
PeerConnectionFactory.InitializationOptions.builder(context)
.setEnableInternalTracer(false)
.setFieldTrials("")
.createInitializationOptions();
PeerConnectionFactory.initialize(initOptions);
EglBase.Context eglBaseContext = EglUtils.getEglBase().getEglBaseContext();
// Create video encoder/decoder factories
VideoEncoderFactory encoderFactory = new DefaultVideoEncoderFactory(
eglBaseContext,
true, // enableIntelVp8Encoder
true // enableH264HighProfile
);
VideoEncoderFactory encoderFactory =
new DefaultVideoEncoderFactory(
eglBaseContext,
true, // enableIntelVp8Encoder
true // enableH264HighProfile
);
VideoDecoderFactory decoderFactory = new DefaultVideoDecoderFactory(eglBaseContext);
@@ -145,21 +145,19 @@ public class WebRTCClient {
options.disableEncryption = false;
options.disableNetworkMonitor = false;
peerConnectionFactory = PeerConnectionFactory.builder()
.setOptions(options)
.setVideoEncoderFactory(encoderFactory)
.setVideoDecoderFactory(decoderFactory)
.createPeerConnectionFactory();
peerConnectionFactory =
PeerConnectionFactory.builder()
.setOptions(options)
.setVideoEncoderFactory(encoderFactory)
.setVideoDecoderFactory(decoderFactory)
.createPeerConnectionFactory();
Log.d(TAG, "PeerConnectionFactory initialized");
}
/**
* Expected JSON format:
* [
* {"urls": "stun:stun.example.com:3478"},
* {"urls": "turn:turn.example.com", "username": "user", "credential": "pass"}
* ]
* Expected JSON format: [ {"urls": "stun:stun.example.com:3478"}, {"urls":
* "turn:turn.example.com", "username": "user", "credential": "pass"} ]
*/
public void configure(String iceServersJson) {
this.iceServers = parseIceServers(iceServersJson);
@@ -195,8 +193,7 @@ public class WebRTCClient {
}
}
PeerConnection.IceServer.Builder builder =
PeerConnection.IceServer.builder(urls);
PeerConnection.IceServer.Builder builder = PeerConnection.IceServer.builder(urls);
if (serverObj.has("username")) {
builder.setUsername(serverObj.getString("username"));
@@ -214,9 +211,7 @@ public class WebRTCClient {
return servers;
}
/**
* Set local media stream
*/
/** Set local media stream */
public void setLocalMediaStream(MediaStream stream) {
this.localStream = stream;
@@ -227,8 +222,12 @@ public class WebRTCClient {
this.localVideoTrack = stream.videoTracks.get(0);
}
Log.d(TAG, "Local media stream set: audio: " + (localAudioTrack != null)
+ ", video: " + (localVideoTrack != null));
Log.d(
TAG,
"Local media stream set: audio: "
+ (localAudioTrack != null)
+ ", video: "
+ (localVideoTrack != null));
}
public boolean hasLocalMediaStream() {
@@ -236,18 +235,15 @@ public class WebRTCClient {
}
private void createPeerConnection() {
PeerConnection.RTCConfiguration rtcConfig =
new PeerConnection.RTCConfiguration(iceServers);
PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
rtcConfig.iceTransportsType = PeerConnection.IceTransportsType.ALL;
rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
rtcConfig.iceCandidatePoolSize = 1;
rtcConfig.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN;
peerConnection = peerConnectionFactory.createPeerConnection(
rtcConfig,
new PeerConnectionObserver()
);
peerConnection =
peerConnectionFactory.createPeerConnection(rtcConfig, new PeerConnectionObserver());
if (peerConnection == null) {
callbacks.onError("Failed to create PeerConnection");
@@ -362,37 +358,38 @@ public class WebRTCClient {
iceTricklingDataChannel = peerConnection.createDataChannel("iceTrickling", init);
iceTricklingDataChannel.registerObserver(new DataChannel.Observer() {
@Override
public void onBufferedAmountChange(long amount) {}
iceTricklingDataChannel.registerObserver(
new DataChannel.Observer() {
@Override
public void onBufferedAmountChange(long amount) {}
@Override
public void onStateChange() {
DataChannel.State state = iceTricklingDataChannel.state();
Log.d(TAG, "ICE Trickling channel state: " + state);
@Override
public void onStateChange() {
DataChannel.State state = iceTricklingDataChannel.state();
Log.d(TAG, "ICE Trickling channel state: " + state);
if (state == DataChannel.State.OPEN) {
iceTricklingChannelOpen = true;
flushIceCandidateBuffer();
} else if (state == DataChannel.State.CLOSED) {
iceTricklingChannelOpen = false;
}
}
if (state == DataChannel.State.OPEN) {
iceTricklingChannelOpen = true;
flushIceCandidateBuffer();
} else if (state == DataChannel.State.CLOSED) {
iceTricklingChannelOpen = false;
}
}
@Override
public void onMessage(DataChannel.Buffer buffer) {
String json = extractString(buffer);
Log.d(TAG, "Received ICE candidate: " + json);
@Override
public void onMessage(DataChannel.Buffer buffer) {
String json = extractString(buffer);
Log.d(TAG, "Received ICE candidate: " + json);
IceCandidate candidate = parseIceCandidate(json);
IceCandidate candidate = parseIceCandidate(json);
if (candidate != null) {
peerConnection.addIceCandidate(candidate);
} else {
Log.d(TAG, "Received end-of-candidates signal");
}
}
});
if (candidate != null) {
peerConnection.addIceCandidate(candidate);
} else {
Log.d(TAG, "Received end-of-candidates signal");
}
}
});
}
private void setupMutedStateDataChannel() {
@@ -402,44 +399,45 @@ public class WebRTCClient {
mutedStateDataChannel = peerConnection.createDataChannel("mutedState", init);
mutedStateDataChannel.registerObserver(new DataChannel.Observer() {
@Override
public void onBufferedAmountChange(long amount) {}
mutedStateDataChannel.registerObserver(
new DataChannel.Observer() {
@Override
public void onBufferedAmountChange(long amount) {}
@Override
public void onStateChange() {
DataChannel.State state = mutedStateDataChannel.state();
Log.d(TAG, "mutedState channel state: " + state);
@Override
public void onStateChange() {
DataChannel.State state = mutedStateDataChannel.state();
Log.d(TAG, "mutedState channel state: " + state);
if (state == DataChannel.State.OPEN) {
mutedStateChannelOpen = true;
if (state == DataChannel.State.OPEN) {
mutedStateChannelOpen = true;
boolean audioEnabled = localAudioTrack != null && localAudioTrack.enabled();
boolean videoEnabled = localVideoTrack != null && localVideoTrack.enabled();
sendMutedState(audioEnabled, videoEnabled);
boolean audioEnabled = localAudioTrack != null && localAudioTrack.enabled();
boolean videoEnabled = localVideoTrack != null && localVideoTrack.enabled();
sendMutedState(audioEnabled, videoEnabled);
} else if (state == DataChannel.State.CLOSED) {
mutedStateChannelOpen = false;
}
}
} else if (state == DataChannel.State.CLOSED) {
mutedStateChannelOpen = false;
}
}
@Override
public void onMessage(DataChannel.Buffer buffer) {
String json = extractString(buffer);
Log.d(TAG, "Received muted state: " + json);
@Override
public void onMessage(DataChannel.Buffer buffer) {
String json = extractString(buffer);
Log.d(TAG, "Received muted state: " + json);
try {
JSONObject obj = new JSONObject(json);
boolean audioEnabled = obj.getBoolean("audioEnabled");
boolean videoEnabled = obj.getBoolean("videoEnabled");
try {
JSONObject obj = new JSONObject(json);
boolean audioEnabled = obj.getBoolean("audioEnabled");
boolean videoEnabled = obj.getBoolean("videoEnabled");
mainHandler.post(() ->
callbacks.onRemoteMutedStateChanged(audioEnabled, videoEnabled));
} catch (JSONException e) {
Log.e(TAG, "Failed to parse muted state JSON", e);
}
}
});
mainHandler.post(
() -> callbacks.onRemoteMutedStateChanged(audioEnabled, videoEnabled));
} catch (JSONException e) {
Log.e(TAG, "Failed to parse muted state JSON", e);
}
}
});
}
// Flush buffered ICE candidates when data channel opens
@@ -465,9 +463,7 @@ public class WebRTCClient {
Log.d(TAG, "Sent ICE candidate using data channel: " + candidate.sdpMid);
}
/**
* Send current muted state to remote peer
*/
/** Send current muted state to remote peer */
public void sendMutedState(boolean audioEnabled, boolean videoEnabled) {
if (!mutedStateChannelOpen) {
Log.w(TAG, "Muted state channel not open");
@@ -479,8 +475,7 @@ public class WebRTCClient {
json.put("audioEnabled", audioEnabled);
json.put("videoEnabled", videoEnabled);
ByteBuffer buffer = ByteBuffer.wrap(
json.toString().getBytes(StandardCharsets.UTF_8));
ByteBuffer buffer = ByteBuffer.wrap(json.toString().getBytes(StandardCharsets.UTF_8));
mutedStateDataChannel.send(new DataChannel.Buffer(buffer, false));
Log.d(TAG, "Sent muted state: audio: " + audioEnabled + ", video: " + videoEnabled);
@@ -519,10 +514,7 @@ public class WebRTCClient {
}
}
/**
* Wait for enough ICE before sending offer/answer
* Mirrors TypeScript gatheredEnoughIce()
*/
/** Wait for enough ICE before sending offer/answer Mirrors TypeScript gatheredEnoughIce() */
private boolean waitForEnoughIce() {
boolean hasTurnServer = false;
boolean hasStunServer = false;
@@ -584,9 +576,7 @@ public class WebRTCClient {
// Outgoing Call
/**
* Start outgoing call
*/
/** Start outgoing call */
public void startOutgoingCall() {
if (localStream == null) {
mainHandler.post(() -> callbacks.onError("Local media stream not set"));
@@ -594,126 +584,129 @@ public class WebRTCClient {
}
Log.d(TAG, "Starting outgoing call");
mainHandler.post(() ->
callbacks.onConnectionStateChanged(PeerConnection.PeerConnectionState.CONNECTING));
mainHandler.post(
() -> callbacks.onConnectionStateChanged(PeerConnection.PeerConnectionState.CONNECTING));
createPeerConnection();
for (AudioTrack track : localStream.audioTracks) {
RtpSender sender = peerConnection.addTrack(track, Collections.singletonList(localStream.getId()));
RtpSender sender =
peerConnection.addTrack(track, Collections.singletonList(localStream.getId()));
Log.d(TAG, "Added audio track, sender: " + sender);
}
for (VideoTrack track : localStream.videoTracks) {
RtpSender sender = peerConnection.addTrack(track, Collections.singletonList(localStream.getId()));
RtpSender sender =
peerConnection.addTrack(track, Collections.singletonList(localStream.getId()));
Log.d(TAG, "Added video track, sender: " + sender);
}
Log.d(TAG, "Total senders: " + peerConnection.getSenders().size());
// Create offer
peerConnection.createOffer(new SdpObserver() {
@Override
public void onCreateSuccess(SessionDescription sdp) {
onOfferCreated(sdp);
}
peerConnection.createOffer(
new SdpObserver() {
@Override
public void onCreateSuccess(SessionDescription sdp) {
onOfferCreated(sdp);
}
@Override
public void onSetSuccess() {}
@Override
public void onSetSuccess() {}
@Override
public void onCreateFailure(String error) {
Log.e(TAG, "Failed to create offer: " + error);
mainHandler.post(() -> callbacks.onError("Failed to create offer: " + error));
}
@Override
public void onCreateFailure(String error) {
Log.e(TAG, "Failed to create offer: " + error);
mainHandler.post(() -> callbacks.onError("Failed to create offer: " + error));
}
@Override
public void onSetFailure(String error) {}
}, new MediaConstraints());
@Override
public void onSetFailure(String error) {}
},
new MediaConstraints());
}
private void onOfferCreated(SessionDescription offerSdp) {
peerConnection.setLocalDescription(new SdpObserver() {
@Override
public void onSetSuccess() {
Log.d(TAG, "Local description set, waiting for ICE...");
peerConnection.setLocalDescription(
new SdpObserver() {
@Override
public void onSetSuccess() {
Log.d(TAG, "Local description set, waiting for ICE...");
// Wait for ICE in background
new Thread(() -> {
boolean gotIce = waitForEnoughIce();
// Wait for ICE in background
new Thread(
() -> {
boolean gotIce = waitForEnoughIce();
if (!gotIce) {
Log.w(TAG, "Proceeding without optimal ICE candidates");
if (!gotIce) {
Log.w(TAG, "Proceeding without optimal ICE candidates");
}
// Get final SDP
SessionDescription localDesc = peerConnection.getLocalDescription();
if (localDesc != null) {
String finalSdp = localDesc.description;
// Enable trickling for additional candidates
enableIceTrickling = true;
// Notify ViewModel
mainHandler.post(() -> callbacks.onOfferReady(finalSdp));
} else {
mainHandler.post(
() ->
callbacks.onError("Local description is null after ICE gathering"));
}
})
.start();
}
// Get final SDP
SessionDescription localDesc = peerConnection.getLocalDescription();
if (localDesc != null) {
String finalSdp = localDesc.description;
@Override
public void onCreateSuccess(SessionDescription sdp) {}
// Enable trickling for additional candidates
enableIceTrickling = true;
@Override
public void onCreateFailure(String error) {}
// Notify ViewModel
mainHandler.post(() -> callbacks.onOfferReady(finalSdp));
} else {
mainHandler.post(() ->
callbacks.onError("Local description is null after ICE gathering"));
@Override
public void onSetFailure(String error) {
Log.e(TAG, "Failed to set local description: " + error);
mainHandler.post(() -> callbacks.onError("Failed to set local description: " + error));
}
}).start();
}
@Override
public void onCreateSuccess(SessionDescription sdp) {}
@Override
public void onCreateFailure(String error) {}
@Override
public void onSetFailure(String error) {
Log.e(TAG, "Failed to set local description: " + error);
mainHandler.post(() ->
callbacks.onError("Failed to set local description: " + error));
}
}, offerSdp);
},
offerSdp);
}
/**
* Handle answer SDP from remote peer for outgoing call
*/
/** Handle answer SDP from remote peer for outgoing call */
public void handleAnswerSdp(String answerSdp) {
Log.d(TAG, "Handling answer SDP");
SessionDescription remoteSdp = new SessionDescription(
SessionDescription.Type.ANSWER,
answerSdp
);
SessionDescription remoteSdp =
new SessionDescription(SessionDescription.Type.ANSWER, answerSdp);
peerConnection.setRemoteDescription(new SdpObserver() {
@Override
public void onSetSuccess() {
Log.d(TAG, "Remote answer set, connection should establish");
}
peerConnection.setRemoteDescription(
new SdpObserver() {
@Override
public void onSetSuccess() {
Log.d(TAG, "Remote answer set, connection should establish");
}
@Override
public void onCreateSuccess(SessionDescription sdp) {}
@Override
public void onCreateSuccess(SessionDescription sdp) {}
@Override
public void onCreateFailure(String error) {}
@Override
public void onCreateFailure(String error) {}
@Override
public void onSetFailure(String error) {
Log.e(TAG, "Failed to set remote description: " + error);
mainHandler.post(() ->
callbacks.onError("Failed to set remote description: " + error));
}
}, remoteSdp);
@Override
public void onSetFailure(String error) {
Log.e(TAG, "Failed to set remote description: " + error);
mainHandler.post(() -> callbacks.onError("Failed to set remote description: " + error));
}
},
remoteSdp);
}
// Incoming Call
/**
* Accept incoming call
*/
/** Accept incoming call */
public void acceptIncomingCall(String offerSdp) {
if (localStream == null) {
mainHandler.post(() -> callbacks.onError("Local media stream not set"));
@@ -721,36 +714,34 @@ public class WebRTCClient {
}
Log.d(TAG, "Accepting incoming call");
mainHandler.post(() ->
callbacks.onConnectionStateChanged(PeerConnection.PeerConnectionState.CONNECTING));
mainHandler.post(
() -> callbacks.onConnectionStateChanged(PeerConnection.PeerConnectionState.CONNECTING));
createPeerConnection();
SessionDescription remoteSdp = new SessionDescription(
SessionDescription.Type.OFFER,
offerSdp
);
SessionDescription remoteSdp = new SessionDescription(SessionDescription.Type.OFFER, offerSdp);
peerConnection.setRemoteDescription(new SdpObserver() {
@Override
public void onSetSuccess() {
Log.d(TAG, "Remote offer set, adding local tracks...");
addLocalTracksAndCreateAnswer();
}
peerConnection.setRemoteDescription(
new SdpObserver() {
@Override
public void onSetSuccess() {
Log.d(TAG, "Remote offer set, adding local tracks...");
addLocalTracksAndCreateAnswer();
}
@Override
public void onCreateSuccess(SessionDescription sdp) {}
@Override
public void onCreateSuccess(SessionDescription sdp) {}
@Override
public void onCreateFailure(String error) {}
@Override
public void onCreateFailure(String error) {}
@Override
public void onSetFailure(String error) {
Log.e(TAG, "Failed to set remote description: " + error);
mainHandler.post(() ->
callbacks.onError("Failed to set remote description: " + error));
}
}, remoteSdp);
@Override
public void onSetFailure(String error) {
Log.e(TAG, "Failed to set remote description: " + error);
mainHandler.post(() -> callbacks.onError("Failed to set remote description: " + error));
}
},
remoteSdp);
}
private void addLocalTracksAndCreateAnswer() {
@@ -763,70 +754,76 @@ public class WebRTCClient {
}
// Create answer
peerConnection.createAnswer(new SdpObserver() {
@Override
public void onCreateSuccess(SessionDescription sdp) {
onAnswerCreated(sdp);
}
peerConnection.createAnswer(
new SdpObserver() {
@Override
public void onCreateSuccess(SessionDescription sdp) {
onAnswerCreated(sdp);
}
@Override
public void onSetSuccess() {}
@Override
public void onSetSuccess() {}
@Override
public void onCreateFailure(String error) {
Log.e(TAG, "Failed to create answer: " + error);
mainHandler.post(() -> callbacks.onError("Failed to create answer: " + error));
}
@Override
public void onCreateFailure(String error) {
Log.e(TAG, "Failed to create answer: " + error);
mainHandler.post(() -> callbacks.onError("Failed to create answer: " + error));
}
@Override
public void onSetFailure(String error) {}
}, new MediaConstraints());
@Override
public void onSetFailure(String error) {}
},
new MediaConstraints());
}
private void onAnswerCreated(SessionDescription answerSdp) {
peerConnection.setLocalDescription(new SdpObserver() {
@Override
public void onSetSuccess() {
Log.d(TAG, "Local answer set, waiting for ICE...");
peerConnection.setLocalDescription(
new SdpObserver() {
@Override
public void onSetSuccess() {
Log.d(TAG, "Local answer set, waiting for ICE...");
// Wait for ICE on background thread
new Thread(() -> {
boolean gotIce = waitForEnoughIce();
// Wait for ICE on background thread
new Thread(
() -> {
boolean gotIce = waitForEnoughIce();
if (!gotIce) {
Log.w(TAG, "Proceeding without optimal ICE candidates");
if (!gotIce) {
Log.w(TAG, "Proceeding without optimal ICE candidates");
}
// Get final SDP
SessionDescription localDesc = peerConnection.getLocalDescription();
if (localDesc != null) {
String finalSdp = localDesc.description;
// Enable trickling for additional candidates
enableIceTrickling = true;
// Notify ViewModel
mainHandler.post(() -> callbacks.onAnswerReady(finalSdp));
} else {
mainHandler.post(
() ->
callbacks.onError("Local description is null after ICE gathering"));
}
})
.start();
}
// Get final SDP
SessionDescription localDesc = peerConnection.getLocalDescription();
if (localDesc != null) {
String finalSdp = localDesc.description;
@Override
public void onCreateSuccess(SessionDescription sdp) {}
// Enable trickling for additional candidates
enableIceTrickling = true;
@Override
public void onCreateFailure(String error) {}
// Notify ViewModel
mainHandler.post(() -> callbacks.onAnswerReady(finalSdp));
} else {
mainHandler.post(() ->
callbacks.onError("Local description is null after ICE gathering"));
@Override
public void onSetFailure(String error) {
Log.e(TAG, "Failed to set local description: " + error);
mainHandler.post(() -> callbacks.onError("Failed to set local description: " + error));
}
}).start();
}
@Override
public void onCreateSuccess(SessionDescription sdp) {}
@Override
public void onCreateFailure(String error) {}
@Override
public void onSetFailure(String error) {
Log.e(TAG, "Failed to set local description: " + error);
mainHandler.post(() ->
callbacks.onError("Failed to set local description: " + error));
}
}, answerSdp);
},
answerSdp);
}
// Media Control
@@ -854,62 +851,67 @@ public class WebRTCClient {
private void detectRelayUsage() {
// Schedule detection after connection settles
mainHandler.postDelayed(() -> {
if (peerConnection == null) return;
mainHandler.postDelayed(
() -> {
if (peerConnection == null) return;
peerConnection.getStats(report -> {
boolean relayUsed = false;
peerConnection.getStats(
report -> {
boolean relayUsed = false;
Map<String, RTCStats> statsMap = report.getStatsMap();
Map<String, RTCStats> statsMap = report.getStatsMap();
// First, find the selected candidate pair
String selectedLocalCandidateId = null;
String selectedRemoteCandidateId = null;
// First, find the selected candidate pair
String selectedLocalCandidateId = null;
String selectedRemoteCandidateId = null;
for (Map.Entry<String, RTCStats> entry : statsMap.entrySet()) {
RTCStats stats = entry.getValue();
for (Map.Entry<String, RTCStats> entry : statsMap.entrySet()) {
RTCStats stats = entry.getValue();
if ("candidate-pair".equals(stats.getType())) {
Map<String, Object> members = stats.getMembers();
if ("candidate-pair".equals(stats.getType())) {
Map<String, Object> members = stats.getMembers();
// Check if this pair is selected/nominated
Object state = members.get("state");
if ("succeeded".equals(state) || Boolean.TRUE.equals(members.get("nominated"))) {
selectedLocalCandidateId = (String) members.get("localCandidateId");
selectedRemoteCandidateId = (String) members.get("remoteCandidateId");
break;
}
}
}
// Now check if either candidate is relay type
if (selectedLocalCandidateId != null || selectedRemoteCandidateId != null) {
for (Map.Entry<String, RTCStats> entry : statsMap.entrySet()) {
RTCStats stats = entry.getValue();
String id = stats.getId();
if (id.equals(selectedLocalCandidateId) || id.equals(selectedRemoteCandidateId)) {
if ("local-candidate".equals(stats.getType()) ||
"remote-candidate".equals(stats.getType())) {
Map<String, Object> members = stats.getMembers();
String candidateType = (String) members.get("candidateType");
if ("relay".equals(candidateType)) {
relayUsed = true;
break;
// Check if this pair is selected/nominated
Object state = members.get("state");
if ("succeeded".equals(state)
|| Boolean.TRUE.equals(members.get("nominated"))) {
selectedLocalCandidateId = (String) members.get("localCandidateId");
selectedRemoteCandidateId = (String) members.get("remoteCandidateId");
break;
}
}
}
}
}
}
}
boolean finalRelayUsed = relayUsed;
mainHandler.post(() -> callbacks.onRelayUsageChanged(finalRelayUsed));
// Now check if either candidate is relay type
if (selectedLocalCandidateId != null || selectedRemoteCandidateId != null) {
for (Map.Entry<String, RTCStats> entry : statsMap.entrySet()) {
RTCStats stats = entry.getValue();
String id = stats.getId();
Log.d(TAG, "Relay usage detected: " + finalRelayUsed);
});
}, 500);
if (id.equals(selectedLocalCandidateId)
|| id.equals(selectedRemoteCandidateId)) {
if ("local-candidate".equals(stats.getType())
|| "remote-candidate".equals(stats.getType())) {
Map<String, Object> members = stats.getMembers();
String candidateType = (String) members.get("candidateType");
if ("relay".equals(candidateType)) {
relayUsed = true;
break;
}
}
}
}
}
boolean finalRelayUsed = relayUsed;
mainHandler.post(() -> callbacks.onRelayUsageChanged(finalRelayUsed));
Log.d(TAG, "Relay usage detected: " + finalRelayUsed);
});
},
500);
}
// Cleanup
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M680,480L680,328L588,420L560,392L672,280L560,168L588,140L680,232L680,80L700,80L814,196L728,280L814,366L700,480L680,480ZM720,404L758,366L720,328L720,404ZM720,232L758,196L720,158L720,232ZM798,840Q673,840 551,785.5Q429,731 329,631Q229,531 174.5,409Q120,287 120,162Q120,144 132,132Q144,120 162,120L324,120Q338,120 349,129.5Q360,139 362,152L388,292Q390,308 387,319Q384,330 376,338L279,436Q299,473 326.5,507.5Q354,542 387,574Q418,605 452,631.5Q486,658 524,680L618,586Q627,577 641.5,572.5Q656,568 670,570L808,598Q822,602 831,612.5Q840,623 840,636L840,798Q840,816 828,828Q816,840 798,840ZM241,360L307,294Q307,294 307,294Q307,294 307,294L290,200Q290,200 290,200Q290,200 290,200L201,200Q201,200 201,200Q201,200 201,200Q206,241 215,281Q224,321 241,360ZM599,718Q638,735 678.5,745Q719,755 760,758Q760,758 760,758Q760,758 760,758L760,670Q760,670 760,670Q760,670 760,670L666,651Q666,651 666,651Q666,651 666,651L599,718ZM241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360ZM599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M680,480L680,328L588,420L560,392L672,280L560,168L588,140L680,232L680,80L700,80L814,196L728,280L814,366L700,480L680,480ZM720,404L758,366L720,328L720,404ZM720,232L758,196L720,158L720,232ZM798,840Q673,840 551,785.5Q429,731 329,631Q229,531 174.5,409Q120,287 120,162Q120,144 132,132Q144,120 162,120L324,120Q338,120 349,129.5Q360,139 362,152L388,292Q390,308 387,319Q384,330 376,338L279,436Q299,473 326.5,507.5Q354,542 387,574Q418,605 452,631.5Q486,658 524,680L618,586Q627,577 641.5,572.5Q656,568 670,570L808,598Q822,602 831,612.5Q840,623 840,636L840,798Q840,816 828,828Q816,840 798,840ZM241,360L307,294Q307,294 307,294Q307,294 307,294L290,200Q290,200 290,200Q290,200 290,200L201,200Q201,200 201,200Q201,200 201,200Q206,241 215,281Q224,321 241,360ZM599,718Q638,735 678.5,745Q719,755 760,758Q760,758 760,758Q760,758 760,758L760,670Q760,670 760,670Q760,670 760,670L666,651Q666,651 666,651Q666,651 666,651L599,718ZM241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360ZM599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M798,840Q673,840 551,785.5Q429,731 329,631Q229,531 174.5,409Q120,287 120,162Q120,144 132,132Q144,120 162,120L324,120Q338,120 349,129.5Q360,139 362,152L388,292Q390,308 387,319Q384,330 376,338L279,436Q299,473 326.5,507.5Q354,542 387,574Q418,605 452,631.5Q486,658 524,680L618,586Q627,577 641.5,572.5Q656,568 670,570L808,598Q822,602 831,612.5Q840,623 840,636L840,798Q840,816 828,828Q816,840 798,840ZM241,360L307,294Q307,294 307,294Q307,294 307,294L290,200Q290,200 290,200Q290,200 290,200L201,200Q201,200 201,200Q201,200 201,200Q206,241 215,281Q224,321 241,360ZM599,718Q638,735 678.5,745Q719,755 760,758Q760,758 760,758Q760,758 760,758L760,670Q760,670 760,670Q760,670 760,670L666,651Q666,651 666,651Q666,651 666,651L599,718ZM241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360ZM599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M798,840Q673,840 551,785.5Q429,731 329,631Q229,531 174.5,409Q120,287 120,162Q120,144 132,132Q144,120 162,120L324,120Q338,120 349,129.5Q360,139 362,152L388,292Q390,308 387,319Q384,330 376,338L279,436Q299,473 326.5,507.5Q354,542 387,574Q418,605 452,631.5Q486,658 524,680L618,586Q627,577 641.5,572.5Q656,568 670,570L808,598Q822,602 831,612.5Q840,623 840,636L840,798Q840,816 828,828Q816,840 798,840ZM241,360L307,294Q307,294 307,294Q307,294 307,294L290,200Q290,200 290,200Q290,200 290,200L201,200Q201,200 201,200Q201,200 201,200Q206,241 215,281Q224,321 241,360ZM599,718Q638,735 678.5,745Q719,755 760,758Q760,758 760,758Q760,758 760,758L760,670Q760,670 760,670Q760,670 760,670L666,651Q666,651 666,651Q666,651 666,651L599,718ZM241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360ZM599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M136,656L44,566Q32,554 32,538Q32,522 44,510Q132,415 247,367.5Q362,320 480,320Q598,320 712.5,367.5Q827,415 916,510Q928,522 928,538Q928,554 916,566L824,656Q813,667 798.5,668Q784,669 772,660L656,572Q648,566 644,558Q640,550 640,540L640,426Q602,414 562,407Q522,400 480,400Q438,400 398,407Q358,414 320,426L320,540Q320,550 316,558Q312,566 304,572L188,660Q176,669 161.5,668Q147,667 136,656ZM240,458Q211,473 184,492.5Q157,512 128,536Q128,536 128,536Q128,536 128,536L168,576Q168,576 168,576Q168,576 168,576L240,520Q240,520 240,520Q240,520 240,520L240,458ZM720,460L720,520Q720,520 720,520Q720,520 720,520L792,576Q792,576 792,576Q792,576 792,576L832,538Q832,538 832,538Q832,538 832,538Q803,512 776,493Q749,474 720,460ZM240,458L240,458Q240,458 240,458Q240,458 240,458L240,458Q240,458 240,458Q240,458 240,458L240,458Q240,458 240,458Q240,458 240,458Q240,458 240,458Q240,458 240,458ZM720,460Q720,460 720,460Q720,460 720,460Q720,460 720,460Q720,460 720,460L720,460Q720,460 720,460Q720,460 720,460L720,460Q720,460 720,460Q720,460 720,460Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M136,656L44,566Q32,554 32,538Q32,522 44,510Q132,415 247,367.5Q362,320 480,320Q598,320 712.5,367.5Q827,415 916,510Q928,522 928,538Q928,554 916,566L824,656Q813,667 798.5,668Q784,669 772,660L656,572Q648,566 644,558Q640,550 640,540L640,426Q602,414 562,407Q522,400 480,400Q438,400 398,407Q358,414 320,426L320,540Q320,550 316,558Q312,566 304,572L188,660Q176,669 161.5,668Q147,667 136,656ZM240,458Q211,473 184,492.5Q157,512 128,536Q128,536 128,536Q128,536 128,536L168,576Q168,576 168,576Q168,576 168,576L240,520Q240,520 240,520Q240,520 240,520L240,458ZM720,460L720,520Q720,520 720,520Q720,520 720,520L792,576Q792,576 792,576Q792,576 792,576L832,538Q832,538 832,538Q832,538 832,538Q803,512 776,493Q749,474 720,460ZM240,458L240,458Q240,458 240,458Q240,458 240,458L240,458Q240,458 240,458Q240,458 240,458L240,458Q240,458 240,458Q240,458 240,458Q240,458 240,458Q240,458 240,458ZM720,460Q720,460 720,460Q720,460 720,460Q720,460 720,460Q720,460 720,460L720,460Q720,460 720,460Q720,460 720,460L720,460Q720,460 720,460Q720,460 720,460Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480ZM800,800L600,800Q600,780 598.5,760Q597,740 594,720L800,720Q800,720 800,720Q800,720 800,720L800,240Q800,240 800,240Q800,240 800,240L160,240Q160,240 160,240Q160,240 160,240L160,286Q140,283 120,281.5Q100,280 80,280L80,240Q80,207 103.5,183.5Q127,160 160,160L800,160Q833,160 856.5,183.5Q880,207 880,240L880,720Q880,753 856.5,776.5Q833,800 800,800ZM80,800L80,680Q130,680 165,715Q200,750 200,800L80,800ZM280,800Q280,717 221.5,658.5Q163,600 80,600L80,520Q197,520 278.5,601.5Q360,683 360,800L280,800ZM440,800Q440,725 411.5,659.5Q383,594 334.5,545.5Q286,497 220.5,468.5Q155,440 80,440L80,360Q171,360 251,394.5Q331,429 391,489Q451,549 485.5,629Q520,709 520,800L440,800Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480ZM800,800L600,800Q600,780 598.5,760Q597,740 594,720L800,720Q800,720 800,720Q800,720 800,720L800,240Q800,240 800,240Q800,240 800,240L160,240Q160,240 160,240Q160,240 160,240L160,286Q140,283 120,281.5Q100,280 80,280L80,240Q80,207 103.5,183.5Q127,160 160,160L800,160Q833,160 856.5,183.5Q880,207 880,240L880,720Q880,753 856.5,776.5Q833,800 800,800ZM80,800L80,680Q130,680 165,715Q200,750 200,800L80,800ZM280,800Q280,717 221.5,658.5Q163,600 80,600L80,520Q197,520 278.5,601.5Q360,683 360,800L280,800ZM440,800Q440,725 411.5,659.5Q383,594 334.5,545.5Q286,497 220.5,468.5Q155,440 80,440L80,360Q171,360 251,394.5Q331,429 391,489Q451,549 485.5,629Q520,709 520,800L440,800Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M400,656L240,496L296,440L400,544L664,280L720,336L400,656Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M400,656L240,496L296,440L400,544L664,280L720,336L400,656Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,920L480,840L760,840Q760,840 760,840Q760,840 760,840L760,800L600,800L600,480L760,480L760,440Q760,324 678,242Q596,160 480,160Q364,160 282,242Q200,324 200,440L200,480L360,480L360,800L200,800Q167,800 143.5,776.5Q120,753 120,720L120,440Q120,366 148.5,300.5Q177,235 226,186Q275,137 340.5,108.5Q406,80 480,80Q554,80 619.5,108.5Q685,137 734,186Q783,235 811.5,300.5Q840,366 840,440L840,840Q840,873 816.5,896.5Q793,920 760,920L480,920ZM200,720L280,720L280,560L200,560L200,720Q200,720 200,720Q200,720 200,720ZM680,720L760,720L760,560L680,560L680,720ZM200,560Q200,560 200,560Q200,560 200,560L200,560L280,560L280,560L200,560ZM680,560L680,560L760,560L760,560L680,560Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M480,920L480,840L760,840Q760,840 760,840Q760,840 760,840L760,800L600,800L600,480L760,480L760,440Q760,324 678,242Q596,160 480,160Q364,160 282,242Q200,324 200,440L200,480L360,480L360,800L200,800Q167,800 143.5,776.5Q120,753 120,720L120,440Q120,366 148.5,300.5Q177,235 226,186Q275,137 340.5,108.5Q406,80 480,80Q554,80 619.5,108.5Q685,137 734,186Q783,235 811.5,300.5Q840,366 840,440L840,840Q840,873 816.5,896.5Q793,920 760,920L480,920ZM200,720L280,720L280,560L200,560L200,720Q200,720 200,720Q200,720 200,720ZM680,720L760,720L760,560L680,560L680,720ZM200,560Q200,560 200,560Q200,560 200,560L200,560L280,560L280,560L200,560ZM680,560L680,560L760,560L760,560L680,560Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M710,598L652,540Q666,517 673,492Q680,467 680,440L760,440Q760,484 747,523.5Q734,563 710,598ZM480,366Q480,366 480,366L480,366L480,366L480,366Q480,366 480,366Q480,366 480,366Q480,366 480,366ZM592,478L520,406L520,200Q520,183 508.5,171.5Q497,160 480,160Q463,160 451.5,171.5Q440,183 440,200L440,326L360,246L360,200Q360,150 395,115Q430,80 480,80Q530,80 565,115Q600,150 600,200L600,440Q600,451 597.5,460Q595,469 592,478ZM440,840L440,717Q336,703 268,624Q200,545 200,440L280,440Q280,523 337.5,581.5Q395,640 480,640Q514,640 544.5,629.5Q575,619 600,600L657,657Q628,680 593.5,696Q559,712 520,717L520,840L440,840ZM792,904L56,168L112,112L848,848L792,904Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M710,598L652,540Q666,517 673,492Q680,467 680,440L760,440Q760,484 747,523.5Q734,563 710,598ZM480,366Q480,366 480,366L480,366L480,366L480,366Q480,366 480,366Q480,366 480,366Q480,366 480,366ZM592,478L520,406L520,200Q520,183 508.5,171.5Q497,160 480,160Q463,160 451.5,171.5Q440,183 440,200L440,326L360,246L360,200Q360,150 395,115Q430,80 480,80Q530,80 565,115Q600,150 600,200L600,440Q600,451 597.5,460Q595,469 592,478ZM440,840L440,717Q336,703 268,624Q200,545 200,440L280,440Q280,523 337.5,581.5Q395,640 480,640Q514,640 544.5,629.5Q575,619 600,600L657,657Q628,680 593.5,696Q559,712 520,717L520,840L440,840ZM792,904L56,168L112,112L848,848L792,904Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M395,525Q360,490 360,440L360,200Q360,150 395,115Q430,80 480,80Q530,80 565,115Q600,150 600,200L600,440Q600,490 565,525Q530,560 480,560Q430,560 395,525ZM480,320Q480,320 480,320L480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320L480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320ZM440,840L440,717Q336,703 268,624Q200,545 200,440L280,440Q280,523 338.5,581.5Q397,640 480,640Q563,640 621.5,581.5Q680,523 680,440L760,440Q760,545 692,624Q624,703 520,717L520,840L440,840ZM508.5,468.5Q520,457 520,440L520,200Q520,183 508.5,171.5Q497,160 480,160Q463,160 451.5,171.5Q440,183 440,200L440,440Q440,457 451.5,468.5Q463,480 480,480Q497,480 508.5,468.5Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M395,525Q360,490 360,440L360,200Q360,150 395,115Q430,80 480,80Q530,80 565,115Q600,150 600,200L600,440Q600,490 565,525Q530,560 480,560Q430,560 395,525ZM480,320Q480,320 480,320L480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320L480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320ZM440,840L440,717Q336,703 268,624Q200,545 200,440L280,440Q280,523 338.5,581.5Q397,640 480,640Q563,640 621.5,581.5Q680,523 680,440L760,440Q760,545 692,624Q624,703 520,717L520,840L440,840ZM508.5,468.5Q520,457 520,440L520,200Q520,183 508.5,171.5Q497,160 480,160Q463,160 451.5,171.5Q440,183 440,200L440,440Q440,457 451.5,468.5Q463,480 480,480Q497,480 508.5,468.5Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M367,433Q320,386 320,320Q320,254 367,207Q414,160 480,160Q546,160 593,207Q640,254 640,320Q640,386 593,433Q546,480 480,480Q414,480 367,433ZM160,800L160,688Q160,654 177.5,625.5Q195,597 224,582Q286,551 350,535.5Q414,520 480,520Q546,520 610,535.5Q674,551 736,582Q765,597 782.5,625.5Q800,654 800,688L800,800L160,800ZM240,720L720,720L720,688Q720,677 714.5,668Q709,659 700,654Q646,627 591,613.5Q536,600 480,600Q424,600 369,613.5Q314,627 260,654Q251,659 245.5,668Q240,677 240,688L240,720ZM536.5,376.5Q560,353 560,320Q560,287 536.5,263.5Q513,240 480,240Q447,240 423.5,263.5Q400,287 400,320Q400,353 423.5,376.5Q447,400 480,400Q513,400 536.5,376.5ZM480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320ZM480,720L480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720L480,720Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M367,433Q320,386 320,320Q320,254 367,207Q414,160 480,160Q546,160 593,207Q640,254 640,320Q640,386 593,433Q546,480 480,480Q414,480 367,433ZM160,800L160,688Q160,654 177.5,625.5Q195,597 224,582Q286,551 350,535.5Q414,520 480,520Q546,520 610,535.5Q674,551 736,582Q765,597 782.5,625.5Q800,654 800,688L800,800L160,800ZM240,720L720,720L720,688Q720,677 714.5,668Q709,659 700,654Q646,627 591,613.5Q536,600 480,600Q424,600 369,613.5Q314,627 260,654Q251,659 245.5,668Q240,677 240,688L240,720ZM536.5,376.5Q560,353 560,320Q560,287 536.5,263.5Q513,240 480,240Q447,240 423.5,263.5Q400,287 400,320Q400,353 423.5,376.5Q447,400 480,400Q513,400 536.5,376.5ZM480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320ZM480,720L480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720L480,720Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M760,480Q760,363 678.5,281.5Q597,200 480,200L480,120Q555,120 620.5,148.5Q686,177 734.5,225.5Q783,274 811.5,339.5Q840,405 840,480L760,480ZM600,480Q600,430 565,395Q530,360 480,360L480,280Q563,280 621.5,338.5Q680,397 680,480L600,480ZM798,840Q673,840 551,785.5Q429,731 329,631Q229,531 174.5,409Q120,287 120,162Q120,144 132,132Q144,120 162,120L324,120Q338,120 349,129.5Q360,139 362,152L388,292Q390,308 387,319Q384,330 376,338L279,436Q299,473 326.5,507.5Q354,542 387,574Q418,605 452,631.5Q486,658 524,680L618,586Q627,577 641.5,572.5Q656,568 670,570L808,598Q822,602 831,612.5Q840,623 840,636L840,798Q840,816 828,828Q816,840 798,840ZM241,360L307,294Q307,294 307,294Q307,294 307,294L290,200Q290,200 290,200Q290,200 290,200L201,200Q201,200 201,200Q201,200 201,200Q206,241 215,281Q224,321 241,360ZM599,718Q638,735 678.5,745Q719,755 760,758Q760,758 760,758Q760,758 760,758L760,670Q760,670 760,670Q760,670 760,670L666,651Q666,651 666,651Q666,651 666,651L599,718ZM241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360ZM599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M760,480Q760,363 678.5,281.5Q597,200 480,200L480,120Q555,120 620.5,148.5Q686,177 734.5,225.5Q783,274 811.5,339.5Q840,405 840,480L760,480ZM600,480Q600,430 565,395Q530,360 480,360L480,280Q563,280 621.5,338.5Q680,397 680,480L600,480ZM798,840Q673,840 551,785.5Q429,731 329,631Q229,531 174.5,409Q120,287 120,162Q120,144 132,132Q144,120 162,120L324,120Q338,120 349,129.5Q360,139 362,152L388,292Q390,308 387,319Q384,330 376,338L279,436Q299,473 326.5,507.5Q354,542 387,574Q418,605 452,631.5Q486,658 524,680L618,586Q627,577 641.5,572.5Q656,568 670,570L808,598Q822,602 831,612.5Q840,623 840,636L840,798Q840,816 828,828Q816,840 798,840ZM241,360L307,294Q307,294 307,294Q307,294 307,294L290,200Q290,200 290,200Q290,200 290,200L201,200Q201,200 201,200Q201,200 201,200Q206,241 215,281Q224,321 241,360ZM599,718Q638,735 678.5,745Q719,755 760,758Q760,758 760,758Q760,758 760,758L760,670Q760,670 760,670Q760,670 760,670L666,651Q666,651 666,651Q666,651 666,651L599,718ZM241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360L241,360Q241,360 241,360Q241,360 241,360ZM599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718L599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Q599,718 599,718Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M320,680Q287,680 263.5,656.5Q240,633 240,600L240,360Q240,327 263.5,303.5Q287,280 320,280L360,280L400,240L560,240L600,280L640,280Q673,280 696.5,303.5Q720,327 720,360L720,600Q720,633 696.5,656.5Q673,680 640,680L320,680ZM320,600L640,600Q640,600 640,600Q640,600 640,600L640,360Q640,360 640,360Q640,360 640,360L320,360Q320,360 320,360Q320,360 320,360L320,600Q320,600 320,600Q320,600 320,600ZM480,560Q513,560 536.5,536.5Q560,513 560,480Q560,447 536.5,423.5Q513,400 480,400Q447,400 423.5,423.5Q400,447 400,480Q400,513 423.5,536.5Q447,560 480,560ZM342,20Q376,9 410.5,4.5Q445,0 480,0Q574,0 657.5,33.5Q741,67 805.5,126.5Q870,186 911,266.5Q952,347 960,440L880,440Q873,368 842,305.5Q811,243 762.5,195.5Q714,148 651,118Q588,88 516,82L578,144L522,200L342,20ZM618,940Q584,951 549.5,955.5Q515,960 480,960Q386,960 302.5,926.5Q219,893 154.5,833.5Q90,774 49,693.5Q8,613 0,520L80,520Q88,592 118.5,654.5Q149,717 197.5,764.5Q246,812 309,842Q372,872 444,878L382,816L438,760L618,940ZM480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M320,680Q287,680 263.5,656.5Q240,633 240,600L240,360Q240,327 263.5,303.5Q287,280 320,280L360,280L400,240L560,240L600,280L640,280Q673,280 696.5,303.5Q720,327 720,360L720,600Q720,633 696.5,656.5Q673,680 640,680L320,680ZM320,600L640,600Q640,600 640,600Q640,600 640,600L640,360Q640,360 640,360Q640,360 640,360L320,360Q320,360 320,360Q320,360 320,360L320,600Q320,600 320,600Q320,600 320,600ZM480,560Q513,560 536.5,536.5Q560,513 560,480Q560,447 536.5,423.5Q513,400 480,400Q447,400 423.5,423.5Q400,447 400,480Q400,513 423.5,536.5Q447,560 480,560ZM342,20Q376,9 410.5,4.5Q445,0 480,0Q574,0 657.5,33.5Q741,67 805.5,126.5Q870,186 911,266.5Q952,347 960,440L880,440Q873,368 842,305.5Q811,243 762.5,195.5Q714,148 651,118Q588,88 516,82L578,144L522,200L342,20ZM618,940Q584,951 549.5,955.5Q515,960 480,960Q386,960 302.5,926.5Q219,893 154.5,833.5Q90,774 49,693.5Q8,613 0,520L80,520Q88,592 118.5,654.5Q149,717 197.5,764.5Q246,812 309,842Q372,872 444,878L382,816L438,760L618,940ZM480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480L480,480Q480,480 480,480Q480,480 480,480Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M880,700L720,540L720,607L640,527L640,240Q640,240 640,240Q640,240 640,240L353,240L273,160L640,160Q673,160 696.5,183.5Q720,207 720,240L720,420L880,260L880,700ZM822,934L26,138L82,82L878,878L822,934ZM498,385L498,385Q498,385 498,385Q498,385 498,385L498,385ZM382,496Q382,496 382,496Q382,496 382,496L382,496Q382,496 382,496Q382,496 382,496L382,496Q382,496 382,496Q382,496 382,496ZM160,160L240,240L160,240Q160,240 160,240Q160,240 160,240L160,720Q160,720 160,720Q160,720 160,720L640,720Q640,720 640,720Q640,720 640,720L640,640L720,720L720,720Q720,753 696.5,776.5Q673,800 640,800L160,800Q127,800 103.5,776.5Q80,753 80,720L80,240Q80,207 103.5,183.5Q127,160 160,160Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M880,700L720,540L720,607L640,527L640,240Q640,240 640,240Q640,240 640,240L353,240L273,160L640,160Q673,160 696.5,183.5Q720,207 720,240L720,420L880,260L880,700ZM822,934L26,138L82,82L878,878L822,934ZM498,385L498,385Q498,385 498,385Q498,385 498,385L498,385ZM382,496Q382,496 382,496Q382,496 382,496L382,496Q382,496 382,496Q382,496 382,496L382,496Q382,496 382,496Q382,496 382,496ZM160,160L240,240L160,240Q160,240 160,240Q160,240 160,240L160,720Q160,720 160,720Q160,720 160,720L640,720Q640,720 640,720Q640,720 640,720L640,640L720,720L720,720Q720,753 696.5,776.5Q673,800 640,800L160,800Q127,800 103.5,776.5Q80,753 80,720L80,240Q80,207 103.5,183.5Q127,160 160,160Z" />
</vector>
+5 -4
View File
@@ -1,10 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M160,800Q127,800 103.5,776.5Q80,753 80,720L80,240Q80,207 103.5,183.5Q127,160 160,160L640,160Q673,160 696.5,183.5Q720,207 720,240L720,420L880,260L880,700L720,540L720,720Q720,753 696.5,776.5Q673,800 640,800L160,800ZM160,720L640,720Q640,720 640,720Q640,720 640,720L640,240Q640,240 640,240Q640,240 640,240L160,240Q160,240 160,240Q160,240 160,240L160,720Q160,720 160,720Q160,720 160,720ZM160,720Q160,720 160,720Q160,720 160,720L160,240Q160,240 160,240Q160,240 160,240L160,240Q160,240 160,240Q160,240 160,240L160,720Q160,720 160,720Q160,720 160,720Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M160,800Q127,800 103.5,776.5Q80,753 80,720L80,240Q80,207 103.5,183.5Q127,160 160,160L640,160Q673,160 696.5,183.5Q720,207 720,240L720,420L880,260L880,700L720,540L720,720Q720,753 696.5,776.5Q673,800 640,800L160,800ZM160,720L640,720Q640,720 640,720Q640,720 640,720L640,240Q640,240 640,240Q640,240 640,240L160,240Q160,240 160,240Q160,240 160,240L160,720Q160,720 160,720Q160,720 160,720ZM160,720Q160,720 160,720Q160,720 160,720L160,240Q160,240 160,240Q160,240 160,240L160,240Q160,240 160,240Q160,240 160,240L160,720Q160,720 160,720Q160,720 160,720Z" />
</vector>
+5 -4
View File
@@ -1,11 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M560,829L560,747Q650,721 705,647Q760,573 760,479Q760,385 705,311Q650,237 560,211L560,129Q684,157 762,254.5Q840,352 840,479Q840,606 762,703.5Q684,801 560,829ZM120,600L120,360L280,360L480,160L480,800L280,600L120,600ZM560,640L560,318Q607,340 633.5,384Q660,428 660,480Q660,531 633.5,574.5Q607,618 560,640ZM400,354L314,440L200,440L200,520L314,520L400,606L400,354ZM300,480L300,480L300,480L300,480L300,480L300,480Z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M560,829L560,747Q650,721 705,647Q760,573 760,479Q760,385 705,311Q650,237 560,211L560,129Q684,157 762,254.5Q840,352 840,479Q840,606 762,703.5Q684,801 560,829ZM120,600L120,360L280,360L480,160L480,800L280,600L120,600ZM560,640L560,318Q607,340 633.5,384Q660,428 660,480Q660,531 633.5,574.5Q607,618 560,640ZM400,354L314,440L200,440L200,520L314,520L400,606L400,354ZM300,480L300,480L300,480L300,480L300,480L300,480Z" />
</vector>
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
@@ -19,4 +20,4 @@
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false" />
</LinearLayout>
</LinearLayout>
+11 -10
View File
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp"
android:gravity="center_vertical"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16dp"
android:gravity="center_vertical"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true">
<ImageView
android:id="@+id/device_icon"
@@ -32,4 +33,4 @@
android:visibility="gone"
android:contentDescription="Currently selected" />
</LinearLayout>
</LinearLayout>
+3 -1
View File
@@ -270,7 +270,9 @@
<item name="android:windowFullscreen">true</item>
</style>
<style name="Theme.App.NoActionBar.Fullscreen" parent="Theme.Material3.Dark.NoActionBar">
<style
name="Theme.App.NoActionBar.Fullscreen"
parent="Theme.Material3.Dark.NoActionBar">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowNoTitle">true</item>