本文整理匯總了Java中android.os.ParcelFileDescriptor.getFd方法的典型用法代碼示例。如果您正苦於以下問題:Java ParcelFileDescriptor.getFd方法的具體用法?Java ParcelFileDescriptor.getFd怎麽用?Java ParcelFileDescriptor.getFd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.ParcelFileDescriptor
的用法示例。
在下文中一共展示了ParcelFileDescriptor.getFd方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendTunFD
import android.os.ParcelFileDescriptor; //導入方法依賴的package包/類
private boolean sendTunFD(String needed, String extra) {
if (!extra.equals("tun")) {
// We only support tun
VpnStatus.logError(String.format("Device type %s requested, but only tun is possible with the Android API, sorry!", extra));
return false;
}
ParcelFileDescriptor pfd = mOpenVPNService.openTun();
if (pfd == null) return false;
Method setInt;
int fdint = pfd.getFd();
try {
setInt = FileDescriptor.class.getDeclaredMethod("setInt$", int.class);
FileDescriptor fdtosend = new FileDescriptor();
setInt.invoke(fdtosend, fdint);
FileDescriptor[] fds = {fdtosend};
mSocket.setFileDescriptorsForSend(fds);
// Trigger a send so we can close the fd on our side of the channel
// The API documentation fails to mention that it will not reset the file descriptor to
// be send and will happily send the file descriptor on every write ...
String cmd = String.format("needok '%s' %s\n", needed, "ok");
managmentCommand(cmd);
// Set the FileDescriptor to null to stop this mad behavior
mSocket.setFileDescriptorsForSend(null);
pfd.close();
return true;
} catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException |
IOException | IllegalAccessException exp) {
VpnStatus.logException("Could not send fd over socket", exp);
}
return false;
}