[英]How some apps track their own uninstall on android
让我试着澄清一下。
在Android 4.4之前,我们可以使用inotify
,它提供了监视文件系统事件的机制,我们创建了一个守护进程来监视我们在应用程序目录中创建的文件是否被删除或者我们的主应用程序目录是否被删除,这应该在用户卸载时发生应用程序,JNI代码将如下所示:
// initializes a new inotify instance and returns a file descriptor
fd = inotify_init();
// watch directory delete/create events
inotify_add_watch(fd, DIRECTORY, IN_DELETE | IN_CREATE);
__android_log_print(ANDROID_LOG_INFO, "TAG", "Watching [%s]", DIRECTORY);
// TODO: implement checkIfDeleted
if(checkIfDeleted()) {
// execute intent to open url
system("/system/bin/am start --user 0 -a android.intent.action.VIEW -d https://www...");
这不再有效,因为卸载还会终止组进程,从当前源代码附加相关代码
看一下git log
我需要更多时间来研究无根设备,360security将应用程序与特定架构(也称为ABI)打包,并且可能每个API都可以减少APK大小,遗憾的是apkmirror(.com)只有ARM可供下载,我更喜欢阅读x86,可能在不久的将来编辑这个答案。
到目前为止,本机代码似乎正在创建文件并使用锁来检测卸载后进程何时死机,然后使用JNI接口来调用回调。
为了简化,似乎它自己锁定,然后加入同步模块notify_and_waitfor
。
您可以在此处查看Android 5.0的本机代码示例
NativeHelper源代码(反编译):
所有带有关键字native
方法都是在eternity
binary中实现的
package com.qihoo.eternity;
import com.qihoo.eternity.b;
public class NativeHelper {
static {
try {
System.loadLibrary((String)"eternity");
}
catch (Exception exception) {}
}
public native void look(String var1, String var2, String var3, String var4, String var5);
public void onU() {
b.a().g();
}
public native void pass(String var1, String var2);
public void peerDead() {
b.a().f();
}
public native void watch(String var1, String var2, String var3, String var4);
public native void watch2(String var1, String var2, String var3, String var4, String var5);
}
NativeHelper的应用程序参考:
com/qihoo/eternity/b.java:203:
new NativeHelper().look(b.this.h.getPackageName(), b.b((b)b.this).f, string2, b.b(b.this.i), string3);
com/qihoo/eternity/b.java:224:
new NativeHelper().watch(new File(file, "a1").getAbsolutePath(), new File(file, "a2").getAbsolutePath(), new File(file, "a3").getAbsolutePath(), new File(file, "a4").getAbsolutePath());
com/qihoo/eternity/b.java:264:
new NativeHelper().watch(new File(file, "a2").getAbsolutePath(), new File(file, "a1").getAbsolutePath(), new File(file, "a4").getAbsolutePath(), new File(file, "a3").getAbsolutePath());
com/qihoo/eternity/b.java:518:
new NativeHelper().pass(this.a, this.b);
com/qihoo/eternity/b.java:563:
new NativeHelper().watch2(new File(file, "b1").getAbsolutePath(), new File(file, "b2").getAbsolutePath(), new File(file, "b3").getAbsolutePath(), new File(file, "b4").getAbsolutePath(), b.this.h.getDir("lib", 0).getAbsolutePath());
com/qihoo/eternity/b.java:588:
new NativeHelper().watch2(new File(file, "b2").getAbsolutePath(), new File(file, "b1").getAbsolutePath(), new File(file, "b4").getAbsolutePath(), new File(file, "b3").getAbsolutePath(), b.this.h.getDir("lib", 0).getAbsolutePath());
一种解决方案是在您的JNI文件夹中包含共享对象eternity.so
并实现NativeHelper.onU
方法:)
该应用可以使用操作指定BroadcastReceiver
:
"android.intent.action.PACKAGE_REMOVED"
每次删除包时都会调用它,即使它是应用程序自己的包。 然后,在Receiver
,应用程序可以检查确切删除了哪个包并做出相应的反应。
请注意,系统的不同版本可能会有不同的处理方式,在应用程序进程关闭之前为Receiver
不同的时间。 因此,执行的操作应该快速并且针对外部目标,例如发送ACTION_VIEW
Intent,其中包含您提到的网页URL :-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.