Example usage for android.net LocalSocket getPeerCredentials

List of usage examples for android.net LocalSocket getPeerCredentials

Introduction

In this page you can find the example usage for android.net LocalSocket getPeerCredentials.

Prototype

public Credentials getPeerCredentials() throws IOException 

Source Link

Document

Retrieves the credentials of this socket's peer.

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  www . j av  a  2 s.  c  o  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);
    }
}