java.lang.securityexception:,java.lang.SecurityException异常:不允许停止服务意图是什么?...

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

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

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值