Loading core/java/android/app/SystemServiceRegistry.java +7 −8 Original line number Original line Diff line number Diff line Loading @@ -226,7 +226,7 @@ final class SystemServiceRegistry { SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE); SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE); registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class, registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class, new StaticOuterContextServiceFetcher<ConnectivityManager>() { new StaticApplicationContextServiceFetcher<ConnectivityManager>() { @Override @Override public ConnectivityManager createService(Context context) { public ConnectivityManager createService(Context context) { IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); Loading Loading @@ -840,22 +840,21 @@ final class SystemServiceRegistry { } } /** /** * Like StaticServiceFetcher, creates only one instance of the service per process, but when * Like StaticServiceFetcher, creates only one instance of the service per application, but when * creating the service for the first time, passes it the outer context of the creating * creating the service for the first time, passes it the application context of the creating * component. * application. * * * TODO: Is this safe in the case where multiple applications share the same process? * TODO: Delete this once its only user (ConnectivityManager) is known to work well in the * 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. * case where multiple application components each have their own ConnectivityManager object. */ */ static abstract class StaticOuterContextServiceFetcher<T> implements ServiceFetcher<T> { static abstract class StaticApplicationContextServiceFetcher<T> implements ServiceFetcher<T> { private T mCachedInstance; private T mCachedInstance; @Override @Override public final T getService(ContextImpl ctx) { public final T getService(ContextImpl ctx) { synchronized (StaticOuterContextServiceFetcher.this) { synchronized (StaticApplicationContextServiceFetcher.this) { if (mCachedInstance == null) { if (mCachedInstance == null) { mCachedInstance = createService(ctx.getOuterContext()); mCachedInstance = createService(ctx.getApplicationContext()); } } return mCachedInstance; return mCachedInstance; } } Loading Loading
core/java/android/app/SystemServiceRegistry.java +7 −8 Original line number Original line Diff line number Diff line Loading @@ -226,7 +226,7 @@ final class SystemServiceRegistry { SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE); SYSTEM_SERVICE_NAMES.put(android.text.ClipboardManager.class, Context.CLIPBOARD_SERVICE); registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class, registerService(Context.CONNECTIVITY_SERVICE, ConnectivityManager.class, new StaticOuterContextServiceFetcher<ConnectivityManager>() { new StaticApplicationContextServiceFetcher<ConnectivityManager>() { @Override @Override public ConnectivityManager createService(Context context) { public ConnectivityManager createService(Context context) { IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE); Loading Loading @@ -840,22 +840,21 @@ final class SystemServiceRegistry { } } /** /** * Like StaticServiceFetcher, creates only one instance of the service per process, but when * Like StaticServiceFetcher, creates only one instance of the service per application, but when * creating the service for the first time, passes it the outer context of the creating * creating the service for the first time, passes it the application context of the creating * component. * application. * * * TODO: Is this safe in the case where multiple applications share the same process? * TODO: Delete this once its only user (ConnectivityManager) is known to work well in the * 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. * case where multiple application components each have their own ConnectivityManager object. */ */ static abstract class StaticOuterContextServiceFetcher<T> implements ServiceFetcher<T> { static abstract class StaticApplicationContextServiceFetcher<T> implements ServiceFetcher<T> { private T mCachedInstance; private T mCachedInstance; @Override @Override public final T getService(ContextImpl ctx) { public final T getService(ContextImpl ctx) { synchronized (StaticOuterContextServiceFetcher.this) { synchronized (StaticApplicationContextServiceFetcher.this) { if (mCachedInstance == null) { if (mCachedInstance == null) { mCachedInstance = createService(ctx.getOuterContext()); mCachedInstance = createService(ctx.getApplicationContext()); } } return mCachedInstance; return mCachedInstance; } } Loading