-
-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Given calling package android does not match caller's uid #4639
Comments
By any chance, is the device rooted? #1606 |
Nope |
adb -d shell id
uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid) context=u:r:shell:s0 |
Having exact same issue. OS: Windows 11 Note: DevTools Android App used to enable Developer options and USB debugging (https://play.google.com/store/apps/details?id=cn.trinea.android.developertools&pcampaignid=web_share) [server] INFO: Device: [ONYX] ONYX NoteAir2P (Android 11) ERROR: Could not retrieve device information |
Check in your system settings or developer options if there is an option to give a permission related to clipboard. |
Just had a dig through and can't find anything in any settings related to clipboard. |
It seems (if you don't need audio) |
|
Same as #4349 (comment) (I don't know the cause) |
I found a solution for this on my Vivo Y21T, I had to download the older version of scrcpy which is v2.2 for now! And fsr, the newer versions don't work on mine and I had this similar error too but this thingy worked for me ^w^ |
2.2 works for you, what about 2.3? |
Not professional android developer, just learning it for interest. The cause of all issues related to Because the manger is initialized somewhere(i don't look into it) with "android" system context, I tried to patch the context in the manger. But after changing context, it gives me that it can't find the app. Because scrcpy is not a app, it can't pass through the getContentResolver's permission check. But, after looking into the However, due to the lack of understanding of Android I still not override the release method in ApplicationContentResolver properly (even though it seems to work fine), so there might still be some issues in my code. And also i use special android sdk, I share the idea here first. If want to set image to clipboard, it also needs a contentResolver: There may be some mistakes in this paragraph, because I did it some time ago, and now I have forgotten it a little, and my English is not very good, I have tried to decrease mistakes. |
@Ercilan Thank you for your investigations. Could you post a branch with your changes? |
@rom1v I'm going to sleep now. It's midnight im my place🌃. package com.genymobile.scrcpy.wrappers;
import android.annotation.SuppressLint;
import android.app.ActivityThread;
import android.content.ContentResolver;
import android.content.Context;
import android.content.IContentProvider;
import android.os.Binder;
import android.os.IBinder;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;
public class ApplicationContentResolver extends ContentResolver {
private final ActivityThread mMainThread;
public ApplicationContentResolver(Context context, ActivityThread mainThread) {
super(context);
mMainThread = Objects.requireNonNull(mainThread);
}
@Override
protected IContentProvider acquireProvider(Context context, String auth) {
return ServiceManager.getActivityManager().getContentProviderExternal(ContentProvider.getAuthorityWithoutUserId(auth), new Binder());
}
@Override
protected IContentProvider acquireExistingProvider(Context context, String auth) {
// it has never been called...
return mMainThread.acquireExistingProvider(context, ContentProvider.getAuthorityWithoutUserId(auth), resolveUserIdFromAuthority(auth), true);
}
@Override
public boolean releaseProvider(IContentProvider provider) {
// todo maybe need to release ContentProviderExternal
return mMainThread.releaseProvider(provider, true);
}
@Override
protected IContentProvider acquireUnstableProvider(Context c, String auth) {
// return mMainThread.acquireProvider(c, ContentProvider.getAuthorityWithoutUserId(auth), resolveUserIdFromAuthority(auth), false);
// I just update here today(24/10/16), clipboardManager call this. not tested enough
return ServiceManager.getActivityManager().getContentProviderExternal(ContentProvider.getAuthorityWithoutUserId(auth), new Binder());
}
@Override
public boolean releaseUnstableProvider(IContentProvider icp) {
// todo maybe need to release ContentProviderExternal
return mMainThread.releaseProvider(icp, false);
}
@SuppressLint("DiscouragedPrivateApi")
@Override
public void unstableProviderDied(IContentProvider icp) {
try {
// mMainThread.handleUnstableProviderDied(icp.asBinder(), true);
Method handleUnstableProviderDied = ActivityThread.class.getDeclaredMethod("handleUnstableProviderDied", IBinder.class, boolean.class);
handleUnstableProviderDied.invoke(mMainThread, icp.asBinder(), true);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
@SuppressLint("SoonBlockedPrivateApi")
@Override
public void appNotRespondingViaProvider(IContentProvider icp) {
try {
// mMainThread.appNotRespondingViaProvider(icp.asBinder());
Method appNotRespondingViaProvider = ActivityThread.class.getDeclaredMethod("appNotRespondingViaProvider", IBinder.class);
appNotRespondingViaProvider.invoke(mMainThread, icp.asBinder());
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
protected int resolveUserIdFromAuthority(String auth) {
return ContentProvider.getUserIdFromAuthority(auth, getUserId());
}
} In the ActivityManager: ...
@TargetApi(Build.VERSION_CODES.Q)
public IContentProvider getContentProviderExternal(String name, IBinder token) {
try {
Method method = getGetContentProviderExternalMethod();
Object[] args;
if (getContentProviderExternalMethodNewVersion) {
// new version
args = new Object[]{name, FakeContext.ROOT_UID, token, null};
} else {
// old version
args = new Object[]{name, FakeContext.ROOT_UID, token};
}
// ContentProviderHolder providerHolder = getContentProviderExternal(...);
Object providerHolder = method.invoke(manager, args);
if (providerHolder == null) {
return null;
}
// IContentProvider provider = providerHolder.provider;
Field providerField = providerHolder.getClass().getDeclaredField("provider");
providerField.setAccessible(true);
Object provider = providerField.get(providerHolder);
return (IContentProvider) provider;
} catch (ReflectiveOperationException e) {
Ln.e("Could not invoke method", e);
return null;
}
}
private ContentProvider getContentProviderExternalInternal(String name, IBinder token) {
IContentProvider provider = getContentProviderExternal(name, token);
return new ContentProvider(this, provider, name, token);
}
void removeContentProviderExternal(String name, IBinder token) {
try {
Method method = getRemoveContentProviderExternalMethod();
method.invoke(manager, name, token);
} catch (ReflectiveOperationException e) {
Ln.e("Could not invoke method", e);
}
}
public ContentProvider createSettingsProvider() {
return getContentProviderExternalInternal("settings", new Binder());
}
... FakeContext: ...
private final ApplicationContentResolver mContentResolver;
private static boolean isAudioManagerPatched = false;
private FakeContext() {
super(Workarounds.getSystemContext());
mContentResolver = new ApplicationContentResolver(this, (ActivityThread) Workarounds.ACTIVITY_THREAD);
}
/**
* getContentResolver without app
*/
@Override
public ContentResolver getContentResolver() {
try {
return mContentResolver;
} catch (Exception e) {
Ln.e("getContentResolver Exception", e);
}
return super.getContentResolver();
}
@Override
public Object getSystemService(String name) {
Object service = super.getSystemService(name);
switch (name) {
case Context.AUDIO_SERVICE:
if (!isAudioManagerPatched) {
patchAudioManagerContext(service);
isAudioManagerPatched = true;
}
break;
// ...
}
return service;
}
@SuppressLint("SoonBlockedPrivateApi")
private void patchAudioManagerContext(Object service) {
try {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S_V2) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Method setContextMethod = AudioManager.class.getDeclaredMethod("setContext", Context.class);
setContextMethod.setAccessible(true);
setContextMethod.invoke(service, this);
} else {
Field mContextField = AudioManager.class.getDeclaredField("mContext");
mContextField.setAccessible(true);
mContextField.set(service, this);
}
} catch (Exception e) {
Ln.e("patchAudioManagerContext Exception", e);
}
}
|
Today, I take a look at the process of invoking system services and made some additions. The system obtains system services through My solution here is to intercept and reflectively modify the internal context in the manager by overriding
I reviewed the error log for this issue, specifically |
Looks like the runtime type checking is so loose that even this works: https://github.com/Genymobile/scrcpy/compare/dev...yume-chan:scrcpy:feat/content-resolver?expand=1 It can be compiled with standard I have tested this on Android 10, 11, 13, 14 on real devices, and 15 on emulator using this patch: diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java
index e0adeea0..4f75d104 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Server.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Server.java
@@ -25,6 +25,7 @@ import com.genymobile.scrcpy.video.SurfaceCapture;
import com.genymobile.scrcpy.video.SurfaceEncoder;
import com.genymobile.scrcpy.video.VideoSource;
+import android.content.ContentResolver;
import android.os.BatteryManager;
import android.os.Build;
@@ -169,6 +170,14 @@ public final class Server {
Workarounds.apply();
+ try {
+ ContentResolver contentResolver = FakeContext.get().getContentResolver();
+ int airplaneMode = android.provider.Settings.Global.getInt(contentResolver, android.provider.Settings.Global.AIRPLANE_MODE_ON);
+ Ln.i("Airplane mode: " + airplaneMode);
+ } catch (Exception e) {
+ Ln.e("Get content resolver failed", e);
+ }
+
List<AsyncProcessor> asyncProcessors = new ArrayList<>();
DesktopConnection connection = DesktopConnection.open(scid, tunnelForward, video, audio, control, sendDummyByte); Prebuilt server: scrcpy-server.zip |
thanks, your server binary is ok on Android15(Xiaomi 15),but when i use your code to compile my own server binary, audio is broken again, and i cannot use |
Any error output?
Maybe need to add scrcpy/server/build_without_gradle.sh Lines 53 to 61 in eff5b4b
|
I fixed building with |
thanks, Everything goes well! |
The source files are encoded in UTF-8. Refs <#4639 (comment)> Signed-off-by: Romain Vimont <rom@rom1v.com>
Thank you, I allowed myself to merge it into |
FYI, I ran |
AFAIK, in all Linux distros, the default encoding is UTF-8. I don't know why it's not the case in your container. I reproduce the problem if I explicitly pass Anyway, specifying the encoding explicitly is the right thing to do. |
This avoids the following error on some devices: Given calling package android does not match caller's uid 2000 Refs #4639 comment <#4639 (comment)> Fixes #4639 <#4639> Signed-off-by: Romain Vimont <rom@rom1v.com>
Please test #5476. |
This avoids the following error on some devices: Given calling package android does not match caller's uid 2000 Refs #4639 comment <#4639 (comment)> Fixes #4639 <#4639> Signed-off-by: Romain Vimont <rom@rom1v.com>
Environment
Describe the bug
Cannot share device screen. It suddenly stopped working.
The text was updated successfully, but these errors were encountered: