Skip to content

Commit

Permalink
Squashed commit:
Browse files Browse the repository at this point in the history
- Update build tools
- Update sublibs
- Add proper PlacePicker, fixes #65
- Add selfcheck
- Improvements to MCS connection, related #31 #54
- Do not crash when permission to GPS is not granted
- Various smaller fixes
  • Loading branch information
mar-v-in committed Jan 27, 2016
1 parent affce9d commit 8fa0515
Show file tree
Hide file tree
Showing 48 changed files with 950 additions and 341 deletions.
2 changes: 1 addition & 1 deletion extern/UnifiedNlp
Binary file modified libs/vtm-android-0.6.0-SNAPSHOT.aar
Binary file not shown.
1 change: 1 addition & 0 deletions microg-ui-tools
File renamed without changes.
31 changes: 28 additions & 3 deletions play-services-core/build.gradle
Expand Up @@ -19,7 +19,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:1.5.0'
}
}

Expand All @@ -33,13 +33,14 @@ repositories {
}

dependencies {
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.squareup.wire:wire-runtime:1.6.1'

compile project(":microg-ui-tools")
compile project(':play-services-api')
compile project(':unifiednlp-base')
compile project(':wearable-lib')

// vtm from ./libs
compile 'org.oscim:vtm-android:0.6.0-SNAPSHOT@aar'
compile 'org.oscim:vtm-themes:0.6.0-SNAPSHOT@jar'
Expand All @@ -53,10 +54,34 @@ dependencies {
compile 'org.slf4j:slf4j-android:1.7.6'
}

String getMyVersionName() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags', '--always', '--dirty'
standardOutput = stdout
}
return stdout.toString().trim()
}

int getMyVersionCode(String ref) {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--count', "$ref..HEAD"
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim())
}

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
versionName("8.4.89 (microG " + getMyVersionName() + ")")
// Update commit id to current when increasing gms version code
versionCode(8489238 + getMyVersionCode('249c935f'))
}

