Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ababf87 authored by Kevin Han's avatar Kevin Han Committed by Android (Google) Code Review
Browse files

Merge "Introduce API to get hibernation stats"

parents 20f853ca caa924a1
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2356,12 +2356,21 @@ package android.apphibernation {
  public class AppHibernationManager {
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_APP_HIBERNATION) public java.util.List<java.lang.String> getHibernatingPackagesForUser();
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_APP_HIBERNATION) public java.util.Map<java.lang.String,android.apphibernation.HibernationStats> getHibernationStatsForUser(@NonNull java.util.Set<java.lang.String>);
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_APP_HIBERNATION) public java.util.Map<java.lang.String,android.apphibernation.HibernationStats> getHibernationStatsForUser();
    method @RequiresPermission(android.Manifest.permission.MANAGE_APP_HIBERNATION) public boolean isHibernatingForUser(@NonNull String);
    method @RequiresPermission(android.Manifest.permission.MANAGE_APP_HIBERNATION) public boolean isHibernatingGlobally(@NonNull String);
    method @RequiresPermission(android.Manifest.permission.MANAGE_APP_HIBERNATION) public void setHibernatingForUser(@NonNull String, boolean);
    method @RequiresPermission(android.Manifest.permission.MANAGE_APP_HIBERNATION) public void setHibernatingGlobally(@NonNull String, boolean);
  }
  public final class HibernationStats implements android.os.Parcelable {
    method public int describeContents();
    method public long getDiskBytesSaved();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.apphibernation.HibernationStats> CREATOR;
  }
}
package android.companion {
+37 −0
Original line number Diff line number Diff line
@@ -24,7 +24,10 @@ import android.content.Context;
import android.os.RemoteException;
import android.os.ServiceManager;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * This class provides an API surface for system apps to manipulate the app hibernation
@@ -129,4 +132,38 @@ public class AppHibernationManager {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns the stats from app hibernation for each package provided.
     *
     * @param packageNames the set of packages to return stats for
     * @hide
     */
    @SystemApi
    @RequiresPermission(value = android.Manifest.permission.MANAGE_APP_HIBERNATION)
    public @NonNull Map<String, HibernationStats> getHibernationStatsForUser(
            @NonNull Set<String> packageNames) {
        try {
            return mIAppHibernationService.getHibernationStatsForUser(
                    new ArrayList(packageNames), mContext.getUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns the stats from app hibernation for all packages for the user
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(value = android.Manifest.permission.MANAGE_APP_HIBERNATION)
    public @NonNull Map<String, HibernationStats> getHibernationStatsForUser() {
        try {
            return mIAppHibernationService.getHibernationStatsForUser(
                    null /* packageNames */, mContext.getUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
+19 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2022, 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.apphibernation;

parcelable HibernationStats;
 No newline at end of file
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.apphibernation;

import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * Stats for a hibernating package.
 * @hide
 */
@SystemApi
public final class HibernationStats implements Parcelable {
    private final long mDiskBytesSaved;

    /** @hide */
    public HibernationStats(long diskBytesSaved) {
        mDiskBytesSaved = diskBytesSaved;
    }

    private HibernationStats(@NonNull Parcel in) {
        mDiskBytesSaved = in.readLong();
    }

    /**
     * Get the disk storage saved from hibernation in bytes.
     */
    public long getDiskBytesSaved() {
        return mDiskBytesSaved;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeLong(mDiskBytesSaved);
    }

    public static final @NonNull Creator<HibernationStats> CREATOR =
            new Creator<HibernationStats>() {
        @Override
        public HibernationStats createFromParcel(Parcel in) {
            return new HibernationStats(in);
        }

        @Override
        public HibernationStats[] newArray(int size) {
            return new HibernationStats[size];
        }
    };
}
+4 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.apphibernation;

import android.apphibernation.HibernationStats;

/**
 * Binder interface to communicate with AppHibernationService.
 * @hide
@@ -26,4 +28,6 @@ interface IAppHibernationService {
    boolean isHibernatingGlobally(String packageName);
    void setHibernatingGlobally(String packageName, boolean isHibernating);
    List<String> getHibernatingPackagesForUser(int userId);
    Map<String, HibernationStats> getHibernationStatsForUser(in List<String> packageNames,
            int userId);
}
 No newline at end of file
Loading