Loading packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginFragment.java +3 −35 Original line number Diff line number Diff line Loading @@ -14,17 +14,13 @@ package com.android.systemui.plugins; import android.annotation.Nullable; import android.app.Fragment; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; import android.view.LayoutInflater; public abstract class PluginFragment extends Fragment implements Plugin { private static final String KEY_PLUGIN_PACKAGE = "plugin_package_name"; private Context mPluginContext; @Override Loading @@ -33,45 +29,17 @@ public abstract class PluginFragment extends Fragment implements Plugin { } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { Context sysuiContext = getContext(); Context pluginContext = recreatePluginContext(sysuiContext, savedInstanceState); onCreate(sysuiContext, pluginContext); } if (mPluginContext == null) { throw new RuntimeException("PluginFragments must call super.onCreate(" + "Context sysuiContext, Context pluginContext)"); } public LayoutInflater getLayoutInflater(Bundle savedInstanceState) { return super.getLayoutInflater(savedInstanceState).cloneInContext(getContext()); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putString(KEY_PLUGIN_PACKAGE, getContext().getPackageName()); } private Context recreatePluginContext(Context sysuiContext, Bundle savedInstanceState) { final String pkg = savedInstanceState.getString(KEY_PLUGIN_PACKAGE); try { ApplicationInfo appInfo = sysuiContext.getPackageManager().getApplicationInfo(pkg, 0); return PluginManager.getInstance(sysuiContext).getContext(appInfo, pkg); } catch (NameNotFoundException e) { throw new RuntimeException("Plugin with invalid package? " + pkg, e); } } @Override public LayoutInflater getLayoutInflater(Bundle savedInstanceState) { return super.getLayoutInflater(savedInstanceState).cloneInContext(mPluginContext); } /** * Should only be called after {@link Plugin#onCreate(Context, Context)}. */ @Override public Context getContext() { return mPluginContext != null ? mPluginContext : super.getContext(); return mPluginContext; } } packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginInstanceManager.java +6 −2 Original line number Diff line number Diff line Loading @@ -177,8 +177,12 @@ public class PluginInstanceManager<T extends Plugin> { if (DEBUG) Log.d(TAG, "onPluginConnected"); PluginPrefs.setHasPlugins(mContext); PluginInfo<T> info = (PluginInfo<T>) msg.obj; if (!(msg.obj instanceof PluginFragment)) { // Only call onDestroy for plugins that aren't fragments, as fragments // will get the onCreate as part of the fragment lifecycle. info.mPlugin.onCreate(mContext, info.mPluginContext); mListener.onPluginConnected(info.mPlugin); } mListener.onPluginConnected(info.mPlugin, info.mPluginContext); break; case PLUGIN_DISCONNECTED: if (DEBUG) Log.d(TAG, "onPluginDisconnected"); Loading packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginListener.java +3 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ package com.android.systemui.plugins; import android.content.Context; /** * Interface for listening to plugins being connected. */ Loading @@ -24,7 +26,7 @@ public interface PluginListener<T extends Plugin> { * It may also be called in the future if the plugin package changes * and needs to be reloaded. */ void onPluginConnected(T plugin); void onPluginConnected(T plugin, Context pluginContext); /** * Called when a plugin has been uninstalled/updated and should be removed Loading packages/SystemUI/src/com/android/systemui/PluginInflateContainer.java +1 −1 Original line number Diff line number Diff line Loading @@ -98,7 +98,7 @@ public class PluginInflateContainer extends AutoReinflateContainer } @Override public void onPluginConnected(ViewProvider plugin) { public void onPluginConnected(ViewProvider plugin, Context context) { mPluginView = plugin.getView(); inflateLayout(); } Loading packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +1 −1 Original line number Diff line number Diff line Loading @@ -207,7 +207,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv PluginManager.getInstance(this).addPluginListener(OverlayPlugin.ACTION, new PluginListener<OverlayPlugin>() { @Override public void onPluginConnected(OverlayPlugin plugin) { public void onPluginConnected(OverlayPlugin plugin, Context pluginContext) { PhoneStatusBar phoneStatusBar = getComponent(PhoneStatusBar.class); if (phoneStatusBar != null) { plugin.setup(phoneStatusBar.getStatusBarWindow(), Loading Loading
packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginFragment.java +3 −35 Original line number Diff line number Diff line Loading @@ -14,17 +14,13 @@ package com.android.systemui.plugins; import android.annotation.Nullable; import android.app.Fragment; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; import android.view.LayoutInflater; public abstract class PluginFragment extends Fragment implements Plugin { private static final String KEY_PLUGIN_PACKAGE = "plugin_package_name"; private Context mPluginContext; @Override Loading @@ -33,45 +29,17 @@ public abstract class PluginFragment extends Fragment implements Plugin { } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { Context sysuiContext = getContext(); Context pluginContext = recreatePluginContext(sysuiContext, savedInstanceState); onCreate(sysuiContext, pluginContext); } if (mPluginContext == null) { throw new RuntimeException("PluginFragments must call super.onCreate(" + "Context sysuiContext, Context pluginContext)"); } public LayoutInflater getLayoutInflater(Bundle savedInstanceState) { return super.getLayoutInflater(savedInstanceState).cloneInContext(getContext()); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putString(KEY_PLUGIN_PACKAGE, getContext().getPackageName()); } private Context recreatePluginContext(Context sysuiContext, Bundle savedInstanceState) { final String pkg = savedInstanceState.getString(KEY_PLUGIN_PACKAGE); try { ApplicationInfo appInfo = sysuiContext.getPackageManager().getApplicationInfo(pkg, 0); return PluginManager.getInstance(sysuiContext).getContext(appInfo, pkg); } catch (NameNotFoundException e) { throw new RuntimeException("Plugin with invalid package? " + pkg, e); } } @Override public LayoutInflater getLayoutInflater(Bundle savedInstanceState) { return super.getLayoutInflater(savedInstanceState).cloneInContext(mPluginContext); } /** * Should only be called after {@link Plugin#onCreate(Context, Context)}. */ @Override public Context getContext() { return mPluginContext != null ? mPluginContext : super.getContext(); return mPluginContext; } }
packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginInstanceManager.java +6 −2 Original line number Diff line number Diff line Loading @@ -177,8 +177,12 @@ public class PluginInstanceManager<T extends Plugin> { if (DEBUG) Log.d(TAG, "onPluginConnected"); PluginPrefs.setHasPlugins(mContext); PluginInfo<T> info = (PluginInfo<T>) msg.obj; if (!(msg.obj instanceof PluginFragment)) { // Only call onDestroy for plugins that aren't fragments, as fragments // will get the onCreate as part of the fragment lifecycle. info.mPlugin.onCreate(mContext, info.mPluginContext); mListener.onPluginConnected(info.mPlugin); } mListener.onPluginConnected(info.mPlugin, info.mPluginContext); break; case PLUGIN_DISCONNECTED: if (DEBUG) Log.d(TAG, "onPluginDisconnected"); Loading
packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginListener.java +3 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ package com.android.systemui.plugins; import android.content.Context; /** * Interface for listening to plugins being connected. */ Loading @@ -24,7 +26,7 @@ public interface PluginListener<T extends Plugin> { * It may also be called in the future if the plugin package changes * and needs to be reloaded. */ void onPluginConnected(T plugin); void onPluginConnected(T plugin, Context pluginContext); /** * Called when a plugin has been uninstalled/updated and should be removed Loading
packages/SystemUI/src/com/android/systemui/PluginInflateContainer.java +1 −1 Original line number Diff line number Diff line Loading @@ -98,7 +98,7 @@ public class PluginInflateContainer extends AutoReinflateContainer } @Override public void onPluginConnected(ViewProvider plugin) { public void onPluginConnected(ViewProvider plugin, Context context) { mPluginView = plugin.getView(); inflateLayout(); } Loading
packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +1 −1 Original line number Diff line number Diff line Loading @@ -207,7 +207,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv PluginManager.getInstance(this).addPluginListener(OverlayPlugin.ACTION, new PluginListener<OverlayPlugin>() { @Override public void onPluginConnected(OverlayPlugin plugin) { public void onPluginConnected(OverlayPlugin plugin, Context pluginContext) { PhoneStatusBar phoneStatusBar = getComponent(PhoneStatusBar.class); if (phoneStatusBar != null) { plugin.setup(phoneStatusBar.getStatusBarWindow(), Loading