Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49ca529a authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Avoid caching services with missing binders.

When fetching system services early during boot, if the underlying
binder interface hasn't been published yet, we end up caching a
manager class that is broken for the remainder of the process
lifetime, and innocent downstream callers end up using the broken
cached manager.

Fix this by using an explicit exception to quickly abort manager
creation when the underlying binder is missing.  The exception is
only used to skip the remainder of the manager creation, and it
doesn't actually crash the process.

Bug: 28634953
Change-Id: I0cb62261e6d6833660704b93a11185aa11a2ac97
parent fc00de50
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.os.Looper;
import android.os.Parcelable;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.StrictMode;
import android.os.SystemProperties;
import android.os.UserHandle;
@@ -5591,7 +5592,11 @@ public class Activity extends ContextThemeWrapper
            return;
        }

        try {
            mSearchManager = new SearchManager(this, null);
        } catch (ServiceNotFoundException e) {
            throw new IllegalStateException(e);
        }
    }

    @Override
+4 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.os.RemoteException;
import android.os.IBinder;
import android.os.IUserManager;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.UserHandle;
import android.os.UserManager;
import android.view.IWindowManager;
@@ -192,12 +193,12 @@ public class KeyguardManager {
    }


    KeyguardManager() {
    KeyguardManager() throws ServiceNotFoundException {
        mWM = WindowManagerGlobal.getWindowManagerService();
        mTrustManager = ITrustManager.Stub.asInterface(
                ServiceManager.getService(Context.TRUST_SERVICE));
                ServiceManager.getServiceOrThrow(Context.TRUST_SERVICE));
        mUserManager = IUserManager.Stub.asInterface(
                ServiceManager.getService(Context.USER_SERVICE));
                ServiceManager.getServiceOrThrow(Context.USER_SERVICE));
    }

    /**
+5 −4
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
@@ -536,7 +537,7 @@ public class SearchManager
    /**
     * Reference to the shared system search service.
     */
    private static ISearchManager mService;
    private final ISearchManager mService;

    private final Context mContext;

@@ -547,11 +548,11 @@ public class SearchManager

    private SearchDialog mSearchDialog;

    /*package*/ SearchManager(Context context, Handler handler)  {
    /*package*/ SearchManager(Context context, Handler handler) throws ServiceNotFoundException {
        mContext = context;
        mHandler = handler;
        mService = ISearchManager.Stub.asInterface(
                ServiceManager.getService(Context.SEARCH_SERVICE));
                ServiceManager.getServiceOrThrow(Context.SEARCH_SERVICE));
    }

    /**
@@ -620,7 +621,7 @@ public class SearchManager
            return;
        }

        UiModeManager uiModeManager = new UiModeManager();
        final UiModeManager uiModeManager = mContext.getSystemService(UiModeManager.class);
        // Don't show search dialog on televisions.
        if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_TELEVISION) {
            ensureSearchDialog();
+130 −119

File changed.

Preview size limit exceeded, changes collapsed.

+3 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.res.Configuration;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.util.Log;

import java.lang.annotation.Retention;
@@ -123,9 +124,9 @@ public class UiModeManager {

    private IUiModeManager mService;

    /*package*/ UiModeManager() {
    /*package*/ UiModeManager() throws ServiceNotFoundException {
        mService = IUiModeManager.Stub.asInterface(
                ServiceManager.getService(Context.UI_MODE_SERVICE));
                ServiceManager.getServiceOrThrow(Context.UI_MODE_SERVICE));
    }

    /**
Loading