mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-04-21 01:33:36 +00:00
This avoids the following error on some devices:
Given calling package android does not match caller's uid 2000
Refs #4639 comment <https://github.com/Genymobile/scrcpy/issues/4639#issuecomment-2466081589>
Fixes #4639 <https://github.com/Genymobile/scrcpy/issues/4639>
PR #5476 <https://github.com/Genymobile/scrcpy/pull/5476>
Signed-off-by: Romain Vimont <rom@rom1v.com>
94 lines
2.8 KiB
Java
94 lines
2.8 KiB
Java
package com.genymobile.scrcpy;
|
|
|
|
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
|
|
|
import android.annotation.TargetApi;
|
|
import android.content.AttributionSource;
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.content.ContextWrapper;
|
|
import android.content.IContentProvider;
|
|
import android.os.Binder;
|
|
import android.os.Process;
|
|
|
|
public final class FakeContext extends ContextWrapper {
|
|
|
|
public static final String PACKAGE_NAME = "com.android.shell";
|
|
public static final int ROOT_UID = 0; // Like android.os.Process.ROOT_UID, but before API 29
|
|
|
|
private static final FakeContext INSTANCE = new FakeContext();
|
|
|
|
public static FakeContext get() {
|
|
return INSTANCE;
|
|
}
|
|
|
|
private final ContentResolver contentResolver = new ContentResolver(this) {
|
|
@SuppressWarnings({"unused", "ProtectedMemberInFinalClass"})
|
|
// @Override (but super-class method not visible)
|
|
protected IContentProvider acquireProvider(Context c, String name) {
|
|
return ServiceManager.getActivityManager().getContentProviderExternal(name, new Binder());
|
|
}
|
|
|
|
@SuppressWarnings("unused")
|
|
// @Override (but super-class method not visible)
|
|
public boolean releaseProvider(IContentProvider icp) {
|
|
return false;
|
|
}
|
|
|
|
@SuppressWarnings({"unused", "ProtectedMemberInFinalClass"})
|
|
// @Override (but super-class method not visible)
|
|
protected IContentProvider acquireUnstableProvider(Context c, String name) {
|
|
return null;
|
|
}
|
|
|
|
@SuppressWarnings("unused")
|
|
// @Override (but super-class method not visible)
|
|
public boolean releaseUnstableProvider(IContentProvider icp) {
|
|
return false;
|
|
}
|
|
|
|
@SuppressWarnings("unused")
|
|
// @Override (but super-class method not visible)
|
|
public void unstableProviderDied(IContentProvider icp) {
|
|
// ignore
|
|
}
|
|
};
|
|
|
|
private FakeContext() {
|
|
super(Workarounds.getSystemContext());
|
|
}
|
|
|
|
@Override
|
|
public String getPackageName() {
|
|
return PACKAGE_NAME;
|
|
}
|
|
|
|
@Override
|
|
public String getOpPackageName() {
|
|
return PACKAGE_NAME;
|
|
}
|
|
|
|
@TargetApi(AndroidVersions.API_31_ANDROID_12)
|
|
@Override
|
|
public AttributionSource getAttributionSource() {
|
|
AttributionSource.Builder builder = new AttributionSource.Builder(Process.SHELL_UID);
|
|
builder.setPackageName(PACKAGE_NAME);
|
|
return builder.build();
|
|
}
|
|
|
|
// @Override to be added on SDK upgrade for Android 14
|
|
@SuppressWarnings("unused")
|
|
public int getDeviceId() {
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public Context getApplicationContext() {
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public ContentResolver getContentResolver() {
|
|
return contentResolver;
|
|
}
|
|
}
|