diff options
Diffstat (limited to 'src/main/java/de')
3 files changed, 105 insertions, 15 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 0d367b3d7..f011c67b1 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -186,8 +186,8 @@ public class XmppConnectionService extends Service { public FileBackend fileBackend = new FileBackend(this); private MemorizingTrustManager mMemorizingTrustManager; private NotificationService mNotificationService = new NotificationService(this); - private ShortcutService mShortcutService = new ShortcutService(this); - private AtomicBoolean mInitialAddressbookSyncCompleted = new AtomicBoolean(false); + private ShortcutService mShortcutService = new ShortcutService(this); + private AtomicBoolean mInitialAddressbookSyncCompleted = new AtomicBoolean(false); private AtomicBoolean mForceForegroundService = new AtomicBoolean(false); private OnMessagePacketReceived mMessageParser = new MessageParser(this); private OnPresencePacketReceived mPresenceParser = new PresenceParser(this); @@ -1005,7 +1005,7 @@ public class XmppConnectionService extends Service { public void onCreate() { ExceptionHelper.init(getApplicationContext()); PRNGFixes.apply(); - Resolver.registerXmppConnectionService(this); + Resolver.init(this); this.mRandom = new SecureRandom(); updateMemorizingTrustmanager(); final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); @@ -2573,9 +2573,9 @@ public class XmppConnectionService extends Service { } public boolean createAdhocConference(final Account account, - final String subject, - final Iterable<Jid> jids, - final UiCallback<Conversation> callback) { + final String subject, + final Iterable<Jid> jids, + final UiCallback<Conversation> callback) { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": creating adhoc conference with " + jids.toString()); if (account.getStatus() == Account.State.ONLINE) { try { @@ -3365,7 +3365,7 @@ public class XmppConnectionService extends Service { } public long getLongPreference(String name, @IntegerRes int res) { - long defaultValue = getResources().getInteger(res); + long defaultValue = getResources().getInteger(res); try { return Long.parseLong(getPreferences().getString(name,String.valueOf(defaultValue))); } catch (NumberFormatException e) { @@ -4105,7 +4105,7 @@ public class XmppConnectionService extends Service { } public void ScheduleAutomaticExport() { - //start export log service every day at given time + //start export log service every day at given time if (Config.ExportLogs) { if (Config.ExportLogs_Hour >= 0 && Config.ExportLogs_Hour <= 23 && Config.ExportLogs_Minute >= 0 && Config.ExportLogs_Minute <= 59) { Calendar now = Calendar.getInstance(); diff --git a/src/main/java/de/pixart/messenger/utils/AndroidUsingExecLowPriority.java b/src/main/java/de/pixart/messenger/utils/AndroidUsingExecLowPriority.java new file mode 100644 index 000000000..6097fcd03 --- /dev/null +++ b/src/main/java/de/pixart/messenger/utils/AndroidUsingExecLowPriority.java @@ -0,0 +1,92 @@ +/* + * Copyright 2015-2016 the original author or authors + * + * This software is licensed under the Apache License, Version 2.0, + * the GNU Lesser General Public License version 2 or later ("LGPL") + * and the WTFPL. + * You may choose either license to govern your use of this software only + * upon the condition that you accept all of the terms of either + * the Apache License 2.0, the LGPL 2.1+ or the WTFPL. + */ + +package de.pixart.messenger.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.net.InetAddress; +import java.util.HashSet; +import java.util.logging.Level; + +import de.measite.minidns.dnsserverlookup.AbstractDNSServerLookupMechanism; +import de.measite.minidns.dnsserverlookup.AndroidUsingReflection; +import de.measite.minidns.dnsserverlookup.DNSServerLookupMechanism; +import de.measite.minidns.util.PlatformDetection; + +/** + * Try to retrieve the list of DNS server by executing getprop. + */ +public class AndroidUsingExecLowPriority extends AbstractDNSServerLookupMechanism { + + public static final DNSServerLookupMechanism INSTANCE = new AndroidUsingExecLowPriority(); + public static final int PRIORITY = AndroidUsingReflection.PRIORITY + 1; + + private AndroidUsingExecLowPriority() { + super(AndroidUsingExecLowPriority.class.getSimpleName(), PRIORITY); + } + + @Override + public String[] getDnsServerAddresses() { + try { + Process process = Runtime.getRuntime().exec("getprop"); + InputStream inputStream = process.getInputStream(); + LineNumberReader lnr = new LineNumberReader( + new InputStreamReader(inputStream)); + String line; + HashSet<String> server = new HashSet<>(6); + while ((line = lnr.readLine()) != null) { + int split = line.indexOf("]: ["); + if (split == -1) { + continue; + } + String property = line.substring(1, split); + String value = line.substring(split + 4, line.length() - 1); + + if (value.isEmpty()) { + continue; + } + + if (property.endsWith(".dns") || property.endsWith(".dns1") || + property.endsWith(".dns2") || property.endsWith(".dns3") || + property.endsWith(".dns4")) { + + // normalize the address + + InetAddress ip = InetAddress.getByName(value); + + if (ip == null) continue; + + value = ip.getHostAddress(); + + if (value == null) continue; + if (value.length() == 0) continue; + + server.add(value); + } + } + if (server.size() > 0) { + return server.toArray(new String[server.size()]); + } + } catch (IOException e) { + LOGGER.log(Level.WARNING, "Exception in findDNSByExec", e); + } + return null; + } + + @Override + public boolean isAvailable() { + return PlatformDetection.isAndroid(); + } + +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/utils/Resolver.java b/src/main/java/de/pixart/messenger/utils/Resolver.java index 7e85258b2..c405a8397 100644 --- a/src/main/java/de/pixart/messenger/utils/Resolver.java +++ b/src/main/java/de/pixart/messenger/utils/Resolver.java @@ -1,6 +1,5 @@ package de.pixart.messenger.utils; -import android.content.Context; import android.support.annotation.NonNull; import android.util.Log; @@ -15,6 +14,7 @@ import java.util.List; import de.measite.minidns.DNSClient; import de.measite.minidns.DNSName; import de.measite.minidns.dnssec.DNSSECResultNotAuthenticException; +import de.measite.minidns.dnsserverlookup.AndroidUsingExec; import de.measite.minidns.hla.DnssecResolverApi; import de.measite.minidns.hla.ResolverApi; import de.measite.minidns.hla.ResolverResult; @@ -38,13 +38,11 @@ public class Resolver { private static XmppConnectionService SERVICE = null; - public static void registerXmppConnectionService(XmppConnectionService service) { + public static void init(XmppConnectionService service) { Resolver.SERVICE = service; - registerLookupMechanism(service); - } - - private static void registerLookupMechanism(Context context) { - DNSClient.addDnsServerLookupMechanism(new AndroidUsingLinkProperties(context)); + DNSClient.removeDNSServerLookupMechanism(AndroidUsingExec.INSTANCE); + DNSClient.addDnsServerLookupMechanism(AndroidUsingExecLowPriority.INSTANCE); + DNSClient.addDnsServerLookupMechanism(new AndroidUsingLinkProperties(service)); } public static List<Result> resolve(String domain) throws NetworkIsUnreachableException { |