Hi KilicBeg,
Have you managed to figure it out? I have the same problem.
My problem simply is adding a custom permission like
android.permission.CAMERA to allow user use some custom
hardware feature. I've added one in platform.xml but failed in
checkCallingPermission(String16(android.permission.MY_PERMISSION))
when client connect to service.
So my question is
1. is it possible to add custom permission in android?
2. how to do it if it is feasible?
BTW, i know that my question may better post into android-post because it
derives from custom hardware,
but i post it here because i do not think this problem is
hardware-independent and hoping for more help.
Cheers,
- rookie
On Tue, Mar 9, 2010 at 6:55 AM, KilicBeg wrote:
> Hi,
>
> I am unable to access my custom service after setting permission.
> 03-08 16:38:15.730: WARN/ActivityManager(53): Permission Denial:
> Accessing service ComponentInfo{com.kilic.service/
> com.kilic.service.AdditionService} from pid=235, uid=10026 requires
> com.kilic.service.permission.MY_FIRST_SERVICE
> 03-08 16:41:53.141: INFO/System.out(314): Not allowed to bind to
> service Intent { act=com.kilic.service.IAdditionService }
>
> If I remove the permission everything works fine. Is there anything
> special I need to do in the client manifest other than permission> ?
>
> Here is my code snippet for the service:
>
> package com.kilic.service;
>
> import android.app.Service;
> import android.content.Intent;
> import android.content.pm.PackageManager;
> import android.os.IBinder;
> import android.util.Log;
>
> /**
> * This class exposes the remote service to the client
> */
> public class AdditionService extends Service {
> private static final String TAG = "AdditionService";
>
>
> private final IAdditionService.Stub binder=new
> IAdditionService.Stub() {
>public int add(int value1, int value2) {
> Log.d(TAG, String.format("AdditionService.add(%d,
> %d)",value1, value2));
>return toppla(value1, value2);
>}
> };
>
> @Override
> public void onCreate() {
>super.onCreate();
>Log.d(TAG, "onCreate()");
> }
>
> @Override
> public IBinder onBind(Intent intent)
> {
> //if(intent.getAction() != null &&
> intent.getAction().equals(ACTION_SERVICE_MANAGEMENT)) {
> // check permission
> System.out.println("intent.getAction() = " + intent.getAction());
>
>
> if(this.checkCallingPermission("com.kilic.service.permission.MY_FIRST_SERVICE")
> == PackageManager.PERMISSION_DENIED) {
> // Log.d(TAG, "Checked for permission:
> " + PERMISSION_MANAGEMENT
> + "\nresult: " + checkCallingPermission(PERMISSION_MANAGEMENT));
> Log.d(TAG, "Checked for
> permission: \nresult: " +
> checkCallingPermission("com.kilic.service.permission.MY_FIRST_SERVICE"));
> throw new SecurityException();
>}
> // return management binder
>//return (binder);
> //}
>
> Log.d(TAG, "onBind finished");
> // call was not local so return public binder
> return (binder);
> }
>
> /*
> @Override
> public IBinder onBind(Intent intent) {
>
>return (binder);
>
> } */
>
> /**
> * Implementation of the add() method
> */
> private int toppla(int value1, int value2) {
> Log.d(TAG, String.format("AdditionService.toppla(%d,
> %d)",value1, value2));
> return value1 + value2;
> }
>
>
> @Override
> public void onDestroy() {
>super.onDestroy();
>Log.d(TAG, "onDestroy()");
> }
> }
>
> --
>
> http://schemas.android.com/apk/res/android";
> package="com.kilic.service"
> android:versionCode="1"
> android:versionName="1.0">
>
>
> android:permission="com.kilic.service.permission.MY_FIRST_SERVICE"
> android:process=":remote"
> android:enabled="true"
> android:exported="true">
>
>
> android:name="com.kilic.service.IAdditionService" />
>
>
>
>
> android:name="com.kilic.service.permission.MY_FIRST_SERVICE"> permission>
>
>
>
> ===
> And this is the client code:
>
> package com.kilic.service.client;
>
> import com.kilic.service.client.R;
> import android.app.Activity;
> import android.content.ComponentName;
> import android.content.Context;
> import android.content.Intent;
> import android.content.ServiceConnection;
> import android.os.Bundle;
> import android.os.IBinder;
> import android.os.RemoteException;
> import android.util.Log;
> import android.view.View;
> import android.view.View.OnClickListener;
> import android.widget.Button;
> import android.