java.lang.SecurityException异常:不允许停止服务意图是什么? [英] java.lang.SecurityException: Not allowed to stop service Intent?

查看:3016
本文介绍了java.lang.SecurityException异常:不允许停止服务意图是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要杀掉由ActivityManager.RunningServiceInfo另一个应用程序的服务器在第三应用程序。
例如,一些应用的服务我想永葆,其他服务(不适合服务START_STICK)会被杀死。
这里是我的code:

I want kill another app's server by ActivityManager.RunningServiceInfo in third app. eg,some app's service I want keep alive,else service(NOT fit for Service START_STICK) will be killed. here is my code:

 ActivityManager actManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);

            List killapplist = actManager.getRunningAppProcesses();

            List killservicelist = actManager.getRunningServices(100);

            for (Object aKillapplist : killapplist) {

                ActivityManager.RunningAppProcessInfo localRunningAppProcessInfo = (ActivityManager.RunningAppProcessInfo)
                        aKillapplist;

                String appname = localRunningAppProcessInfo.processName;

                if (localRunningAppProcessInfo.pkgList != null) {

                    for (Object aKillservicelist : killservicelist) {
                        ActivityManager.RunningServiceInfo localRunningServiceInfo = (ActivityManager.RunningServiceInfo) aKillservicelist;
  //some condition start
                        try {
                            Intent intentstop = new Intent();

                            intentstop.setComponent(localRunningServiceInfo.service);
                            mContext.stopService(intentstop);
                        } catch (SecurityException e) {
                            e.printStackTrace();

                        }
 //some condition end
                    }

                }

            }

        } else {
            throw new MyException("kill list is empty");
        }

然后总是提醒味精

then always get warn msg

WARN/ActivityManager(363): Permission Denial: Accessing service ComponentInfo
WARN/System.err(5992): java.lang.SecurityException: Not allowed to stop service Intent 

是SYS签名的问题?
我使用了一些权限

is the problem of sys signature ? I used some permission

uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"
uses-permission android:name="android.permission.SHUTDOWN"
uses-permission android:name="android.permission.FORCE_STOP_PACKAGES"

如何解决呢?
谢谢

how to fix it? thanks

推荐答案

您无法使用权​​限android.permission.SHUTDOWN android.permission.FORCE_STOP_PACKAGES,除非你的包与系统证书签名。具有权限android.permission.KILL_BACKGROUND_PROCESSES将允许你只杀死你的进程。

You cannot use the permissions "android.permission.SHUTDOWN" and "android.permission.FORCE_STOP_PACKAGES" unless your package is signed with system certificate. Having the permission "android.permission.KILL_BACKGROUND_PROCESSES" will allow you to kill only your processes.

这篇关于java.lang.SecurityException异常:不允许停止服务意图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