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

Commit 2423ad19 authored by Amith Yamasani's avatar Amith Yamasani Committed by Android Git Automerger
Browse files

am 2ec5ef32: am 8fdfdbbb: Call PRE_BOOT_COMPLETED on starting any user

* commit '2ec5ef329f6e36a722f3cac1dac380d75889f603':
  Call PRE_BOOT_COMPLETED on starting any user
parents 8b260d0b c475b7fe
Loading
Loading
Loading
Loading
+111 −83
Original line number Diff line number Diff line
@@ -46,8 +46,8 @@ import android.os.PersistableBundle;
import android.service.voice.IVoiceInteractionSession;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.SparseIntArray;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.IAppOpsService;
@@ -222,7 +222,11 @@ import java.util.concurrent.atomic.AtomicLong;
public final class ActivityManagerService extends ActivityManagerNative
        implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {
    private static final String USER_DATA_DIR = "/data/user/";
    // File that stores last updated system version and called preboot receivers
    static final String CALLED_PRE_BOOTS_FILENAME = "called_pre_boots.dat";
    static final String TAG = "ActivityManager";
    static final String TAG_MU = "ActivityManagerServiceMU";
    static final boolean DEBUG = false;
@@ -354,6 +358,8 @@ public final class ActivityManagerService extends ActivityManagerNative
    static final int ALLOW_NON_FULL_IN_PROFILE = 1;
    static final int ALLOW_FULL_ONLY = 2;
    static final int LAST_PREBOOT_DELIVERED_FILE_VERSION = 10000;
    /** All system services */
    SystemServiceManager mSystemServiceManager;
@@ -9947,12 +9953,10 @@ public final class ActivityManagerService extends ActivityManagerNative
    private static File getCalledPreBootReceiversFile() {
        File dataDir = Environment.getDataDirectory();
        File systemDir = new File(dataDir, "system");
        File fname = new File(systemDir, "called_pre_boots.dat");
        File fname = new File(systemDir, CALLED_PRE_BOOTS_FILENAME);
        return fname;
    }
    static final int LAST_DONE_VERSION = 10000;
    private static ArrayList<ComponentName> readLastDonePreBootReceivers() {
        ArrayList<ComponentName> lastDoneReceivers = new ArrayList<ComponentName>();
        File file = getCalledPreBootReceiversFile();
@@ -9961,7 +9965,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            fis = new FileInputStream(file);
            DataInputStream dis = new DataInputStream(new BufferedInputStream(fis, 2048));
            int fvers = dis.readInt();
            if (fvers == LAST_DONE_VERSION) {
            if (fvers == LAST_PREBOOT_DELIVERED_FILE_VERSION) {
                String vers = dis.readUTF();
                String codename = dis.readUTF();
                String build = dis.readUTF();
@@ -9996,10 +10000,9 @@ public final class ActivityManagerService extends ActivityManagerNative
        FileOutputStream fos = null;
        DataOutputStream dos = null;
        try {
            Slog.i(TAG, "Writing new set of last done pre-boot receivers...");
            fos = new FileOutputStream(file);
            dos = new DataOutputStream(new BufferedOutputStream(fos, 2048));
            dos.writeInt(LAST_DONE_VERSION);
            dos.writeInt(LAST_PREBOOT_DELIVERED_FILE_VERSION);
            dos.writeUTF(android.os.Build.VERSION.RELEASE);
            dos.writeUTF(android.os.Build.VERSION.CODENAME);
            dos.writeUTF(android.os.Build.VERSION.INCREMENTAL);
@@ -10024,35 +10027,14 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
    }
    public void systemReady(final Runnable goingCallback) {
        synchronized(this) {
            if (mSystemReady) {
                if (goingCallback != null) goingCallback.run();
                return;
            }
            // Make sure we have the current profile info, since it is needed for
            // security checks.
            updateCurrentProfileIdsLocked();
            if (mRecentTasks == null) {
                mRecentTasks = mTaskPersister.restoreTasksLocked();
                if (!mRecentTasks.isEmpty()) {
                    mStackSupervisor.createStackForRestoredTaskHistory(mRecentTasks);
                }
                mTaskPersister.startPersisting();
            }
            // Check to see if there are any update receivers to run.
            if (!mDidUpdate) {
                if (mWaitingUpdate) {
                    return;
                }
    private boolean deliverPreBootCompleted(final Runnable onFinishCallback,
            ArrayList<ComponentName> doneReceivers, int userId) {
        boolean waitingUpdate = false;
        Intent intent = new Intent(Intent.ACTION_PRE_BOOT_COMPLETED);
        List<ResolveInfo> ris = null;
        try {
            ris = AppGlobals.getPackageManager().queryIntentReceivers(
                            intent, null, 0, 0);
                    intent, null, 0, userId);
        } catch (RemoteException e) {
        }
        if (ris != null) {
@@ -10064,9 +10046,10 @@ public final class ActivityManagerService extends ActivityManagerNative
            }
            intent.addFlags(Intent.FLAG_RECEIVER_BOOT_UPGRADE);
            // For User 0, load the version number. When delivering to a new user, deliver
            // to all receivers.
            if (userId == UserHandle.USER_OWNER) {
                ArrayList<ComponentName> lastDoneReceivers = readLastDonePreBootReceivers();
                    final ArrayList<ComponentName> doneReceivers = new ArrayList<ComponentName>();
                for (int i=0; i<ris.size(); i++) {
                    ActivityInfo ai = ris.get(i).activityInfo;
                    ComponentName comp = new ComponentName(ai.packageName, ai.name);
@@ -10080,8 +10063,11 @@ public final class ActivityManagerService extends ActivityManagerNative
                        doneReceivers.add(comp);
                    }
                }
            }
                    final int[] users = getUsersLocked();
            // If primary user, send broadcast to all available users, else just to userId
            final int[] users = userId == UserHandle.USER_OWNER ? getUsersLocked()
                    : new int[] { userId };
            for (int i = 0; i < ris.size(); i++) {
                ActivityInfo ai = ris.get(i).activityInfo;
                ComponentName comp = new ComponentName(ai.packageName, ai.name);
@@ -10089,7 +10075,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                intent.setComponent(comp);
                for (int j=0; j<users.length; j++) {
                    IIntentReceiver finisher = null;
                            if (i == ris.size()-1 && j == users.length-1) {
                    // On last receiver and user, set up a completion callback
                    if (i == ris.size() - 1 && j == users.length - 1 && onFinishCallback != null) {
                        finisher = new IIntentReceiver.Stub() {
                            public void performReceive(Intent intent, int resultCode,
                                    String data, Bundle extras, boolean ordered,
@@ -10097,18 +10084,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                                // The raw IIntentReceiver interface is called
                                // with the AM lock held, so redispatch to
                                // execute our code without the lock.
                                        mHandler.post(new Runnable() {
                                            public void run() {
                                                synchronized (ActivityManagerService.this) {
                                                    mDidUpdate = true;
                                                }
                                                writeLastDonePreBootReceivers(doneReceivers);
                                                showBootMessage(mContext.getText(
                                                        R.string.android_upgrading_complete),
                                                        false);
                                                systemReady(goingCallback);
                                            }
                                        });
                                mHandler.post(onFinishCallback);
                            }
                        };
                    }
@@ -10119,11 +10095,57 @@ public final class ActivityManagerService extends ActivityManagerNative
                            true, false, MY_PID, Process.SYSTEM_UID,
                            users[j]);
                    if (finisher != null) {
                                mWaitingUpdate = true;
                        waitingUpdate = true;
                    }
                }
            }
        }
        return waitingUpdate;
    }
    public void systemReady(final Runnable goingCallback) {
        synchronized(this) {
            if (mSystemReady) {
                // If we're done calling all the receivers, run the next "boot phase" passed in
                // by the SystemServer
                if (goingCallback != null) {
                    goingCallback.run();
                }
                return;
            }
            // Make sure we have the current profile info, since it is needed for
            // security checks.
            updateCurrentProfileIdsLocked();
            if (mRecentTasks == null) {
                mRecentTasks = mTaskPersister.restoreTasksLocked();
                if (!mRecentTasks.isEmpty()) {
                    mStackSupervisor.createStackForRestoredTaskHistory(mRecentTasks);
                }
                mTaskPersister.startPersisting();
            }
            // Check to see if there are any update receivers to run.
            if (!mDidUpdate) {
                if (mWaitingUpdate) {
                    return;
                }
                final ArrayList<ComponentName> doneReceivers = new ArrayList<ComponentName>();
                mWaitingUpdate = deliverPreBootCompleted(new Runnable() {
                    public void run() {
                        synchronized (ActivityManagerService.this) {
                            mDidUpdate = true;
                        }
                        writeLastDonePreBootReceivers(doneReceivers);
                        showBootMessage(mContext.getText(
                                R.string.android_upgrading_complete),
                                false);
                        systemReady(goingCallback);
                    }
                }, doneReceivers, UserHandle.USER_OWNER);
                if (mWaitingUpdate) {
                    return;
                }
@@ -17156,6 +17178,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                }
                if (needStart) {
                    // Send USER_STARTED broadcast
                    Intent intent = new Intent(Intent.ACTION_USER_STARTED);
                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
                            | Intent.FLAG_RECEIVER_FOREGROUND);
@@ -17167,6 +17190,11 @@ public final class ActivityManagerService extends ActivityManagerNative
                if ((userInfo.flags&UserInfo.FLAG_INITIALIZED) == 0) {
                    if (userId != UserHandle.USER_OWNER) {
                        // Send PRE_BOOT_COMPLETED broadcasts for this new user
                        final ArrayList<ComponentName> doneReceivers
                                = new ArrayList<ComponentName>();
                        deliverPreBootCompleted(null, doneReceivers, userId);
                        Intent intent = new Intent(Intent.ACTION_USER_INITIALIZE);
                        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
                        broadcastIntentLocked(null, null, intent, null,