1. 目的

基于《软件绿色联盟应用体验标准》中 GPS 资源的定义,对 GPS 后台持续定位的测试apk。旨在触发手机中异常功耗管控机制。

2. 测试步骤

H手机和T手机、其他手机进行安装该apk.
所有手机都需要设置应用为白名单。

2.1 手机白名单设置方法:

手机管家->应用启动设置:允许自启动、允许关联启动、允许后台启动

2.2 测试环境

  1. 必须开启GPS和WiFi连接,再打开app进行测试
  2. home 回到桌面,灭屏至少30分钟以上,再亮屏查看消息通知栏

2.3 运行本apk

测试:本次亮灭屏GPS累计使用超过5分钟,是否会弹出通知栏

3. apk 源码

本apk作用:仅使用GPS定位,但是后台一直无限制进行GPS位置监听。

3.1 UI

3.2 核心逻辑

3.2.1 MainActivity

主要为申请GPS的动态运行时权限和开启前台服务

package com.sufadi.blockgpsimport android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.location.Location
import android.location.LocationListener
import android.location.LocationManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import android.widget.Toast
import com.sufadi.commlib.services.ForegroundServiceclass MainActivity : AppCompatActivity() {val TAG = "GPS_SU"val REQUES_CODE_OK = 200override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)applyPermission()}override fun onDestroy() {super.onDestroy()}fun applyPermission() {if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED|| ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED|| ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED){//未开启定位权限Log.d(TAG, "applyPermission")ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION), REQUES_CODE_OK)} else {Log.d(TAG, "startService BlockNetLocationService")startService(Intent(this, BlockGpsService::class.java))}}override fun onRequestPermissionsResult(requestCode: Int,permissions: Array<String>,grantResults: IntArray) {when (requestCode) {REQUES_CODE_OK-> if (grantResults.size == 2 &&grantResults[0] == PackageManager.PERMISSION_GRANTED) {for (grant in grantResults) {Log.d(TAG, "grant: $grant")}ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION), REQUES_CODE_OK)/*Toast.makeText(this@MainActivity, "未开启定位权限,请手动到设置去开启权限", Toast.LENGTH_LONG).show()finish()*/} else {Log.d(TAG, "startService BlockNetLocationService 1")startService(Intent(this, BlockGpsService::class.java))}}super.onRequestPermissionsResult(requestCode, permissions, grantResults)}
}

3.2.2 BlockGpsService

主要通过前台服务后台持续定位GPS

package com.sufadi.blockgpsimport android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.location.Location
import android.location.LocationListener
import android.location.LocationManager
import android.os.Bundle
import android.os.IBinder
import android.util.Logclass BlockGpsService: Service() {companion object {val TAG = "BlockGpsService"val FORGROUND_ID = 0x11}lateinit var locationManager: LocationManagerlateinit var gpsListener: GpsLocationListeneroverride fun onBind(p0: Intent?): IBinder? {return null}override fun onCreate() {super.onCreate()Log.d(TAG, "onCreate")startMyForeground()locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManagergpsListener = GpsLocationListener()locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 0f, gpsListener)}override fun onDestroy() {super.onDestroy()locationManager.removeUpdates(gpsListener)stopForeground(true)}inner class GpsLocationListener : LocationListener {override// 位置的改变fun onLocationChanged(location: Location) {// TODO Auto-generated method stubval latitude = location.latitude// 维度val longitude = location.longitude// 经度//显示当前坐标Log.d(TAG, "gps 定位:($latitude,$longitude)")//sendRequestWithHttpClient();}override// gps卫星有一个没有找到fun onStatusChanged(provider: String, status: Int, extras: Bundle) {// TODO Auto-generated method stubLog.d(TAG,"GpsLocationListener onStatusChanged:provider$provider,status: $status, extras:$extras")}override// 某个设置被打开fun onProviderEnabled(provider: String) {// TODO Auto-generated method stub}override// 某个设置被关闭fun onProviderDisabled(provider: String) {// TODO Auto-generated method stub}}private fun startMyForeground() {Log.d(TAG, "startMyForeground show notification")Log.d(TAG, "PhoneDataService startMyForeground sdk :" + android.os.Build.VERSION.SDK_INT)val nb = Notification.Builder(this)if (android.os.Build.VERSION.SDK_INT >= 26) {val CHANNEL_ONE_ID = "channel_id_foreground"val CHANNEL_ONE_NAME = "Channel One"var notificationChannel: NotificationChannel? = nullnotificationChannel = NotificationChannel(CHANNEL_ONE_ID,CHANNEL_ONE_NAME, NotificationManager.IMPORTANCE_LOW)nb.setChannelId(CHANNEL_ONE_ID)val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManagermanager.createNotificationChannel(notificationChannel)}nb.setSmallIcon(R.mipmap.ic_launcher)nb.setContentTitle(getString(R.string.notification_title))nb.setContentText(getString(R.string.notification_Content))try {startForeground(FORGROUND_ID, nb.build())} catch (e: Exception) {e.printStackTrace()}}
}

