Android下新增JNI过程中addService遇安全错误问题


    今天新增一个JNI的时候遇到一个调用用addService的时候发生异常的问题:
首先是在SystemService.java添加一个自己定义的binder service,代码如下:

try {      Slog.i(TAG, "Xxx Service");      ServiceManager.addService("xxx", new XxxService());  } catch (Throwable e) {      reportWtf("starting Xxx Service", e);}

结果发现执行到这的时候发生异常: SystemServer: BOOT FAILURE starting Xxx Service。

查看系统log发现:
…………
01-03 02:26:15.040  3907  3907 I SystemServiceManager: Starting com.android.server.midi.MidiService$Lifecycle
01-03 02:26:15.054  3907  3907 I SystemServiceManager: Starting com.android.server.usb.UsbService$Lifecycle
01-03 02:26:15.171  3907  3907 I SystemServiceManager: Starting com.android.server.twilight.TwilightService
01-03 02:26:15.201  3907  3907 I SystemServiceManager: Starting com.android.server.job.JobSchedulerService
01-03 02:26:15.249  3907  3907 I SystemServiceManager: Starting com.android.server.backup.BackupManagerService$Lifecycle
01-03 02:26:15.327  3907  3907 I SystemServiceManager: Starting com.android.server.appwidget.AppWidgetService
01-03 02:26:15.422  3907  3907 I SystemServiceManager: Starting com.android.server.GestureLauncherService
01-03 02:26:15.433   261   261 E ServiceManager: add_service('xxx',54) uid=1000 - PERMISSION DENIED
01-03 02:26:15.436  3907  3907 E SystemServer:     at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:150)
01-03 02:26:15.436  3907  3907 E SystemServer:     at android.os.ServiceManager.addService(ServiceManager.java:72)
01-03 02:26:15.485  3907  3907 I SystemServiceManager: Starting com.android.server.dreams.DreamManagerService
01-03 02:26:15.504  3907  3907 I SystemServiceManager: Starting com.android.server.print.PrintManagerService
01-03 02:26:15.517  3907  3907 I SystemServiceManager: Starting com.android.server.restrictions.RestrictionsManagerService
01-03 02:26:15.523  3907  3907 I SystemServiceManager: Starting com.android.server.media.MediaSessionService
01-03 02:26:15.558  3907  3907 I SystemServiceManager: Starting com.android.server.trust.TrustManagerService
01-03 02:26:15.581  3907  3907 I SystemServiceManager: Starting com.android.server.fingerprint.FingerprintService
01-03 02:26:15.624  3907  3907 I SystemServiceManager: Starting com.android.server.pm.LauncherAppsService
01-03 02:26:15.632  3907  3907 I SystemServiceManager: Starting com.android.server.media.projection.MediaProjectionManagerService
01-03 02:26:15.687  3907  3907 I SystemServiceManager: Starting com.android.server.MmsServiceBroker
………………

解决方案:
1. 在/external/sepolicy/service.te中仿写添加:
type xxx_service, system_api_service, system_server_service, service_manager_type;
2. 在 /external/sepolicy/service_contexts下仿写添加:
xxx                               u:object_r:xxx_service:s0
   
    添加完成编译,问题便可解决。




更多相关文章

  1. android修改或添加SettingsProvider的默认值
  2. android实现图片加水印
  3. RecyclerView
  4. Android(安卓)使用OPENCV实现图像实时对比
  5. AndroidN新增物理按键[android7.1.2][msm8953]
  6. Android7.0添加快捷方式(Shortcut)到手机桌面
  7. android String.xlm中使用emoji表情的方法
  8. Android(安卓)Action Bar学习(一)--基本介绍及使用
  9. 软件开发文档(以太网)

随机推荐

  1. windows vista 下安装 Android(安卓)USB
  2. Android(安卓)shap Animation
  3. Android-Handler使用
  4. 安卓开源框架集合
  5. 安卓布局应用学习代码附带效果图
  6. WebRTC-M68-官方编译文档-Android'
  7. Understanding Android(安卓)Custom Attr
  8. 使用TypefaceSpan
  9. Android(安卓)Volley
  10. 24 Android(安卓)自定义对话框