Loading core/java/android/app/ActivityManagerInternal.java +27 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.content.ComponentName; import android.content.IIntentReceiver; import android.content.IIntentSender; import android.content.Intent; import android.content.ServiceConnection; import android.content.pm.ActivityInfo; import android.content.pm.ActivityPresentationInfo; import android.content.pm.ApplicationInfo; Loading Loading @@ -922,4 +923,30 @@ public abstract class ActivityManagerInternal { * @param callingPid The PID mapped with the callback. */ public abstract void unregisterStrictModeCallback(int callingPid); /** * Start a foreground service delegate. * @param options foreground service delegate options. * @param connection a service connection served as callback to caller. * @return true if delegate is started successfully, false otherwise. * @hide */ public abstract boolean startForegroundServiceDelegate( @NonNull ForegroundServiceDelegationOptions options, @Nullable ServiceConnection connection); /** * Stop a foreground service delegate. * @param options the foreground service delegate options. * @hide */ public abstract void stopForegroundServiceDelegate( @NonNull ForegroundServiceDelegationOptions options); /** * Stop a foreground service delegate by service connection. * @param connection service connection used to start delegate previously. * @hide */ public abstract void stopForegroundServiceDelegate(@NonNull ServiceConnection connection); } services/core/java/com/android/server/am/ForegroundServiceDelegationOptions.java→core/java/android/app/ForegroundServiceDelegationOptions.java +39 −3 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * Copyright (C) 2023 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. Loading @@ -14,12 +14,11 @@ * limitations under the License. */ package com.android.server.am; package android.app; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.IApplicationThread; import android.content.ComponentName; import java.lang.annotation.Retention; Loading @@ -32,6 +31,8 @@ import java.lang.annotation.RetentionPolicy; * is higher than the app's actual process state if the app is in the background. This can help to * keep the app in the memory and extra run-time. * The app does not need to define an actual service component nor add it into manifest file. * * @hide */ public class ForegroundServiceDelegationOptions { Loading Loading @@ -191,6 +192,11 @@ public class ForegroundServiceDelegationOptions { } } /** * The helper class to build the instance of {@link ForegroundServiceDelegate}. * * @hide */ public static class Builder { int mClientPid; // The actual app PID int mClientUid; // The actual app UID Loading @@ -202,51 +208,81 @@ public class ForegroundServiceDelegationOptions { int mForegroundServiceTypes; // The foreground service types it consists of @DelegationService int mDelegationService; // The internal service's name, i.e. VOIP /** * Set the client app's PID. */ public Builder setClientPid(int clientPid) { mClientPid = clientPid; return this; } /** * Set the client app's UID. */ public Builder setClientUid(int clientUid) { mClientUid = clientUid; return this; } /** * Set the client app's package name. */ public Builder setClientPackageName(@NonNull String clientPackageName) { mClientPackageName = clientPackageName; return this; } /** * Set the notification ID from the client app. */ public Builder setClientNotificationId(int clientNotificationId) { mClientNotificationId = clientNotificationId; return this; } /** * Set the client app's application thread. */ public Builder setClientAppThread(@NonNull IApplicationThread clientAppThread) { mClientAppThread = clientAppThread; return this; } /** * Set the client instance of this service. */ public Builder setClientInstanceName(@NonNull String clientInstanceName) { mClientInstanceName = clientInstanceName; return this; } /** * Set stickiness of this service. */ public Builder setSticky(boolean isSticky) { mSticky = isSticky; return this; } /** * Set the foreground service type. */ public Builder setForegroundServiceTypes(int foregroundServiceTypes) { mForegroundServiceTypes = foregroundServiceTypes; return this; } /** * Set the delegation service type. */ public Builder setDelegationService(@DelegationService int delegationService) { mDelegationService = delegationService; return this; } /** * @return An instance of {@link ForegroundServiceDelegationOptions}. */ public ForegroundServiceDelegationOptions build() { return new ForegroundServiceDelegationOptions(mClientPid, mClientUid, Loading services/core/java/com/android/server/am/ActiveServices.java +1 −0 Original line number Diff line number Diff line Loading @@ -112,6 +112,7 @@ import android.app.ActivityManagerInternal.ServiceNotificationPolicy; import android.app.ActivityThread; import android.app.AppGlobals; import android.app.AppOpsManager; import android.app.ForegroundServiceDelegationOptions; import android.app.ForegroundServiceStartNotAllowedException; import android.app.ForegroundServiceTypePolicy; import android.app.ForegroundServiceTypePolicy.ForegroundServicePolicyCheckCode; Loading services/core/java/com/android/server/am/ActivityManagerLocal.java +0 −25 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ package com.android.server.am; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.content.Context; Loading Loading @@ -118,28 +117,4 @@ public interface ActivityManagerLocal { * sandbox. This is obtained using {@link Context#getIApplicationThreadBinder()}. */ void killSdkSandboxClientAppProcess(@NonNull IBinder clientApplicationThreadBinder); /** * Start a foreground service delegate. * @param options foreground service delegate options. * @param connection a service connection served as callback to caller. * @return true if delegate is started successfully, false otherwise. * @hide */ boolean startForegroundServiceDelegate(@NonNull ForegroundServiceDelegationOptions options, @Nullable ServiceConnection connection); /** * Stop a foreground service delegate. * @param options the foreground service delegate options. * @hide */ void stopForegroundServiceDelegate(@NonNull ForegroundServiceDelegationOptions options); /** * Stop a foreground service delegate by service connection. * @param connection service connection used to start delegate previously. * @hide */ void stopForegroundServiceDelegate(@NonNull ServiceConnection connection); } services/core/java/com/android/server/am/ActivityManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -186,6 +186,7 @@ import android.app.ApplicationThreadConstants; import android.app.BroadcastOptions; import android.app.ComponentOptions; import android.app.ContentProviderHolder; import android.app.ForegroundServiceDelegationOptions; import android.app.IActivityController; import android.app.IActivityManager; import android.app.IApplicationThread; Loading Loading @@ -18604,10 +18605,10 @@ public class ActivityManagerService extends IActivityManager.Stub for (int i = delegates.size() - 1; i >= 0; i--) { final ForegroundServiceDelegationOptions options = delegates.get(i); if (isStart) { ((ActivityManagerLocal) mInternal).startForegroundServiceDelegate(options, mInternal.startForegroundServiceDelegate(options, null /* connection */); } else { ((ActivityManagerLocal) mInternal).stopForegroundServiceDelegate(options); mInternal.stopForegroundServiceDelegate(options); } } } Loading
core/java/android/app/ActivityManagerInternal.java +27 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.content.ComponentName; import android.content.IIntentReceiver; import android.content.IIntentSender; import android.content.Intent; import android.content.ServiceConnection; import android.content.pm.ActivityInfo; import android.content.pm.ActivityPresentationInfo; import android.content.pm.ApplicationInfo; Loading Loading @@ -922,4 +923,30 @@ public abstract class ActivityManagerInternal { * @param callingPid The PID mapped with the callback. */ public abstract void unregisterStrictModeCallback(int callingPid); /** * Start a foreground service delegate. * @param options foreground service delegate options. * @param connection a service connection served as callback to caller. * @return true if delegate is started successfully, false otherwise. * @hide */ public abstract boolean startForegroundServiceDelegate( @NonNull ForegroundServiceDelegationOptions options, @Nullable ServiceConnection connection); /** * Stop a foreground service delegate. * @param options the foreground service delegate options. * @hide */ public abstract void stopForegroundServiceDelegate( @NonNull ForegroundServiceDelegationOptions options); /** * Stop a foreground service delegate by service connection. * @param connection service connection used to start delegate previously. * @hide */ public abstract void stopForegroundServiceDelegate(@NonNull ServiceConnection connection); }
services/core/java/com/android/server/am/ForegroundServiceDelegationOptions.java→core/java/android/app/ForegroundServiceDelegationOptions.java +39 −3 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * Copyright (C) 2023 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. Loading @@ -14,12 +14,11 @@ * limitations under the License. */ package com.android.server.am; package android.app; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.IApplicationThread; import android.content.ComponentName; import java.lang.annotation.Retention; Loading @@ -32,6 +31,8 @@ import java.lang.annotation.RetentionPolicy; * is higher than the app's actual process state if the app is in the background. This can help to * keep the app in the memory and extra run-time. * The app does not need to define an actual service component nor add it into manifest file. * * @hide */ public class ForegroundServiceDelegationOptions { Loading Loading @@ -191,6 +192,11 @@ public class ForegroundServiceDelegationOptions { } } /** * The helper class to build the instance of {@link ForegroundServiceDelegate}. * * @hide */ public static class Builder { int mClientPid; // The actual app PID int mClientUid; // The actual app UID Loading @@ -202,51 +208,81 @@ public class ForegroundServiceDelegationOptions { int mForegroundServiceTypes; // The foreground service types it consists of @DelegationService int mDelegationService; // The internal service's name, i.e. VOIP /** * Set the client app's PID. */ public Builder setClientPid(int clientPid) { mClientPid = clientPid; return this; } /** * Set the client app's UID. */ public Builder setClientUid(int clientUid) { mClientUid = clientUid; return this; } /** * Set the client app's package name. */ public Builder setClientPackageName(@NonNull String clientPackageName) { mClientPackageName = clientPackageName; return this; } /** * Set the notification ID from the client app. */ public Builder setClientNotificationId(int clientNotificationId) { mClientNotificationId = clientNotificationId; return this; } /** * Set the client app's application thread. */ public Builder setClientAppThread(@NonNull IApplicationThread clientAppThread) { mClientAppThread = clientAppThread; return this; } /** * Set the client instance of this service. */ public Builder setClientInstanceName(@NonNull String clientInstanceName) { mClientInstanceName = clientInstanceName; return this; } /** * Set stickiness of this service. */ public Builder setSticky(boolean isSticky) { mSticky = isSticky; return this; } /** * Set the foreground service type. */ public Builder setForegroundServiceTypes(int foregroundServiceTypes) { mForegroundServiceTypes = foregroundServiceTypes; return this; } /** * Set the delegation service type. */ public Builder setDelegationService(@DelegationService int delegationService) { mDelegationService = delegationService; return this; } /** * @return An instance of {@link ForegroundServiceDelegationOptions}. */ public ForegroundServiceDelegationOptions build() { return new ForegroundServiceDelegationOptions(mClientPid, mClientUid, Loading
services/core/java/com/android/server/am/ActiveServices.java +1 −0 Original line number Diff line number Diff line Loading @@ -112,6 +112,7 @@ import android.app.ActivityManagerInternal.ServiceNotificationPolicy; import android.app.ActivityThread; import android.app.AppGlobals; import android.app.AppOpsManager; import android.app.ForegroundServiceDelegationOptions; import android.app.ForegroundServiceStartNotAllowedException; import android.app.ForegroundServiceTypePolicy; import android.app.ForegroundServiceTypePolicy.ForegroundServicePolicyCheckCode; Loading
services/core/java/com/android/server/am/ActivityManagerLocal.java +0 −25 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ package com.android.server.am; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.content.Context; Loading Loading @@ -118,28 +117,4 @@ public interface ActivityManagerLocal { * sandbox. This is obtained using {@link Context#getIApplicationThreadBinder()}. */ void killSdkSandboxClientAppProcess(@NonNull IBinder clientApplicationThreadBinder); /** * Start a foreground service delegate. * @param options foreground service delegate options. * @param connection a service connection served as callback to caller. * @return true if delegate is started successfully, false otherwise. * @hide */ boolean startForegroundServiceDelegate(@NonNull ForegroundServiceDelegationOptions options, @Nullable ServiceConnection connection); /** * Stop a foreground service delegate. * @param options the foreground service delegate options. * @hide */ void stopForegroundServiceDelegate(@NonNull ForegroundServiceDelegationOptions options); /** * Stop a foreground service delegate by service connection. * @param connection service connection used to start delegate previously. * @hide */ void stopForegroundServiceDelegate(@NonNull ServiceConnection connection); }
services/core/java/com/android/server/am/ActivityManagerService.java +3 −2 Original line number Diff line number Diff line Loading @@ -186,6 +186,7 @@ import android.app.ApplicationThreadConstants; import android.app.BroadcastOptions; import android.app.ComponentOptions; import android.app.ContentProviderHolder; import android.app.ForegroundServiceDelegationOptions; import android.app.IActivityController; import android.app.IActivityManager; import android.app.IApplicationThread; Loading Loading @@ -18604,10 +18605,10 @@ public class ActivityManagerService extends IActivityManager.Stub for (int i = delegates.size() - 1; i >= 0; i--) { final ForegroundServiceDelegationOptions options = delegates.get(i); if (isStart) { ((ActivityManagerLocal) mInternal).startForegroundServiceDelegate(options, mInternal.startForegroundServiceDelegate(options, null /* connection */); } else { ((ActivityManagerLocal) mInternal).stopForegroundServiceDelegate(options); mInternal.stopForegroundServiceDelegate(options); } } }