1 package com.xtremelabs.robolectric.shadows; 2 3 import android.os.Binder; 4 import android.os.Parcel; 5 import android.os.RemoteException; 6 import android.os.ShadowBinderBridge; 7 8 import com.xtremelabs.robolectric.internal.Implementation; 9 import com.xtremelabs.robolectric.internal.Implements; 10 import com.xtremelabs.robolectric.internal.RealObject; 11 12 @Implements(android.os.Binder.class) 13 public class ShadowBinder { 14 @RealObject 15 Binder realObject; 16 17 private static Integer callingUid; 18 private static Integer callingPid; 19 20 @Implementation transact(int code, Parcel data, Parcel reply, int flags)21 public boolean transact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { 22 return new ShadowBinderBridge(realObject).onTransact(code, data, reply, flags); 23 } 24 25 @Implementation getCallingPid()26 public static final int getCallingPid() { 27 if (callingPid != null) { 28 return callingPid; 29 } 30 return android.os.Process.myPid(); 31 } 32 33 @Implementation getCallingUid()34 public static final int getCallingUid() { 35 if (callingUid != null) { 36 return callingUid; 37 } 38 return android.os.Process.myUid(); 39 } 40 setCallingPid(int pid)41 public static void setCallingPid(int pid) { 42 ShadowBinder.callingPid = pid; 43 } 44 setCallingUid(int uid)45 public static void setCallingUid(int uid) { 46 ShadowBinder.callingUid = uid; 47 } 48 reset()49 public static void reset() { 50 ShadowBinder.callingPid = null; 51 ShadowBinder.callingUid = null; 52 } 53 } 54