Genymobile / Genymobile/scrcpy
If can bindService or startService ?
- Dominant language
- C
- Stars
- 150k
- Forks
- 13.7k
- Avg merge
- 4d 13h
- Merged PRs (30d)
- 2
Description
`private static Context getContext(){
try {
Class activityThreadClass = Class.forName("android.app.ActivityThread");
Constructor activityThreadConstructor = activityThreadClass.getDeclaredConstructor();
activityThreadConstructor.setAccessible(true);
Object activityThread = activityThreadConstructor.newInstance();
// ActivityThread.sCurrentActivityThread = activityThread;
Field sCurrentActivityThreadField = activityThreadClass.getDeclaredField("sCurrentActivityThread");
sCurrentActivityThreadField.setAccessible(true);
sCurrentActivityThreadField.set(null, activityThread);
// ActivityThread.AppBindData appBindData = new ActivityThread.AppBindData();
Class appBindDataClass = Class.forName("android.app.ActivityThread$AppBindData");
Constructor appBindDataConstructor = appBindDataClass.getDeclaredConstructor();
appBindDataConstructor.setAccessible(true);
Object appBindData = appBindDataConstructor.newInstance();
ApplicationInfo applicationInfo = new ApplicationInfo();
applicationInfo.packageName = "com.xhuwei.firstview";
applicationInfo.theme = R.style.AppTheme;
// appBindData.appInfo = applicationInfo;
Field appInfoField = appBindDataClass.getDeclaredField("appInfo");
appInfoField.setAccessible(true);
appInfoField.set(appBindData, applicationInfo);
// activityThread.mBoundApplication = appBindData;
Field mBoundApplicationField = activityThreadClass.getDeclaredField("mBoundApplication");
mBoundApplicationField.setAccessible(true);
mBoundApplicationField.set(activityThread, appBindData);
Method getSystemContextMethod = activityThreadClass.getDeclaredMethod("getSystemContext");
Context ctx = (Context) getSystemContextMethod.invoke(activityThread);
Ln.i(ctx.toString());
return ctx;
} catch (Throwable throwable) {
// this is a workaround, so failing is not an error
Ln.d("Could not fill app info: " + throwable.getMessage());
return null;
}
}`
`private static void bindAIDLService(){
try{
Context context = getContext();
/*Intent intent = new Intent();
intent.setPackage("com.xhuwei.firstview");
intent.setAction("org.xhuwei.shixun.RemoteService");
context.bindService(intent, connection, context.BIND_AUTO_CREATE);*/
Intent service = new Intent(context, RemoteService.class);
context.startService(service);
}catch (Exception e){
Ln.e("bindAIDLService : " + e.toString());
e.printStackTrace();
}
}`
bindService and startService got errors:
java.lang.SecurityException: Unable to find app for caller android.app.IApplicationThread$Stub$Proxy@f838900 (pid=9750) when binding service Intent { act=org.xhuwei.shixun.RemoteService pkg=com.xhuwei.firstview }
java.lang.SecurityException: Unable to find app for caller android.app.IApplicationThread$Stub$Proxy@680d95b (pid=2246) when starting service Intent { cmp=android/com.xhuwei.firstview.RemoteService }
How to do this ?
Thanks!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the getContext() and bindAIDLService() snippets in the issue, then reproduce the bindService and startService SecurityException on Android. Trace how the constructed Context and RemoteService intent are used, and compare both failure paths. Done means the supported way to start or bind the service is identified and the reported errors are resolved or clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100