add http upload manager
This commit is contained in:
parent
d136928322
commit
d7ab5e1a4b
|
@ -0,0 +1,31 @@
|
||||||
|
package im.conversations.android.tls;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import im.conversations.android.database.model.Account;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
|
public class TrustManager implements X509TrustManager {
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
private final Account account;
|
||||||
|
|
||||||
|
public TrustManager(final Context context, final Account account) {
|
||||||
|
this.context = context;
|
||||||
|
this.account = account;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkClientTrusted(final X509Certificate[] chain, final String authType)
|
||||||
|
throws CertificateException {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkServerTrusted(final X509Certificate[] chain, final String authType)
|
||||||
|
throws CertificateException {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return new X509Certificate[0];
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,15 +3,12 @@ package im.conversations.android.ui.activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.databinding.DataBindingUtil;
|
import androidx.databinding.DataBindingUtil;
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
import im.conversations.android.R;
|
import im.conversations.android.R;
|
||||||
import im.conversations.android.databinding.ActivityMainBinding;
|
import im.conversations.android.databinding.ActivityMainBinding;
|
||||||
import im.conversations.android.service.ForegroundService;
|
import im.conversations.android.service.ForegroundService;
|
||||||
import im.conversations.android.ui.Activities;
|
import im.conversations.android.ui.Activities;
|
||||||
import im.conversations.android.ui.model.MainViewModel;
|
import im.conversations.android.ui.model.MainViewModel;
|
||||||
import im.conversations.android.ui.model.SetupViewModel;
|
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity {
|
public class MainActivity extends BaseActivity {
|
||||||
|
|
||||||
|
@ -24,12 +21,16 @@ public class MainActivity extends BaseActivity {
|
||||||
final ViewModelProvider viewModelProvider =
|
final ViewModelProvider viewModelProvider =
|
||||||
new ViewModelProvider(this, getDefaultViewModelProviderFactory());
|
new ViewModelProvider(this, getDefaultViewModelProviderFactory());
|
||||||
final var mainViewModel = viewModelProvider.get(MainViewModel.class);
|
final var mainViewModel = viewModelProvider.get(MainViewModel.class);
|
||||||
mainViewModel.hasNoAccounts().observe(this, hasNoAccounts -> {
|
mainViewModel
|
||||||
if (Boolean.TRUE.equals(hasNoAccounts)) {
|
.hasNoAccounts()
|
||||||
startActivity(new Intent(this,SetupActivity.class));
|
.observe(
|
||||||
finish();
|
this,
|
||||||
}
|
hasNoAccounts -> {
|
||||||
});
|
if (Boolean.TRUE.equals(hasNoAccounts)) {
|
||||||
|
startActivity(new Intent(this, SetupActivity.class));
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
Activities.setStatusAndNavigationBarColors(this, binding.getRoot());
|
Activities.setStatusAndNavigationBarColors(this, binding.getRoot());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package im.conversations.android.ui.model;
|
package im.conversations.android.ui.model;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.Transformations;
|
import androidx.lifecycle.Transformations;
|
||||||
|
|
||||||
import im.conversations.android.repository.AccountRepository;
|
import im.conversations.android.repository.AccountRepository;
|
||||||
|
|
||||||
public class MainViewModel extends AndroidViewModel {
|
public class MainViewModel extends AndroidViewModel {
|
||||||
|
|
|
@ -12,6 +12,8 @@ import im.conversations.android.xmpp.manager.BookmarkManager;
|
||||||
import im.conversations.android.xmpp.manager.CarbonsManager;
|
import im.conversations.android.xmpp.manager.CarbonsManager;
|
||||||
import im.conversations.android.xmpp.manager.ChatStateManager;
|
import im.conversations.android.xmpp.manager.ChatStateManager;
|
||||||
import im.conversations.android.xmpp.manager.DiscoManager;
|
import im.conversations.android.xmpp.manager.DiscoManager;
|
||||||
|
import im.conversations.android.xmpp.manager.HttpUploadManager;
|
||||||
|
import im.conversations.android.xmpp.manager.JingleConnectionManager;
|
||||||
import im.conversations.android.xmpp.manager.NickManager;
|
import im.conversations.android.xmpp.manager.NickManager;
|
||||||
import im.conversations.android.xmpp.manager.PepManager;
|
import im.conversations.android.xmpp.manager.PepManager;
|
||||||
import im.conversations.android.xmpp.manager.PresenceManager;
|
import im.conversations.android.xmpp.manager.PresenceManager;
|
||||||
|
@ -36,6 +38,10 @@ public final class Managers {
|
||||||
.put(CarbonsManager.class, new CarbonsManager(context, connection))
|
.put(CarbonsManager.class, new CarbonsManager(context, connection))
|
||||||
.put(ChatStateManager.class, new ChatStateManager(context, connection))
|
.put(ChatStateManager.class, new ChatStateManager(context, connection))
|
||||||
.put(DiscoManager.class, new DiscoManager(context, connection))
|
.put(DiscoManager.class, new DiscoManager(context, connection))
|
||||||
|
.put(HttpUploadManager.class, new HttpUploadManager(context, connection))
|
||||||
|
.put(
|
||||||
|
JingleConnectionManager.class,
|
||||||
|
new JingleConnectionManager(context, connection))
|
||||||
.put(NickManager.class, new NickManager(context, connection))
|
.put(NickManager.class, new NickManager(context, connection))
|
||||||
.put(PepManager.class, new PepManager(context, connection))
|
.put(PepManager.class, new PepManager(context, connection))
|
||||||
.put(PresenceManager.class, new PresenceManager(context, connection))
|
.put(PresenceManager.class, new PresenceManager(context, connection))
|
||||||
|
|
|
@ -1793,13 +1793,14 @@ public class XmppConnection implements Runnable {
|
||||||
this.sendPacket(response);
|
this.sendPacket(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendErrorFor(final Iq request, final Condition condition) {
|
public void sendErrorFor(final Iq request, final Error.Type type, final Condition condition) {
|
||||||
final var from = request.getFrom();
|
final var from = request.getFrom();
|
||||||
final var id = request.getId();
|
final var id = request.getId();
|
||||||
final var response = new Iq(Iq.Type.ERROR);
|
final var response = new Iq(Iq.Type.ERROR);
|
||||||
response.setTo(from);
|
response.setTo(from);
|
||||||
response.setId(id);
|
response.setId(id);
|
||||||
final Error error = response.addExtension(new Error());
|
final Error error = response.addExtension(new Error());
|
||||||
|
error.setType(type);
|
||||||
error.setCondition(condition);
|
error.setCondition(condition);
|
||||||
this.sendPacket(response);
|
this.sendPacket(response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import im.conversations.android.xmpp.model.disco.info.InfoQuery;
|
||||||
import im.conversations.android.xmpp.model.disco.items.Item;
|
import im.conversations.android.xmpp.model.disco.items.Item;
|
||||||
import im.conversations.android.xmpp.model.disco.items.ItemsQuery;
|
import im.conversations.android.xmpp.model.disco.items.ItemsQuery;
|
||||||
import im.conversations.android.xmpp.model.error.Condition;
|
import im.conversations.android.xmpp.model.error.Condition;
|
||||||
|
import im.conversations.android.xmpp.model.error.Error;
|
||||||
import im.conversations.android.xmpp.model.stanza.Iq;
|
import im.conversations.android.xmpp.model.stanza.Iq;
|
||||||
import im.conversations.android.xmpp.model.version.Version;
|
import im.conversations.android.xmpp.model.version.Version;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -303,7 +304,7 @@ public class DiscoManager extends AbstractManager {
|
||||||
serviceDescription = cachedServiceDescription;
|
serviceDescription = cachedServiceDescription;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("No disco info was cached for node {}", nodeRequest);
|
LOGGER.warn("No disco info was cached for node {}", nodeRequest);
|
||||||
connection.sendErrorFor(request, new Condition.ItemNotFound());
|
connection.sendErrorFor(request, Error.Type.CANCEL, new Condition.ItemNotFound());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,7 +315,7 @@ public class DiscoManager extends AbstractManager {
|
||||||
|
|
||||||
public void handleVersion(final Iq request) {
|
public void handleVersion(final Iq request) {
|
||||||
if (isPrivacyModeEnabled()) {
|
if (isPrivacyModeEnabled()) {
|
||||||
connection.sendErrorFor(request, new Condition.ServiceUnavailable());
|
connection.sendErrorFor(request, Error.Type.CANCEL, new Condition.ServiceUnavailable());
|
||||||
} else {
|
} else {
|
||||||
final var version = new Version();
|
final var version = new Version();
|
||||||
version.setSoftwareName(BuildConfig.APP_NAME);
|
version.setSoftwareName(BuildConfig.APP_NAME);
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package im.conversations.android.xmpp.manager;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import im.conversations.android.xmpp.XmppConnection;
|
||||||
|
|
||||||
|
public class HttpUploadManager extends AbstractManager {
|
||||||
|
|
||||||
|
public HttpUploadManager(Context context, XmppConnection connection) {
|
||||||
|
super(context, connection);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package im.conversations.android.xmpp.manager;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import im.conversations.android.xmpp.XmppConnection;
|
||||||
|
import im.conversations.android.xmpp.model.stanza.Iq;
|
||||||
|
|
||||||
|
public class JingleConnectionManager extends AbstractManager {
|
||||||
|
public JingleConnectionManager(Context context, XmppConnection connection) {
|
||||||
|
super(context, connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleJingle(Iq packet) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package im.conversations.android.xmpp.model.error;
|
||||||
import im.conversations.android.annotation.XmlElement;
|
import im.conversations.android.annotation.XmlElement;
|
||||||
import im.conversations.android.xml.Namespace;
|
import im.conversations.android.xml.Namespace;
|
||||||
import im.conversations.android.xmpp.model.Extension;
|
import im.conversations.android.xmpp.model.Extension;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
@XmlElement(namespace = Namespace.JABBER_CLIENT)
|
@XmlElement(namespace = Namespace.JABBER_CLIENT)
|
||||||
public class Error extends Extension {
|
public class Error extends Extension {
|
||||||
|
@ -22,4 +23,15 @@ public class Error extends Extension {
|
||||||
public Text getText() {
|
public Text getText() {
|
||||||
return this.getExtension(Text.class);
|
return this.getExtension(Text.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setType(final Type type) {
|
||||||
|
this.setAttribute("type", type.toString().toLowerCase(Locale.ROOT));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
MODIFY,
|
||||||
|
CANCEL,
|
||||||
|
AUTH,
|
||||||
|
WAIT
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package im.conversations.android.xmpp.model.jingle;
|
||||||
|
|
||||||
|
import im.conversations.android.annotation.XmlElement;
|
||||||
|
import im.conversations.android.xmpp.model.Extension;
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public class Jingle extends Extension {
|
||||||
|
|
||||||
|
|
||||||
|
public Jingle() {
|
||||||
|
super(Jingle.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,11 +5,14 @@ import com.google.common.base.Preconditions;
|
||||||
import im.conversations.android.xmpp.XmppConnection;
|
import im.conversations.android.xmpp.XmppConnection;
|
||||||
import im.conversations.android.xmpp.manager.BlockingManager;
|
import im.conversations.android.xmpp.manager.BlockingManager;
|
||||||
import im.conversations.android.xmpp.manager.DiscoManager;
|
import im.conversations.android.xmpp.manager.DiscoManager;
|
||||||
|
import im.conversations.android.xmpp.manager.JingleConnectionManager;
|
||||||
import im.conversations.android.xmpp.manager.RosterManager;
|
import im.conversations.android.xmpp.manager.RosterManager;
|
||||||
import im.conversations.android.xmpp.model.blocking.Block;
|
import im.conversations.android.xmpp.model.blocking.Block;
|
||||||
import im.conversations.android.xmpp.model.blocking.Unblock;
|
import im.conversations.android.xmpp.model.blocking.Unblock;
|
||||||
import im.conversations.android.xmpp.model.disco.info.InfoQuery;
|
import im.conversations.android.xmpp.model.disco.info.InfoQuery;
|
||||||
import im.conversations.android.xmpp.model.error.Condition;
|
import im.conversations.android.xmpp.model.error.Condition;
|
||||||
|
import im.conversations.android.xmpp.model.error.Error;
|
||||||
|
import im.conversations.android.xmpp.model.jingle.Jingle;
|
||||||
import im.conversations.android.xmpp.model.ping.Ping;
|
import im.conversations.android.xmpp.model.ping.Ping;
|
||||||
import im.conversations.android.xmpp.model.roster.Query;
|
import im.conversations.android.xmpp.model.roster.Query;
|
||||||
import im.conversations.android.xmpp.model.stanza.Iq;
|
import im.conversations.android.xmpp.model.stanza.Iq;
|
||||||
|
@ -68,9 +71,13 @@ public class IqProcessor extends XmppConnection.Delegate implements Consumer<Iq>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type == Iq.Type.SET && packet.hasExtension(Jingle.class)) {
|
||||||
|
getManager(JingleConnectionManager.class).handleJingle(packet);
|
||||||
|
}
|
||||||
|
|
||||||
final var extensionIds = packet.getExtensionIds();
|
final var extensionIds = packet.getExtensionIds();
|
||||||
LOGGER.info("Received from {} type {}", packet.getFrom(), type);
|
LOGGER.info("Received from {} type {}", packet.getFrom(), type);
|
||||||
LOGGER.info("Could not handle {}. Sending feature-not-implemented", extensionIds);
|
LOGGER.info("Could not handle {}. Sending feature-not-implemented", extensionIds);
|
||||||
connection.sendErrorFor(packet, new Condition.FeatureNotImplemented());
|
connection.sendErrorFor(packet, Error.Type.CANCEL, new Condition.FeatureNotImplemented());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue