Skip to content

Commit 5934c9d

Browse files
committed
Route vision face detectors through self package context
The package-rename diagnostics showed that the Vision/MLKit face detector creators were still using the canonical package context even though the actual detector helper and model asset are owned by the serving self APK. In both the upstream/pre-fix and post-fix diagnostics runs, the representative ThickFaceDetectorCreator probe still resolved `createdContextPackage=com.google.android.gms` and then failed helper initialization with `helperInit=RuntimeException: faceDetectorYN initialization failed`. The same probe's forced self alternative resolved `createdContextPackage=app.revanced.android.gms` and succeeded with `helperInit=success`. The supporting artifact probes explain why: canonical had resources, but it did not expose `FaceDetectorHelper` or the `face_detection_yunet_2023mar.onnx` asset, while self exposed both. The diagnostics conclusion for these creators was: `Evidence supports SELF ownership: FaceDetectorHelper depends on context.assets and only the self package exposes the face model asset in this run.` Apply that ownership decision to all four remaining Vision/MLKit face detector creators by replacing `GooglePlayServicesUtil.getRemoteContext(...)` with an explicit self package context. This keeps detector loading tied to the serving GmsCore APK in side-by-side installs instead of the stock sidecar package.
1 parent 4d52c7f commit 5934c9d

4 files changed

Lines changed: 20 additions & 20 deletions

File tree

play-services-vision/core/src/main/kotlin/com/google/android/gms/vision/client/DynamiteNativeFaceDetectorCreator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import android.content.Context
99
import android.os.SystemClock
1010
import android.util.Log
1111
import androidx.annotation.Keep
12-
import com.google.android.gms.common.GooglePlayServicesUtil
1312
import com.google.android.gms.dynamic.IObjectWrapper
1413
import com.google.android.gms.dynamic.unwrap
1514
import com.google.android.gms.vision.face.internal.client.DetectionOptions
1615
import com.google.android.gms.vision.face.internal.client.INativeFaceDetector
1716
import com.google.android.gms.vision.face.internal.client.INativeFaceDetectorCreator
17+
import org.microg.gms.common.PackageUtils
1818
import org.microg.gms.vision.face.TAG
1919
import org.microg.gms.vision.face.FaceDetector
2020
import org.opencv.android.OpenCVLoader
@@ -27,16 +27,16 @@ class DynamiteNativeFaceDetectorCreator : INativeFaceDetectorCreator.Stub() {
2727
try {
2828
val elapsedRealtime = SystemClock.elapsedRealtime()
2929
val context = context.unwrap<Context>() ?: throw RuntimeException("Context is null")
30-
val remoteContext = GooglePlayServicesUtil.getRemoteContext(context) ?: throw RuntimeException("remoteContext is null")
31-
Log.d(TAG, "newFaceDetector: context: ${context.packageName} remoteContext: ${remoteContext.packageName}")
30+
val detectorContext = context.createPackageContext(PackageUtils.getSelfPackageName(context), 0)
31+
Log.d(TAG, "newFaceDetector: context: ${context.packageName} detectorContext: ${detectorContext.packageName}")
3232
if (!OpenCVLoader.initLocal()) {
3333
throw RuntimeException("Unable to load OpenCV")
3434
}
3535
Log.d(TAG, "DynamiteNativeFaceDetectorCreator newFaceDetector: load <openCV> library in ${SystemClock.elapsedRealtime() - elapsedRealtime}ms")
36-
return FaceDetector(remoteContext, faceDetectionOptions)
36+
return FaceDetector(detectorContext, faceDetectionOptions)
3737
} catch (e: Throwable) {
3838
Log.w(TAG, "DynamiteNativeFaceDetectorCreator newFaceDetector load failed ", e)
3939
return null
4040
}
4141
}
42-
}
42+
}

play-services-vision/core/src/main/kotlin/com/google/android/gms/vision/face/ChimeraNativeFaceDetectorCreator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import android.content.Context
99
import android.os.SystemClock
1010
import android.util.Log
1111
import androidx.annotation.Keep
12-
import com.google.android.gms.common.GooglePlayServicesUtil
1312
import com.google.android.gms.dynamic.IObjectWrapper
1413
import com.google.android.gms.dynamic.unwrap
1514
import com.google.android.gms.vision.face.internal.client.DetectionOptions
1615
import com.google.android.gms.vision.face.internal.client.INativeFaceDetector
1716
import com.google.android.gms.vision.face.internal.client.INativeFaceDetectorCreator
17+
import org.microg.gms.common.PackageUtils
1818
import org.microg.gms.vision.face.FaceDetector
1919
import org.microg.gms.vision.face.TAG
2020
import org.opencv.android.OpenCVLoader
@@ -26,16 +26,16 @@ class ChimeraNativeFaceDetectorCreator : INativeFaceDetectorCreator.Stub() {
2626
try {
2727
val elapsedRealtime = SystemClock.elapsedRealtime()
2828
val context = context.unwrap<Context>() ?: throw RuntimeException("Context is null")
29-
val remoteContext = GooglePlayServicesUtil.getRemoteContext(context) ?: throw RuntimeException("remoteContext is null")
30-
Log.d(TAG, "newFaceDetector: context: ${context.packageName} remoteContext: ${remoteContext.packageName}")
29+
val detectorContext = context.createPackageContext(PackageUtils.getSelfPackageName(context), 0)
30+
Log.d(TAG, "newFaceDetector: context: ${context.packageName} detectorContext: ${detectorContext.packageName}")
3131
if (!OpenCVLoader.initLocal()) {
3232
throw RuntimeException("Unable to load OpenCV")
3333
}
3434
Log.d(TAG, "ChimeraNativeFaceDetectorCreator newFaceDetector: load <openCV> library in ${SystemClock.elapsedRealtime() - elapsedRealtime}ms")
35-
return FaceDetector(remoteContext, faceDetectionOptions)
35+
return FaceDetector(detectorContext, faceDetectionOptions)
3636
} catch (e: Throwable) {
3737
Log.w(TAG, "ChimeraNativeFaceDetectorCreator newFaceDetector load failed ", e)
3838
return null
3939
}
4040
}
41-
}
41+
}

play-services-vision/core/src/main/kotlin/com/google/android/gms/vision/face/mlkit/FaceDetectorCreator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import android.content.Context
99
import android.os.SystemClock
1010
import android.util.Log
1111
import androidx.annotation.Keep
12-
import com.google.android.gms.common.GooglePlayServicesUtil
1312
import com.google.android.gms.dynamic.IObjectWrapper
1413
import com.google.android.gms.dynamic.unwrap
1514
import com.google.mlkit.vision.face.FaceDetectionOptions
1615
import com.google.mlkit.vision.face.aidls.IFaceDetector
1716
import com.google.mlkit.vision.face.aidls.IFaceDetectorCreator
17+
import org.microg.gms.common.PackageUtils
1818
import org.microg.gms.vision.face.TAG
1919
import org.microg.gms.vision.face.mlkit.FaceDetector
2020
import org.opencv.android.OpenCVLoader
@@ -27,16 +27,16 @@ class FaceDetectorCreator : IFaceDetectorCreator.Stub() {
2727
try {
2828
val elapsedRealtime = SystemClock.elapsedRealtime()
2929
val context = context.unwrap<Context>() ?: throw RuntimeException("Context is null")
30-
val remoteContext = GooglePlayServicesUtil.getRemoteContext(context) ?: throw RuntimeException("remoteContext is null")
31-
Log.d(TAG, "newFaceDetector: context: ${context.packageName} remoteContext: ${remoteContext.packageName}")
30+
val detectorContext = context.createPackageContext(PackageUtils.getSelfPackageName(context), 0)
31+
Log.d(TAG, "newFaceDetector: context: ${context.packageName} detectorContext: ${detectorContext.packageName}")
3232
if (!OpenCVLoader.initLocal()) {
3333
throw RuntimeException("Unable to load OpenCV")
3434
}
3535
Log.d(TAG, "FaceDetectorCreator newFaceDetector: load <openCV> library in ${SystemClock.elapsedRealtime() - elapsedRealtime}ms")
36-
return FaceDetector(remoteContext, faceDetectionOptions)
36+
return FaceDetector(detectorContext, faceDetectionOptions)
3737
} catch (e: Throwable) {
3838
Log.w(TAG, "FaceDetectorCreator newFaceDetector load failed ", e)
3939
return null
4040
}
4141
}
42-
}
42+
}

play-services-vision/core/src/main/kotlin/com/google/mlkit/vision/face/bundled/internal/ThickFaceDetectorCreator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import android.content.Context
99
import android.os.SystemClock
1010
import android.util.Log
1111
import androidx.annotation.Keep
12-
import com.google.android.gms.common.GooglePlayServicesUtil
1312
import com.google.android.gms.dynamic.IObjectWrapper
1413
import com.google.android.gms.dynamic.unwrap
1514
import com.google.mlkit.vision.face.FaceDetectionOptions
1615
import com.google.mlkit.vision.face.aidls.IFaceDetector
1716
import com.google.mlkit.vision.face.aidls.IFaceDetectorCreator
17+
import org.microg.gms.common.PackageUtils
1818
import org.microg.gms.vision.face.TAG
1919
import org.microg.gms.vision.face.mlkit.FaceDetector
2020
import org.opencv.android.OpenCVLoader
@@ -27,16 +27,16 @@ class ThickFaceDetectorCreator : IFaceDetectorCreator.Stub() {
2727
try {
2828
val elapsedRealtime = SystemClock.elapsedRealtime()
2929
val context = context.unwrap<Context>() ?: throw RuntimeException("Context is null")
30-
val remoteContext = GooglePlayServicesUtil.getRemoteContext(context) ?: throw RuntimeException("remoteContext is null")
31-
Log.d(TAG, "ThickFaceDetectorCreator newFaceDetector: context: ${context.packageName} remoteContext: ${remoteContext.packageName}")
30+
val detectorContext = context.createPackageContext(PackageUtils.getSelfPackageName(context), 0)
31+
Log.d(TAG, "ThickFaceDetectorCreator newFaceDetector: context: ${context.packageName} detectorContext: ${detectorContext.packageName}")
3232
if (!OpenCVLoader.initLocal()) {
3333
throw RuntimeException("Unable to load OpenCV")
3434
}
3535
Log.d(TAG, "ThickFaceDetectorCreator newFaceDetector: load <openCV> library in ${SystemClock.elapsedRealtime() - elapsedRealtime}ms")
36-
return FaceDetector(remoteContext, faceDetectionOptions)
36+
return FaceDetector(detectorContext, faceDetectionOptions)
3737
} catch (e: Throwable) {
3838
Log.w(TAG, "ThickFaceDetectorCreator newFaceDetector load failed ", e)
3939
return null
4040
}
4141
}
42-
}
42+
}

0 commit comments

Comments
 (0)