forked from microg/GmsCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DroidGuard service API and client
- Loading branch information
Showing
16 changed files
with
397 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2020, microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'maven-publish' | ||
apply plugin: 'signing' | ||
|
||
android { | ||
compileSdkVersion androidCompileSdk | ||
buildToolsVersion "$androidBuildVersionTools" | ||
|
||
defaultConfig { | ||
versionName version | ||
minSdkVersion androidMinSdk | ||
targetSdkVersion androidTargetSdk | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
} | ||
} | ||
|
||
apply from: '../gradle/publish-android.gradle' | ||
|
||
description = 'microG API for play-services-droidguard' | ||
|
||
dependencies { | ||
api project(':play-services-basement') | ||
api project(':play-services-base-api') | ||
|
||
implementation "androidx.annotation:annotation:$annotationVersion" | ||
} |
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"?> | ||
<!-- | ||
~ SPDX-FileCopyrightText: 2020, microG Project Team | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<manifest package="org.microg.gms.droidguard.api"/> |
3 changes: 3 additions & 0 deletions
3
...ard-api/src/main/aidl/com/google/android/gms/droidguard/internal/DroidGuardInitReply.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 com.google.android.gms.droidguard.internal; | ||
|
||
parcelable DroidGuardInitReply; |
3 changes: 3 additions & 0 deletions
3
...pi/src/main/aidl/com/google/android/gms/droidguard/internal/DroidGuardResultsRequest.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 com.google.android.gms.droidguard.internal; | ||
|
||
parcelable DroidGuardResultsRequest; |
5 changes: 5 additions & 0 deletions
5
...rd-api/src/main/aidl/com/google/android/gms/droidguard/internal/IDroidGuardCallbacks.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,5 @@ | ||
package com.google.android.gms.droidguard.internal; | ||
|
||
interface IDroidGuardCallbacks { | ||
void onResult(in byte[] res); | ||
} |
13 changes: 13 additions & 0 deletions
13
...guard-api/src/main/aidl/com/google/android/gms/droidguard/internal/IDroidGuardHandle.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,13 @@ | ||
package com.google.android.gms.droidguard.internal; | ||
|
||
import com.google.android.gms.droidguard.internal.DroidGuardInitReply; | ||
import com.google.android.gms.droidguard.internal.DroidGuardResultsRequest; | ||
|
||
interface IDroidGuardHandle { | ||
void init(String flow) = 0; | ||
DroidGuardInitReply initWithRequest(String flow, in DroidGuardResultsRequest request) = 4; | ||
|
||
byte[] guard(in Map map) = 1; | ||
|
||
void close() = 2; | ||
} |
14 changes: 14 additions & 0 deletions
14
...uard-api/src/main/aidl/com/google/android/gms/droidguard/internal/IDroidGuardService.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,14 @@ | ||
package com.google.android.gms.droidguard.internal; | ||
|
||
import com.google.android.gms.droidguard.internal.IDroidGuardCallbacks; | ||
import com.google.android.gms.droidguard.internal.IDroidGuardHandle; | ||
import com.google.android.gms.droidguard.internal.DroidGuardResultsRequest; | ||
|
||
interface IDroidGuardService { | ||
void guard(IDroidGuardCallbacks callbacks, String flow, in Map map) = 0; | ||
void guardWithRequest(IDroidGuardCallbacks callbacks, String flow, in Map map, in DroidGuardResultsRequest request) = 3; | ||
|
||
IDroidGuardHandle getHandle() = 1; | ||
|
||
int getClientTimeoutMillis() = 2; | ||
} |
48 changes: 48 additions & 0 deletions
48
...ard-api/src/main/java/com/google/android/gms/droidguard/internal/DroidGuardInitReply.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,48 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2020, microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.google.android.gms.droidguard.internal; | ||
|
||
import android.os.Parcel; | ||
import android.os.ParcelFileDescriptor; | ||
import android.os.Parcelable; | ||
|
||
public class DroidGuardInitReply implements Parcelable { | ||
public ParcelFileDescriptor pfd; | ||
public Parcelable object; | ||
|
||
public DroidGuardInitReply(ParcelFileDescriptor pfd, Parcelable object) { | ||
this.pfd = pfd; | ||
this.object = object; | ||
} | ||
|
||
@Override | ||
public int describeContents() { | ||
return (pfd != null ? Parcelable.CONTENTS_FILE_DESCRIPTOR : 0) | (object != null ? object.describeContents() : 0); | ||
} | ||
|
||
@Override | ||
public void writeToParcel(Parcel dest, int flags) { | ||
dest.writeParcelable(pfd, flags); | ||
dest.writeParcelable(object, flags); | ||
} | ||
|
||
public final static Creator<DroidGuardInitReply> CREATOR = new Creator<DroidGuardInitReply>() { | ||
@Override | ||
public DroidGuardInitReply createFromParcel(Parcel source) { | ||
ParcelFileDescriptor pfd = source.readParcelable(ParcelFileDescriptor.class.getClassLoader()); | ||
Parcelable object = source.readParcelable(getClass().getClassLoader()); | ||
if (pfd != null && object != null) { | ||
return new DroidGuardInitReply(pfd, object); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public DroidGuardInitReply[] newArray(int size) { | ||
return new DroidGuardInitReply[size]; | ||
} | ||
}; | ||
} |
93 changes: 93 additions & 0 deletions
93
...pi/src/main/java/com/google/android/gms/droidguard/internal/DroidGuardResultsRequest.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,93 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2020, microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.google.android.gms.droidguard.internal; | ||
|
||
import android.net.Network; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.os.ParcelFileDescriptor; | ||
|
||
import androidx.annotation.RequiresApi; | ||
|
||
import org.microg.gms.common.Constants; | ||
import org.microg.safeparcel.AutoSafeParcelable; | ||
|
||
public class DroidGuardResultsRequest extends AutoSafeParcelable { | ||
private static final String KEY_APP_ARCHITECTURE = "appArchitecture"; | ||
private static final String KEY_CLIENT_VERSION = "clientVersion"; | ||
private static final String KEY_FD = "fd"; | ||
private static final String KEY_NETWORK_TO_USE = "networkToUse"; | ||
private static final String KEY_TIMEOUT_MS = "timeoutMs"; | ||
public static final String KEY_OPEN_HANDLES = "openHandles"; | ||
|
||
@Field(2) | ||
public Bundle bundle; | ||
|
||
public DroidGuardResultsRequest() { | ||
bundle = new Bundle(); | ||
String arch; | ||
try { | ||
arch = System.getProperty("os.arch"); | ||
} catch (Exception ignored) { | ||
arch = "?"; | ||
} | ||
bundle.putString(KEY_APP_ARCHITECTURE, arch); | ||
setClientVersion(Constants.GMS_VERSION_CODE); | ||
} | ||
|
||
public String getAppArchitecture() { | ||
return bundle.getString(KEY_APP_ARCHITECTURE); | ||
} | ||
|
||
public int getTimeoutMillis() { | ||
return bundle.getInt(KEY_TIMEOUT_MS, 60000); | ||
} | ||
|
||
public DroidGuardResultsRequest setTimeoutMillis(int millis) { | ||
bundle.putInt(KEY_TIMEOUT_MS, millis); | ||
return this; | ||
} | ||
|
||
public int getClientVersion() { | ||
return bundle.getInt(KEY_CLIENT_VERSION); | ||
} | ||
|
||
public DroidGuardResultsRequest setClientVersion(int clientVersion) { | ||
bundle.putInt(KEY_CLIENT_VERSION, clientVersion); | ||
return this; | ||
} | ||
|
||
public ParcelFileDescriptor getFd() { | ||
return bundle.getParcelable(KEY_FD); | ||
} | ||
|
||
public DroidGuardResultsRequest setFd(ParcelFileDescriptor fd) { | ||
bundle.putParcelable(KEY_FD, fd); | ||
return this; | ||
} | ||
|
||
public int getOpenHandles() { | ||
return bundle.getInt(KEY_OPEN_HANDLES); | ||
} | ||
|
||
public DroidGuardResultsRequest setOpenHandles(int openHandles) { | ||
bundle.putInt(KEY_OPEN_HANDLES, openHandles); | ||
return this; | ||
} | ||
|
||
@RequiresApi(api = 21) | ||
public Network getNetworkToUse() { | ||
return bundle.getParcelable(KEY_NETWORK_TO_USE); | ||
} | ||
|
||
@RequiresApi(api = 21) | ||
public DroidGuardResultsRequest setNetworkToUse(Network networkToUse) { | ||
bundle.putParcelable(KEY_NETWORK_TO_USE, networkToUse); | ||
return this; | ||
} | ||
|
||
public static final Creator<DroidGuardResultsRequest> CREATOR = new AutoCreator<>(DroidGuardResultsRequest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2020, microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'maven-publish' | ||
apply plugin: 'signing' | ||
|
||
android { | ||
compileSdkVersion androidCompileSdk | ||
buildToolsVersion "$androidBuildVersionTools" | ||
|
||
defaultConfig { | ||
versionName version | ||
minSdkVersion androidMinSdk | ||
targetSdkVersion androidTargetSdk | ||
} | ||
|
||
sourceSets { | ||
main.java.srcDirs += 'src/main/kotlin' | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
} | ||
} | ||
|
||
apply from: '../gradle/publish-android.gradle' | ||
|
||
description = 'microG implementation of play-services-droidguard' | ||
|
||
dependencies { | ||
api project(':play-services-base') | ||
api project(':play-services-droidguard-api') | ||
|
||
implementation "androidx.annotation:annotation:$annotationVersion" | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" | ||
} |
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"?> | ||
<!-- | ||
~ SPDX-FileCopyrightText: 2020, microG Project Team | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<manifest package="org.microg.gms.droidguard"/> |
25 changes: 25 additions & 0 deletions
25
play-services-droidguard/src/main/kotlin/org/microg/gms/droidguard/DroidGuardApiClient.kt
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,25 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2020, microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.droidguard | ||
|
||
import android.content.Context | ||
import android.os.IBinder | ||
import com.google.android.gms.droidguard.internal.IDroidGuardHandle | ||
import com.google.android.gms.droidguard.internal.IDroidGuardService | ||
import org.microg.gms.common.GmsClient | ||
import org.microg.gms.common.GmsService | ||
import org.microg.gms.common.api.ConnectionCallbacks | ||
import org.microg.gms.common.api.OnConnectionFailedListener | ||
|
||
class DroidGuardApiClient(context: Context, connectionCallbacks: ConnectionCallbacks, onConnectionFailedListener: OnConnectionFailedListener) : GmsClient<IDroidGuardService>(context, connectionCallbacks, onConnectionFailedListener, GmsService.DROIDGUARD.ACTION) { | ||
init { | ||
serviceId = GmsService.DROIDGUARD.SERVICE_ID | ||
} | ||
|
||
override fun interfaceFromBinder(binder: IBinder): IDroidGuardService = IDroidGuardService.Stub.asInterface(binder) | ||
|
||
fun getHandle() = serviceInterface.handle | ||
} |
13 changes: 13 additions & 0 deletions
13
play-services-droidguard/src/main/kotlin/org/microg/gms/droidguard/DroidGuardClient.kt
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,13 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2020, microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.droidguard | ||
|
||
import com.google.android.gms.droidguard.internal.IDroidGuardHandle | ||
import com.google.android.gms.tasks.Task | ||
|
||
interface DroidGuardClient { | ||
fun getHandle(): Task<DroidGuardHandle> | ||
} |
33 changes: 33 additions & 0 deletions
33
play-services-droidguard/src/main/kotlin/org/microg/gms/droidguard/DroidGuardClientImpl.kt
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,33 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2020, microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.droidguard | ||
|
||
import android.content.Context | ||
import android.os.Looper | ||
import com.google.android.gms.common.api.Api | ||
import com.google.android.gms.common.api.Api.ApiOptions.NoOptions | ||
import com.google.android.gms.common.api.GoogleApi | ||
import com.google.android.gms.tasks.Task | ||
import org.microg.gms.common.api.ApiClientBuilder | ||
import org.microg.gms.common.api.ApiClientSettings | ||
import org.microg.gms.common.api.ConnectionCallbacks | ||
import org.microg.gms.common.api.OnConnectionFailedListener | ||
|
||
class DroidGuardClientImpl(context: Context) : GoogleApi<NoOptions>(context, API), DroidGuardClient { | ||
companion object { | ||
private val API = Api(ApiClientBuilder { _: NoOptions?, context: Context, _: Looper?, _: ApiClientSettings?, callbacks: ConnectionCallbacks, connectionFailedListener: OnConnectionFailedListener -> DroidGuardApiClient(context, callbacks, connectionFailedListener) }) | ||
} | ||
|
||
override fun getHandle(): Task<DroidGuardHandle> { | ||
return scheduleTask { client: DroidGuardApiClient, completionSource -> | ||
try { | ||
completionSource.setResult(DroidGuardHandle(client.getHandle())) | ||
} catch (e: Exception) { | ||
completionSource.setException(e) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.