Repo Created
This commit is contained in:
parent
eb305e2886
commit
a8c22c65db
4784 changed files with 329907 additions and 2 deletions
40
play-services-ads/core/build.gradle
Normal file
40
play-services-ads/core/build.gradle
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
dependencies {
|
||||
api project(':play-services-ads')
|
||||
implementation project(':play-services-base-core')
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "org.microg.gms.ads.impl"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = 1.8
|
||||
}
|
||||
}
|
||||
15
play-services-ads/core/src/main/AndroidManifest.xml
Normal file
15
play-services-ads/core/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ SPDX-FileCopyrightText: 2023 microG Project Team
|
||||
~ SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application>
|
||||
<service android:name="org.microg.gms.ads.AdRequestService">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.gms.ads.service.START" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package com.google.android.gms.dynamite.descriptors.com.google.android.gms.ads.dynamite;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static android.os.Build.DEVICE;
|
||||
import static android.os.Build.DISPLAY;
|
||||
import static android.os.Build.VERSION.RELEASE;
|
||||
|
||||
@Keep
|
||||
public class ModuleDescriptor {
|
||||
public static final String MODULE_ID = "com.google.android.gms.ads.dynamite";
|
||||
public static final int MODULE_VERSION = 230500001;
|
||||
private static final String TAG = "AdsDynamiteModule";
|
||||
|
||||
/**
|
||||
* The ads module might try to access the user agent, requiring initialization on the main thread,
|
||||
* which may result in deadlocks when invoked from any other thread. This only happens with microG,
|
||||
* because we don't use the highly privileged SELinux Sandbox that regular Play Services uses
|
||||
* (which allows apps to read the user-agent from Play Services instead of the WebView). To prevent
|
||||
* the issue we pre-emptively write a user agent in the local storage of the app.
|
||||
*/
|
||||
public static void init(Context context) {
|
||||
do {
|
||||
try {
|
||||
injectUserAgentSharedPreference(context);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (context instanceof ContextWrapper) {
|
||||
Context baseContext = ((ContextWrapper) context).getBaseContext();
|
||||
if (context == baseContext) break;
|
||||
context = baseContext;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (context != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A user-agent representing a browser on the current device.
|
||||
*/
|
||||
private static String buildDefaultUserAgent() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Mozilla/5.0 (Linux; U; Android");
|
||||
if (RELEASE != null) sb.append(" ").append(RELEASE);
|
||||
sb.append("; ").append(Locale.getDefault());
|
||||
if (DEVICE != null) {
|
||||
sb.append("; ").append(DEVICE);
|
||||
if (DISPLAY != null) sb.append(" Build/").append(DISPLAY);
|
||||
}
|
||||
sb.append(") AppleWebKit/533 Version/4.0 Safari/533");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
private static void injectUserAgentSharedPreference(Context context) {
|
||||
SharedPreferences preferences = context.getSharedPreferences("admob_user_agent", Context.MODE_PRIVATE);
|
||||
if (!preferences.contains("user_agent")) {
|
||||
preferences.edit().putString("user_agent", buildDefaultUserAgent()).commit();
|
||||
Log.d(TAG, "Injected admob_user_agent into package " + context.getPackageName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2023 microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.microg.gms.ads
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Parcel
|
||||
import android.util.Log
|
||||
import com.google.android.gms.ads.internal.ExceptionParcel
|
||||
import com.google.android.gms.ads.internal.NonagonRequestParcel
|
||||
import com.google.android.gms.ads.internal.request.IAdRequestService
|
||||
import com.google.android.gms.ads.internal.request.INonagonStreamingResponseListener
|
||||
import com.google.android.gms.common.api.CommonStatusCodes
|
||||
import com.google.android.gms.common.internal.GetServiceRequest
|
||||
import com.google.android.gms.common.internal.IGmsCallbacks
|
||||
import org.microg.gms.BaseService
|
||||
import org.microg.gms.common.GmsService
|
||||
import org.microg.gms.common.PackageUtils
|
||||
import org.microg.gms.utils.warnOnTransactionIssues
|
||||
|
||||
private const val TAG = "AdRequestService"
|
||||
|
||||
class AdRequestService : BaseService(TAG, GmsService.ADREQUEST) {
|
||||
override fun handleServiceRequest(callback: IGmsCallbacks, request: GetServiceRequest, service: GmsService) {
|
||||
val packageName = PackageUtils.getAndCheckCallingPackage(this, request.packageName)
|
||||
?: throw IllegalArgumentException("Missing package name")
|
||||
val binder = AdRequestServiceImpl().asBinder()
|
||||
callback.onPostInitComplete(CommonStatusCodes.SUCCESS, binder, Bundle())
|
||||
}
|
||||
}
|
||||
|
||||
class AdRequestServiceImpl : IAdRequestService.Stub() {
|
||||
override fun getAdRequest(request: NonagonRequestParcel, listener: INonagonStreamingResponseListener) {
|
||||
Log.d(TAG, "getAdRequest")
|
||||
listener.onException(ExceptionParcel().apply {
|
||||
message = "Not supported"
|
||||
code = CommonStatusCodes.INTERNAL_ERROR
|
||||
})
|
||||
}
|
||||
|
||||
override fun getSignals(request: NonagonRequestParcel, listener: INonagonStreamingResponseListener) {
|
||||
Log.d(TAG, "getSignals")
|
||||
listener.onException(ExceptionParcel().apply {
|
||||
message = "Not supported"
|
||||
code = CommonStatusCodes.INTERNAL_ERROR
|
||||
})
|
||||
}
|
||||
|
||||
override fun getUrlAndCacheKey(request: NonagonRequestParcel, listener: INonagonStreamingResponseListener) {
|
||||
Log.d(TAG, "getUrlAndCacheKey")
|
||||
listener.onException(ExceptionParcel().apply {
|
||||
message = "Not supported"
|
||||
code = CommonStatusCodes.INTERNAL_ERROR
|
||||
})
|
||||
}
|
||||
|
||||
override fun removeCacheUrl(key: String, listener: INonagonStreamingResponseListener) {
|
||||
Log.d(TAG, "removeCacheUrl")
|
||||
listener.onException(ExceptionParcel().apply {
|
||||
message = "Not supported"
|
||||
code = CommonStatusCodes.INTERNAL_ERROR
|
||||
})
|
||||
}
|
||||
|
||||
override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean = warnOnTransactionIssues(code, reply, flags, TAG) { super.onTransact(code, data, reply, flags) }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue