Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions app/src/main/java/io/netbird/client/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private enum ConnectionState {

private boolean isSSOFinishedWell = false;
private boolean isRunningOnTV = false;
private boolean useDeviceCodeFlow = false;

// Last known state for UI updates
private ConnectionState lastKnownState = ConnectionState.UNKNOWN;
Expand Down Expand Up @@ -105,9 +106,13 @@ protected void onCreate(Bundle savedInstanceState) {
setSupportActionBar(binding.appBarMain.toolbar);

isRunningOnTV = PlatformUtils.isAndroidTV(this);
useDeviceCodeFlow = PlatformUtils.requiresDeviceCodeFlow(this);
if (isRunningOnTV) {
Log.i(LOGTAG, "Running on Android TV - optimizing for D-pad navigation");
}
if (useDeviceCodeFlow && !isRunningOnTV) {
Log.i(LOGTAG, "Running on ChromeOS - using device code flow for authentication");
}

setVersionText();

Expand Down Expand Up @@ -177,7 +182,7 @@ public void onDrawerClosed(View drawerView) {
}
});

if (!isRunningOnTV) {
if (!useDeviceCodeFlow) {
urlOpener = new CustomTabURLOpener(this, () -> {
if (isSSOFinishedWell) {
return;
Expand All @@ -202,11 +207,20 @@ public void open(String url, String userCode) {
mBinder.stopEngine();
});
qrCodeDialog.show(getSupportFragmentManager(), "QrCodeDialog");

if (!isRunningOnTV) {
try {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
} catch (Exception e) {
Log.e(LOGTAG, "Failed to open browser for device code flow: " + e.getMessage());
}
}
}

@Override
public void onLoginSuccess() {
Log.d(LOGTAG, "onLoginSuccess fired for TV.");
Log.d(LOGTAG, "onLoginSuccess fired for device code flow.");
if (qrCodeDialog != null && qrCodeDialog.isVisible()) {
qrCodeDialog.dismiss();
qrCodeDialog = null;
Expand All @@ -233,12 +247,12 @@ public void onLoginSuccess() {
if (VPNService.isUsingAlwaysOnVPN(this)) {
showAlwaysOnDialog(() -> {
if (mBinder != null) {
mBinder.runEngine(urlOpener, isRunningOnTV);
mBinder.runEngine(urlOpener, useDeviceCodeFlow);
}
});
} else {
if (mBinder != null) {
mBinder.runEngine(urlOpener, isRunningOnTV);
mBinder.runEngine(urlOpener, useDeviceCodeFlow);
}
}
});
Expand Down Expand Up @@ -345,7 +359,7 @@ public void switchConnection(boolean status) {
if (prepareIntent != null) {
vpnActivityResultLauncher.launch(prepareIntent);
} else {
mBinder.runEngine(urlOpener, isRunningOnTV);
mBinder.runEngine(urlOpener, useDeviceCodeFlow);
}
}

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/io/netbird/client/PlatformUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.UiModeManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;

public final class PlatformUtils {
Expand All @@ -16,5 +17,15 @@ public static boolean isAndroidTV(Context context) {
}
return false;
}

public static boolean isChromeOS(Context context) {
PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature("org.chromium.arc")
|| pm.hasSystemFeature("org.chromium.arc.device_management");
}

public static boolean requiresDeviceCodeFlow(Context context) {
return isAndroidTV(context) || isChromeOS(context);
}
}

2 changes: 1 addition & 1 deletion netbird
Submodule netbird updated 116 files
Loading