H. Zhiliang
H. Zhiliang

Reputation: 61

Android/ServiceManager.addService() java.lang.SecurityException

I hava created system app. It has one aidl file and Service. I have implemented the aidl interface and addService in service method onStartCommand().

mBinder = getBDBinder();
    try {
        ServiceManager.addService("test", mBinder);
        BDLog.r(TAG, "create and add");
    } catch (SecurityException e) {
        BDLog.e(TAG, "Add service SecurityException");
    }

The SecurityException has happend.What can I do? I tried two methods to solove this problem, but it had no effect.

  1. setenforce 0
  2. add my service in service_context file

Here is my manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxx.xxx.xxxx"
    android:sharedUserId="android.uid.system"
    android:versionCode="1200000"
    android:versionName="1.2.0" >

    <uses-feature android:name="android.hardware.type.watch" />

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="23" />

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
    <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowClearUserData="false"
        android:name=".xx"
        android:allowBackup="false"
        android:label="xx">

    </application>
</manifest>

Upvotes: 5

Views: 2425

Answers (1)

H. Zhiliang
H. Zhiliang

Reputation: 61

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxx.xxx.xxxx"
    android:sharedUserId="android.uid.system"
    android:versionCode="1200000"
    android:versionName="1.2.0" >

    <uses-feature android:name="android.hardware.type.watch" />

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="23" />

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
    <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowClearUserData="false"
        android:name=".xx"
        android:allowBackup="false"
        android:label="xx">

    </application>
</manifest>

Upvotes: 1

Related Questions