MTK 手机重启案例分析

程序员Android

共 3491字,需浏览 7分钟

 ·

2024-07-12 07:40

和你一起终身学习,这里是程序员Android

经典好文推荐,通过阅读本文,您将收获以下知识点:

一、Service not registered 异常导致手机重启
二、Service not registered 解决方案

一、Service not registered 异常导致手机重启

1.重启 的部分Log如下:

Service not registered 重启异常

二、Service not registered 解决方案

从 Log 中分析发现异常信息,并尝试进行如下修改。

1.修改ContextImpl类

文件路径如下:
\frameworks\base\core\java\android\app\ContextImpl.java文件

优化unbindService方法实现如下:

    @Override
public void unbindService(ServiceConnection conn) {
if (conn == null) {
throw new IllegalArgumentException("connection is null");
}
if (mPackageInfo != null) {
IServiceConnection sd = mPackageInfo.forgetServiceDispatcher(
getOuterContext(), conn);
try {
ActivityManager.getService().unbindService(sd);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
// add for Service not registered unbindService() triger reboot exception
} catch (IllegalArgumentException e) {
//com.google.android.gms.ui Service not registered Crash
android.util.Log.e("wjwj","---ContextImpl GMS Crash---");
e.printStackTrace();
}
// add for Service not registered unbindService() triger reboot exception
} else {
throw new RuntimeException("Not supported in system context");
}
}

2.修改 TransportManager 类

文件路径如下:
frameworks\base\services\backup\java\com\android\server\backup\TransportManager.java 将异常捕获,防止重启。

优化unbindService方法实现如下:

    void onPackageRemoved(String packageName) {
// Package removed. Remove all its transports from our list. These transports have already
// been removed from mBoundTransports because onServiceDisconnected would already been
// called on TransportConnection objects.
synchronized (mTransportLock) {
Iterator<Map.Entry<ComponentName, TransportConnection>> iter =
mValidTransports.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<ComponentName, TransportConnection> validTransport = iter.next();
ComponentName componentName = validTransport.getKey();
if (componentName.getPackageName().equals(packageName)) {
TransportConnection transportConnection = validTransport.getValue();
iter.remove();
if (transportConnection != null) {
/* 360OS begin */
/* unbindService() triger reboot exception,
* catch it && add log to find out witch package do it. */

try {
Slog.d(TAG, "onPackageRemoved trace, componentName:"
+ componentName.toString(), new Throwable());
mContext.unbindService(transportConnection);
} catch (IllegalArgumentException e) {
Slog.e(TAG, "unbindService fail.", e);
}
/* 360OS end */
log_verbose("Package removed, removing transport: "
+ componentName.flattenToShortString());
}
}
}
}
}

至此,本篇已结束。转载网络的文章,小编觉得很优秀,欢迎点击阅读原文,支持原创作者,如有侵权,恳请联系小编删除。同时感谢您的阅读,期待您的关注。

浏览 55
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报