华为应用市场静默安装

最近有个需求,领导要求华为应用市场实现静默安装。反编译华为应用市场后发现只要加个权限就可以实现。

直接上代码,位置在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);
        }
    }
相关推荐
爱笑的眼睛1117 分钟前
HarmonyOS截屏与录屏API深度解析:从系统权限到像素流处理
华为·harmonyos
zhangfeng11331 小时前
医疗智能体(eiHealth) 3.4.0 使用指南(for 华为云Stack 8.5.0) 0. 华为除了这个 还有医疗 和生信方面的 产品
华为·华为云·生物信息
2501_916007471 小时前
iOS文件管理工具深度剖析,从系统沙盒到跨平台文件操作的多工具协同实践
android·macos·ios·小程序·uni-app·cocoa·iphone
Android疑难杂症2 小时前
鸿蒙Notification Kit通知服务开发快速指南
android·前端·harmonyos
lcanfly2 小时前
Mysql作业5
android·数据库·mysql
进阶的小叮当3 小时前
Vue代码打包成apk?Cordova帮你解决!
android·前端·javascript
BlackWolfSky3 小时前
鸿蒙三方库httpclient使用
华为·harmonyos·鸿蒙
-指短琴长-4 小时前
MySQL快速入门——基本查询(上)
android·数据库·mysql
爱笑的眼睛114 小时前
HarmonyOS 分布式输入法开发指南:实现跨设备无缝输入体验
华为·harmonyos
夏文强4 小时前
HarmonyOS开发-系统AI视觉能力-图片识别
人工智能·华为·harmonyos