mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-09 17:49:03 +00:00
Expose APK path from Java
The cleanup process will need to know the APK path to execute the CleanUp java executable.
This commit is contained in:
parent
8578c5072e
commit
c0e00c485b
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;
|
||||||
|
|
||||||
|
@ -312,4 +315,12 @@ public final class Device {
|
||||||
wm.thawRotation();
|
wm.thawRotation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getInstalledApkPath() {
|
||||||
|
ApplicationInfo info = ServiceManager.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ public final class ServiceManager {
|
||||||
private static StatusBarManager statusBarManager;
|
private static StatusBarManager statusBarManager;
|
||||||
private static ClipboardManager clipboardManager;
|
private static ClipboardManager clipboardManager;
|
||||||
private static ActivityManager activityManager;
|
private static ActivityManager activityManager;
|
||||||
|
private static PackageManager packageManager;
|
||||||
|
|
||||||
private ServiceManager() {
|
private ServiceManager() {
|
||||||
/* not instantiable */
|
/* not instantiable */
|
||||||
|
@ -122,4 +123,20 @@ public final class ServiceManager {
|
||||||
|
|
||||||
return activityManager;
|
return activityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static 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