[英]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.