Example usage for android.os Binder getCallingPid

List of usage examples for android.os Binder getCallingPid

Introduction

In this page you can find the example usage for android.os Binder getCallingPid.

Prototype

public static final native int getCallingPid();

Source Link

Document

Return the ID of the process that sent you the current transaction that is being processed.

Usage

From source file:Main.java

public static boolean check(Context context, String... premissions) {
    try {//from  w  w  w.j ava  2 s . com
        if (null == context)
            throw new RuntimeException("Context is null.");
        for (int i = 0; i < premissions.length; i++) {
            Integer check = context.checkPermission(premissions[i], Binder.getCallingPid(),
                    Binder.getCallingUid());
            if (check == -1) {
                return false;
            }
        }
        return true;
    } catch (Exception e) {
        Log.e(TAG, e.getMessage(), e);
        return false;
    }
}

From source file:edu.umich.flowfence.service.Sandbox.java

public static Sandbox getCallingSandbox() {
    Sandbox sb = Sandbox.forPid(Binder.getCallingPid());
    if (sb == null) {
        throw new IllegalStateException("Not calling from a sandbox");
    }// w  w  w . j  a  v a 2s . com

    if (sb.getRunningCallRecord() == null) {
        throw new IllegalStateException("Not currently running a QM in this sandbox");
    }
    return sb;
}

From source file:edu.umich.oasis.service.Sandbox.java

public static Sandbox getCallingSandbox() {
    Sandbox sb = Sandbox.forPid(Binder.getCallingPid());
    if (sb == null) {
        throw new IllegalStateException("Not calling from a sandbox");
    }/*ww w .  j  a  va  2s . c  o m*/

    if (sb.getRunningCallRecord() == null) {
        throw new IllegalStateException("Not currently running a SODA in this sandbox");
    }
    return sb;
}

From source file:edu.umich.flowfence.service.Sandbox.java

public static boolean isCallingFromSandbox() {
    Sandbox sb = Sandbox.forPid(Binder.getCallingPid());
    return (sb != null && sb.getRunningCallRecord() != null);
}

From source file:edu.stanford.mobisocial.dungbeetle.DungBeetleContentProvider.java

private String getCallingActivityId() {
    int pid = Binder.getCallingPid();
    ActivityManager am = (ActivityManager) getContext().getSystemService(Activity.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> lstAppInfo = am.getRunningAppProcesses();

    for (ActivityManager.RunningAppProcessInfo ai : lstAppInfo) {
        if (ai.pid == pid) {
            return ai.processName;
        }//from   w  ww . j ava  2  s  . c  o  m
    }
    return null;
}

From source file:com.android.server.MountService.java

@Override
public StorageVolume[] getVolumeList() {
    final int callingUserId = UserHandle.getCallingUserId();
    final boolean accessAll = (mContext.checkPermission(android.Manifest.permission.ACCESS_ALL_EXTERNAL_STORAGE,
            Binder.getCallingPid(), Binder.getCallingUid()) == PERMISSION_GRANTED);

    synchronized (mVolumesLock) {
        final ArrayList<StorageVolume> filtered = Lists.newArrayList();
        for (StorageVolume volume : mVolumes) {
            final UserHandle owner = volume.getOwner();
            final boolean ownerMatch = owner == null || owner.getIdentifier() == callingUserId;
            if (accessAll || ownerMatch) {
                if (!accessAll && volume.isEmulated()) {
                    filtered.add(0, volume);
                } else {
                    filtered.add(volume);
                }// ww w.j a  va 2 s  . c om
            }
        }
        return filtered.toArray(new StorageVolume[filtered.size()]);
    }
}