Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
First working version, including library to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
mar-v-in committed Sep 24, 2016
1 parent 1d6d7ca commit 99b7d04
Show file tree
Hide file tree
Showing 32 changed files with 1,120 additions and 292 deletions.
14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
language: android
sudo: false
git:
submodules: false
before_install:
- git submodule update --init --recursive
before_script:
- echo sdk.dir $ANDROID_HOME > local.properties
script:
- export JAVA_OPTS="-XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx2048m"
- export TERM=dumb
- export JAVA_OPTS="-XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx2048m"
- ./gradlew build
- echo sdk.dir $ANDROID_HOME > local.properties
- jdk_switcher use oraclejdk8
- ./gradlew assemble
android:
components:
- platform-tools
- tools
- build-tools-23.0.3
- android-23
- build-tools-24.0.2
- android-24
- extra-android-m2repository
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.android.tools.build:gradle:2.2.0'
}
}

allprojects {
apply plugin: 'idea'
ext.androidBuildVersionTools = "23.0.3"
ext.androidBuildVersionTools = "24.0.2"
ext.isReleaseVersion = false
}

def androidCompileSdk() { return 23 }
def androidCompileSdk() { return 24 }

def androidTargetSdk() { return 23 }
def androidTargetSdk() { return 24 }

def androidMinSdk() { return 10 }

Expand Down
39 changes: 39 additions & 0 deletions remote-droid-guard-lib/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apply plugin: 'com.android.library'

dependencies {
compile 'org.microg:safe-parcel:1.4.0'
}

String getMyVersionName() {
def stdout = new ByteArrayOutputStream()
if (rootProject.file("gradlew").exists())
exec {
commandLine 'git', 'describe', '--tags', '--always', '--dirty'; standardOutput = stdout
}
else // automatic build system, don't tag dirty
exec { commandLine 'git', 'describe', '--tags', '--always'; standardOutput = stdout }
return stdout.toString().trim().substring(1)
}

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

android {
compileSdkVersion androidCompileSdk()
buildToolsVersion "$androidBuildVersionTools"

defaultConfig {
versionName getMyVersionName()
versionCode getMyVersionCode()
}
}

if (file('user.gradle').exists()) {
apply from: 'user.gradle'
}
7 changes: 7 additions & 0 deletions remote-droid-guard-lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.microg.gms.droidguard.lib"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-sdk android:minSdkVersion="9"/>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.microg.gms.droidguard;

import org.microg.gms.droidguard.IRemoteDroidGuardCallback;
import org.microg.gms.droidguard.RemoteDroidGuardRequest;

