Code Monkey home page Code Monkey logo

appuninstall's Introduction

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 [email protected]

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.

appuninstall's People

Contributors

venshine avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.