Skip to content

Commit

Permalink
Add draft of patch to fix gapps crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
cawilliamson committed Dec 31, 2023
1 parent fc7f4c3 commit 7c65112
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ repo sync -c -j$(nproc --all) --force-sync --no-clone-bundle --no-tags
### Apply the patches
Copy the patches folder to the ROM folder and copy the apply-patches.sh to the rom folder. and run this in the ROM folder:
```bash
./apply-patches.sh . trebledroid
./apply-patches.sh . ponces
./apply-patches.sh . personal
./patches/apply.sh . trebledroid
./patches/apply.sh . ponces
./patches/apply.sh . personal
./patches/apply.sh . graphene
```

## Adapting for VoltageOS
Expand Down
1 change: 1 addition & 0 deletions build-rom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ repo forall -c git lfs pull
./patches/apply.sh . trebledroid
./patches/apply.sh . ponces
./patches/apply.sh . personal
./patches/apply.sh . graphene

# generate basic device config
pushd device/phh/treble || exit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
From a8cba3a50455616dad8d07b4ecdf710f1b676efe Mon Sep 17 00:00:00 2001
From: Dmitry Muhomor <[email protected]>
Date: Wed, 8 Nov 2023 15:56:51 +0200
Subject: [PATCH] gmscompat: replace cross-user intent broadcasts with
user-local ones

Cross-user broadcasts require a privileged permission.
---
core/java/android/app/ContextImpl.java | 12 +++++++++++-
.../gmscompat/sysservice/GmcUserManager.java | 11 ++++++++++-
2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index d4547d5cea32..9c52e4a8caaa 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -100,9 +100,9 @@
import android.window.WindowTokenClient;

import com.android.internal.annotations.GuardedBy;
-import com.android.internal.gmscompat.GmsInfo;
import com.android.internal.gmscompat.sysservice.GmcPackageManager;
import com.android.internal.gmscompat.GmsHooks;
+import com.android.internal.gmscompat.sysservice.GmcUserManager;
import com.android.internal.util.Preconditions;

import dalvik.system.BlockGuard;
@@ -1462,6 +1462,10 @@ resultReceiver, getOuterContext(), scheduler, null, false)

@Override
public void sendBroadcastAsUser(Intent intent, UserHandle user) {
+ if (GmsCompat.isEnabled()) {
+ user = GmcUserManager.translateUserHandle(user);
+ }
+
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
try {
intent.prepareToLeaveProcess(this);
@@ -1485,6 +1489,7 @@ public void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverP
Bundle options) {
if (GmsCompat.isEnabled()) {
options = GmsHooks.filterBroadcastOptions(intent, options);
+ user = GmcUserManager.translateUserHandle(user);
}

String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
@@ -1505,6 +1510,10 @@ public void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverP
@Override
public void sendBroadcastAsUser(Intent intent, UserHandle user,
String receiverPermission, int appOp) {
+ if (GmsCompat.isEnabled()) {
+ user = GmcUserManager.translateUserHandle(user);
+ }
+
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
String[] receiverPermissions = receiverPermission == null ? null
: new String[] {receiverPermission};
@@ -1542,6 +1551,7 @@ public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
if (GmsCompat.isEnabled()) {
options = GmsHooks.filterBroadcastOptions(intent, options);
+ user = GmcUserManager.translateUserHandle(user);
}

IIntentReceiver rd = null;
diff --git a/core/java/com/android/internal/gmscompat/sysservice/GmcUserManager.java b/core/java/com/android/internal/gmscompat/sysservice/GmcUserManager.java
index 82891af48024..2b1a8db750b0 100644
--- a/core/java/com/android/internal/gmscompat/sysservice/GmcUserManager.java
+++ b/core/java/com/android/internal/gmscompat/sysservice/GmcUserManager.java
@@ -43,11 +43,20 @@ private static int getUserId() {
}

private static void checkUserId(int userId) {
- if (userId != getUserId()) {
+ if (userId != getUserId() && userId != UserHandle.USER_CURRENT) {
throw new IllegalStateException("unexpected userId " + userId);
}
}

+ public static UserHandle translateUserHandle(UserHandle h) {
+ if (UserHandle.ALL.equals(h)) {
+ return UserHandle.of(getUserId());
+ }
+
+ checkUserId(h.getIdentifier());
+ return h;
+ }
+
private static int getUserSerialNumber() {
// GMS has several hardcoded (userSerialNumber == 0) checks
return 0;

0 comments on commit 7c65112

Please sign in to comment.