Various fixes

Fixes #24
This commit is contained in:
mar-v-in 2015-08-06 17:38:46 +02:00
parent 44f4bdc6ac
commit bd69c16c62
9 changed files with 50 additions and 68 deletions

View File

@ -33,8 +33,8 @@ repositories {
}
dependencies {
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.squareup.wire:wire-runtime:1.6.1'
compile project(':play-services-api')

View File

@ -73,6 +73,7 @@
<uses-permission android:name="org.microg.gms.STATUS_BROADCAST" />
<application
android:allowBackup="false"
android:icon="@drawable/ic_microg_app"
android:label="@string/gms_app_name">
<meta-data

View File

@ -267,12 +267,13 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity {
}
View view = convertView;
if (view == null) {
view = LayoutInflater.from(AskPermissionActivity.this).inflate(R.layout.ask_permission_list_entry, null);
view = LayoutInflater.from(AskPermissionActivity.this)
.inflate(R.layout.ask_permission_list_entry, parent, false);
}
((TextView) view.findViewById(android.R.id.text1)).setText(label);
TextView textView = (TextView) view.findViewById(android.R.id.text2);
if (description != null && !description.isEmpty()) {
textView.setText(Html.fromHtml(description.trim().replace("\n","<br>")));
textView.setText(Html.fromHtml(description.trim().replace("\n", "<br>")));
textView.setVisibility(VISIBLE);
} else {
textView.setVisibility(GONE);

View File

@ -18,6 +18,7 @@ package org.microg.gms.auth.login;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Color;
@ -79,6 +80,7 @@ public class LoginActivity extends AssistantActivity {
private AccountManager accountManager;
private InputMethodManager inputMethodManager;
@SuppressLint("AddJavascriptInterface")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -141,6 +143,7 @@ public class LoginActivity extends AssistantActivity {
return webView;
}
@SuppressLint("SetJavaScriptEnabled")
private static void prepareWebViewSettings(WebSettings settings) {
settings.setUserAgentString(settings.getUserAgentString() + MAGIC_USER_AGENT);
settings.setJavaScriptEnabled(true);
@ -258,8 +261,8 @@ public class LoginActivity extends AssistantActivity {
.appendQueryParameter("source", "android")
.appendQueryParameter("xoauth_display_name", "Android Device")
.appendQueryParameter("lang", locale.getLanguage())
.appendQueryParameter("cc", locale.getCountry().toLowerCase())
.appendQueryParameter("langCountry", locale.toString().toLowerCase())
.appendQueryParameter("cc", locale.getCountry().toLowerCase(Locale.US))
.appendQueryParameter("langCountry", locale.toString().toLowerCase(Locale.US))
.appendQueryParameter("hl", locale.toString().replace("_", "-"))
.appendQueryParameter("tmpl", tmpl)
.build().toString();

View File

@ -24,6 +24,7 @@ import org.microg.gms.common.Build;
import org.microg.gms.common.DeviceConfiguration;
import org.microg.gms.common.DeviceIdentifier;
import org.microg.gms.common.PhoneInfo;
import org.microg.gms.common.Utils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -64,20 +65,7 @@ public class CheckinClient {
if (connection.getResponseCode() != 200) {
try {
InputStream is = new GZIPInputStream(connection.getErrorStream());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
if (is != null) {
final byte[] buff = new byte[1024];
while (true) {
final int nb = is.read(buff);
if (nb < 0) {
break;
}
bos.write(buff, 0, nb);
}
is.close();
}
throw new IOException(bos.toString());
throw new IOException(new String(Utils.readStreamToEnd(new GZIPInputStream(connection.getErrorStream()))));
} catch (Exception e) {
throw new IOException(connection.getResponseMessage(), e);
}

View File

@ -16,6 +16,7 @@
package org.microg.gms.common;
import java.util.Locale;
import java.util.Random;
public class Build {
@ -33,11 +34,11 @@ public class Build {
public String id = android.os.Build.ID;
public String serial = generateSerialNumber(); // TODO: static
@SuppressWarnings("deprecation")
private static String getRadio() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
return android.os.Build.getRadioVersion();
} else {
//noinspection deprecation
return android.os.Build.RADIO;
}
}
@ -47,7 +48,7 @@ public class Build {
Random rand = new Random();
for (int i = 0; i < 10; i++)
serial += Integer.toString(rand.nextInt(16), 16);
serial = serial.toUpperCase();
serial = serial.toUpperCase(Locale.US);
return serial;
}
}

View File

@ -24,6 +24,7 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.opengl.GLES10;
import android.os.Build;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import java.util.ArrayList;
@ -80,13 +81,7 @@ public class DeviceConfiguration {
if (featureInfo.name != null) availableFeatures.add(featureInfo.name);
}
Collections.sort(availableFeatures);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
nativePlatforms = Arrays.asList(Build.SUPPORTED_ABIS);
} else {
nativePlatforms = new ArrayList<String>();
nativePlatforms.add(Build.CPU_ABI);
if (Build.CPU_ABI2 != null) nativePlatforms.add(Build.CPU_ABI2);
}
this.nativePlatforms = getNativePlatforms();
widthPixels = displayMetrics.widthPixels;
heightPixels = displayMetrics.heightPixels;
locales = new ArrayList<String>(Arrays.asList(context.getAssets().getLocales()));
@ -100,6 +95,19 @@ public class DeviceConfiguration {
Collections.sort(this.glExtensions);
}
@SuppressWarnings({"deprecation", "InlinedApi"})
private static List<String> getNativePlatforms() {
List<String> nativePlatforms;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return Arrays.asList(Build.SUPPORTED_ABIS);
} else {
nativePlatforms = new ArrayList<String>();
nativePlatforms.add(Build.CPU_ABI);
if (Build.CPU_ABI2 != null) nativePlatforms.add(Build.CPU_ABI2);
return nativePlatforms;
}
}
private static void addEglExtensions(Set<String> glExtensions) {
EGL10 egl10 = (EGL10) EGLContext.getEGL();
if (egl10 != null) {

View File

@ -17,18 +17,12 @@
package org.microg.gms.common;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import org.microg.gms.checkin.LastCheckinInfo;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Locale;
public class Utils {
@ -48,13 +42,10 @@ public class Utils {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
if (is != null) {
final byte[] buff = new byte[1024];
while (true) {
final int nb = is.read(buff);
if (nb < 0) {
break;
}
bos.write(buff, 0, nb);
}
int read;
do {
bos.write(buff, 0, (read = is.read(buff)) < 0 ? 0 : read);
} while (read >= 0);
is.close();
}
return bos.toByteArray();

View File

@ -47,12 +47,13 @@ public class McsInputStream extends Thread {
private static final String TAG = "GmsGcmMcsInput";
private final InputStream is;
private final Handler mainHandler;
private boolean initialized;
private int version = -1;
private int lastStreamIdReported = -1;
private int streamId = 0;
private long lastMsgTime = 0;
private Handler mainHandler;
public McsInputStream(InputStream is, Handler mainHandler) {
this(is, mainHandler, false);
@ -69,11 +70,7 @@ public class McsInputStream extends Thread {
public void run() {
try {
while (!Thread.currentThread().isInterrupted()) {
Message message = read();
if (message != null) {
lastMsgTime = System.currentTimeMillis();
mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_INPUT, message));
}
mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_INPUT, read()));
}
} catch (IOException e) {
try {
@ -93,10 +90,6 @@ public class McsInputStream extends Thread {
return streamId;
}
public long getLastMsgTime() {
return lastMsgTime;
}
public boolean newStreamIdAvailable() {
return lastStreamIdReported != streamId;
}
@ -106,7 +99,7 @@ public class McsInputStream extends Thread {
return version;
}
private void ensureVersionRead() {
private synchronized void ensureVersionRead() {
if (!initialized) {
try {
version = is.read();
@ -122,14 +115,15 @@ public class McsInputStream extends Thread {
ensureVersionRead();
int mcsTag = is.read();
int mcsSize = readVarint();
if (mcsTag < 0 || mcsSize < 0) return null;
byte[] bytes = new byte[mcsSize];
int len = 0;
while (len < mcsSize) {
len += is.read(bytes, len, mcsSize - len);
int len = 0, read = 0;
while (len < mcsSize && read >= 0) {
len += (read = is.read(bytes, len, mcsSize - len)) < 0 ? 0 : read;
}
Message read = read(mcsTag, bytes, len);
Message message = read(mcsTag, bytes, len);
streamId++;
return read;
return message;
}
private static Message read(int mcsTag, byte[] bytes, int len) throws IOException {
@ -156,16 +150,11 @@ public class McsInputStream extends Thread {
}
private int readVarint() throws IOException {
int res = 0;
int s = 0;
int b = 0x80;
while ((b & 0x80) == 0x80) {
b = is.read();
res |= (b & 0x7F) << s;
s += 7;
}
int res = 0, s = -7, read;
do {
res |= ((read = is.read()) & 0x7F) << (s += 7);
} while (read >= 0 && (read & 0x80) == 0x80 && s < 32);
if (read < 0) return -1;
return res;
}
}