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

Commit dd97f423 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Install providers enabled after app started.

When an app has already been started, and a ContentProvider component
is enabled with DONT_KILL_APP, use the existing ProcessRecord to
install the provider.

Bug: 11118692
Change-Id: I990f18b337eb19768ee1db895f1e2eb982046cce
parent a6af40cd
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ import com.android.internal.os.SamplingProfilerIntegration;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.Objects;
import com.android.org.conscrypt.OpenSSLSocketImpl;
import com.google.android.collect.Lists;

import java.io.File;
import java.io.FileDescriptor;
@@ -1277,6 +1278,11 @@ public final class ActivityThread {
                }
            }
        }

        @Override
        public void scheduleInstallProvider(ProviderInfo provider) {
            queueOrSendMessage(H.INSTALL_PROVIDER, provider);
        }
    }

    private class H extends Handler {
@@ -1325,6 +1331,7 @@ public final class ActivityThread {
        public static final int UNSTABLE_PROVIDER_DIED  = 142;
        public static final int REQUEST_ASSIST_CONTEXT_EXTRAS = 143;
        public static final int TRANSLUCENT_CONVERSION_COMPLETE = 144;
        public static final int INSTALL_PROVIDER        = 145;
        String codeToString(int code) {
            if (DEBUG_MESSAGES) {
                switch (code) {
@@ -1373,6 +1380,7 @@ public final class ActivityThread {
                    case UNSTABLE_PROVIDER_DIED: return "UNSTABLE_PROVIDER_DIED";
                    case REQUEST_ASSIST_CONTEXT_EXTRAS: return "REQUEST_ASSIST_CONTEXT_EXTRAS";
                    case TRANSLUCENT_CONVERSION_COMPLETE: return "TRANSLUCENT_CONVERSION_COMPLETE";
                    case INSTALL_PROVIDER: return "INSTALL_PROVIDER";
                }
            }
            return Integer.toString(code);
@@ -1590,6 +1598,9 @@ public final class ActivityThread {
                case TRANSLUCENT_CONVERSION_COMPLETE:
                    handleTranslucentConversionComplete((IBinder)msg.obj, msg.arg1 == 1);
                    break;
                case INSTALL_PROVIDER:
                    handleInstallProvider((ProviderInfo) msg.obj);
                    break;
            }
            if (DEBUG_MESSAGES) Slog.v(TAG, "<<< done: " + codeToString(msg.what));
        }
@@ -2330,6 +2341,10 @@ public final class ActivityThread {
        }
    }

    public void handleInstallProvider(ProviderInfo info) {
        installContentProviders(mInitialApplication, Lists.newArrayList(info));
    }

    private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>();

    /**
+18 −0
Original line number Diff line number Diff line
@@ -618,6 +618,15 @@ public abstract class ApplicationThreadNative extends Binder
            reply.writeNoException();
            return true;
        }

        case SCHEDULE_INSTALL_PROVIDER_TRANSACTION:
        {
            data.enforceInterface(IApplicationThread.descriptor);
            ProviderInfo provider = ProviderInfo.CREATOR.createFromParcel(data);
            scheduleInstallProvider(provider);
            reply.writeNoException();
            return true;
        }
        }

        return super.onTransact(code, data, reply, flags);
@@ -1248,4 +1257,13 @@ class ApplicationThreadProxy implements IApplicationThread {
        mRemote.transact(SET_PROCESS_STATE_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
        data.recycle();
    }

    @Override
    public void scheduleInstallProvider(ProviderInfo provider) throws RemoteException {
        Parcel data = Parcel.obtain();
        data.writeInterfaceToken(IApplicationThread.descriptor);
        provider.writeToParcel(data, 0);
        mRemote.transact(SCHEDULE_INSTALL_PROVIDER_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
        data.recycle();
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ public interface IApplicationThread extends IInterface {
    void scheduleTranslucentConversionComplete(IBinder token, boolean timeout)
            throws RemoteException;
    void setProcessState(int state) throws RemoteException;
    void scheduleInstallProvider(ProviderInfo provider) throws RemoteException;

    String descriptor = "android.app.IApplicationThread";

@@ -189,4 +190,5 @@ public interface IApplicationThread extends IInterface {
    int REQUEST_ASSIST_CONTEXT_EXTRAS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+47;
    int SCHEDULE_TRANSLUCENT_CONVERSION_COMPLETE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+48;
    int SET_PROCESS_STATE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+49;
    int SCHEDULE_INSTALL_PROVIDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+50;
}
+24 −10
Original line number Diff line number Diff line
@@ -7526,7 +7526,20 @@ public final class ActivityManagerService extends ActivityManagerNative
                                    + cpr.appInfo.packageName + ": " + e);
                        }
                        ProcessRecord proc = startProcessLocked(cpi.processName,
                        // Use existing process if already started
                        ProcessRecord proc = getProcessRecordLocked(
                                cpi.processName, cpr.appInfo.uid, false);
                        if (proc != null) {
                            if (DEBUG_PROVIDER) {
                                Slog.d(TAG, "Installing in existing process " + proc);
                            }
                            proc.pubProviders.put(cpi.name, cpr);
                            try {
                                proc.thread.scheduleInstallProvider(cpi);
                            } catch (RemoteException e) {
                            }
                        } else {
                            proc = startProcessLocked(cpi.processName,
                                    cpr.appInfo, false, 0, "content provider",
                                    new ComponentName(cpi.applicationInfo.packageName,
                                            cpi.name), false, false, false);
@@ -7537,6 +7550,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                                        + name + ": process is bad");
                                return null;
                            }
                        }
                        cpr.launchingApp = proc;
                        mLaunchingProviders.add(cpr);
                    } finally {