华为应用市场静默安装

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

直接上代码,位置在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);
        }
    }

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-17 08:38:05       70 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-17 08:38:05       74 阅读
  3. 在Django里面运行非项目文件

    2024-07-17 08:38:05       62 阅读
  4. Python语言-面向对象

    2024-07-17 08:38:05       72 阅读

热门阅读

  1. 使用Micronaut进行无服务器应用开发

    2024-07-17 08:38:05       26 阅读
  2. GCC链接静态库和动态库详解

    2024-07-17 08:38:05       26 阅读
  3. 数据库SQL Server时间函数Datetime

    2024-07-17 08:38:05       27 阅读
  4. Redis⑥ —— 缓存设计

    2024-07-17 08:38:05       22 阅读
  5. 记录vue3中h函数的各种使用方式

    2024-07-17 08:38:05       28 阅读
  6. funasr的gpu部署

    2024-07-17 08:38:05       32 阅读
  7. MySQL源码安装

    2024-07-17 08:38:05       25 阅读
  8. AI学习指南机器学习篇-模型应用与Python实践

    2024-07-17 08:38:05       27 阅读
  9. qt 鼠标接近某线时,形状变化举例

    2024-07-17 08:38:05       25 阅读
  10. 探索 IPython 的历史记录:全局命令的魔法

    2024-07-17 08:38:05       27 阅读
  11. vue2使用g6,G6

    2024-07-17 08:38:05       21 阅读
  12. IPython %paste:剪贴板代码的快速执行秘籍

    2024-07-17 08:38:05       27 阅读