This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First working version, including library to use it
- Loading branch information
Showing
32 changed files
with
1,120 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
8 changes: 8 additions & 0 deletions
8
remote-droid-guard-lib/src/main/aidl/org/microg/gms/droidguard/IRemoteDroidGuard.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
6 changes: 6 additions & 0 deletions
6
...te-droid-guard-lib/src/main/aidl/org/microg/gms/droidguard/IRemoteDroidGuardCallback.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
3 changes: 3 additions & 0 deletions
3
remote-droid-guard-lib/src/main/aidl/org/microg/gms/droidguard/RemoteDroidGuardRequest.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package org.microg.gms.droidguard; | ||
|
||
parcelable RemoteDroidGuardRequest; |
23 changes: 23 additions & 0 deletions
23
remote-droid-guard-lib/src/main/java/org/microg/gms/droidguard/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-"; | ||
} |
153 changes: 153 additions & 0 deletions
153
...te-droid-guard-lib/src/main/java/org/microg/gms/droidguard/RemoteDroidGuardConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
remote-droid-guard-lib/src/main/java/org/microg/gms/droidguard/RemoteDroidGuardRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.