Commit 235e49c8 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Fixes as per code review

parent 1448814e
......@@ -118,11 +118,6 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
//I've received their broadcast and should connect to their TCP socket and send my identity.
private void udpPacketReceived(DatagramPacket packet) {
if (TrustedNetworkHelper.isNotTrustedNetwork(context)) {
Log.w("LanLinkProvider", "Current WiFi isn't a Trusted Network");
return;
}
final InetAddress address = packet.getAddress();
try {
......@@ -370,15 +365,19 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
}
lastBroadcast = System.currentTimeMillis();
if (TrustedNetworkHelper.isNotTrustedNetwork(context)) {
Log.w("LanLinkProvider", "Current WiFi isn't a Trusted Network");
return;
}
new Thread(() -> {
ArrayList<String> iplist = CustomDevicesActivity
.getCustomDeviceList(PreferenceManager.getDefaultSharedPreferences(context));
iplist.add("255.255.255.255"); //Default: broadcast.
if (TrustedNetworkHelper.isTrustedNetwork(context)) {
iplist.add("255.255.255.255"); //Default: broadcast.
} else {
Log.i("LanLinkProvider", "Current network isn't trusted, not broadcasting");
}
if (iplist.isEmpty()) {
return;
}
NetworkPacket identity = NetworkPacket.createIdentityPacket(context);
int port = (tcpServer == null || !tcpServer.isBound()) ? MIN_PORT : tcpServer.getLocalPort();
......
......@@ -71,27 +71,23 @@ public class TrustedNetworkHelper {
public String currentSSID() {
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
Log.d("Fou", "get");
if (wifiManager == null) return "";
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo.getSupplicantState() != SupplicantState.COMPLETED) {
Log.d("Fou", "fooo");
return "";
}
String ssid = wifiInfo.getSSID();
if (ssid.equalsIgnoreCase(NOT_AVAILABLE_SSID_RESULT)){
Log.d("Fou", "navail");
return "";
}
Log.d("Fou", "retn");
return ssid;
}
public static boolean isNotTrustedNetwork(Context context) {
public static boolean isTrustedNetwork(Context context) {
TrustedNetworkHelper trustedNetworkHelper = new TrustedNetworkHelper(context);
if (trustedNetworkHelper.allAllowed()){
return false;
return true;
}
return trustedNetworkHelper.read().indexOf(trustedNetworkHelper.currentSSID()) == -1;
return trustedNetworkHelper.read().contains(trustedNetworkHelper.currentSSID());
}
}
......@@ -190,10 +190,10 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
//Check if we're on Wi-Fi. If we still see a device, don't do anything special
if (someDevicesReachable || wifi.isConnected()) {
if (TrustedNetworkHelper.isNotTrustedNetwork(getContext())) {
((ListView) rootView.findViewById(R.id.devices_list)).addHeaderView(notTrustedText);
} else {
if (TrustedNetworkHelper.isTrustedNetwork(getContext())) {
((ListView) rootView.findViewById(R.id.devices_list)).addHeaderView(headerText);
} else {
((ListView) rootView.findViewById(R.id.devices_list)).addHeaderView(notTrustedText);
}
} else {
((ListView) rootView.findViewById(R.id.devices_list)).addHeaderView(noWifiHeader);
......
package org.kde.kdeconnect.UserInterface;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
......@@ -8,6 +9,7 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ListView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
......@@ -25,6 +27,20 @@ public class TrustedNetworksActivity extends AppCompatActivity {
private CheckBox allowAllCheckBox;
private TrustedNetworkHelper trustedNetworkHelper;
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
boolean grantedPermission = false;
for (int result : grantResults) {
if (result == PackageManager.PERMISSION_GRANTED) {
grantedPermission = true;
break;
}
}
if (grantedPermission) {
allowAllCheckBox.setChecked(false);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment