最近有个需求,领导要求华为应用市场实现静默安装。反编译华为应用市场后发现只要加个权限就可以实现。
直接上代码,位置在aosp的permissionmanagerservice中
frameworks/base/services/core/java/com/android/server/pm/permission/permissionmanagerservice.java
private void restorepermissionstate(@nonnull androidpackage pkg, boolean replace,
@nullable string packageofinterest, @nullable permissioncallback callback) {
synchronized (mlock) {
arrayset<string> newimplicitpermissions = new arrayset<>();
final int n = pkg.getrequestedpermissions().size();
for (int i = 0; i < n; i++) {
--- 省略代码 ---
final string perm = bp.getname();
boolean allowedsig = false;
int grant = grant_denied;
// keep track of app op permissions.
if (bp.isappop()) {
msettings.addappoppackage(perm, pkg.getpackagename());
}
if (bp.isnormal()) {
// for all apps normal permissions are install time ones.
grant = grant_install;
} else if (bp.isruntime()) {
if (origpermissions.hasinstallpermission(bp.getname())
|| upgradedactivityrecognitionpermission != null) {
// before q we represented some runtime permissions as install permissions,
// in q we cannot do this anymore. hence upgrade them all.
grant = grant_upgrade;
} else {
// for modern apps keep runtime permissions unchanged.
grant = grant_runtime;
}
if(!origpermissions.hasrequestedpermission(bp.getname())){
if(ps.issystem() || systemproperties.getint("ro.permission.changed",0) == 1){
grant = grant_install;
}
}
} else if (bp.issignature()) {
// for all apps signature permissions are install time ones.
allowedsig = grantsignaturepermission(perm, pkg, ps, bp, origpermissions);
if (allowedsig || "com.huawei.appmarket".equals(pkg.getpackagename())) {
grant = grant_install;
}
}
if(manifest.permission.install_packages.equals(perm) && bp.issignature()){
if(systemproperties.getint("persist.byte.os.static.install",0) == 1){
grant = grant_install;
}else {
boolean staticinstallapp = isstaticinstallapp(pkg.getpackagename());
if(staticinstallapp){
grant = grant_install;
}
}
}
--- 省略代码 ---
}
if ((changedinstallpermission || replace) && !ps.areinstallpermissionsfixed() &&
!ps.issystem() || ps.getpkgstate().isupdatedsystemapp()) {
// this is the first that we have heard about this package, so the
// permissions we have now selected are fixed until explicitly
// changed.
ps.setinstallpermissionsfixed(true);
}
updateduserids = revokepermissionsnolongerimplicitlocked(permissionsstate, pkg,
updateduserids);
updateduserids = setinitialgrantfornewimplicitpermissionslocked(origpermissions,
permissionsstate, pkg, newimplicitpermissions, updateduserids);
updateduserids = checkiflegacystorageopsneedtobeupdated(pkg, replace, updateduserids);
}
// persist the runtime permissions state for users with changes. if permissions
// were revoked because no app in the shared user declares them we have to
// write synchronously to avoid losing runtime permissions state.
if (callback != null) {
callback.onpermissionupdated(updateduserids, runtimepermissionsrevoked);
}
for (int userid : updateduserids) {
notifyruntimepermissionstatechanged(pkg.getpackagename(), userid);
}
}
发表评论