Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

venshine/AppUninstall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Android App监听自身卸载,反馈统计

方案

  1. 监听系统卸载广播:只能监听到其他应用的卸载广播,无法监听到自己是否被卸载。
  2. 读取系统log:第三方软件卸载无法得知。
  3. 静默安装另一个程序,监听自己是否被卸载:需要root权限。
  4. Java线程轮询,监听/data/data/{package-name}目录是否存在:卸载app,进程退出,线程也被销毁。
  5. C进程轮询,监听/data/data/{package-name}目录是否存在:目前业界普遍采用的方案。

原理

从前四种方案可以看到,单纯的Java层代码是无法监听自身卸载的。既然Java层无法实现,我们试着使用C语言在底层实现。借助Linux进程fork出来的C进程在应用被卸载后不会被销毁,监听/data/data/{package-name}目录是否存在,如果不存在,就证明应用被卸载了。

本程序采用第5种解决方案,对其进行优化,通过linux中的inotify机制来监听应用的卸载。

实现

  1. fork()子进程
  2. 创建监听文件
  3. 初始化inotify实例
  4. 注册监听事件
  5. 调用read函数开始监听
  6. 卸载反馈统计

场景

  1. 正常卸载
  2. 断网卸载
  3. 清除数据(5.0以上不支持)
  4. kill进程(5.0以上不支持)
  5. 插拔USB线
  6. 覆盖安装
  7. 内部存储移到SD卡
  8. 开机监听(官方不推荐)
  9. 打开浏览器(5.0以上部分机型无法开启)

参考

About

License

Copyright (C) 2016 venshine.cn@gmail.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Android App监听自身卸载,反馈统计

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published