Example usage for android.net Credentials getUid

List of usage examples for android.net Credentials getUid

Introduction

In this page you can find the example usage for android.net Credentials getUid.

Prototype

public int getUid() 

Source Link

Usage

From source file:com.facebook.stetho.server.SecureHttpRequestHandler.java

private static void enforcePermission(Context context, LocalSocket peer)
        throws IOException, PeerAuthorizationException {
    Credentials credentials = peer.getPeerCredentials();

    int uid = credentials.getUid();
    int pid = credentials.getPid();

    if (LogUtil.isLoggable(Log.VERBOSE)) {
        LogUtil.v("Got request from uid=%d, pid=%d", uid, pid);
    }/*from   ww  w  .  j  a  va2s . co m*/

    String requiredPermission = Manifest.permission.DUMP;
    int checkResult = context.checkPermission(requiredPermission, pid, uid);
    if (checkResult != PackageManager.PERMISSION_GRANTED) {
        throw new PeerAuthorizationException(
                "Peer pid=" + pid + ", uid=" + uid + " does not have " + requiredPermission);
    }
}