diff options
| author | 2019-01-27 23:26:06 +0000 | |
|---|---|---|
| committer | 2019-01-28 14:34:01 +0000 | |
| commit | 9694b80d803677e70c89a178d227b0d227279f4c (patch) | |
| tree | ab967779f41d352df06ed8f6b8d87d1c4f8359b4 | |
| parent | a12232a4c2ebab1dd27602964248adaacdcd74f6 (diff) | |
Avoid sending broadcasts before boot completes.
Fix: 123413830
Bug: 118865310
Test: Verified with a small app that pre-reboot broadcasts are sent
correctly, and no exception is reported at boot time when an APEX is
activated.
Change-Id: Ife9de5132ca0c858f842ee32f22cec5586efa4e5
| -rw-r--r-- | services/core/java/com/android/server/pm/PackageInstallerService.java | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/pm/PackageInstallerService.java b/services/core/java/com/android/server/pm/PackageInstallerService.java index eab5c8f866a8..146a2f3d8433 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerService.java +++ b/services/core/java/com/android/server/pm/PackageInstallerService.java @@ -28,8 +28,10 @@ import android.app.NotificationManager; import android.app.PackageDeleteObserver; import android.app.PackageInstallObserver; import android.app.admin.DevicePolicyManagerInternal; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.IntentSender; import android.content.IntentSender.SendIntentException; import android.content.pm.ApplicationInfo; @@ -138,6 +140,8 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements private final Callbacks mCallbacks; + private volatile boolean mBootCompleted = false; + /** * File storing persisted {@link #mSessions} metadata. */ @@ -203,9 +207,20 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements mStagingManager = new StagingManager(pm); } + private void setBootCompleted() { + mBootCompleted = true; + } + public void systemReady() { mAppOps = mContext.getSystemService(AppOpsManager.class); + mContext.registerReceiver(new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + setBootCompleted(); + mContext.unregisterReceiver(this); + } + }, new IntentFilter(Intent.ACTION_BOOT_COMPLETED)); synchronized (mSessions) { readSessionsLocked(); @@ -1126,8 +1141,10 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements public void onStagedSessionChanged(PackageInstallerSession session) { writeSessionsAsync(); - // TODO(b/118865310): don't send broadcast if system is not ready. - mPm.sendSessionUpdatedBroadcast(session.generateInfo(false), session.userId); + if (mBootCompleted) { + mPm.sendSessionUpdatedBroadcast(session.generateInfo(false), + session.userId); + } } public void onSessionFinished(final PackageInstallerSession session, boolean success) { |