diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index c79c28ccc4975..d56a937fff4ba 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -161,7 +161,7 @@ package android {
field public static final String LOCAL_MAC_ADDRESS = "android.permission.LOCAL_MAC_ADDRESS";
field public static final String LOCATION_BYPASS = "android.permission.LOCATION_BYPASS";
field public static final String LOCK_DEVICE = "android.permission.LOCK_DEVICE";
- field public static final String LOG_PROCESS_ACTIVITIES = "android.permission.LOG_PROCESS_ACTIVITIES";
+ field public static final String LOG_FOREGROUND_RESOURCE_USE = "android.permission.LOG_FOREGROUND_RESOURCE_USE";
field public static final String LOOP_RADIO = "android.permission.LOOP_RADIO";
field public static final String MANAGE_ACCESSIBILITY = "android.permission.MANAGE_ACCESSIBILITY";
field @Deprecated public static final String MANAGE_ACTIVITY_STACKS = "android.permission.MANAGE_ACTIVITY_STACKS";
@@ -538,15 +538,15 @@ package android.app {
method @RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) public int getUidImportance(int);
method @RequiresPermission(android.Manifest.permission.FORCE_STOP_PACKAGES) public void killProcessesWhenImperceptible(@NonNull int[], @NonNull String);
method @RequiresPermission(android.Manifest.permission.KILL_UID) public void killUid(int, String);
- method @RequiresPermission(android.Manifest.permission.LOG_PROCESS_ACTIVITIES) public void noteForegroundResourceUse(int, int, int, int);
+ method @RequiresPermission(android.Manifest.permission.LOG_FOREGROUND_RESOURCE_USE) public void noteForegroundResourceUseBegin(int, int, int) throws java.lang.SecurityException;
+ method @RequiresPermission(android.Manifest.permission.LOG_FOREGROUND_RESOURCE_USE) public void noteForegroundResourceUseEnd(int, int, int) throws java.lang.SecurityException;
method @RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) public void removeOnUidImportanceListener(android.app.ActivityManager.OnUidImportanceListener);
method public void setDeviceLocales(@NonNull android.os.LocaleList);
method @RequiresPermission(android.Manifest.permission.RESTRICTED_VR_ACCESS) public static void setPersistentVrThread(int);
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) public boolean startProfile(@NonNull android.os.UserHandle);
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) public boolean stopProfile(@NonNull android.os.UserHandle);
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public boolean switchUser(@NonNull android.os.UserHandle);
- field public static final int FOREGROUND_SERVICE_API_EVENT_BEGIN = 1; // 0x1
- field public static final int FOREGROUND_SERVICE_API_EVENT_END = 2; // 0x2
+ field public static final int FOREGROUND_SERVICE_API_TYPE_AUDIO = 5; // 0x5
field public static final int FOREGROUND_SERVICE_API_TYPE_BLUETOOTH = 2; // 0x2
field public static final int FOREGROUND_SERVICE_API_TYPE_CAMERA = 1; // 0x1
field public static final int FOREGROUND_SERVICE_API_TYPE_CDM = 9; // 0x9
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index b4068dbf07979..ff75098ae5e82 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -666,6 +666,7 @@ public class ActivityManager {
* Used to log FGS API events from Audio API
* @hide
*/
+ @SystemApi
public static final int FOREGROUND_SERVICE_API_TYPE_AUDIO = 5;
/**
* Used to log FGS API events from microphone API
@@ -715,13 +716,11 @@ public class ActivityManager {
* Used to log a start event for an FGS API
* @hide
*/
- @SystemApi
public static final int FOREGROUND_SERVICE_API_EVENT_BEGIN = 1;
/**
* Used to log a stop event for an FGS API
* @hide
*/
- @SystemApi
public static final int FOREGROUND_SERVICE_API_EVENT_END = 2;
/**
* Constants used to denote API state
@@ -5617,23 +5616,32 @@ public class ActivityManager {
*
*/
@SystemApi
- @RequiresPermission(android.Manifest.permission.LOG_PROCESS_ACTIVITIES)
- public void noteForegroundResourceUse(@ForegroundServiceApiType int apiType,
- @ForegroundServiceApiEvent int apiEvent, int uid, int pid) {
+ @RequiresPermission(android.Manifest.permission.LOG_FOREGROUND_RESOURCE_USE)
+ public void noteForegroundResourceUseBegin(@ForegroundServiceApiType int apiType,
+ int uid, int pid) throws SecurityException {
try {
- switch (apiEvent) {
- case FOREGROUND_SERVICE_API_EVENT_BEGIN:
- getService().logFgsApiBegin(apiType, uid, pid);
- break;
- case FOREGROUND_SERVICE_API_EVENT_END:
- getService().logFgsApiEnd(apiType, uid, pid);
- break;
- default:
- throw new IllegalArgumentException("Argument of "
- + apiType + " not supported for foreground resource use logging");
- }
+ getService().logFgsApiBegin(apiType, uid, pid);
} catch (RemoteException e) {
- e.rethrowFromSystemServer();
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Internal method for logging API end. Used with
+ * FGS metrics logging. Is called by APIs that are
+ * used with FGS to log an API event (eg when
+ * the camera starts).
+ * @hide
+ *
+ */
+ @SystemApi
+ @RequiresPermission(android.Manifest.permission.LOG_FOREGROUND_RESOURCE_USE)
+ public void noteForegroundResourceUseEnd(@ForegroundServiceApiType int apiType,
+ int uid, int pid) throws SecurityException {
+ try {
+ getService().logFgsApiEnd(apiType, uid, pid);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
}
}
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl
index 5c38c42fe21f3..62298a5e96565 100644
--- a/core/java/android/app/IActivityManager.aidl
+++ b/core/java/android/app/IActivityManager.aidl
@@ -870,11 +870,11 @@ interface IActivityManager {
boolean shouldServiceTimeOut(in ComponentName className, in IBinder token);
/** Logs start of an API call to associate with an FGS, used for FGS Type Metrics */
- oneway void logFgsApiBegin(int apiType, int appUid, int appPid);
+ void logFgsApiBegin(int apiType, int appUid, int appPid);
/** Logs stop of an API call to associate with an FGS, used for FGS Type Metrics */
- oneway void logFgsApiEnd(int apiType, int appUid, int appPid);
+ void logFgsApiEnd(int apiType, int appUid, int appPid);
/** Logs API state change to associate with an FGS, used for FGS Type Metrics */
- oneway void logFgsApiStateChanged(int apiType, int state, int appUid, int appPid);
+ void logFgsApiStateChanged(int apiType, int state, int appUid, int appPid);
}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 5be18fb482b58..496cc3a9e3215 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -7620,8 +7620,8 @@
-
+
+
+
diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml
index 8cbf5f8d4c301..4c48f0e63b16f 100644
--- a/packages/Shell/AndroidManifest.xml
+++ b/packages/Shell/AndroidManifest.xml
@@ -828,6 +828,8 @@
+
+