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 <uses-
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()");
}
}
------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kilic.service"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/
app_name">
<service android:name=".AdditionService"
android:permission="com.kilic.service.permission.MY_FIRST_SERVICE"
android:process=":remote"
android:enabled="true"
android:exported="true">
<intent-filter>
<action
android:name="com.kilic.service.IAdditionService" />
</intent-filter>
</service>
</application>
<uses-sdk android:minSdkVersion="4" />
<uses-permission
android:name="com.kilic.service.permission.MY_FIRST_SERVICE"></uses-
permission>
</manifest>
===============================================
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.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.kilic.service.IAdditionService;
public class AIDLDemo extends Activity {
private static final String TAG = "AIDLDemo";
private IAdditionService service= null;
//private AdditionServiceConnection connection;
/**
* This class represents the actual service connection. It casts the
bound
* stub implementation of the service to the AIDL interface.
*/
private ServiceConnection svcConn = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder
boundService) {
service = IAdditionService.Stub.asInterface(boundService);
Log.d(AIDLDemo.TAG, "onServiceConnected() connected");
Toast.makeText(AIDLDemo.this, "Service connected",
Toast.LENGTH_LONG)
.show();
}
public void onServiceDisconnected(ComponentName name) {
service = null;
Log.d(AIDLDemo.TAG, "onServiceDisconnected() disconnected");
Toast.makeText(AIDLDemo.this, "Service connected",
Toast.LENGTH_LONG)
.show();
}
};
/** Unbinds this activity from the service. */
private void releaseService() {
unbindService(svcConn);
svcConn = null;
Log.d(TAG, "releaseService() unbound.");
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Setup the UI
Button buttonCalc = (Button) findViewById(R.id.buttonCalc);
buttonCalc.setOnClickListener(new OnClickListener() {
TextView result = (TextView) findViewById(R.id.result);
EditText value1 = (EditText) findViewById(R.id.value1);
EditText value2 = (EditText) findViewById(R.id.value2);
public void onClick(View v) {
int v1, v2, res = -1;
v1 = Integer.parseInt(value1.getText().toString());
v2 = Integer.parseInt(value2.getText().toString());
try {
res = service.add(v1, v2);
} catch (RemoteException e) {
Log.d(AIDLDemo.TAG, "onClick failed with: " + e);
e.printStackTrace();
}
result.setText(new Integer(res).toString());
}
});
/** Binds this activity to the service. */
try {
boolean ret = bindService(new
Intent(IAdditionService.class.getName()), svcConn,
Context.BIND_AUTO_CREATE);
}
catch (SecurityException se) {
System.out.println(se.getMessage());
}
}
/** Called when the activity is about to be destroyed. */
@Override
protected void onDestroy() {
super.onDestroy();
releaseService();
}
}
-----------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kilic.service.client"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/
app_name">
<activity android:name=".AIDLDemo"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="5" />
<uses-permission
android:name="com.kilic.service.permission.MY_FIRST_SERVICE"></uses-
permission>
</manifest>
================================================================================
I would appreciate any help.
Thanks,
- Kilic
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en