鸿蒙OS开发文档 鸿蒙OS IPCSkeleton

2024-02-25 开发教程 鸿蒙OS开发文档 匿名 3

IPCSkeleton

java.lang.Object
|---ohos.rpc.IPCSkeleton

public class IPCSkeleton
extends Object

在IPC骨架中提供静态接口,用于获取服务、读写对象、获取UID和PID、获取本地和对端设备的ID、检查是否在同一设备上进行了接口调用。

构造函数摘要

构造函数描述
IPCSkeleton()

方法总结

修饰符和类型方法描述
static intflushCommands(IRemoteObject object)将所有挂起的命令从指定的 RemoteProxy 刷新到相应的 RemoteObject。
static StringgetCallingDeviceID()获取对端进程所在设备的ID。
static intgetCallingPid()获取代理的PID。
static intgetCallingUid()获取代理的 UID。
static IRemoteObjectgetContextObject()获取已注册服务的本地 IRemoteObject 引用。
static StringgetLocalDeviceID()获取本地设备的ID。
static booleanisLocalCalling()检查是否在同一设备上进行了呼叫。
static StringresetCallingIdentity()将远程用户的 UID 和 PID 替换为本地用户的 UID 和 PID。
static booleansetCallingIdentity(String identity)将 UID 和 PID 恢复为远程用户的 UID 和 PID。
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

构造函数详细信息

IPCSkeleton

public IPCSkeleton()

方法详情

getContextObject

public static IRemoteObject getContextObject()

获取已注册服务的本地 IRemoteObject 引用。

此方法是静态的。

返回:

返回已注册服务的 IRemoteObject 引用。

getCallingPid

public static int getCallingPid()

获取代理的PID。

此方法是静态的。 RemoteProxy对象与RemoteObject对象通信时PID为正整数,通信结束后恢复为0。 如果从 RemoteProxy 对象调用该方法,则返回 0; 如果从 RemoteObject 对象调用该方法,则返回对应的 RemoteProxy 对象的 PID。

返回:

返回代理的 PID。

getCallingUid

public static int getCallingUid()

获取代理的 UID。

此方法是静态的。 RemoteProxy对象与RemoteObject对象通信时UID为正整数,通信结束后恢复为0。 如果从 RemoteProxy 对象调用该方法,则返回 0; 如果从 RemoteObject 对象调用该方法,则返回对应的 RemoteProxy 对象的 UID。

返回:

返回代理的 UID。

getCallingDeviceID

public static String getCallingDeviceID()

获取对端进程所在设备的ID。

此方法是静态的。

返回:

返回对等进程所在设备的ID。

getLocalDeviceID

public static String getLocalDeviceID()

获取本地设备的ID。

此方法是静态的。

返回:

返回本地设备的 ID。

isLocalCalling

public static boolean isLocalCalling()

检查是否在同一设备上进行了呼叫。

此方法是静态的。

返回:

如果在同一设备上进行调用,则返回 true; 否则返回 false。

flushCommands

public static int flushCommands(IRemoteObject object)

将所有挂起的命令从指定的 RemoteProxy 刷新到相应的 RemoteObject。

此方法是静态的。 建议您在执行任何对时间敏感的操作之前调用该方法。

参数:

参数名称参数描述
object表示指定的 RemoteProxy。

返回:

如果操作成功,则返回 0; 如果输入对象为空或RemoteObject,或操作失败,则返回错误代码。

resetCallingIdentity

public static String resetCallingIdentity()

将远程用户的 UID 和 PID 替换为本地用户的 UID 和 PID。

此方法是静态的。 它可以用于身份验证等场景。

返回:

返回包含远程用户的 UID 和 PID 的字符串。

setCallingIdentity

public static boolean setCallingIdentity(String identity)

将 UID 和 PID 恢复为远程用户的 UID 和 PID。

此方法是静态的。 它通常在使用resetCallingIdentity 后调用,需要resetCallingIdentity 返回的远程用户的UID 和PID。

参数:

参数名称参数描述
identity表示远程用户的UID和PID的字符串,resetCallingIdentity返回。

返回:

如果操作成功,则返回 true; 否则返回 false。