fixed signing properties

This commit is contained in:
Mariotaku Lee 2017-03-01 15:04:11 +08:00
parent 2d3d536e6d
commit 685e61cc7e
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
3 changed files with 22 additions and 33 deletions

View File

@ -31,6 +31,11 @@ import android.webkit.WebSettings;
import android.webkit.WebView;
import java.lang.reflect.Constructor;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* Created by mariotaku on 15/4/12.
@ -73,48 +78,32 @@ public class UserAgentUtils {
@WorkerThread
@Nullable
public static String getDefaultUserAgentStringSafe(Context context) {
public static String getDefaultUserAgentStringSafe(final Context context) {
if (Looper.myLooper() == Looper.getMainLooper()) {
//noinspection ResourceType
return getDefaultUserAgentString(context);
}
final Handler handler = new Handler(Looper.getMainLooper());
FutureTask<String> task = new FutureTask<>(new Callable<String>() {
@Override
public String call() throws Exception {
return getDefaultUserAgentString(context);
}
});
try {
final FetchUserAgentRunnable runnable = new FetchUserAgentRunnable(context);
handler.post(runnable);
runnable.waitForExecution();
return runnable.getUserAgent();
handler.post(task);
return task.get(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (TimeoutException e) {
throw new RuntimeException(e);
} finally {
handler.removeCallbacksAndMessages(null);
}
}
private static class FetchUserAgentRunnable implements Runnable {
private final Context context;
private String userAgent;
private boolean userAgentSet;
public FetchUserAgentRunnable(Context context) {
this.context = context;
}
@Override
public void run() {
userAgent = getDefaultUserAgentString(context);
userAgentSet = true;
}
public String getUserAgent() {
return userAgent;
}
public void waitForExecution() {
//noinspection StatementWithEmptyBody
while (!userAgentSet) ;
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
static class NewApiWrapper {
private NewApiWrapper() {

View File

@ -169,7 +169,7 @@ internal object AccountDataQueue {
} else handler.post {
future.run()
}
return future.get()
return future.get(1, TimeUnit.SECONDS)
}
fun peekAuthToken(manager: AccountManager, account: Account, authTokenType: String): String? {
@ -179,7 +179,7 @@ internal object AccountDataQueue {
} else handler.post {
future.run()
}
return future.get()
return future.get(1, TimeUnit.SECONDS)
}
}