summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libartservice/service/java/com/android/server/art/DexoptHelper.java25
-rw-r--r--libartservice/service/javatests/com/android/server/art/DexoptHelperTest.java35
2 files changed, 5 insertions, 55 deletions
diff --git a/libartservice/service/java/com/android/server/art/DexoptHelper.java b/libartservice/service/java/com/android/server/art/DexoptHelper.java
index fda43ca919..8f402918f6 100644
--- a/libartservice/service/java/com/android/server/art/DexoptHelper.java
+++ b/libartservice/service/java/com/android/server/art/DexoptHelper.java
@@ -28,7 +28,6 @@ import android.content.Context;
import android.os.Binder;
import android.os.Build;
import android.os.CancellationSignal;
-import android.os.PowerManager;
import android.os.RemoteException;
import android.os.WorkSource;
@@ -72,12 +71,6 @@ import java.util.stream.Collectors;
public class DexoptHelper {
private static final String TAG = ArtManagerLocal.TAG;
- /**
- * Timeout of the wake lock. This is required by AndroidLint, but we set it to a very large
- * value so that it should normally never triggered.
- */
- private static final long WAKE_LOCK_TIMEOUT_MS = TimeUnit.DAYS.toMillis(1);
-
@NonNull private final Injector mInjector;
public DexoptHelper(@NonNull Context context, @NonNull Config config) {
@@ -127,17 +120,10 @@ public class DexoptHelper {
@NonNull DexoptParams params, @NonNull CancellationSignal cancellationSignal,
@NonNull Executor dexoptExecutor, @Nullable Executor progressCallbackExecutor,
@Nullable Consumer<OperationProgress> progressCallback) {
- int callingUid = Binder.getCallingUid();
+ // TODO(jiakaiz): Find out whether this is still needed.
long identityToken = Binder.clearCallingIdentity();
- PowerManager.WakeLock wakeLock = null;
try {
- // Acquire a wake lock.
- PowerManager powerManager = mInjector.getPowerManager();
- wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
- wakeLock.setWorkSource(new WorkSource(callingUid));
- wakeLock.acquire(WAKE_LOCK_TIMEOUT_MS);
-
List<CompletableFuture<PackageDexoptResult>> futures = new ArrayList<>();
// Child threads will set their own listeners on the cancellation signal, so we must
@@ -205,9 +191,6 @@ public class DexoptHelper {
return result;
} finally {
- if (wakeLock != null) {
- wakeLock.release();
- }
Binder.restoreCallingIdentity(identityToken);
// Make sure nothing leaks even if the caller holds `cancellationSignal` forever.
cancellationSignal.setOnCancelListener(null);
@@ -340,7 +323,6 @@ public class DexoptHelper {
// Call the getters for the dependencies that aren't optional, to ensure correct
// initialization order.
getAppHibernationManager();
- getPowerManager();
}
@NonNull
@@ -365,11 +347,6 @@ public class DexoptHelper {
}
@NonNull
- public PowerManager getPowerManager() {
- return Objects.requireNonNull(mContext.getSystemService(PowerManager.class));
- }
-
- @NonNull
public Config getConfig() {
return mConfig;
}
diff --git a/libartservice/service/javatests/com/android/server/art/DexoptHelperTest.java b/libartservice/service/javatests/com/android/server/art/DexoptHelperTest.java
index eaad82d10c..527203b5a3 100644
--- a/libartservice/service/javatests/com/android/server/art/DexoptHelperTest.java
+++ b/libartservice/service/javatests/com/android/server/art/DexoptHelperTest.java
@@ -39,7 +39,6 @@ import static org.mockito.Mockito.when;
import android.apphibernation.AppHibernationManager;
import android.os.CancellationSignal;
-import android.os.PowerManager;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -96,8 +95,6 @@ public class DexoptHelperTest {
@Mock private PrimaryDexopter mPrimaryDexopter;
@Mock private SecondaryDexopter mSecondaryDexopter;
@Mock private AppHibernationManager mAhm;
- @Mock private PowerManager mPowerManager;
- @Mock private PowerManager.WakeLock mWakeLock;
@Mock private PackageManagerLocal.FilteredSnapshot mSnapshot;
private PackageState mPkgStateFoo;
private PackageState mPkgStateBar;
@@ -122,10 +119,6 @@ public class DexoptHelperTest {
@Before
public void setUp() throws Exception {
- lenient()
- .when(mPowerManager.newWakeLock(eq(PowerManager.PARTIAL_WAKE_LOCK), any()))
- .thenReturn(mWakeLock);
-
lenient().when(mAhm.isHibernatingGlobally(any())).thenReturn(false);
lenient().when(mAhm.isOatArtifactDeletionEnabled()).thenReturn(true);
@@ -161,7 +154,6 @@ public class DexoptHelperTest {
.build();
lenient().when(mInjector.getAppHibernationManager()).thenReturn(mAhm);
- lenient().when(mInjector.getPowerManager()).thenReturn(mPowerManager);
lenient().when(mInjector.getConfig()).thenReturn(mConfig);
mDexoptHelper = new DexoptHelper(mInjector);
@@ -205,13 +197,10 @@ public class DexoptHelperTest {
checkPackageResult(result, 5 /* index */, PKG_NAME_LIB4, DexoptResult.DEXOPT_PERFORMED,
List.of(mPrimaryResults, mSecondaryResults));
- // The order matters. It should acquire the wake lock only once, at the beginning, and
- // release the wake lock at the end. When running in a single thread, it should dexopt
- // primary dex files and the secondary dex files together for each package, and it should
- // dexopt requested packages, in the given order, and then dexopt dependencies.
- InOrder inOrder = inOrder(mInjector, mWakeLock);
- inOrder.verify(mWakeLock).setWorkSource(any());
- inOrder.verify(mWakeLock).acquire(anyLong());
+ // The order matters. When running in a single thread, it should dexopt primary dex files
+ // and the secondary dex files together for each package, and it should dexopt requested
+ // packages, in the given order, and then dexopt dependencies.
+ InOrder inOrder = inOrder(mInjector);
inOrder.verify(mInjector).getPrimaryDexopter(
same(mPkgStateFoo), same(mPkgFoo), same(mParams), any());
inOrder.verify(mInjector).getSecondaryDexopter(
@@ -236,11 +225,8 @@ public class DexoptHelperTest {
same(mPkgStateLib4), same(mPkgLib4), same(mParams), any());
inOrder.verify(mInjector).getSecondaryDexopter(
same(mPkgStateLib4), same(mPkgLib4), same(mParams), any());
- inOrder.verify(mWakeLock).release();
verifyNoMoreDexopt(6 /* expectedPrimaryTimes */, 6 /* expectedSecondaryTimes */);
-
- verifyNoMoreInteractions(mWakeLock);
}
@Test
@@ -519,19 +505,6 @@ public class DexoptHelperTest {
List.of(mPrimaryResults, mSecondaryResults));
}
- @Test
- public void testDexoptAlwaysReleasesWakeLock() throws Exception {
- when(mPrimaryDexopter.dexopt()).thenThrow(IllegalStateException.class);
-
- try {
- mDexoptHelper.dexopt(
- mSnapshot, mRequestedPackages, mParams, mCancellationSignal, mExecutor);
- } catch (Exception ignored) {
- }
-
- verify(mWakeLock).release();
- }
-
@Test(expected = IllegalArgumentException.class)
public void testDexoptPackageNotFound() throws Exception {
when(mSnapshot.getPackageState(any())).thenReturn(null);