Update ArtManagerLocal constructor to take the context.
ART Services needs the context for:
1. Getting PowerManager and AppHibernationManager
2. Getting resource strings such as R.string.config_systemUi
Bug: 236954191
Test: adb shell pm art optimize-package -m speed-profile -f \
com.google.android.youtube
Ignore-AOSP-First: ART Services
Change-Id: I47d79e251fa5a1e327c6db8fd08f2a0e76a1e492
diff --git a/libartservice/service/api/system-server-current.txt b/libartservice/service/api/system-server-current.txt
index d35f8c7..1e8711b 100644
--- a/libartservice/service/api/system-server-current.txt
+++ b/libartservice/service/api/system-server-current.txt
@@ -2,7 +2,8 @@
package com.android.server.art {
public final class ArtManagerLocal {
- ctor public ArtManagerLocal();
+ ctor @Deprecated public ArtManagerLocal();
+ ctor public ArtManagerLocal(@NonNull android.content.Context);
method @NonNull public com.android.server.art.model.DeleteResult deleteOptimizedArtifacts(@NonNull com.android.server.pm.snapshot.PackageDataSnapshot, @NonNull String);
method @NonNull public com.android.server.art.model.DeleteResult deleteOptimizedArtifacts(@NonNull com.android.server.pm.snapshot.PackageDataSnapshot, @NonNull String, int);
method @NonNull public com.android.server.art.model.OptimizationStatus getOptimizationStatus(@NonNull com.android.server.pm.snapshot.PackageDataSnapshot, @NonNull String);
diff --git a/libartservice/service/java/com/android/server/art/ArtManagerLocal.java b/libartservice/service/java/com/android/server/art/ArtManagerLocal.java
index cf083cc..594b89e 100644
--- a/libartservice/service/java/com/android/server/art/ArtManagerLocal.java
+++ b/libartservice/service/java/com/android/server/art/ArtManagerLocal.java
@@ -64,13 +64,11 @@
@NonNull private final Injector mInjector;
- // TODO(b/236954191): Deprecate this.
+ @Deprecated
public ArtManagerLocal() {
- this(new Injector());
+ this(new Injector(null /* context */));
}
- // TODO(b/236954191): Expose this.
- /** @hide */
public ArtManagerLocal(@NonNull Context context) {
this(new Injector(context));
}
@@ -273,10 +271,6 @@
@Nullable private final Context mContext;
@Nullable private final PackageManagerLocal mPackageManagerLocal;
- Injector() {
- this(null /* context */);
- }
-
Injector(@Nullable Context context) {
mContext = context;
@@ -294,9 +288,11 @@
mPackageManagerLocal = packageManagerLocal;
}
- // TODO(b/236954191): Make this @NonNull.
- @Nullable
+ @NonNull
public Context getContext() {
+ if (mContext == null) {
+ throw new IllegalStateException("Context is null");
+ }
return mContext;
}
diff --git a/libartservice/service/java/com/android/server/art/DexOptHelper.java b/libartservice/service/java/com/android/server/art/DexOptHelper.java
index 64060ca..f6df0c3 100644
--- a/libartservice/service/java/com/android/server/art/DexOptHelper.java
+++ b/libartservice/service/java/com/android/server/art/DexOptHelper.java
@@ -56,7 +56,7 @@
@NonNull private final Injector mInjector;
- public DexOptHelper(@Nullable Context context) {
+ public DexOptHelper(@NonNull Context context) {
this(new Injector(context));
}
@@ -147,10 +147,9 @@
*/
@VisibleForTesting
public static class Injector {
- // TODO(b/236954191): Make this @NonNull.
- @Nullable private final Context mContext;
+ @NonNull private final Context mContext;
- Injector(@Nullable Context context) {
+ Injector(@NonNull Context context) {
mContext = context;
}
@@ -159,14 +158,16 @@
return new PrimaryDexOptimizer(mContext);
}
+ // TODO(b/244289352): Investigate whether this can be @NonNull.
@Nullable
public AppHibernationManager getAppHibernationManager() {
- return mContext != null ? mContext.getSystemService(AppHibernationManager.class) : null;
+ return mContext.getSystemService(AppHibernationManager.class);
}
+ // TODO(b/244289352): Investigate whether this can be @NonNull.
@Nullable
public PowerManager getPowerManager() {
- return mContext != null ? mContext.getSystemService(PowerManager.class) : null;
+ return mContext.getSystemService(PowerManager.class);
}
}
}
diff --git a/libartservice/service/java/com/android/server/art/PrimaryDexOptimizer.java b/libartservice/service/java/com/android/server/art/PrimaryDexOptimizer.java
index 1336889..49708b3 100644
--- a/libartservice/service/java/com/android/server/art/PrimaryDexOptimizer.java
+++ b/libartservice/service/java/com/android/server/art/PrimaryDexOptimizer.java
@@ -50,7 +50,7 @@
@NonNull private final Injector mInjector;
- public PrimaryDexOptimizer(@Nullable Context context) {
+ public PrimaryDexOptimizer(@NonNull Context context) {
this(new Injector(context));
}
@@ -305,17 +305,13 @@
*/
@VisibleForTesting
public static class Injector {
- // TODO(b/236954191): Make this @NonNull.
- @Nullable private final Context mContext;
+ @NonNull private final Context mContext;
- Injector(@Nullable Context context) {
+ Injector(@NonNull Context context) {
mContext = context;
}
boolean isSystemUiPackage(@NonNull String packageName) {
- if (mContext == null) {
- return false;
- }
return packageName.equals(mContext.getString(R.string.config_systemUi));
}