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

Commit 19655fc0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "SysUI fragments: Integrate new support for constructing"

parents 4bd54c70 20ff3f92
Loading
Loading
Loading
Loading
+3 −35
Original line number Diff line number Diff line
@@ -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
@@ -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;
    }
}
+6 −2
Original line number Diff line number Diff line
@@ -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");
+3 −1
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@

package com.android.systemui.plugins;

import android.content.Context;

/**
 * Interface for listening to plugins being connected.
 */
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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();
    }
+1 −1
Original line number Diff line number Diff line
@@ -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