interface IRemoteDroidGuard {
void guard(IRemoteDroidGuardCallback callbach, in RemoteDroidGuardRequest request) = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.microg.gms.droidguard;

interface IRemoteDroidGuardCallback {
void onResult(in byte[] result) = 0;
void onError(String msg) = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.microg.gms.droidguard;

parcelable RemoteDroidGuardRequest;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2013-2016 microG Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.microg.gms.droidguard;

public class Constants {
public static final String GMS_PACKAGE_NAME = "com.google.android.gms";
public static final int GMS_VERSION_CODE = 9683430;
public static final String GMS_VERSION_NAME_PREFIX = "9.6.83 (430-";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright 2013-2016 microG Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.microg.gms.droidguard;

import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.telephony.TelephonyManager;
import android.util.Log;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class RemoteDroidGuardConnector {
private static final String TAG = "GmsDroidGuardConn";

private Context context;

public RemoteDroidGuardConnector(Context context) {
this.context = context;
}

public Result guard(final String type, final String androidIdLong) {
return guard(type, androidIdLong, new Bundle());
}

@SuppressLint("HardwareIds")
public Result guard(final String type, final String androidIdLong, final Bundle extras) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return guard(type, androidIdLong, extras, tm.getDeviceId(), tm.getSubscriberId());
}

public synchronized Result guard(final String type, final String androidIdLong, final Bundle extras, final String deviceId, final String subscriberId) {
final Result res = new Result();
res.statusCode = 14;
connectForTask(new Task() {
@Override
public void run(IRemoteDroidGuard remote, final CountDownLatch countDownLatch) {
try {
RemoteDroidGuardRequest request = new RemoteDroidGuardRequest();
request.packageName = context.getPackageName();
request.reason = type;
request.androidIdLong = androidIdLong;
request.extras = extras;
request.deviceId = deviceId;
request.subscriberId = subscriberId;
remote.guard(new IRemoteDroidGuardCallback.Stub() {
@Override
public void onResult(byte[] result) throws RemoteException {
res.result = result;
res.statusCode = 0;
countDownLatch.countDown();
}

@Override
public void onError(String err) throws RemoteException {
res.statusCode = 8;
res.errorMsg = err;
countDownLatch.countDown();
}
}, request);
} catch (RemoteException e) {
Log.w(TAG, e);
res.statusCode = 8;
countDownLatch.countDown();
}
}
});
return res;
}

private boolean connectForTask(Task todo) {
CountDownLatch countDownLatch = new CountDownLatch(1);
Intent intent = new Intent("org.microg.gms.droidguard.REMOTE");
intent.setPackage("org.microg.gms.droidguard");
boolean b = context.bindService(intent, new Connection(countDownLatch, todo), Context.BIND_AUTO_CREATE);
if (!b) return false;
try {
countDownLatch.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
}
return true;
}

private interface Task {
void run(IRemoteDroidGuard remote, CountDownLatch countDownLatch);
}

private class Connection implements ServiceConnection {

private CountDownLatch countDownLatch;
private Task todo;

public Connection(CountDownLatch countDownLatch, Task todo) {
this.countDownLatch = countDownLatch;
this.todo = todo;
}

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
try {
if (todo != null) {
todo.run(IRemoteDroidGuard.Stub.asInterface(service), countDownLatch);
}
todo = null;
} catch (Exception e) {
context.unbindService(this);
}
}

@Override
public void onServiceDisconnected(ComponentName name) {
countDownLatch.countDown();
}
}

public class Result {
private byte[] result;
private int statusCode;
private String errorMsg;

public byte[] getResult() {
return result;
}

public int getStatusCode() {
return statusCode;
}

public String getErrorMsg() {
return errorMsg;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2013-2016 microG Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.microg.gms.droidguard;

import android.os.Bundle;

import org.microg.safeparcel.AutoSafeParcelable;
import org.microg.safeparcel.SafeParceled;

public class RemoteDroidGuardRequest extends AutoSafeParcelable {

// should match caller
@SafeParceled(1)
public String packageName;

// Where to put this DroidGuard response, known values: "attest", "fast"
@SafeParceled(2)
public String reason;

// From GSettings store
@SafeParceled(3)
public String androidIdLong;

// From TelephonyManager
@SafeParceled(10)
public String deviceId;
@SafeParceled(11)
public String subscriberId;

// additional fields, known key: "contentBinding"
@SafeParceled(100)
public Bundle extras;

public RemoteDroidGuardRequest() {

}

public static final Creator<RemoteDroidGuardRequest> CREATOR = new AutoCreator<>(RemoteDroidGuardRequest.class);
}
9 changes: 9 additions & 0 deletions remote-droid-guard/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
apply plugin: 'com.android.application'

repositories {
flatDir {
dirs 'libs'
}
}

dependencies {
compile 'com.squareup.wire:wire-runtime:1.6.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ':arthook:@aar'
compile project(':remote-droid-guard-lib')
}

String getMyVersionName() {
Expand Down
Binary file added remote-droid-guard/libs/arthook.aar
Binary file not shown.
Binary file added remote-droid-guard/libs/droidguasso.jar
Binary file not shown.
Loading

0 comments on commit 99b7d04

Please sign in to comment.