mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-02 22:29:25 +00:00
Expose APK path from Java
This commit is contained in:
parent
2bc1f59b5b
commit
64b70724e0
3 changed files with 64 additions and 0 deletions
|
@ -7,6 +7,7 @@ import com.genymobile.scrcpy.wrappers.SurfaceControl;
|
||||||
import com.genymobile.scrcpy.wrappers.WindowManager;
|
import com.genymobile.scrcpy.wrappers.WindowManager;
|
||||||
|
|
||||||
import android.content.IOnPrimaryClipChangedListener;
|
import android.content.IOnPrimaryClipChangedListener;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
@ -21,6 +22,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public final class Device {
|
public final class Device {
|
||||||
|
|
||||||
|
private static final String SCRCPY_PACKAGE_NAME = "com.genymobile.scrcpy";
|
||||||
|
|
||||||
public static final int POWER_MODE_OFF = SurfaceControl.POWER_MODE_OFF;
|
public static final int POWER_MODE_OFF = SurfaceControl.POWER_MODE_OFF;
|
||||||
public static final int POWER_MODE_NORMAL = SurfaceControl.POWER_MODE_NORMAL;
|
public static final int POWER_MODE_NORMAL = SurfaceControl.POWER_MODE_NORMAL;
|
||||||
|
|
||||||
|
@ -319,4 +322,12 @@ public final class Device {
|
||||||
public static Settings getSettings() {
|
public static Settings getSettings() {
|
||||||
return SETTINGS;
|
return SETTINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getApkPath() {
|
||||||
|
ApplicationInfo info = SERVICE_MANAGER.getPackageManager().getApplicationInfo(SCRCPY_PACKAGE_NAME);
|
||||||
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return info.sourceDir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.genymobile.scrcpy.wrappers;
|
||||||
|
|
||||||
|
import com.genymobile.scrcpy.Ln;
|
||||||
|
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.os.IInterface;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class PackageManager {
|
||||||
|
|
||||||
|
private IInterface manager;
|
||||||
|
private Method getApplicationInfoMethod;
|
||||||
|
|
||||||
|
public PackageManager(IInterface manager) {
|
||||||
|
this.manager = manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Method getGetApplicationInfoMethod() throws NoSuchMethodException {
|
||||||
|
if (getApplicationInfoMethod == null) {
|
||||||
|
getApplicationInfoMethod = manager.getClass().getDeclaredMethod("getApplicationInfo", String.class, int.class, int.class);
|
||||||
|
}
|
||||||
|
return getApplicationInfoMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationInfo getApplicationInfo(String packageName) {
|
||||||
|
try {
|
||||||
|
Method method = getGetApplicationInfoMethod();
|
||||||
|
return (ApplicationInfo) method.invoke(manager, packageName, 0, ServiceManager.USER_ID);
|
||||||
|
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||||
|
Ln.e("Cannot get application info", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ public final class ServiceManager {
|
||||||
private StatusBarManager statusBarManager;
|
private StatusBarManager statusBarManager;
|
||||||
private ClipboardManager clipboardManager;
|
private ClipboardManager clipboardManager;
|
||||||
private ActivityManager activityManager;
|
private ActivityManager activityManager;
|
||||||
|
private PackageManager packageManager;
|
||||||
|
|
||||||
public ServiceManager() {
|
public ServiceManager() {
|
||||||
try {
|
try {
|
||||||
|
@ -119,4 +120,20 @@ public final class ServiceManager {
|
||||||
|
|
||||||
return activityManager;
|
return activityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PackageManager getPackageManager() {
|
||||||
|
if (packageManager == null) {
|
||||||
|
try {
|
||||||
|
//IInterface manager = getService("package", "android.content.pm.IPackageManager");
|
||||||
|
Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
|
||||||
|
Method getPackageManager = activityThreadClass.getDeclaredMethod("getPackageManager");
|
||||||
|
IInterface manager = (IInterface) getPackageManager.invoke(null);
|
||||||
|
return new PackageManager(manager);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return packageManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue