crash fixes

This commit is contained in:
Mariotaku Lee 2017-07-07 16:01:59 +08:00
parent 691d2e7aaa
commit 34966dfd4e
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
8 changed files with 126 additions and 120 deletions

View File

@ -43,7 +43,7 @@ subprojects {
PlayServices : '3.1.0',
]
libVersions = [
Kotlin : '1.1.2-5',
Kotlin : '1.1.3-2',
SupportLib : '26.0.0-beta2',
MariotakuCommons : '0.9.15',
RestFu : '0.9.57',

View File

@ -21,8 +21,8 @@ package org.mariotaku.microblog.library.twitter.model;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.mariotaku.restfu.http.HttpResponse;
import org.mariotaku.microblog.library.twitter.util.InternalParseUtil;
import org.mariotaku.restfu.http.HttpResponse;
import java.util.AbstractList;
import java.util.ArrayList;
@ -72,25 +72,10 @@ public class QueryResult extends AbstractList<Status> implements TwitterResponse
@Override
public int size() {
if (statuses == null) return 0;
return statuses.size();
}
public double getCompletedIn() {
return metadata.completedIn;
}
public long getMaxId() {
return metadata.maxId;
}
public String getQuery() {
return metadata.query;
}
public int getResultsPerPage() {
return metadata.count;
}
@Override
public long getNextCursor() {
return nextCursor;
@ -112,10 +97,32 @@ public class QueryResult extends AbstractList<Status> implements TwitterResponse
}
public long getSinceId() {
if (metadata == null) return -1;
return metadata.sinceId;
}
public double getCompletedIn() {
if (metadata == null) return Double.NaN;
return metadata.completedIn;
}
public long getMaxId() {
if (metadata == null) return -1;
return metadata.maxId;
}
public String getQuery() {
if (metadata == null) return null;
return metadata.query;
}
public int getResultsPerPage() {
if (metadata == null) return -1;
return metadata.count;
}
public String getWarning() {
if (metadata == null) return null;
return metadata.warning;
}

View File

@ -1,95 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.util.net;
import android.os.Build;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
/**
* @author fkrauthan
*/
public class TLSSocketFactory extends SSLSocketFactory {
private SSLSocketFactory internalSSLSocketFactory;
public TLSSocketFactory() throws KeyManagementException, NoSuchAlgorithmException {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, null, null);
internalSSLSocketFactory = context.getSocketFactory();
}
@Override
public String[] getDefaultCipherSuites() {
return internalSSLSocketFactory.getDefaultCipherSuites();
}
@Override
public String[] getSupportedCipherSuites() {
return internalSSLSocketFactory.getSupportedCipherSuites();
}
@Override
public Socket createSocket() throws IOException {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket());
}
@Override
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(s, host, port, autoClose));
}
@Override
public Socket createSocket(String host, int port) throws IOException {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
}
@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port, localHost, localPort));
}
@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
}
@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(address, port, localAddress, localPort));
}
private Socket enableTLSOnSocket(Socket socket) {
if (socket == null || (!(socket instanceof SSLSocket))) {
return socket;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return socket;
((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1.1", "TLSv1.2"});
return socket;
}
}

View File

@ -32,6 +32,14 @@ fun Cursor.safeGetInt(columnIndex: Int, def: Int = -1): Int {
}
}
fun Cursor.safeGetString(columnIndex: Int, def: String = ""): String {
try {
return getString(columnIndex)
} catch(e: IllegalStateException) {
return def
}
}
fun <T> Cursor.map(indices: ObjectCursor.CursorIndices<T>): List<T> {
val list = ArrayList<T>()
moveToFirst()

View File

@ -1933,6 +1933,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
adapter.setSelection(layoutPosition)
return@setOnLongClickListener true
}
iconView.style = adapter.profileImageStyle
}
fun showAccount(adapter: AccountIconsAdapter, account: AccountDetails, isSelected: Boolean) {

View File

@ -439,8 +439,8 @@ abstract class ParcelableStatusesAdapter(
if (!cursor.safeMoveToPosition(dataPosition)) return defValue
val indices = data.indices
val _id = cursor.safeGetLong(indices[Statuses._ID])
val accountKey = UserKey.valueOf(cursor.getString(indices[Statuses.ACCOUNT_KEY]))
val id = cursor.getString(indices[Statuses.ID])
val accountKey = UserKey.valueOf(cursor.safeGetString(indices[Statuses.ACCOUNT_KEY]))
val id = cursor.safeGetString(indices[Statuses.ID])
val timestamp = cursor.safeGetLong(indices[Statuses.TIMESTAMP])
val sortId = cursor.safeGetLong(indices[Statuses.SORT_ID])
val positionKey = cursor.safeGetLong(indices[Statuses.POSITION_KEY])

View File

@ -0,0 +1,85 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.util.net
import java.io.IOException
import java.net.InetAddress
import java.net.Socket
import javax.net.ssl.SSLContext
import javax.net.ssl.SSLSocket
import javax.net.ssl.SSLSocketFactory
/**
* @author fkrauthan
*/
class TLSSocketFactory : SSLSocketFactory() {
private val internalSSLSocketFactory: SSLSocketFactory
init {
val context = SSLContext.getInstance("TLS")
context.init(null, null, null)
internalSSLSocketFactory = context.socketFactory
}
override fun getDefaultCipherSuites(): Array<String> {
return internalSSLSocketFactory.defaultCipherSuites
}
override fun getSupportedCipherSuites(): Array<String> {
return internalSSLSocketFactory.supportedCipherSuites
}
@Throws(IOException::class)
override fun createSocket(s: Socket, host: String, port: Int, autoClose: Boolean): Socket {
return internalSSLSocketFactory.createSocket(s, host, port, autoClose).applyTLS()
}
@Throws(IOException::class)
override fun createSocket(host: String, port: Int): Socket {
return internalSSLSocketFactory.createSocket(host, port).applyTLS()
}
@Throws(IOException::class)
override fun createSocket(host: String, port: Int, localHost: InetAddress, localPort: Int): Socket {
return internalSSLSocketFactory.createSocket(host, port, localHost, localPort).applyTLS()
}
@Throws(IOException::class)
override fun createSocket(host: InetAddress, port: Int): Socket {
return internalSSLSocketFactory.createSocket(host, port).applyTLS()
}
@Throws(IOException::class)
override fun createSocket(address: InetAddress, port: Int, localAddress: InetAddress, localPort: Int): Socket {
return internalSSLSocketFactory.createSocket(address, port, localAddress, localPort).applyTLS()
}
private fun Socket.applyTLS(): Socket {
if (this is SSLSocket) {
enabledProtocols = this.supportedProtocols.intersect(tlsProtocols).toTypedArray()
}
return this
}
companion object {
private val tlsProtocols = listOf("TLSv1.2", "TLSv1.1", "TLSv1")
}
}

View File

@ -276,16 +276,16 @@ class TwidereDns(context: Context, private val preferences: SharedPreferences) :
val a = lookup.run()
if (a == null) {
if (lookup.result == Lookup.TYPE_NOT_FOUND) {
val aaaa = newLookup(resolver, name, Type.AAAA).run()
if (aaaa != null)
return aaaa
// val aaaa = newLookup(resolver, name, Type.AAAA).run()
// if (aaaa != null) return aaaa
}
throw UnknownHostException("unknown host")
}
if (!all)
return a
val aaaa = newLookup(resolver, name, Type.AAAA).run() ?: return a
return a + aaaa
// val aaaa = newLookup(resolver, name, Type.AAAA).run() ?: return a
// return a + aaaa
return a
} catch (e: TextParseException) {
throw UnknownHostException("invalid name")
}