Loading core/api/system-current.txt +10 −0 Original line number Diff line number Diff line Loading @@ -1411,6 +1411,15 @@ package android.app.usage { } package android.apphibernation { public final class AppHibernationManager { method public boolean isHibernating(@NonNull String); method public void setHibernating(@NonNull String, boolean); } } package android.bluetooth { public final class BluetoothA2dp implements android.bluetooth.BluetoothProfile { Loading Loading @@ -1707,6 +1716,7 @@ package android.content { method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public abstract void sendBroadcastAsUser(@RequiresPermission android.content.Intent, android.os.UserHandle, @Nullable String, @Nullable android.os.Bundle); method public abstract void sendOrderedBroadcast(@NonNull android.content.Intent, @Nullable String, @Nullable android.os.Bundle, @Nullable android.content.BroadcastReceiver, @Nullable android.os.Handler, int, @Nullable String, @Nullable android.os.Bundle); method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public void startActivityAsUser(@NonNull @RequiresPermission android.content.Intent, @NonNull android.os.UserHandle); field public static final String APP_HIBERNATION_SERVICE = "app_hibernation"; field public static final String APP_INTEGRITY_SERVICE = "app_integrity"; field public static final String APP_PREDICTION_SERVICE = "app_prediction"; field public static final String BACKUP_SERVICE = "backup"; Loading core/java/android/apphibernation/AppHibernationManager.java 0 → 100644 +79 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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.annotation.SystemService; import android.content.Context; import android.os.RemoteException; import android.os.ServiceManager; /** * This class provides an API surface for system apps to manipulate the app hibernation * state of a package for the user provided in the context. * @hide */ @SystemApi @SystemService(Context.APP_HIBERNATION_SERVICE) public final class AppHibernationManager { private static final String TAG = "AppHibernationManager"; private final Context mContext; private final IAppHibernationService mIAppHibernationService; /** * Creates a new instance. * * @param context The current context associated with the user * * @hide */ public AppHibernationManager(@NonNull Context context) { mContext = context; mIAppHibernationService = IAppHibernationService.Stub.asInterface( ServiceManager.getService(Context.APP_HIBERNATION_SERVICE)); } /** * Returns true if the package is hibernating, false otherwise. * * @hide */ @SystemApi public boolean isHibernating(@NonNull String packageName) { try { return mIAppHibernationService.isHibernating(packageName, mContext.getUserId()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Set whether the package is hibernating. * * @hide */ @SystemApi public void setHibernating(@NonNull String packageName, boolean isHibernating) { try { mIAppHibernationService.setHibernating(packageName, mContext.getUserId(), isHibernating); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } } core/java/android/apphibernation/IAppHibernationService.aidl 0 → 100644 +26 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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; /** * Binder interface to communicate with AppHibernationService. * @hide */ interface IAppHibernationService { boolean isHibernating(String packageName, int userId); void setHibernating(String packageName, int userId, boolean isHibernating); } No newline at end of file core/java/android/content/Context.java +11 −0 Original line number Diff line number Diff line Loading @@ -4538,6 +4538,17 @@ public abstract class Context { */ public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller"; /** * Use with {@link #getSystemService(String) to retrieve an * {@link android.apphibernation.AppHibernationManager}} for * communicating with the hibernation service. * @hide * * @see #getSystemService(String) */ @SystemApi public static final String APP_HIBERNATION_SERVICE = "app_hibernation"; /** * Use with {@link #getSystemService(String)} to retrieve an * {@link android.app.backup.IBackupManager IBackupManager} for communicating Loading services/core/java/com/android/server/apphibernation/AppHibernationService.java 0 → 100644 +111 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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.server.apphibernation; import static android.provider.DeviceConfig.NAMESPACE_APP_HIBERNATION; import android.annotation.NonNull; import android.apphibernation.IAppHibernationService; import android.content.Context; import android.provider.DeviceConfig; import com.android.server.SystemService; /** * System service that manages app hibernation state, a state apps can enter that means they are * not being actively used and can be optimized for storage. The actual policy for determining * if an app should hibernate is managed by PermissionController code. */ public final class AppHibernationService extends SystemService { private final Context mContext; /** * Initializes the system service. * <p> * Subclasses must define a single argument constructor that accepts the context * and passes it to super. * </p> * * @param context The system server context. */ public AppHibernationService(@NonNull Context context) { super(context); mContext = context; } @Override public void onStart() { publishBinderService(Context.APP_HIBERNATION_SERVICE, mServiceStub); } /** * Whether a package is hibernating for a given user. * * @param packageName the package to check * @param userId the user to check * @return true if package is hibernating for the user */ public boolean isHibernating(String packageName, int userId) { // Stub throw new UnsupportedOperationException("Hibernation state management not implemented yet"); } /** * Set whether the package is hibernating for the given user. * * @param packageName package to modify state * @param userId user * @param isHibernating new hibernation state */ public void setHibernating(String packageName, int userId, boolean isHibernating) { // Stub throw new UnsupportedOperationException("Hibernation state management not implemented yet"); } private final AppHibernationServiceStub mServiceStub = new AppHibernationServiceStub(this); static final class AppHibernationServiceStub extends IAppHibernationService.Stub { final AppHibernationService mService; AppHibernationServiceStub(AppHibernationService service) { mService = service; } @Override public boolean isHibernating(String packageName, int userId) { return mService.isHibernating(packageName, userId); } @Override public void setHibernating(String packageName, int userId, boolean isHibernating) { mService.setHibernating(packageName, userId, isHibernating); } } /** * Whether app hibernation is enabled on this device. * * @return true if enabled, false otherwise */ public static boolean isAppHibernationEnabled() { return DeviceConfig.getBoolean( NAMESPACE_APP_HIBERNATION, AppHibernationConstants.KEY_APP_HIBERNATION_ENABLED, false /* defaultValue */); } } Loading
core/api/system-current.txt +10 −0 Original line number Diff line number Diff line Loading @@ -1411,6 +1411,15 @@ package android.app.usage { } package android.apphibernation { public final class AppHibernationManager { method public boolean isHibernating(@NonNull String); method public void setHibernating(@NonNull String, boolean); } } package android.bluetooth { public final class BluetoothA2dp implements android.bluetooth.BluetoothProfile { Loading Loading @@ -1707,6 +1716,7 @@ package android.content { method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public abstract void sendBroadcastAsUser(@RequiresPermission android.content.Intent, android.os.UserHandle, @Nullable String, @Nullable android.os.Bundle); method public abstract void sendOrderedBroadcast(@NonNull android.content.Intent, @Nullable String, @Nullable android.os.Bundle, @Nullable android.content.BroadcastReceiver, @Nullable android.os.Handler, int, @Nullable String, @Nullable android.os.Bundle); method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public void startActivityAsUser(@NonNull @RequiresPermission android.content.Intent, @NonNull android.os.UserHandle); field public static final String APP_HIBERNATION_SERVICE = "app_hibernation"; field public static final String APP_INTEGRITY_SERVICE = "app_integrity"; field public static final String APP_PREDICTION_SERVICE = "app_prediction"; field public static final String BACKUP_SERVICE = "backup"; Loading
core/java/android/apphibernation/AppHibernationManager.java 0 → 100644 +79 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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.annotation.SystemService; import android.content.Context; import android.os.RemoteException; import android.os.ServiceManager; /** * This class provides an API surface for system apps to manipulate the app hibernation * state of a package for the user provided in the context. * @hide */ @SystemApi @SystemService(Context.APP_HIBERNATION_SERVICE) public final class AppHibernationManager { private static final String TAG = "AppHibernationManager"; private final Context mContext; private final IAppHibernationService mIAppHibernationService; /** * Creates a new instance. * * @param context The current context associated with the user * * @hide */ public AppHibernationManager(@NonNull Context context) { mContext = context; mIAppHibernationService = IAppHibernationService.Stub.asInterface( ServiceManager.getService(Context.APP_HIBERNATION_SERVICE)); } /** * Returns true if the package is hibernating, false otherwise. * * @hide */ @SystemApi public boolean isHibernating(@NonNull String packageName) { try { return mIAppHibernationService.isHibernating(packageName, mContext.getUserId()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Set whether the package is hibernating. * * @hide */ @SystemApi public void setHibernating(@NonNull String packageName, boolean isHibernating) { try { mIAppHibernationService.setHibernating(packageName, mContext.getUserId(), isHibernating); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } }
core/java/android/apphibernation/IAppHibernationService.aidl 0 → 100644 +26 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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; /** * Binder interface to communicate with AppHibernationService. * @hide */ interface IAppHibernationService { boolean isHibernating(String packageName, int userId); void setHibernating(String packageName, int userId, boolean isHibernating); } No newline at end of file
core/java/android/content/Context.java +11 −0 Original line number Diff line number Diff line Loading @@ -4538,6 +4538,17 @@ public abstract class Context { */ public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller"; /** * Use with {@link #getSystemService(String) to retrieve an * {@link android.apphibernation.AppHibernationManager}} for * communicating with the hibernation service. * @hide * * @see #getSystemService(String) */ @SystemApi public static final String APP_HIBERNATION_SERVICE = "app_hibernation"; /** * Use with {@link #getSystemService(String)} to retrieve an * {@link android.app.backup.IBackupManager IBackupManager} for communicating Loading
services/core/java/com/android/server/apphibernation/AppHibernationService.java 0 → 100644 +111 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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.server.apphibernation; import static android.provider.DeviceConfig.NAMESPACE_APP_HIBERNATION; import android.annotation.NonNull; import android.apphibernation.IAppHibernationService; import android.content.Context; import android.provider.DeviceConfig; import com.android.server.SystemService; /** * System service that manages app hibernation state, a state apps can enter that means they are * not being actively used and can be optimized for storage. The actual policy for determining * if an app should hibernate is managed by PermissionController code. */ public final class AppHibernationService extends SystemService { private final Context mContext; /** * Initializes the system service. * <p> * Subclasses must define a single argument constructor that accepts the context * and passes it to super. * </p> * * @param context The system server context. */ public AppHibernationService(@NonNull Context context) { super(context); mContext = context; } @Override public void onStart() { publishBinderService(Context.APP_HIBERNATION_SERVICE, mServiceStub); } /** * Whether a package is hibernating for a given user. * * @param packageName the package to check * @param userId the user to check * @return true if package is hibernating for the user */ public boolean isHibernating(String packageName, int userId) { // Stub throw new UnsupportedOperationException("Hibernation state management not implemented yet"); } /** * Set whether the package is hibernating for the given user. * * @param packageName package to modify state * @param userId user * @param isHibernating new hibernation state */ public void setHibernating(String packageName, int userId, boolean isHibernating) { // Stub throw new UnsupportedOperationException("Hibernation state management not implemented yet"); } private final AppHibernationServiceStub mServiceStub = new AppHibernationServiceStub(this); static final class AppHibernationServiceStub extends IAppHibernationService.Stub { final AppHibernationService mService; AppHibernationServiceStub(AppHibernationService service) { mService = service; } @Override public boolean isHibernating(String packageName, int userId) { return mService.isHibernating(packageName, userId); } @Override public void setHibernating(String packageName, int userId, boolean isHibernating) { mService.setHibernating(packageName, userId, isHibernating); } } /** * Whether app hibernation is enabled on this device. * * @return true if enabled, false otherwise */ public static boolean isAppHibernationEnabled() { return DeviceConfig.getBoolean( NAMESPACE_APP_HIBERNATION, AppHibernationConstants.KEY_APP_HIBERNATION_ENABLED, false /* defaultValue */); } }