Code cleanup (9/n)
* Remove dead code
* No need for waitForSessionReady() for Install.commit() has called it
internally.
Bug: 210359798
Test: atest StagedInstallInternalTest
Change-Id: I6c70012beead9de3d1f51821c6d93374c6f83d9d
diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java
index 17ce33f..2aa6618 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerSession.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java
@@ -59,8 +59,6 @@
import android.app.admin.DevicePolicyManagerInternal;
import android.content.ComponentName;
import android.content.Context;
-import android.content.IIntentReceiver;
-import android.content.IIntentSender;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.ApplicationInfo;
@@ -102,7 +100,6 @@
import android.os.FileBridge;
import android.os.FileUtils;
import android.os.Handler;
-import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.ParcelFileDescriptor;
@@ -558,19 +555,6 @@
return install();
}
- private void updateRemoteStatusReceiver(IntentSender remoteStatusReceiver) {
- synchronized (mLock) {
- setRemoteStatusReceiver(remoteStatusReceiver);
- if (isMultiPackage()) {
- final IntentSender childIntentSender = new ChildStatusIntentReceiver(
- mChildSessions.clone(), remoteStatusReceiver).getIntentSender();
- for (int i = mChildSessions.size() - 1; i >= 0; --i) {
- mChildSessions.valueAt(i).setRemoteStatusReceiver(childIntentSender);
- }
- }
- }
- }
-
@Override
public boolean hasParentSessionId() {
return PackageInstallerSession.this.hasParentSessionId();
@@ -1773,71 +1757,6 @@
}
}
- private class ChildStatusIntentReceiver {
- private final SparseArray<PackageInstallerSession> mChildSessionsRemaining;
- private final IntentSender mStatusReceiver;
- private final IIntentSender.Stub mLocalSender = new IIntentSender.Stub() {
- @Override
- public void send(int code, Intent intent, String resolvedType, IBinder whitelistToken,
- IIntentReceiver finishedReceiver, String requiredPermission, Bundle options) {
- statusUpdate(intent);
- }
- };
-
- private ChildStatusIntentReceiver(SparseArray<PackageInstallerSession> remainingSessions,
- IntentSender statusReceiver) {
- this.mChildSessionsRemaining = remainingSessions;
- this.mStatusReceiver = statusReceiver;
- }
-
- public IntentSender getIntentSender() {
- return new IntentSender((IIntentSender) mLocalSender);
- }
-
- public void statusUpdate(Intent intent) {
- mHandler.post(() -> {
- if (mChildSessionsRemaining.size() == 0) {
- // no children to deal with, ignore.
- return;
- }
- final boolean destroyed;
- synchronized (mLock) {
- destroyed = mDestroyed;
- }
- if (destroyed) {
- // the parent has already been terminated, ignore.
- return;
- }
- final int sessionId = intent.getIntExtra(
- PackageInstaller.EXTRA_SESSION_ID, 0);
- final int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS,
- PackageInstaller.STATUS_FAILURE);
- final int sessionIndex = mChildSessionsRemaining.indexOfKey(sessionId);
- final String message = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
- if (PackageInstaller.STATUS_SUCCESS == status) {
- mChildSessionsRemaining.removeAt(sessionIndex);
- if (mChildSessionsRemaining.size() == 0) {
- destroyInternal();
- dispatchSessionFinished(INSTALL_SUCCEEDED,
- "Session installed", null);
- }
- } else if (PackageInstaller.STATUS_PENDING_USER_ACTION == status) {
- try {
- mStatusReceiver.sendIntent(mContext, 0, intent, null, null);
- } catch (IntentSender.SendIntentException ignore) {
- }
- } else { // failure, let's forward and clean up this session.
- intent.putExtra(PackageInstaller.EXTRA_SESSION_ID,
- PackageInstallerSession.this.sessionId);
- mChildSessionsRemaining.clear(); // we're done. Don't send any more.
- destroyInternal();
- dispatchSessionFinished(INSTALL_FAILED_INTERNAL_ERROR,
- "Child session " + sessionId + " failed: " + message, null);
- }
- });
- }
- }
-
/**
* Returns whether or not a package can be installed while Secure FRP is enabled.
* <p>
@@ -2060,12 +1979,6 @@
maybeFinishChildSessions(error, msg);
}
- private void onSessionInstallationFailure(int error, String detailedMessage) {
- Slog.e(TAG, "Install of session " + sessionId + " failed: " + detailedMessage);
- destroyInternal();
- dispatchSessionFinished(error, detailedMessage, null);
- }
-
private void onSystemDataLoaderUnrecoverable() {
final DeletePackageHelper deletePackageHelper = new DeletePackageHelper(mPm);
final String packageName = getPackageName();
diff --git a/services/core/java/com/android/server/pm/StagingManager.java b/services/core/java/com/android/server/pm/StagingManager.java
index 804e5ec..79901ce 100644
--- a/services/core/java/com/android/server/pm/StagingManager.java
+++ b/services/core/java/com/android/server/pm/StagingManager.java
@@ -23,11 +23,8 @@
import android.apex.ApexSessionParams;
import android.content.BroadcastReceiver;
import android.content.Context;
-import android.content.IIntentReceiver;
-import android.content.IIntentSender;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.IntentSender;
import android.content.pm.ApexStagedEvent;
import android.content.pm.IStagedApexObserver;
import android.content.pm.PackageInstaller;
@@ -36,7 +33,6 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.StagedApexInfo;
-import android.os.Bundle;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.RemoteException;
@@ -78,8 +74,6 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
/**
@@ -809,35 +803,6 @@
BackgroundThread.getExecutor().execute(() -> logFailedApexSessionsIfNecessary());
}
- private static class LocalIntentReceiverSync {
- private final LinkedBlockingQueue<Intent> mResult = new LinkedBlockingQueue<>();
-
- private final IIntentSender.Stub mLocalSender = new IIntentSender.Stub() {
- @Override
- public void send(int code, Intent intent, String resolvedType, IBinder whitelistToken,
- IIntentReceiver finishedReceiver, String requiredPermission,
- Bundle options) {
- try {
- mResult.offer(intent, 5, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- };
-
- public IntentSender getIntentSender() {
- return new IntentSender((IIntentSender) mLocalSender);
- }
-
- public Intent getResult() {
- try {
- return mResult.take();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- }
-
private StagedSession getStagedSession(int sessionId) {
StagedSession session;
synchronized (mStagedSessions) {
diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java
index bb4866f..4cddcfe 100644
--- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java
+++ b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java
@@ -171,9 +171,8 @@
@Test
public void testRollbackApexWithApkCrashing_Phase1_Install() throws Exception {
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
- int sessionId = Install.single(TEST_APEX_WITH_APK_V2_CRASHING).setStaged()
+ Install.single(TEST_APEX_WITH_APK_V2_CRASHING).setStaged()
.setEnableRollback().commit();
- InstallUtils.waitForSessionReady(sessionId);
}
/**
diff --git a/tests/StagedInstallTest/app/src/com/android/tests/stagedinstallinternal/StagedInstallInternalTest.java b/tests/StagedInstallTest/app/src/com/android/tests/stagedinstallinternal/StagedInstallInternalTest.java
index 426f3be..e9300da 100644
--- a/tests/StagedInstallTest/app/src/com/android/tests/stagedinstallinternal/StagedInstallInternalTest.java
+++ b/tests/StagedInstallTest/app/src/com/android/tests/stagedinstallinternal/StagedInstallInternalTest.java
@@ -17,7 +17,6 @@
package com.android.tests.stagedinstallinternal;
import static com.android.cts.install.lib.InstallUtils.getPackageInstaller;
-import static com.android.cts.install.lib.InstallUtils.waitForSessionReady;
import static com.android.cts.shim.lib.ShimPackage.SHIM_APEX_PACKAGE_NAME;
import static com.google.common.truth.Truth.assertThat;
@@ -458,7 +457,6 @@
assertThat(result).hasLength(0);
// Stage an apex
int sessionId = Install.single(APEX_V2).setStaged().commit();
- waitForSessionReady(sessionId);
result = getPackageManagerNative().getStagedApexModuleNames();
assertThat(result).hasLength(1);
assertThat(result).isEqualTo(new String[]{SHIM_APEX_PACKAGE_NAME});
@@ -475,7 +473,6 @@
assertThat(result).isNull();
// Stage an apex
int sessionId = Install.single(TEST_APEX_CLASSPATH).setStaged().commit();
- waitForSessionReady(sessionId);
// Query proper module name
result = getPackageManagerNative().getStagedApexInfo(TEST_APEX_PACKAGE_NAME);
assertThat(result.moduleName).isEqualTo(TEST_APEX_PACKAGE_NAME);
@@ -499,7 +496,6 @@
// Stage an apex and verify observer was called
int sessionId = Install.single(APEX_V2).setStaged().commit();
- waitForSessionReady(sessionId);
ArgumentCaptor<ApexStagedEvent> captor = ArgumentCaptor.forClass(ApexStagedEvent.class);
verify(observer, timeout(5000)).onApexStaged(captor.capture());
assertThat(captor.getValue().stagedApexModuleNames).isEqualTo(