summaryrefslogtreecommitdiff
path: root/tests/RollbackTest/lib
diff options
context:
space:
mode:
authorJW Wang <wangchun@google.com>2020-07-08 17:06:36 +0800
committerMohammad Samiul Islam <samiul@google.com>2020-09-29 15:03:20 +0100
commit5b51c8c18995232a3430cae3fd783f17e5e4ce9a (patch)
tree9a7bbe33f6644f9a66345c84461f933bafc1d541 /tests/RollbackTest/lib
parent08e7cbb0b5399be7733a8dc2bb467cc8d9c48d6b (diff)
Rewrite how we abandon sessions
The original code is flawed in that `pm install-abandon` only abandons the 1st session returned by `pm get-stagedsessions ...`. 1. move AbandonSessionsRule to be shared by multiple host tests 2. use AbandonSessionsRule to do the job Bug: 160754072 Test: StagedInstallInternalTest Change-Id: Ib7b32fbd7b1133ac6a8e6782234a4fe2c5a782bd Merged-In: Ib7b32fbd7b1133ac6a8e6782234a4fe2c5a782bd (cherry picked from commit 3ac333f2d20e240093235d957ba67ce174fe2db8)
Diffstat (limited to 'tests/RollbackTest/lib')
-rw-r--r--tests/RollbackTest/lib/src/com/android/tests/rollback/host/AbandonSessionsRule.java62
1 files changed, 0 insertions, 62 deletions
diff --git a/tests/RollbackTest/lib/src/com/android/tests/rollback/host/AbandonSessionsRule.java b/tests/RollbackTest/lib/src/com/android/tests/rollback/host/AbandonSessionsRule.java
deleted file mode 100644
index b08621314ee0..000000000000
--- a/tests/RollbackTest/lib/src/com/android/tests/rollback/host/AbandonSessionsRule.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.tests.rollback.host;
-
-import com.android.tradefed.device.ITestDevice;
-import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
-
-import org.junit.rules.ExternalResource;
-
-public class AbandonSessionsRule extends ExternalResource {
- private final BaseHostJUnit4Test mHost;
-
- public AbandonSessionsRule(BaseHostJUnit4Test host) {
- mHost = host;
- }
-
- @Override
- protected void before() throws Throwable {
- abandonSessions(mHost.getDevice());
- }
-
- @Override
- protected void after() {
- try {
- abandonSessions(mHost.getDevice());
- } catch (Exception ignore) {
- }
- }
-
- /**
- * Abandons all sessions to prevent interference in our tests.
- */
- private static void abandonSessions(ITestDevice device) throws Exception {
- // No point in abandoning applied or failed sessions. We care about ready sessions only.
- String cmdListReadySessions =
- "pm list staged-sessions --only-sessionid --only-parent --only-ready";
- String output = device.executeShellCommand(cmdListReadySessions);
- if (output.trim().isEmpty()) {
- // No sessions to abandon
- return;
- }
- // Ensure we have sufficient privilege to abandon sessions from other apps
- device.enableAdbRoot();
- device.executeShellCommand("for i in $(" + cmdListReadySessions
- + "); do pm install-abandon $i; done");
- device.disableAdbRoot();
- }
-}