mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 14:15:14 +00:00
Do not broadcast in 3G + info message
This commit is contained in:
@@ -70,7 +70,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/unpair_message"
|
||||
android:id="@+id/not_reachable_message"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:drawableStart="@drawable/ic_error_outline_black_48dp"
|
||||
@@ -82,6 +82,19 @@
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/on_data_message"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:drawableStart="@drawable/ic_error_outline_black_48dp"
|
||||
android:drawableLeft="@drawable/ic_error_outline_black_48dp"
|
||||
android:drawablePadding="8dip"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/on_data_message"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/buttons_list"
|
||||
android:layout_width="match_parent"
|
||||
|
@@ -193,6 +193,7 @@
|
||||
<string name="device_rename_confirm">Rename</string>
|
||||
<string name="refresh">Refresh</string>
|
||||
<string name="unreachable_description">This paired device is not reachable. Make sure it is connected to your same network.</string>
|
||||
<string name="on_data_message">It looks like you are on a mobile data connection. KDE Connect only works on local networks.</string>
|
||||
<string name="no_file_browser">There are no file browsers installed.</string>
|
||||
<string name="pref_plugin_telepathy">Send SMS</string>
|
||||
<string name="pref_plugin_telepathy_desc">Send text messages from your desktop</string>
|
||||
|
@@ -31,6 +31,7 @@ import org.kde.kdeconnect.Backends.BaseLinkProvider;
|
||||
import org.kde.kdeconnect.BackgroundService;
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.Helpers.DeviceHelper;
|
||||
import org.kde.kdeconnect.Helpers.NetworkHelper;
|
||||
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
||||
import org.kde.kdeconnect.Helpers.StringsHelper;
|
||||
import org.kde.kdeconnect.NetworkPackage;
|
||||
@@ -362,6 +363,11 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
||||
|
||||
private void broadcastUdpPackage() {
|
||||
|
||||
if (NetworkHelper.isOnMobileNetwork(context)) {
|
||||
Log.w("LanLinkProvider", "On 3G network, not sending broadcast.");
|
||||
return;
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@@ -119,7 +119,7 @@ public class BackgroundService extends Service {
|
||||
}
|
||||
};
|
||||
|
||||
private void onDeviceListChanged() {
|
||||
public void onDeviceListChanged() {
|
||||
for(DeviceListChangedCallback callback : deviceListChangedCallbacks.values()) {
|
||||
callback.onDeviceListChanged();
|
||||
}
|
||||
|
16
src/org/kde/kdeconnect/Helpers/NetworkHelper.java
Normal file
16
src/org/kde/kdeconnect/Helpers/NetworkHelper.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package org.kde.kdeconnect.Helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.util.Log;
|
||||
|
||||
public class NetworkHelper {
|
||||
|
||||
public static boolean isOnMobileNetwork(Context context) {
|
||||
final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo info = connMgr.getActiveNetworkInfo();
|
||||
return (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE);
|
||||
}
|
||||
|
||||
}
|
@@ -67,6 +67,7 @@ public class KdeConnectBroadcastReceiver extends BroadcastReceiver
|
||||
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
||||
@Override
|
||||
public void onServiceStart(BackgroundService service) {
|
||||
service.onDeviceListChanged();
|
||||
service.onNetworkChange();
|
||||
}
|
||||
});
|
||||
|
@@ -40,6 +40,7 @@ import android.widget.TextView;
|
||||
|
||||
import org.kde.kdeconnect.BackgroundService;
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.Helpers.NetworkHelper;
|
||||
import org.kde.kdeconnect.Helpers.SecurityHelpers.SslHelper;
|
||||
import org.kde.kdeconnect.Plugins.Plugin;
|
||||
import org.kde.kdeconnect.UserInterface.List.CustomItem;
|
||||
@@ -333,9 +334,11 @@ public class DeviceFragment extends Fragment {
|
||||
|
||||
boolean paired = device.isPaired();
|
||||
boolean reachable = device.isReachable();
|
||||
boolean onData = NetworkHelper.isOnMobileNetwork(getContext());
|
||||
|
||||
rootView.findViewById(R.id.pairing_buttons).setVisibility(paired ? View.GONE : View.VISIBLE);
|
||||
rootView.findViewById(R.id.unpair_message).setVisibility((paired && !reachable) ? View.VISIBLE : View.GONE);
|
||||
rootView.findViewById(R.id.not_reachable_message).setVisibility((paired && !reachable && !onData) ? View.VISIBLE : View.GONE);
|
||||
rootView.findViewById(R.id.on_data_message).setVisibility((paired && !reachable && onData) ? View.VISIBLE : View.GONE);
|
||||
|
||||
try {
|
||||
ArrayList<ListAdapter.Item> items = new ArrayList<>();
|
||||
|
@@ -36,6 +36,7 @@ import android.widget.TextView;
|
||||
|
||||
import org.kde.kdeconnect.BackgroundService;
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.Helpers.NetworkHelper;
|
||||
import org.kde.kdeconnect.UserInterface.List.ListAdapter;
|
||||
import org.kde.kdeconnect.UserInterface.List.PairingDeviceItem;
|
||||
import org.kde.kdeconnect.UserInterface.List.SectionItem;
|
||||
@@ -60,6 +61,8 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
|
||||
boolean listRefreshCalledThisFrame = false;
|
||||
|
||||
TextView headerText;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
@@ -74,10 +77,10 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
|
||||
rootView = inflater.inflate(R.layout.activity_list, container, false);
|
||||
|
||||
TextView text = new TextView(inflater.getContext());
|
||||
text.setText(getString(R.string.pairing_description));
|
||||
text.setPadding(0, (int) (16 * getResources().getDisplayMetrics().density), 0, (int) (12 * getResources().getDisplayMetrics().density));
|
||||
((ListView) rootView).addHeaderView(text);
|
||||
headerText = new TextView(inflater.getContext());
|
||||
headerText.setText(getString(R.string.pairing_description));
|
||||
headerText.setPadding(0, (int) (16 * getResources().getDisplayMetrics().density), 0, (int) (12 * getResources().getDisplayMetrics().density));
|
||||
((ListView) rootView).addHeaderView(headerText);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
@@ -104,6 +107,8 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
}
|
||||
listRefreshCalledThisFrame = true;
|
||||
|
||||
headerText.setText(getString(NetworkHelper.isOnMobileNetwork(getContext()) ? R.string.on_data_message : R.string.pairing_description));
|
||||
|
||||
try {
|
||||
Collection<Device> devices = service.getDevices().values();
|
||||
final ArrayList<ListAdapter.Item> items = new ArrayList<>();
|
||||
|
Reference in New Issue
Block a user