diff options
| author | Zimuzo Ezeozue <zezeozue@google.com> | 2019-04-25 09:58:52 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-04-25 09:58:52 +0000 |
| commit | 0f6db7d1ddb434518fcdf535b857bb952c56ceba (patch) | |
| tree | f8f5e96cba5109b5f9bff52e81cb3d5f620ae203 /core/java | |
| parent | 515e9b3b6359dac68491159ec9826a96a7d3aa43 (diff) | |
| parent | 1a9aac7b33284898a362b696c4604ccabbce51f5 (diff) | |
Merge "Change watchdog PackageInfo to PackageConfig" into qt-dev
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/service/watchdog/ExplicitHealthCheckService.java | 119 | ||||
| -rw-r--r-- | core/java/android/service/watchdog/PackageConfig.aidl (renamed from core/java/android/service/watchdog/PackageInfo.aidl) | 2 | ||||
| -rw-r--r-- | core/java/android/service/watchdog/PackageInfo.java | 130 |
3 files changed, 117 insertions, 134 deletions
diff --git a/core/java/android/service/watchdog/ExplicitHealthCheckService.java b/core/java/android/service/watchdog/ExplicitHealthCheckService.java index 682b872d676b..eeefb4ae10fa 100644 --- a/core/java/android/service/watchdog/ExplicitHealthCheckService.java +++ b/core/java/android/service/watchdog/ExplicitHealthCheckService.java @@ -16,6 +16,8 @@ package android.service.watchdog; +import static android.os.Parcelable.Creator; + import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SdkConstant; @@ -26,13 +28,18 @@ import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Looper; +import android.os.Parcel; +import android.os.Parcelable; import android.os.RemoteCallback; import android.os.RemoteException; import android.util.Log; +import com.android.internal.util.Preconditions; + import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.concurrent.TimeUnit; /** * A service to provide packages supporting explicit health checks and route checks to these @@ -61,7 +68,7 @@ public abstract class ExplicitHealthCheckService extends Service { private static final String TAG = "ExplicitHealthCheckService"; /** - * {@link Bundle} key for a {@link List} of {@link PackageInfo} value. + * {@link Bundle} key for a {@link List} of {@link PackageConfig} value. * * {@hide} */ @@ -130,7 +137,7 @@ public abstract class ExplicitHealthCheckService extends Service { * * @return all packages supporting explicit health checks */ - @NonNull public abstract List<PackageInfo> onGetSupportedPackages(); + @NonNull public abstract List<PackageConfig> onGetSupportedPackages(); /** * Called when the system requests for all the packages that it has currently requested @@ -167,6 +174,112 @@ public abstract class ExplicitHealthCheckService extends Service { }); } + /** + * A PackageConfig contains a package supporting explicit health checks and the + * timeout in {@link System#uptimeMillis} across reboots after which health + * check requests from clients are failed. + * + * @hide + */ + @SystemApi + public static final class PackageConfig implements Parcelable { + // TODO: Receive from DeviceConfig flag + private static final long DEFAULT_HEALTH_CHECK_TIMEOUT_MILLIS = TimeUnit.HOURS.toMillis(1); + + private final String mPackageName; + private final long mHealthCheckTimeoutMillis; + + /** + * Creates a new instance. + * + * @param packageName the package name + * @param durationMillis the duration in milliseconds, must be greater than or + * equal to 0. If it is 0, it will use a system default value. + */ + public PackageConfig(@NonNull String packageName, long healthCheckTimeoutMillis) { + mPackageName = Preconditions.checkNotNull(packageName); + if (healthCheckTimeoutMillis == 0) { + mHealthCheckTimeoutMillis = DEFAULT_HEALTH_CHECK_TIMEOUT_MILLIS; + } else { + mHealthCheckTimeoutMillis = Preconditions.checkArgumentNonnegative( + healthCheckTimeoutMillis); + } + } + + private PackageConfig(Parcel parcel) { + mPackageName = parcel.readString(); + mHealthCheckTimeoutMillis = parcel.readLong(); + } + + /** + * Gets the package name. + * + * @return the package name + */ + public @NonNull String getPackageName() { + return mPackageName; + } + + /** + * Gets the timeout in milliseconds to evaluate an explicit health check result after a + * request. + * + * @return the duration in {@link System#uptimeMillis} across reboots + */ + public long getHealthCheckTimeoutMillis() { + return mHealthCheckTimeoutMillis; + } + + @Override + public String toString() { + return "PackageConfig{" + mPackageName + ", " + mHealthCheckTimeoutMillis + "}"; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof PackageConfig)) { + return false; + } + + PackageConfig otherInfo = (PackageConfig) other; + return Objects.equals(otherInfo.getHealthCheckTimeoutMillis(), + mHealthCheckTimeoutMillis) + && Objects.equals(otherInfo.getPackageName(), mPackageName); + } + + @Override + public int hashCode() { + return Objects.hash(mPackageName, mHealthCheckTimeoutMillis); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int flags) { + parcel.writeString(mPackageName); + parcel.writeLong(mHealthCheckTimeoutMillis); + } + + public static final @NonNull Creator<PackageConfig> CREATOR = new Creator<PackageConfig>() { + @Override + public PackageConfig createFromParcel(Parcel source) { + return new PackageConfig(source); + } + + @Override + public PackageConfig[] newArray(int size) { + return new PackageConfig[size]; + } + }; + } + + private class ExplicitHealthCheckServiceWrapper extends IExplicitHealthCheckService.Stub { @Override public void setCallback(RemoteCallback callback) throws RemoteException { @@ -188,7 +301,7 @@ public abstract class ExplicitHealthCheckService extends Service { @Override public void getSupportedPackages(RemoteCallback callback) throws RemoteException { mHandler.post(() -> { - List<PackageInfo> packages = + List<PackageConfig> packages = ExplicitHealthCheckService.this.onGetSupportedPackages(); Objects.requireNonNull(packages, "Supported package list must be non-null"); Bundle bundle = new Bundle(); diff --git a/core/java/android/service/watchdog/PackageInfo.aidl b/core/java/android/service/watchdog/PackageConfig.aidl index 5605aec1c4fe..013158676f79 100644 --- a/core/java/android/service/watchdog/PackageInfo.aidl +++ b/core/java/android/service/watchdog/PackageConfig.aidl @@ -19,4 +19,4 @@ package android.service.watchdog; /** * @hide */ -parcelable PackageInfo; +parcelable PackageConfig; diff --git a/core/java/android/service/watchdog/PackageInfo.java b/core/java/android/service/watchdog/PackageInfo.java deleted file mode 100644 index cee9b6d0fbf9..000000000000 --- a/core/java/android/service/watchdog/PackageInfo.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2019 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 android.service.watchdog; - -import android.annotation.NonNull; -import android.annotation.SystemApi; -import android.os.Parcel; -import android.os.Parcelable; - -import com.android.internal.util.Preconditions; - -import java.util.Objects; -import java.util.concurrent.TimeUnit; - -/** - * A PackageInfo contains a package supporting explicit health checks and the - * timeout in {@link System#uptimeMillis} across reboots after which health - * check requests from clients are failed. - * - * @hide - */ -@SystemApi -public final class PackageInfo implements Parcelable { - // TODO: Receive from DeviceConfig flag - private static final long DEFAULT_HEALTH_CHECK_TIMEOUT_MILLIS = TimeUnit.HOURS.toMillis(1); - - private final String mPackageName; - private final long mHealthCheckTimeoutMillis; - - /** - * Creates a new instance. - * - * @param packageName the package name - * @param durationMillis the duration in milliseconds, must be greater than or - * equal to 0. If it is 0, it will use a system default value. - */ - public PackageInfo(@NonNull String packageName, long healthCheckTimeoutMillis) { - mPackageName = Preconditions.checkNotNull(packageName); - if (healthCheckTimeoutMillis == 0) { - mHealthCheckTimeoutMillis = DEFAULT_HEALTH_CHECK_TIMEOUT_MILLIS; - } else { - mHealthCheckTimeoutMillis = Preconditions.checkArgumentNonnegative( - healthCheckTimeoutMillis); - } - } - - private PackageInfo(Parcel parcel) { - mPackageName = parcel.readString(); - mHealthCheckTimeoutMillis = parcel.readLong(); - } - - /** - * Gets the package name. - * - * @return the package name - */ - public @NonNull String getPackageName() { - return mPackageName; - } - - /** - * Gets the timeout in milliseconds to evaluate an explicit health check result after a request. - * - * @return the duration in {@link System#uptimeMillis} across reboots - */ - public long getHealthCheckTimeoutMillis() { - return mHealthCheckTimeoutMillis; - } - - @Override - public String toString() { - return "PackageInfo{" + mPackageName + ", " + mHealthCheckTimeoutMillis + "}"; - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - if (!(other instanceof PackageInfo)) { - return false; - } - - PackageInfo otherInfo = (PackageInfo) other; - return Objects.equals(otherInfo.getHealthCheckTimeoutMillis(), mHealthCheckTimeoutMillis) - && Objects.equals(otherInfo.getPackageName(), mPackageName); - } - - @Override - public int hashCode() { - return Objects.hash(mPackageName, mHealthCheckTimeoutMillis); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int flags) { - parcel.writeString(mPackageName); - parcel.writeLong(mHealthCheckTimeoutMillis); - } - - public static final @NonNull Creator<PackageInfo> CREATOR = new Creator<PackageInfo>() { - @Override - public PackageInfo createFromParcel(Parcel source) { - return new PackageInfo(source); - } - - @Override - public PackageInfo[] newArray(int size) { - return new PackageInfo[size]; - } - }; -} |
