Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

Commit

Permalink
Merge branch 'GrapheneOS:14' into thunderpluck
Browse files Browse the repository at this point in the history
  • Loading branch information
0xf104a authored Oct 17, 2023
2 parents a5ea5bb + e75336d commit ec0d389
Show file tree
Hide file tree
Showing 31 changed files with 824 additions and 994 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 20
uses: actions/setup-java@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-gradle-wrapper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ jobs:
name: Validation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v1
7 changes: 3 additions & 4 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="app.grapheneos.gmscompat"
android:versionCode="1003"
android:versionCode="1005"
android:versionName="1"
>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<permission
Expand All @@ -31,6 +29,7 @@
android:name=".PersistentFgService"
android:exported="false"
android:directBootAware="true"
android:foregroundServiceType="specialUse"
/>

<provider
Expand Down
8 changes: 4 additions & 4 deletions config-holder/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ java {
android {
namespace = "app.grapheneos.gmscompat.config"

compileSdk = 33
buildToolsVersion = "33.0.2"
compileSdk = 34
buildToolsVersion = "34.0.0"

defaultConfig {
minSdk = 32
targetSdk = 33
versionCode = 60
targetSdk = 34
versionCode = 78
versionName = versionCode.toString()
}

Expand Down
2 changes: 1 addition & 1 deletion config-holder/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
plugins {
id("com.android.application") version "8.0.1" apply false
id("com.android.application") version "8.1.1" apply false
}
663 changes: 338 additions & 325 deletions config-holder/gradle/verification-metadata.xml

Large diffs are not rendered by default.

Binary file modified config-holder/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions config-holder/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=e111cb9948407e26351227dabce49822fb88c37ee72f1d1582a69c68af2e702f
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionSha256Sum=591855b517fc635b9e04de1d05d5e76ada3f89f5fc76f87978d1b245b4f69225
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
15 changes: 10 additions & 5 deletions config-holder/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,10 +131,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
Expand Down Expand Up @@ -197,6 +198,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
11 changes: 10 additions & 1 deletion gmscompat_config
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ finsky.kill_switch_phenotype_gservices_check set-string 0

[[stubs]]

[android.app.ActivityManager]
addOnUidImportanceListener void

[android.app.admin.DevicePolicyManager]
isDeviceProvisioned true
isDeviceProvisioningConfigApplied true
Expand Down Expand Up @@ -112,6 +115,7 @@ queryValidVerificationPackageNames emptyList

[android.hardware.usb.UsbManager]
getPorts emptyList
grantPermission void

[android.location.LocationManager]
setExtraLocationControllerPackage void
Expand Down Expand Up @@ -179,7 +183,7 @@ getServiceState null
[[versionMap]]
# section name is gmscompat version, section contents are max supported versions of GmsCore and Play Store
[1000]
232499999 83639999
234099999 83799999

[[stubs_12.1]]

Expand All @@ -201,3 +205,8 @@ unregisterBluetoothConnectionCallback false
[[force_default_flags]]
[com.google.android.gms.fido]
.+

[[force_ComponentEnabledSettings]]
[com.google.android.gms]
# causes chain crashes on Pixel Tablet due to the missing Dock Manager app
disable com.google.android.gms.homegraph.PersistentListenerService
6 changes: 4 additions & 2 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<string name="app_name">Google Play Services compatability layer</string>
<string name="activity_name">Sandboxed Google Play</string>
<string name="reroute_location_requests_to_os_apis">Reroute location requests to the OS</string>
<string name="missing_location_permission">Location permission needs to be set to “%s”.</string>
<string name="open_app_info">Open app info</string>
<string name="open_settings">Open settings</string>
<string name="persistent_fg_service_notif">Sandboxed Google Play is running</string>
Expand Down Expand Up @@ -67,7 +66,8 @@ To receive them quicker, set “Battery usage” to “Unrestricted” in Play s
"Play services needs the “Nearby devices“ permission to enable Nearby Share"
</string>

<string name="missing_play_games_app">This game needs the Play Games app</string>
<string name="notif_ch_missing_play_games_app">Missing Play Games app</string>
<string name="missing_play_games_app">%1$s needs the Play Games app</string>
<string name="install">Install</string>

<string name="notif_channel_bg_activity_start">Request to show a screen</string>
Expand Down Expand Up @@ -101,4 +101,6 @@ Update to an unknown version may cause crashes and errors in sandboxed Google Pl
</string>

<string name="notif_screen_capture_is_running">Screen capture is running</string>

<string name="notif_GmsCore_missing_nearby_devices_perm_generic">%1$s requires Play services to have the “Nearby devices” permission</string>
</resources>
16 changes: 11 additions & 5 deletions src/app/grapheneos/gmscompat/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@

import com.android.internal.gmscompat.GmsCompatApp;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class App extends Application {
private static Context ctx;
private static Context deviceProtectedStorageContext;
private static NotificationManager notificationManager;
private static SharedPreferences preferences;
private static Thread mainThread;
private static Executor bgExecutor;

public void onCreate() {
super.onCreate();
Expand All @@ -25,14 +29,13 @@ static void maybeInit(Context componentContext) {
}
ctx = componentContext.getApplicationContext();
mainThread = Thread.currentThread();
bgExecutor = Executors.newSingleThreadExecutor();

if (GmsCompatApp.PKG_NAME.equals(Application.getProcessName())) {
// main process
deviceProtectedStorageContext = ctx.createDeviceProtectedStorageContext();
preferences = deviceProtectedStorageContext
.getSharedPreferences(MAIN_PROCESS_PREFS_FILE, MODE_PRIVATE);
Redirections.init(preferences);

notificationManager = ctx.getSystemService(NotificationManager.class);
Notifications.createNotificationChannels();

Expand All @@ -53,19 +56,22 @@ public static NotificationManager notificationManager() {
}

public static SharedPreferences preferences() {
UtilsKt.mainProcess();
return preferences;
}

public static Thread mainThread() {
return mainThread;
}

public static Executor bgExecutor() {
return bgExecutor;
}

private static final String MAIN_PROCESS_PREFS_FILE = "prefs";

public interface MainProcessPrefs {
String ENABLED_REDIRECTIONS = "enabled_redirections";
String INITED_REDIRECTIONS = "inited_redirections";
String LOCATION_REQUEST_REDIRECTION_ENABLED = "enabled_redirections"; // historical name

String GmsCore_POWER_EXEMPTION_PROMPT_DISMISSED = "GmsCore_power_exemption_prompt_dismissed";
String NOTIFICATION_DO_NOT_SHOW_AGAIN_PREFIX = "do_not_show_notification_";

Expand Down
53 changes: 3 additions & 50 deletions src/app/grapheneos/gmscompat/BinderClientOfGmsCore2Gca.kt
Original file line number Diff line number Diff line change
@@ -1,37 +1,17 @@
package app.grapheneos.gmscompat

import android.Manifest
import android.app.compat.gms.GmsCompat
import android.content.Intent
import android.net.Uri
import android.util.ArrayMap
import com.android.internal.gmscompat.BinderRedirector
import com.android.internal.gmscompat.GmsInfo
import android.os.BinderDef
import com.android.internal.gmscompat.IClientOfGmsCore2Gca
import com.android.internal.gmscompat.dynamite.server.IFileProxyService

object BinderClientOfGmsCore2Gca : IClientOfGmsCore2Gca.Stub() {

val descriptorsOfNotableInterfaces = NotableInterface.values().map { it.descriptor }.sorted()
val mapOfDescriptorsOfNotableInterfaces = ArrayMap<String, NotableInterface>(NotableInterface.values().size).apply {
NotableInterface.values().forEach {
put(it.descriptor, it)
}
}

override fun getRedirectableInterfaces(outNotableInterfaces: MutableList<String>): Array<String> {
outNotableInterfaces.addAll(descriptorsOfNotableInterfaces)
return Redirections.getInterfaces()
override fun maybeGetBinderDef(callerPkg: String, processState: Int, ifaceName: String): BinderDef? {
return BinderDefs.maybeGetBinderDef(callerPkg, processState, ifaceName, false)
}

override fun getBinderRedirector(id: Int): BinderRedirector = Redirections.getRedirector(id)

override fun getDynamiteFileProxyService(): IFileProxyService = BinderGms2Gca.dynamiteFileProxyService!!

override fun onNotableInterfaceAcquired(interfaceDescriptor: String) {
mapOfDescriptorsOfNotableInterfaces[interfaceDescriptor]!!.onAcquiredByClient()
}

override fun showMissingAppNotification(pkgName: String) {
val prompt = when (pkgName) {
"com.google.android.tts" -> R.string.missing_speech_services
Expand All @@ -42,30 +22,3 @@ object BinderClientOfGmsCore2Gca : IClientOfGmsCore2Gca.Stub() {
}
}

enum class NotableInterface(val descriptor: String) {
ExposureNotificationService("com.google.android.gms.nearby.exposurenotification.internal.INearbyExposureNotificationService"),
GamesService("com.google.android.gms.games.internal.IGamesService"),
;

fun onAcquiredByClient() {
val ctx = App.ctx()
when (this) {
ExposureNotificationService -> {
if (!gmsCoreHasPermission(Manifest.permission.BLUETOOTH_SCAN)) {
Notifications.configurationRequired(
Notifications.CH_MISSING_PERMISSION,
ctx.getText(R.string.missing_permission),
ctx.getText(R.string.missing_permission_nearby_exposurenotifications),
ctx.getText(R.string.open_settings),
appSettingsIntent(GmsInfo.PACKAGE_GMS_CORE, APP_INFO_ITEM_PERMISSIONS)
).show(Notifications.ID_GMS_CORE_MISSING_NEARBY_DEVICES_PERMISSION)
}
}
GamesService -> {
Notifications.handleMissingApp(Notifications.CH_MISSING_PLAY_GAMES_APP,
ctx.getText(R.string.missing_play_games_app),
"com.google.android.play.games")
}
}
}
}
27 changes: 27 additions & 0 deletions src/app/grapheneos/gmscompat/BinderDefSupplier.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package app.grapheneos.gmscompat

import android.content.Context
import android.os.Binder
import android.os.BinderDef
import java.util.Arrays
import kotlin.reflect.KClass

abstract class BinderDefSupplier(val ifaceName: String, implClass: KClass<out Binder>) {
val className = implClass.java.name

// Path of APK from which to load class that is referred to by className
open fun apkPath(ctx: Context): String {
return ctx.applicationInfo.sourceDir
}

// Binder transaction codes
abstract fun transactionCodes(callerPkg: String): IntArray?

fun get(ctx: Context, callerPkg: String): BinderDef {
val txnCodes = transactionCodes(callerPkg)
if (txnCodes != null) {
Arrays.sort(txnCodes)
}
return BinderDef(ifaceName, apkPath(ctx), className, txnCodes)
}
}
Loading

0 comments on commit ec0d389

Please sign in to comment.