Skip to content

Commit

Permalink
消除类型转换警告
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangning17 committed Aug 9, 2021
1 parent 13e54a6 commit 05b6d48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ object SimpleService : ServiceManager {
return true
}

@Suppress("UNCHECKED_CAST")
override fun <T : Any> getService(cls: Class<T>): T? {
return serviceMap[cls] as? T
}
Expand Down Expand Up @@ -191,6 +192,7 @@ object SimpleService : ServiceManager {

}

@Suppress("UNCHECKED_CAST")
private fun <T : Any> getRemoteServiceFromLocal(cls: Class<T>): T? {
val cached = serviceMap[cls]
if (cls.isInstance(cached)) {
Expand Down Expand Up @@ -236,6 +238,7 @@ object SimpleService : ServiceManager {
}
}

@Suppress("UNCHECKED_CAST")
override fun <T : Any, R : IBinder> getServiceRemote(cls: Class<T>, service: T): R {
try {
return RemoteServiceHelper.getServiceRemote(cls, service) as R
Expand All @@ -252,6 +255,7 @@ object SimpleService : ServiceManager {
}
}

@Suppress("UNCHECKED_CAST")
override fun <T : IInterface> getServiceRemoteInterface(proxy: Any): T {
try {
return (proxy as IRemoteServiceProxy).getRemoteInterface() as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ object RemoteServiceHelper {
}
}

@Suppress("UNCHECKED_CAST")
fun <T> getServiceRemoteProxy(cls: Class<T>, service: IBinder): T {
return proxies.getOrPut(service) {
WeakReference(createServiceRemoteProxy(cls, service))
}.get() as T
return (proxies[service]?.get() ?: createServiceRemoteProxy(cls, service).let {
proxies[service] = WeakReference(it)
}) as T
}

fun registerMethodErrorHandler(cls: Class<*>, handler: IMethodErrorHandler) {
Expand Down

0 comments on commit 05b6d48

Please sign in to comment.