I think it was already done. from what I see, it already uses what is 
explained in 
http://developer.android.com/guide/components/bound-services.html 

please see sources below (can ignore the prints and debugging stuff...)

thanks!

package com.example.remoteservice;

import android.app.Service;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.widget.Toast;
import android.os.Messenger;

public class RemoteService extends Service {
    
    //
    //Messenger
    //
    
    
    final Messenger myMessenger = new Messenger(new IncomingHandler());
    
    
    private void printUidAndProcessInfo() {
        PackageManager pm = getPackageManager();
        ApplicationInfo ai;
        try {
            ai = pm.getApplicationInfo("com.example.remoteservice", 
PackageManager.GET_META_DATA);
            System.out.println("-------------");
            System.out.println("RemoteService info: ai.uid: " + ai.uid + " 
" + android.os.Process.myPid() + " ai.processName: " + ai.processName);
            String permission = "android.permission.INTERNET";
            System.out.println("check self - service - permission:" + 
checkPermission(permission, android.os.Process.myPid(), ai.uid));
            System.out.println("-------------");
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }    
    
    
    @Override
    public IBinder onBind(Intent intent) {
        printUidAndProcessInfo();
        isCallingClientHasPermissions();
        return myMessenger.getBinder();
    }
    
    
    //
    //Handler
    // 

    class IncomingHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            printUidAndProcessInfo();
            Bundle data = msg.getData();            
            String dataString = data.getString("MyString");
            dataString += isCallingClientHasPermissions()? "\nAuthorized" : 
"\nNot authorized";
            Toast.makeText(getApplicationContext(), dataString, 
Toast.LENGTH_LONG).show();
        }
     }
    
    
    private boolean isCallingClientHasPermissions(){
        
System.out.println("+RemoteService.isCallingClientHasPermissions------------");
        int pid = Binder.getCallingPid();
        int uid = Binder.getCallingUid();
        System.out.println("caller pid:" + pid + ", uid:" + uid);
        int ret = checkPermission("android.permission.INTERNET", pid, uid);
        boolean authorized = ret == PackageManager.PERMISSION_GRANTED;
        System.out.println("ret=" + ret + " authorized=" + authorized);
        
System.out.println("-RemoteService.isCallingClientHasPermissions------------");
        return authorized;
    }
    

}


package com.example.remoteclient;


import com.example.remoteclient.R;

import android.os.Bundle;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.view.Menu;
import android.view.View;

public class RemoteClient extends Activity {

    Messenger myService = null;
    boolean isBound;
    TEEAdminRA admin;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_remote_bound);
        
          Intent intent = new 
Intent("com.example.remoteservice.RemoteService");
          bindService(intent, myConnection, Context.BIND_AUTO_CREATE);
    }



    //
    //Service binding
    //
    
    
    private ServiceConnection myConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, 
                                                IBinder service) {
            myService = new Messenger(service);
            isBound = true;
        }

        public void onServiceDisconnected(ComponentName className) {
            myService = null;
            isBound = false;
        }
    };    
    
    public void sendMessage(View view)
    {
          if (!isBound) return;
              showUidAndProcessInfo();
            
            Message msg = Message.obtain();
            
            Bundle bundle = new Bundle();
            bundle.putString("MyString", "Message from RemoteClient");
            
            msg.setData(bundle);
            
            try {
                myService.send(msg);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
            
    }    
    
    private void showUidAndProcessInfo() {
        PackageManager pm = getPackageManager();
        ApplicationInfo ai;
        try {
            ai = pm.getApplicationInfo("com.example.remoteclient", 
PackageManager.GET_META_DATA);
            System.out.println("---------");
            System.out.println("RemoteClient info:");
            System.out.println(ai.processName + ", " + 
android.os.Process.myPid() + ", ai.uid: " + ai.uid);
            System.out.println("check self - client - permission:" + 
checkPermission("android.permission.INTERNET", android.os.Process.myPid(), 
ai.uid));
            System.out.println("---------");
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }        
}



On Thursday, March 6, 2014 7:19:16 AM UTC+2, Nikolay Elenkov wrote:
>
> On Thu, Mar 6, 2014 at 2:08 PM, smoogli <[email protected] <javascript:>> 
> wrote: 
> > 
> > (I can only assume there is some configuration that needs to be set, or 
> > something that I am missing here) 
> > 
>
> You need a bound service for this to work and you will only get the UID of 
> the activity on binder calls. 
>
> http://developer.android.com/guide/components/bound-services.html 
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to