SWT restart case studies (five)

Highly recommended article: Welcome Favorite
Android Dry Share

Reading five minutes, ten o'clock daily, lifelong learning with you, here is the Android programmer

This article describes the Androidpart of the development of knowledge by reading this article, you will reap the following:

A, Service not registered abnormalities cause the phone to restart
two, Service not registered Solution
2.1 modify ContextImpl class
2.2 modify TransportManager class

A, Service not registered abnormalities cause the phone to reboot

Restarting section Logis as follows:
Service not registered abnormal restart

Two, Service not registered Solutions

From Logthe analysis found abnormal information, and try to make the following changes.

1. Modify class ContextImpl

File path:
\frameworks\base\core\java\android\app\ContextImpl.javafile

Optimization unbindServicemethod implementation is as follows:

    @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. Modify the class TransportManager

File path is as follows:
frameworks\base\services\backup\java\com\android\server\backup\TransportManager.javaThe exception caught prevent restart.

Optimization unbindServicemethod implementation is as follows:

    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());
                    }
                }
            }
        }
    }

So far herein, this has ended, if the wrong place, welcome your suggestions and corrections. At the same time look forward to your attention, thank you for reading, thank you!

Micro-channel public concern number: Programmer Android, receive welfare

Guess you like

Origin www.cnblogs.com/wangjie1990/p/11326944.html