测试apk-异常管控Gps攻击者开发相关推荐

  1. 测试apk-异常管控Bluetooth攻击者开发

    1. 目的 基于<软件绿色联盟应用体验标准>中 Bluetooth 资源的定义,对 Bluetooth 后台持续定位的测试apk.旨在触发手机中异常功耗管控机制. 2. 测试步骤 H手机和 ...

  2. 测试apk-异常管控Sensor攻击者开发

    1. 目的 基于<软件绿色联盟应用体验标准>中 Sensor 资源的定义,对 Sensor 后台持续使用的测试apk.旨在触发手机中异常功耗管控机制. 可以明确,不会触发Sensor的异常 ...

  3. 测试apk-异常管控WiFi Scan攻击者开发

    1. 目的 基于<软件绿色联盟应用体验标准>中 WiFi scan 资源的定义,对 WiFi scan 后台持续扫描的测试apk.旨在触发手机中异常功耗管控机制. 没有弹出消息通知,但是确 ...

  4. java开发常见异常_最常见的Java异常及其对Java开发人员的评价

    java开发常见异常 我知道我说过在完成视频之前我不会发帖,但这一直困扰着我. 至于视频的更新,我有些懒散,有些忙碌,但是我已经准备好记录第一集,这是我第一次有机会,而且我不需要太多的编辑. 无论如何 ...

  5. 最常见的Java异常及其对Java开发人员的评价

    我知道我说在完成视频之前我不会张贴帖子,但这一直困扰着我. 至于视频的更新,我有些懒散,有些忙碌,但是我已经准备好记录第一集,这是我第一次有机会,而且我不需要太多的编辑. 无论如何,还是今天的话题. ...

  6. 云上可靠性测试:让我们一起给开发找点事儿

    摘要:在产品上云之前,云上数据的可信(安全性.可靠性等)成为大家关注的重点. 引言 疫情之下,科技支撑有目共睹,多个产业迎来逆势增长.科技创新赋能的"云技术",不再仅仅是战&quo ...

  7. 海云安应用安全测试、移动应用安全、开发安全再次上榜

    2022年4月27日,数说安全正式发布<2022年中国网络安全市场全景图>(以下简称全景图),海云安实力上榜应用安全测试.移动应用安全.开发安全三个领域. 数说安全作为一家行业内以数据为基 ...

  8. APP渗透测试-----APK反编译

    本系列文章旨在对于有一定网络安全基础的人员,在日常工作中对APP进行安全测试,请勿应用非法途径. 一.准备必要工具 工欲善其事,必先利其器,首先我们要下载好反编译apk时需要的相关工具 1.1.使用工 ...

  9. [PHPUnit]自动生成PHPUnit测试骨架脚本-提供您的开发效率【2015升级版】

    2019独角兽企业重金招聘Python工程师标准>>> 场景 在编写PHPUnit单元测试代码时,其实很多都是对各个类的各个外部调用的函数进行测试验证,检测代码覆盖率,验证预期效果. ...

最新文章

  1. oracle命令导入表
  2. Provisioning Services 7.6 入门到精通系列之九:创建和配置目标设备
  3. (转载)linux如何设置为低内核启动(降核)
  4. kafka安装(版本kafka_2.11-0.11.0.0)
  5. 奇小葩讲设备树(1/5)-- Linux设备树详解(一) 基础知识
  6. 接受拒绝采样(Acceptance-Rejection Sampling)
  7. 计算机专业常用图论,同等学力申硕计算机专业--数学公式集合(新增学习笔记)...
  8. 程序员面试金典 - 面试题 17.07. 婴儿名字(并查集)
  9. iis设置导致python调用urllib.request.urlopen出错问题
  10. ThreadLocal原理解析以及是否需要调用remove方法
  11. idea中java文件红色处理
  12. Windows10下VB6.0开发——常见控件使用整理
  13. svn客户端(Windows版本)
  14. 软件测试 | App测试——Appium实战总结,淘宝App测试项目案例
  15. 2021数学建模C题详细思路,代码,论文,参考文献
  16. HashMap源码分析图解
  17. 李勇强seo,李勇强SEO
  18. 【狂神】HTML笔记
  19. 记一次路由器频繁掉线问题的分析、解决与发展
  20. 超详细Spring MVC的环境配置:IDEA环境下创建Maven WebAp

热门文章

  1. 浪客云黑-自助收录网站源码
  2. 顺丰bsp系统 java_顺丰BSP订单号查询接口SOAP的请求示例
  3. 干货来袭!java怎么创建包和类
  4. InputStream read()方法详解
  5. COGS 2057. [ZLXOI2015]殉国
  6. 记忆宫殿心法技法入门
  7. [iOS]URL编码和解码
  8. win10怎么连接宽带
  9. Coherent Reconstruction of Multiple Humans from a Single Image运行代码
  10. 英文单词缩写----DXNRY – Dictionary 字典