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

Commit fbf7614d authored by Chalard Jean's avatar Chalard Jean Committed by Automerger Merge Worker
Browse files

Merge "Remove the static application context fetcher" am: 35cbd1d5 am:...

Merge "Remove the static application context fetcher" am: 35cbd1d5 am: ac2bc495 am: 4afb2fa8 am: 9bdb1308 am: 62f13c3f

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1870453

Change-Id: Ic58d0d022593350a010c9fae9ab1a41a26dc3917
parents dbe9f5ae 62f13c3f
Loading
Loading
Loading
Loading
+0 −33
Original line number Diff line number Diff line
@@ -1925,39 +1925,6 @@ public final class SystemServiceRegistry {
        public abstract T createService() throws ServiceNotFoundException;
    }

    /**
     * Like StaticServiceFetcher, creates only one instance of the service per application, but when
     * creating the service for the first time, passes it the application context of the creating
     * application.
     *
     * TODO: Delete this once its only user (ConnectivityManager) is known to work well in the
     * case where multiple application components each have their own ConnectivityManager object.
     */
    static abstract class StaticApplicationContextServiceFetcher<T> implements ServiceFetcher<T> {
        private T mCachedInstance;

        @Override
        public final T getService(ContextImpl ctx) {
            synchronized (StaticApplicationContextServiceFetcher.this) {
                if (mCachedInstance == null) {
                    Context appContext = ctx.getApplicationContext();
                    // If the application context is null, we're either in the system process or
                    // it's the application context very early in app initialization. In both these
                    // cases, the passed-in ContextImpl will not be freed, so it's safe to pass it
                    // to the service. http://b/27532714 .
                    try {
                        mCachedInstance = createService(appContext != null ? appContext : ctx);
                    } catch (ServiceNotFoundException e) {
                        onServiceNotFound(e);
                    }
                }
                return mCachedInstance;
            }
        }

        public abstract T createService(Context applicationContext) throws ServiceNotFoundException;
    }

    /** @hide */
    public static void onServiceNotFound(ServiceNotFoundException e) {
        // We're mostly interested in tracking down long-lived core system