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

Commit

Permalink
gmscompat: adjust to DynamiteLoader changes in GmsCore 24.22
Browse files Browse the repository at this point in the history
APKs of Dynamite modules are now opened via ParcelFileDescriptor.open().
  • Loading branch information
muhomorr authored and thestinger committed Jun 5, 2024
1 parent 1d8179d commit c5767a0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
10 changes: 10 additions & 0 deletions core/java/android/os/ParcelFileDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import android.util.Log;
import android.util.Slog;

import com.android.internal.gmscompat.dynamite.GmsDynamiteClientHooks;

import dalvik.system.CloseGuard;
import dalvik.system.VMRuntime;

Expand Down Expand Up @@ -345,6 +347,14 @@ private static FileDescriptor openInternal(File file, int mode) throws FileNotFo
if ((mode & MODE_WORLD_WRITEABLE) != 0) realMode |= S_IWOTH;

final String path = file.getPath();

if (GmsDynamiteClientHooks.enabled()) {
FileDescriptor override = GmsDynamiteClientHooks.openFileDescriptor(path);
if (override != null) {
return override;
}
}

try {
return Os.open(path, flags, realMode);
} catch (ErrnoException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package com.android.internal.gmscompat.dynamite;

import android.app.compat.gms.GmsCompat;
import android.content.Context;
import android.content.res.ApkAssets;
import android.content.res.loader.AssetsProvider;
import android.os.Environment;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.system.ErrnoException;
import android.system.Os;
import android.util.ArrayMap;
import android.util.Log;

Expand All @@ -38,6 +38,8 @@

import dalvik.system.DelegateLastClassLoader;

import static android.system.OsConstants.F_DUPFD_CLOEXEC;

public final class GmsDynamiteClientHooks {
static final String TAG = "GmsCompat/DynamiteClient";
private static final boolean DEBUG = false;
Expand Down Expand Up @@ -127,6 +129,24 @@ public static long getFileLastModified(File file) {
return 0L;
}

public static FileDescriptor openFileDescriptor(String path) {
if (!path.startsWith(gmsCoreDataPrefix)) {
return null;
}

FileDescriptor fd = modulePathToFd(path);
int dupFd;
try {
dupFd = Os.fcntlInt(fd, F_DUPFD_CLOEXEC, 0);
} catch (ErrnoException e) {
throw new RuntimeException(e);
}

var dupJfd = new FileDescriptor();
dupJfd.setInt$(dupFd);
return dupJfd;
}

// Replaces file paths of Dynamite modules with "/proc/self/fd" file descriptor references
// DelegateLastClassLoader#maybeModifyClassLoaderPath(String, Boolean)
public static String maybeModifyClassLoaderPath(String path, Boolean nativeLibsPathB) {
Expand Down Expand Up @@ -175,7 +195,7 @@ public static String maybeModifyClassLoaderPath(String path, Boolean nativeLibsP
// Returned file descriptor should never be closed, because it may be dup()-ed at any time by the native code
private static FileDescriptor modulePathToFd(String path) {
if (DEBUG) {
new Exception("path " + path).printStackTrace();
Log.d(TAG, "path " + path, new Throwable());
}
try {
ArrayMap<String, ParcelFileDescriptor> cache = pfdCache;
Expand Down

0 comments on commit c5767a0

Please sign in to comment.