Check local network permissions

master
M66B 2 months ago
parent b48bb38b5d
commit 797d06cbb0

@ -197,6 +197,7 @@ import java.io.OutputStream;
import java.io.Serializable; import java.io.Serializable;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.InetAddress;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.Principal; import java.security.Principal;
import java.security.PrivateKey; import java.security.PrivateKey;
@ -5905,6 +5906,7 @@ public class FragmentMessages extends FragmentBase
if (!checkFingerprint()) if (!checkFingerprint())
if (!checkGmail()) if (!checkGmail())
if (!checkOutlook()) if (!checkOutlook())
if (!checkLan())
; ;
prefs.registerOnSharedPreferenceChangeListener(this); prefs.registerOnSharedPreferenceChangeListener(this);
@ -6401,6 +6403,68 @@ public class FragmentMessages extends FragmentBase
} }
}.execute(this, new Bundle(), "outlook:check"); }.execute(this, new Bundle(), "outlook:check");
return false;
}
private boolean checkLan() {
new SimpleTask<Boolean>() {
@Override
protected Boolean onExecute(Context context, Bundle args) throws Throwable {
if (Helper.hasPermission(context, Manifest.permission.ACCESS_LOCAL_NETWORK))
return false;
DB db = DB.getInstance(context);
List<EntityAccount> accounts = db.account().getSynchronizingAccounts(null);
if (accounts != null)
for (EntityAccount account : accounts)
try {
InetAddress addr = InetAddress.getByName(account.host);
if (addr.isSiteLocalAddress() || addr.isLinkLocalAddress() || addr.isLoopbackAddress())
return true;
List<EntityIdentity> identities = db.identity().getSynchronizingIdentities(account.id);
if (identities != null)
for (EntityIdentity identity : identities)
try {
addr = InetAddress.getByName(identity.host);
if (addr.isSiteLocalAddress() || addr.isLinkLocalAddress() || addr.isLoopbackAddress())
return true;
} catch (Throwable ignored) {
}
} catch (Throwable ignored) {
}
return false;
}
@Override
protected void onExecuted(Bundle args, Boolean lan) {
if (!Boolean.TRUE.equals(lan))
return;
final Snackbar snackbar = Helper.setSnackbarOptions(Snackbar.make(view, R.string.title_lan_required, Snackbar.LENGTH_INDEFINITE));
Helper.setSnackbarLines(snackbar, 5);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View v) {
snackbar.dismiss();
if (BuildConfig.PLAY_STORE_RELEASE)
Helper.viewFAQ(v.getContext(), 210);
else
v.getContext().startActivity(new Intent(v.getContext(), ActivitySetup.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
.putExtra("tab", "connection"));
}
});
snackbar.show();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, new Bundle(), "checklan");
return true; return true;
} }

@ -1303,6 +1303,7 @@
<string name="title_pop3" translatable="false">POP3</string> <string name="title_pop3" translatable="false">POP3</string>
<string name="title_smtp" translatable="false">SMTP</string> <string name="title_smtp" translatable="false">SMTP</string>
<string name="title_lan">Local network permissions must be granted on the connection settings tab page</string> <string name="title_lan">Local network permissions must be granted on the connection settings tab page</string>
<string name="title_lan_required">Local network permissions required</string>
<string name="title_aliases">Aliases</string> <string name="title_aliases">Aliases</string>
<string name="title_provider">Provider</string> <string name="title_provider">Provider</string>
<string name="title_custom">Custom</string> <string name="title_custom">Custom</string>

Loading…
Cancel
Save