APK的更新、安装、隐藏、解除隐藏
⼀、⽤户安装的apk发⽣更新
publicvoidregisterReceiver(Contextcontext){
Slog.d("PMSdddd","systemReady1");
IntentFilterfilter=newIntentFilter();
ion(_PACKAGE_ADDED);
ion(_PACKAGE_CHANGED);
ion(_PACKAGE_REPLACED);
ion(_PACKAGE_REMOVED);
aScheme("package");
BroadcastReceiverpackgeMonitorReceiver=newBroadcastReceiver(){
@Override
publicvoidonReceive(Contextcontext,Intentintent){
finalStringaction=ion();
finalStringpackageName=
a().getSchemeSpecificPart();
finalbooleanreplacing=
leanExtra(_REPLACING,fal);
finalbooleandataRemoved=
leanExtra(_DATA_REMOVED,fal);
Slog.d("PMSdddd","action:"+action+"packageName:"
+packageName+"replacing:"+replacing
+"dataRemoved:"+dataRemoved);
}
};
erReceiver(packgeMonitorReceiver,filter);
}
第1步,新安装apk
adbinstallapk
Line52701:02-0121:26:23.21317271727DPMSdddd:action:E_ADDEDpackageName:replacing:faldataRe
第2步,hide此apk
adbshellpmhideapk
Line53895:02-0121:28:22.DPMSdddd:action:E_REMOVEDpackageName:replacing:faldat
第3步,adbinstall更新
adbinstall-rapk
Line54477:02-0121:29:41.55017271727DPMSdddd:action:E_REMOVEDpackageName:replacing:truedata
Line54512:02-0121:29:41.64817271727DPMSdddd:action:E_ADDEDpackageName:replacing:truedataRemoved
第4步,再unhide此apk
adbshellpmunhideapk
Line55640:02-0121:32:25.65117271727DPMSdddd:action:E_ADDEDpackageName:replacing:faldataRe
第5步,adbuninstall卸载apk
Line61310:02-0121:52:36.39517271727DPMSdddd:action:E_REMOVEDpackageName:replacing:faldat
总结:
hide命令:系统会发送⼴播E_REMOVED,data数据并不会删除
unhide命令:系统会发送⼴播E_ADDED,data数据不会删除
更新apk时:
系统先发送⼴播E_REMOVED,leanExtra(_REPLACING,fal)获取的值为
true
系统随后发送⼴播E_ADDED,leanExtra(_REPLACING,fal)获取的值也为
true
卸载apk时:
系统发送⼴播E_REMOVED,leanExtra(_DATA_REMOVED,fal)获取的值
为true
⼆、系统apk(位于:system/app⽬录)发⽣更新
第1步,预置apk(v1.0)到system/app
adbpushapksystem/app
再恢复出⼚设置
第2步,adbinstall-r更新apk到v2.0
Line8118:02-0202:55:59.42811301130DPMSdddd:action:E_REMOVEDpackageName:lacing:truedataR
Line8134:02-0202:55:59.5DPMSdddd:action:E_ADDEDpackageName:lacing:truedataRemoved:fa
Line8281:02-0202:55:59.9DPMSdddd:action:E_REPLACEDpackageName:lacing:truedataRemov
更新后的apk安装在data/app⽬录:
Line8550:02-0205:12:10.8IPackageManager:epathfrom/system/operator/app/AndroidDemoV1.0.
Line8550:02-0205:12:10.8IPackageManager:epathfrom/system/operator/app/
Line8551:02-0205:12:10.8IPackageManager:ourcepathfrom/system/operator/app/
Line8551:02-0205:12:10.8IPackageManager:ourcepathfrom/system/operator/app/
第3步,Settings“应⽤信息”界⾯⽆法卸载,没有卸载按钮(打开、停⽤、强⾏停⽌三个按钮)
总结:
系统apk发⽣更新时,系统依次发送⼴播:action:E_REMOVED、action:
E_ADDED、action:E_REPLACED
且leanExtra(_REPLACING,fal)获取的值为true
Android监听多⽤户切换,隐藏和禁⽤指定Apk
IntentFilterfilter=newIntentFilter();
ion(_USER_SWITCHED);
ion(_USER_ADDED);
BroadcastReceivermUrSwitchedReceiver=newBroadcastReceiver(){
@Override
publicvoidonReceive(Contextcontext,Intentintent){
finalStringaction=ion();
finalinturId=Extra(_USER_HANDLE,_NULL);
if(urId==_NULL){
Slog.e("PMSdddd","receivedaninvalidEXTRA_USER_HANDLE");
return;
}
if(_USER_(action)&&urId>0){
Slog.d("PMSdddd","UrswitchedtourId"+urId);
e(newRunnable(){
@Override
publicvoidrun(){
Slog.d("PMSdddd","installstart11");
herBrandAppWhenUrSwitched();
}
});
}elif(_USER_(action)&&urId>0){
Slog.d("PMSdddd","AddedUrurId"+urId);
e(newRunnable(){
@Override
publicvoidrun(){
Slog.d("PMSdddd","installstart11");
Sbbbbbbbbbbb
.hideOtherBrandAppWhenUrSwitched();}});}}};erReceiver(mUrSwitchedReceiver,filter);
是否隐藏和禁⽤apk
/**
*onlyhideappbutdon'tdeleteurdata
*
*@parampkgName
*/
privatevoidhide(StringpkgName){
finalPackageManagerpm=kageManager();
inturId=rentUr();
licationHiddenSettingAsUr(pkgName,true,newUrHandle(urId));
disableApplication(pkgName);
}
privatevoidunhide(StringpkgName){
finalPackageManagerpm=kageManager();
inturId=rentUr();
licationHiddenSettingAsUr(pkgName,fal,newUrHandle(urId));
enableApplication(pkgName);
}
privatevoiddisableApplication(StringpkgName){
finalPackageManagerpm=kageManager();
try{
intstate=licationEnabledSetting(pkgName);
Slog.d(TAG,"disableApplicationstate:"+state+"pkgName:"+pkgName);
if(state==ENT_ENABLED_STATE_DISABLED)
return;
licationEnabledSetting(pkgName,ENT_ENABLED_STATE_DISABLED,0);
}catch(IllegalArgumentExceptionexeption){
Slog.w(TAG,"disableApplicationerror:"+sage());
}
}
privatevoidenableApplication(StringpkgName){
finalPackageManagerpm=kageManager();
try{
intstate=licationEnabledSetting(pkgName);
Slog.d(TAG,"enableApplicationstate:"+state+"pkgName:"+pkgName);
if(state==ENT_ENABLED_STATE_ENABLED)
return;
licationEnabledSetting(pkgName,ENT_ENABLED_STATE_ENABLED,0);
}catch(IllegalArgumentExceptionexeption){
Slog.w(TAG,"enableApplicationerror:"+sage());
}
}
隐藏的apk或disable的apk,信息保存在/data/system/urs/0/⽂件内
apk被hide后,保存的信息:hidden="true"
apk被disable后,根据tApplicationEnabledSetting传⼊的常量参数不同,enabled=的值就会不同,如下介绍:
publicstaticfinalintCOMPONENT_ENABLED_STATE_DISABLED=2;//disable应⽤时,若传⼊此参数,则应⽤在桌⾯没有图标,且在设置界⾯、应⽤程序列表⾥⾯也没有图
publicstaticfinalintCOMPONENT_ENABLED_STATE_DISABLED_USER=3;//disable应⽤时,若传⼊此参数,则应⽤在桌⾯没有图标,但是在设置界⾯、应⽤程序列表⾥⾯
另外:adbshellpmdisable-ur应⽤包名:相当于传⼊的参数是COMPONENT_ENABLED_STATE_DISABLED。
查看⼿机有哪些应⽤处于disable状态的⽅法:
⽅法1:adbshellpmlistpackages-d
C:Urszzz>adbshellpmlistpackages-d
package:es
package:
package:ager
⽅法2:adbshellpmdumppackages>Desktop/
enabled=2---->表⽰应⽤处于disable状态,对应的值:COMPONENT_ENABLED_STATE_DISABLED
Package[ager](a926214):
urId=10098
pkg=Package{ager}
codePath=/system/app/appmanager
resourcePath=/system/app/appmanager
legacyNativeLibraryDir=/system/app/appmanager/lib
primaryCpuAbi=arm64-v8a
condaryCpuAbi=null
versionCode=277606887minSdk=21targetSdk=30
versionName=67.3.0
splits=[ba]
apkSigningVersion=2
applicationInfo=ApplicationInfo{ager}
flags=[SYSTEMHAS_CODEALLOW_CLEAR_USER_DATA]
privateFlags=[PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSIONALLOW_AUDIO_PLAYBACK_CAPTUREHAS_DOMAIN_URLSPRIVA
forceQueryable=fal
queriesIntents=[Intent{act=_QUERY_PACKAGES}]
dataDir=/data/ur/0/ager
supportsScreens=[small,medium,large,xlarge,resizeable,anyDensity]
timeStamp=2021-07-1223:30:37
firstInstallTime=2021-07-1223:30:37
lastUpdateTime=2021-07-1223:30:37
signatures=PackageSignatures{18e58b2version:2,signatures:[c4e416cc],pastsignatures:[]}
installPermissionsFixed=true
pkgFlags=[SYSTEMHAS_CODEALLOW_CLEAR_USER_DATA]
declaredpermissions:
:prot=signature,INSTALLED
_ACCESS:prot=normal,INSTALLED
installpermissions:
AD_WITHOUT_NOTIFICATION:granted=true
OUND_SERVICE:granted=true
E_BOOT_COMPLETED:granted=true
ET:granted=true
_PACKAGE_SIZE:granted=true
:granted=true
_NETWORK_STATE:granted=true
_WIFI_STATE:granted=true
_LOCK:granted=true
Ur0:ceDataInode=4785installed=truehidden=falsuspended=faldistractionFlags=0stopped=falnotLaunched=falenabled=2instant=falvirtual=fal
overlaypaths:
/product/overlay/NavigationBarModeGestural/
lastDisabledCaller:android
gids=[3003]
查看哪些应⽤属于系统签名?
⽅法:adbshellpmdumppackages>Desktop/
包名为"android"的apk属于平台apk,肯定是系统签名,⾸先看⼀下包名为"android"的apk的签名信息:
Package[android](ad28bfa):
urId=1000
sharedUr=SharedUrSetting{/1000}
pkg=Package{6103b22android}
codePath=/system/framework/
resourcePath=/system/framework/
legacyNativeLibraryDir=/system/lib64/framework-res
primaryCpuAbi=arm64-v8a
condaryCpuAbi=null
versionCode=30minSdk=30targetSdk=30
versionName=11
splits=[ba]
apkSigningVersion=3
applicationInfo=ApplicationInfo{6103b22android}
flags=[SYSTEMPERSISTENTALLOW_BACKUP]
privateFlags=[PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSIONALLOW_AUDIO_PLAYBACK_CAPTUREDEFAULT_TO_DEVICE_PRO
forceQueryable=true
queriesPackages=[]
dataDir=/data/system
supportsScreens=[small,medium,large,xlarge,resizeable,anyDensity]
timeStamp=2021-07-1223:27:41
firstInstallTime=2021-07-1223:27:41
lastUpdateTime=2021-07-1223:27:41
signatures=PackageSignatures{539b9b3version:3,signatures:[a0521abc],pastsignatures:[]}
installPermissionsFixed=true
pkgFlags=[SYSTEMPERSISTENTALLOW_BACKUP]
declaredpermissions:
_CONTACTS:prot=dangerous,INSTALLED
_CONTACTS:prot=dangerous,INSTALLED
........
Ur0:ceDataInode=4316installed=truehidden=falsuspended=faldistractionFlags=0stopped=falnotLaunched=falenabled=0instant=falvirtual=fal
overlaypaths:
/product/overlay/NavigationBarModeGestural/
从上⾯信息可以看到,签名信息:signatures:[a0521abc],然后在⽂件全局搜索“a0521abc”,可以列出所有系统签名的应⽤。
结语:后续会持续更新哦,喜欢的话点赞关注⼀下吧。
相关视频
【Android进阶】APK的加固优化
本文发布于:2023-03-04 18:19:19,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/1677925160137616.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:怎样隐藏应用.doc
本文 PDF 下载地址:怎样隐藏应用.pdf
留言与评论(共有 0 条评论) |