sourceSets {
main {
java.srcDirs += 'src/main/protos-java'
Expand Down
20 changes: 8 additions & 12 deletions play-services-core/src/main/AndroidManifest.xml
Expand Up @@ -14,11 +14,8 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<manifest
package="com.google.android.gms"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="8489238"
android:versionName="8.4.89 (microG v0.02)">
<manifest package="com.google.android.gms"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-sdk
android:minSdkVersion="14"
Expand Down Expand Up @@ -57,6 +54,10 @@
android:name="org.microg.gms.STATUS_BROADCAST"
android:label="@string/perm_status_broadcast_label"
android:protectionLevel="normal"/>
<permission
android:name="org.microg.gms.EXTENDED_ACCESS"
android:label="@string/perm_extended_access_label"
android:protectionLevel="dangerous"/>

<uses-permission android:name="android.permission.FAKE_PACKAGE_SIGNATURE"/>

Expand All @@ -78,6 +79,7 @@
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="com.google.android.c2dm.permission.SEND"/>
<uses-permission android:name="org.microg.gms.STATUS_BROADCAST"/>
<uses-permission android:name="org.microg.gms.EXTENDED_ACCESS"/>

<application
android:allowBackup="false"
Expand Down Expand Up @@ -208,8 +210,7 @@
android:name="org.microg.gms.maps.data.SharedTileProvider"
android:authorities="org.microg.gms.map.tile"
android:enabled="true"
android:exported="true">
</provider>
android:exported="true"/>

<!-- DroidGuard -->

Expand Down Expand Up @@ -360,11 +361,6 @@
</intent-filter>
</activity>

<activity
android:name="org.microg.gms.ui.SelfCheckActivity"
android:label="@string/self_check_title"
android:theme="@style/SettingsTheme"/>

<!-- Other -->

<service
Expand Down
Expand Up @@ -22,14 +22,14 @@
import com.google.android.gms.dynamic.ObjectWrapper;
import com.google.android.gms.plus.internal.IPlusOneButtonCreator;

import org.microg.gms.common.Constants;
import org.microg.gms.auth.AuthConstants;
import org.microg.gms.plus.PlusOneButtonImpl;

public class PlusOneButtonCreatorImpl extends IPlusOneButtonCreator.Stub {
@Override
public IObjectWrapper create(IObjectWrapper context, int size, int annotation, String url, int activityRequestCode) throws RemoteException {
Context ctx = (Context) ObjectWrapper.unwrap(context);
return ObjectWrapper.wrap(new PlusOneButtonImpl(ctx, size, annotation, url, Constants.DEFAULT_ACCOUNT));
return ObjectWrapper.wrap(new PlusOneButtonImpl(ctx, size, annotation, url, AuthConstants.DEFAULT_ACCOUNT));
}

@Override
Expand Down
Expand Up @@ -16,17 +16,30 @@

package org.microg.gms.auth;

import android.Manifest;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.google.android.gms.R;

import org.microg.gms.common.PackageUtils;

import java.util.Arrays;

import static org.microg.gms.auth.AuthConstants.PROVIDER_EXTRA_ACCOUNTS;
import static org.microg.gms.auth.AuthConstants.PROVIDER_EXTRA_CLEAR_PASSWORD;
import static org.microg.gms.auth.AuthConstants.PROVIDER_METHOD_CLEAR_PASSWORD;
import static org.microg.gms.auth.AuthConstants.PROVIDER_METHOD_GET_ACCOUNTS;

public class AccountContentProvider extends ContentProvider {
private static final String TAG = "GmsAuthProvider";

Expand All @@ -38,13 +51,20 @@ public boolean onCreate() {
@Nullable
@Override
public Bundle call(String method, String arg, Bundle extras) {
// FIXME: Restrict access!
if ("get_accounts".equals(method) && getContext().getString(R.string.google_account_type).equals(arg)) {
if (!PackageUtils.callerHasExtendedAccess(getContext())) {
String[] packagesForUid = getContext().getPackageManager().getPackagesForUid(Binder.getCallingUid());
if (packagesForUid != null && packagesForUid.length != 0)
Log.w(TAG, "Not granting access to " + Arrays.toString(packagesForUid)
+ ", signature: " + PackageUtils.firstSignatureDigest(getContext(), packagesForUid[0]));
if (getContext().checkCallingPermission(Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED)
throw new SecurityException("Access denied, missing GET_ACCOUNTS or EXTENDED_ACCESS permission");
}
if (PROVIDER_METHOD_GET_ACCOUNTS.equals(method) && getContext().getString(R.string.google_account_type).equals(arg)) {
Bundle result = new Bundle();
result.putParcelableArray("accounts", AccountManager.get(getContext()).getAccountsByType(arg));
result.putParcelableArray(PROVIDER_EXTRA_ACCOUNTS, AccountManager.get(getContext()).getAccountsByType(arg));
return result;
} else if ("clear_password".equals(method)) {
Account a = extras.getParcelable("clear_password");
} else if (PROVIDER_METHOD_CLEAR_PASSWORD.equals(method)) {
Account a = extras.getParcelable(PROVIDER_EXTRA_CLEAR_PASSWORD);
AccountManager.get(getContext()).clearPassword(a);
return null;
}
Expand Down
Expand Up @@ -25,7 +25,6 @@

import com.google.android.gms.R;

import org.microg.gms.common.Constants;
import org.microg.gms.common.PackageUtils;

import java.io.IOException;
Expand Down Expand Up @@ -180,7 +179,7 @@ private boolean isSystemApp() {
}

public AuthResponse requestAuth(boolean legacy) throws IOException {
if (service.equals(Constants.SCOPE_GET_ACCOUNT_ID)) {
if (service.equals(AuthConstants.SCOPE_GET_ACCOUNT_ID)) {
AuthResponse response = new AuthResponse();
response.accountId = response.auth = getAccountManager().getUserData(getAccount(), "GoogleUserId");
return response;
Expand Down
Expand Up @@ -20,12 +20,35 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Binder;

import com.google.android.gms.Manifest;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

import static org.microg.gms.common.Constants.GMS_PACKAGE_SIGNATURE_SHA1;

public class PackageUtils {

private static final String[] KNOWN_GOOGLE_SIGNATURES = {GMS_PACKAGE_SIGNATURE_SHA1};

public static boolean isGoogleSignedPackages(Context context, String packageName) {
return Arrays.asList(KNOWN_GOOGLE_SIGNATURES).contains(firstSignatureDigest(context, packageName));
}

public static void assertExtendedAccess(Context context) {
if (!callerHasExtendedAccess(context))
throw new SecurityException("Access denied, missing EXTENDED_ACCESS permission");
}

public static boolean callerHasExtendedAccess(Context context) {
String[] packagesForUid = context.getPackageManager().getPackagesForUid(Binder.getCallingUid());
return (packagesForUid != null && packagesForUid.length != 0 && isGoogleSignedPackages(context, packagesForUid[0])) ||
context.checkCallingPermission(Manifest.permission.EXTENDED_ACCESS) == PackageManager.PERMISSION_GRANTED;
}

public static void checkPackageUid(Context context, String packageName, int callingUid) {
String[] packagesForUid = context.getPackageManager().getPackagesForUid(callingUid);
if (packagesForUid != null && !Arrays.asList(packagesForUid).contains(packageName)) {
Expand Down
15 changes: 15 additions & 0 deletions play-services-core/src/main/java/org/microg/gms/common/Utils.java
Expand Up @@ -16,7 +16,12 @@

package org.microg.gms.common;

import android.Manifest;
import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.widget.Toast;

import com.google.android.gms.R;

import org.microg.gms.checkin.LastCheckinInfo;

Expand All @@ -25,6 +30,8 @@
import java.io.InputStream;
import java.util.Locale;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;

public class Utils {
public static String getAndroidIdHex(Context context) {
return Long.toHexString(LastCheckinInfo.read(context).androidId);
Expand All @@ -38,6 +45,14 @@ public static Build getBuild(Context context) {
return new Build();
}

public static boolean hasSelfPermissionOrNotify(Context context, String permission) {
if (ContextCompat.checkSelfPermission(context, permission) != PERMISSION_GRANTED) {
Toast.makeText(context, context.getString(R.string.lacking_permission_toast, permission), Toast.LENGTH_SHORT).show();
return false;
}
return true;
}

public static byte[] readStreamToEnd(final InputStream is) throws IOException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
if (is != null) {
Expand Down
Expand Up @@ -16,7 +16,7 @@

package org.microg.gms.gcm;

public class Constants {
public final class McsConstants {
public static final int MCS_HEARTBEAT_PING_TAG = 0;
public static final int MCS_HEARTBEAT_ACK_TAG = 1;
public static final int MCS_LOGIN_REQUEST_TAG = 2;
Expand All @@ -32,6 +32,7 @@ public class Constants {
public static final int MSG_OUTPUT = 20;
public static final int MSG_OUTPUT_ERROR = 21;
public static final int MSG_OUTPUT_READY = 22;
public static final int MSG_OUTPUT_DONE = 23;
public static final int MSG_TEARDOWN = 30;
public static final int MSG_CONNECT = 40;
public static final int MSG_HEARTBEAT = 41;
Expand Down
Expand Up @@ -33,16 +33,16 @@
import java.io.IOException;
import java.io.InputStream;

import static org.microg.gms.gcm.Constants.MCS_CLOSE_TAG;
import static org.microg.gms.gcm.Constants.MCS_DATA_MESSAGE_STANZA_TAG;
import static org.microg.gms.gcm.Constants.MCS_HEARTBEAT_ACK_TAG;
import static org.microg.gms.gcm.Constants.MCS_HEARTBEAT_PING_TAG;
import static org.microg.gms.gcm.Constants.MCS_IQ_STANZA_TAG;
import static org.microg.gms.gcm.Constants.MCS_LOGIN_REQUEST_TAG;
import static org.microg.gms.gcm.Constants.MCS_LOGIN_RESPONSE_TAG;
import static org.microg.gms.gcm.Constants.MSG_INPUT;
import static org.microg.gms.gcm.Constants.MSG_INPUT_ERROR;
import static org.microg.gms.gcm.Constants.MSG_TEARDOWN;
import static org.microg.gms.gcm.McsConstants.MCS_CLOSE_TAG;
import static org.microg.gms.gcm.McsConstants.MCS_DATA_MESSAGE_STANZA_TAG;
import static org.microg.gms.gcm.McsConstants.MCS_HEARTBEAT_ACK_TAG;
import static org.microg.gms.gcm.McsConstants.MCS_HEARTBEAT_PING_TAG;
import static org.microg.gms.gcm.McsConstants.MCS_IQ_STANZA_TAG;
import static org.microg.gms.gcm.McsConstants.MCS_LOGIN_REQUEST_TAG;
import static org.microg.gms.gcm.McsConstants.MCS_LOGIN_RESPONSE_TAG;
import static org.microg.gms.gcm.McsConstants.MSG_INPUT;
import static org.microg.gms.gcm.McsConstants.MSG_INPUT_ERROR;
import static org.microg.gms.gcm.McsConstants.MSG_TEARDOWN;

public class McsInputStream extends Thread {
private static final String TAG = "GmsGcmMcsInput";
Expand Down Expand Up @@ -71,10 +71,9 @@ public McsInputStream(InputStream is, Handler mainHandler, boolean initialized)
public void run() {
try {
while (!Thread.currentThread().isInterrupted()) {
Message msg = read();
Log.d(TAG, "Incoming message: " + msg);
android.os.Message msg = read();
if (msg != null) {
mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_INPUT, msg));
mainHandler.dispatchMessage(msg);
} else {
mainHandler.dispatchMessage(mainHandler.obtainMessage(MSG_TEARDOWN, "null message"));
}
Expand Down Expand Up @@ -118,7 +117,7 @@ private synchronized void ensureVersionRead() {
}
}

public synchronized Message read() throws IOException {
public synchronized android.os.Message read() throws IOException {
ensureVersionRead();
int mcsTag = is.read();
int mcsSize = readVarint();
Expand All @@ -132,8 +131,10 @@ public synchronized Message read() throws IOException {
len += (read = is.read(bytes, len, mcsSize - len)) < 0 ? 0 : read;
}
Message message = read(mcsTag, bytes, len);
if (message == null) return null;
Log.d(TAG, "Incoming message: " + message);
streamId++;
return message;
return mainHandler.obtainMessage(MSG_INPUT, mcsTag, streamId, message);
}

private static Message read(int mcsTag, byte[] bytes, int len) throws IOException {
Expand Down

0 comments on commit 8fa0515

Please sign in to comment.