Reschedule the pre-reboot verification after boot completed.
Bug: 143528612
Test: atest CtsStagedInstallHostTestCases
Change-Id: I34d7ee3b84bc351d58ebf024a7ed10dd7db1f55b
Merged-In: I34d7ee3b84bc351d58ebf024a7ed10dd7db1f55b
(cherry picked from commit b793c2174e)
This commit is contained in:
committed by
Mohammad Samiul Islam
parent
739300762b
commit
7347288f91
@@ -218,6 +218,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
|||||||
|
|
||||||
public void systemReady() {
|
public void systemReady() {
|
||||||
mAppOps = mContext.getSystemService(AppOpsManager.class);
|
mAppOps = mContext.getSystemService(AppOpsManager.class);
|
||||||
|
mStagingManager.systemReady();
|
||||||
|
|
||||||
synchronized (mSessions) {
|
synchronized (mSessions) {
|
||||||
readSessionsLocked();
|
readSessionsLocked();
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ import android.annotation.Nullable;
|
|||||||
import android.apex.ApexInfo;
|
import android.apex.ApexInfo;
|
||||||
import android.apex.ApexInfoList;
|
import android.apex.ApexInfoList;
|
||||||
import android.apex.ApexSessionInfo;
|
import android.apex.ApexSessionInfo;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.IIntentReceiver;
|
import android.content.IIntentReceiver;
|
||||||
import android.content.IIntentSender;
|
import android.content.IIntentSender;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.IntentSender;
|
import android.content.IntentSender;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageInstaller;
|
import android.content.pm.PackageInstaller;
|
||||||
@@ -73,12 +75,16 @@ public class StagingManager {
|
|||||||
private final PackageInstallerService mPi;
|
private final PackageInstallerService mPi;
|
||||||
private final ApexManager mApexManager;
|
private final ApexManager mApexManager;
|
||||||
private final PowerManager mPowerManager;
|
private final PowerManager mPowerManager;
|
||||||
|
private final Context mContext;
|
||||||
private final Handler mBgHandler;
|
private final Handler mBgHandler;
|
||||||
|
private PackageInstallerSession mPendingSession;
|
||||||
|
private boolean mIsReady;
|
||||||
|
|
||||||
@GuardedBy("mStagedSessions")
|
@GuardedBy("mStagedSessions")
|
||||||
private final SparseArray<PackageInstallerSession> mStagedSessions = new SparseArray<>();
|
private final SparseArray<PackageInstallerSession> mStagedSessions = new SparseArray<>();
|
||||||
|
|
||||||
StagingManager(PackageInstallerService pi, ApexManager am, Context context) {
|
StagingManager(PackageInstallerService pi, ApexManager am, Context context) {
|
||||||
|
mContext = context;
|
||||||
mPi = pi;
|
mPi = pi;
|
||||||
mApexManager = am;
|
mApexManager = am;
|
||||||
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
@@ -204,6 +210,11 @@ public class StagingManager {
|
|||||||
|
|
||||||
private void preRebootVerification(@NonNull PackageInstallerSession session) {
|
private void preRebootVerification(@NonNull PackageInstallerSession session) {
|
||||||
try {
|
try {
|
||||||
|
if (!mIsReady) {
|
||||||
|
mPendingSession = session;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
|
|
||||||
final ApexInfoList apexInfoList = new ApexInfoList();
|
final ApexInfoList apexInfoList = new ApexInfoList();
|
||||||
@@ -691,6 +702,28 @@ public class StagingManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void systemReady() {
|
||||||
|
// Register the receiver of boot completed intent for staging manager.
|
||||||
|
mContext.registerReceiver(new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context ctx, Intent intent) {
|
||||||
|
readyToStart();
|
||||||
|
ctx.unregisterReceiver(this);
|
||||||
|
}
|
||||||
|
}, new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify the handler that system is ready, and reschedule the pre-reboot verifications.
|
||||||
|
private synchronized void readyToStart() {
|
||||||
|
mIsReady = true;
|
||||||
|
if (mPendingSession != null) {
|
||||||
|
mBgHandler.post(() -> {
|
||||||
|
preRebootVerification(mPendingSession);
|
||||||
|
mPendingSession = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class LocalIntentReceiver {
|
private static class LocalIntentReceiver {
|
||||||
private final LinkedBlockingQueue<Intent> mResult = new LinkedBlockingQueue<>();
|
private final LinkedBlockingQueue<Intent> mResult = new LinkedBlockingQueue<>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user