避免在设置中强制停止某一应用

音乐播放过程中,在设置-》应用中,对音乐执行强制停止,相关日志如下:


framework层相关代码alps\frameworks\base\services\core\java\com\android\server\am\ActivityManagerService.java中对应用停止运行执行的代码如下:

    @Override
    public void forceStopPackage(final String packageName, int userId) {
        if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES)
                != PackageManager.PERMISSION_GRANTED) {
            String msg = "Permission Denial: forceStopPackage() from pid="
                    + Binder.getCallingPid()
                    + ", uid=" + Binder.getCallingUid()
                    + " requires " + android.Manifest.permission.FORCE_STOP_PACKAGES;
            Slog.w(TAG, msg);
            throw new SecurityException(msg);
        }
        final int callingPid = Binder.getCallingPid();
        userId = mUserController.handleIncomingUser(callingPid, Binder.getCallingUid(),
                userId, true, ALLOW_FULL_ONLY, "forceStopPackage", null);
        long callingId = Binder.clearCallingIdentity();
        try {
            IPackageManager pm = AppGlobals.getPackageManager();
            synchronized(this) {
                int[] users = userId == UserHandle.USER_ALL
                        ? mUserController.getUsers() : new int[] { userId };
                for (int user : users) {
                    int pkgUid = -1;
                    try {
                        pkgUid = pm.getPackageUid(packageName, MATCH_DEBUG_TRIAGED_MISSING,
                                user);
                    } catch (RemoteException e) {
                    }
                    if (pkgUid == -1) {
                        Slog.w(TAG, "Invalid packageName: " + packageName);
                        continue;
                    }
                    try {
                        pm.setPackageStoppedState(packageName, true, user);
                    } catch (RemoteException e) {
                    } catch (IllegalArgumentException e) {
                        Slog.w(TAG, "Failed trying to unstop package "
                                + packageName + ": " + e);
                    }

                    /// M: [process suppression] @{
                    if ("1".equals(SystemProperties.get("persist.runningbooster.support")) ||
                            "1".equals(SystemProperties.get("ro.mtk_aws_support"))) {
                        AMEventHookData.PackageStoppedStatusChanged eventData =
                                AMEventHookData.PackageStoppedStatusChanged.createInstance();
                        eventData.set(packageName, SUPPRESS_ACTION_STOP, "forceStopPackage");
                        mAMEventHook.hook(AMEventHook.Event.AM_PackageStoppedStatusChanged,
                                eventData);
                    }
                    /// M: [process suppression] @}

                    if (mUserController.isUserRunningLocked(user, 0)) {
                        forceStopPackageLocked(packageName, pkgUid, "from pid " + callingPid);
                        finishForceStopPackageLocked(packageName, pkgUid);
                    }
                }
            }
        } finally {
            Binder.restoreCallingIdentity(callingId);
        }
    }

在设置中对音乐点击强制停止,如果想让音乐继续后台播放,可以在ActivityManagerService.java中对代码进行控制,判断packageName是否为音乐,如果是音乐,直接返回即可。到时产生的效果是,点击强制停止,会没有响应,达到了想要的效果。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值