Android 13 framework方法通过AIDL方式供三方APP使用
增加接口服务供外部调用
diff --git a/frameworks/base/core/api/current.txt b/frameworks/base/core/api/current.txt
index 6eeeb7dcb5..2b6445eed8 100644
--- a/frameworks/base/core/api/current.txt
+++ b/frameworks/base/core/api/current.txt
@@ -4590,6 +4590,14 @@ package android.app {
field public static final String EXTRA_USAGE_TIME_REPORT_PACKAGES = "android.usage_time_packages";
}
+ public class AemManager {
+ method public void addLmkWhiteList(@Nullable String);
+ method public void clearLmkWhiteList();
+ method public void delLmkWhiteList(@Nullable String);
+ method public void mockNotifyMessage(@Nullable String, int, @NonNull android.app.Notification, int);
+ method @Nullable public String queryLmkWhiteList();
+ }
+
public class AlarmManager {
method public boolean canScheduleExactAlarms();
method public void cancel(android.app.PendingIntent);
@@ -6496,6 +6504,7 @@ package android.app {
method public boolean isNotificationListenerAccessGranted(android.content.ComponentName);
method public boolean isNotificationPolicyAccessGranted();
method @WorkerThread public boolean matchesCallFilter(@NonNull android.net.Uri);
+ method public void mockNotifyMessage(@Nullable String, int, @NonNull android.app.Notification, int);
method public void notify(int, android.app.Notification);
method public void notify(String, int, android.app.Notification);
method public void notifyAsPackage(@NonNull String, @Nullable String, int, @NonNull android.app.Notification);
@@ -9772,6 +9781,7 @@ package android.content {
field public static final String ACCESSIBILITY_SERVICE = "accessibility";
field public static final String ACCOUNT_SERVICE = "account";
field public static final String ACTIVITY_SERVICE = "activity";
+ field public static final String AEM_SERVICE = "aemManager";
field public static final String ALARM_SERVICE = "alarm";
field public static final String APPWIDGET_SERVICE = "appwidget";
field public static final String APP_OPS_SERVICE = "appops";
diff --git a/frameworks/base/core/java/android/app/AemManager.java b/frameworks/base/core/java/android/app/AemManager.java
new file mode 100755
index 0000000000..8062e3a335
--- /dev/null
+++ b/frameworks/base/core/java/android/app/AemManager.java
@@ -0,0 +1,85 @@
+package android.app;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.SystemService;
+import android.content.Context;
+import android.os.IBinder;
+import android.compat.annotation.UnsupportedAppUsage;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.app.IAemManager;
+import android.util.Log;
+
+@SystemService(Context.AEM_SERVICE)
+public class AemManager {
+ private IAemManager mService;
+ private static AemManager sInstance;
+ /**
+ *@hide
+ */
+ public AemManager(IAemManager service){
+ mService=service;
+ }
+ /**
+ *@hide
+ */
+ @NonNull
+ @UnsupportedAppUsage
+ public static AemManager getInstance() {
+ synchronized (AemManager.class) {
+ if (sInstance == null) {
+ try {
+ IBinder b = ServiceManager.getServiceOrThrow(Context.AEM_SERVICE);
+ sInstance = new AemManager(IAemManager.Stub
+ .asInterface(ServiceManager.getServiceOrThrow(Context.AEM_SERVICE)));
+ } catch (ServiceManager.ServiceNotFoundException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return sInstance;
+ }
+ }
+
+ @Nullable
+ public String queryLmkWhiteList() {
+ try {
+ return mService.queryLmkWhiteList();
+ } catch (RemoteException e) {
+ e.rethrowFromSystemServer();
+ }
+ return "";
+ }
+
+ public void clearLmkWhiteList() {
+ try {
+ mService.clearLmkWhiteList();
+ } catch (RemoteException e) {
+ e.rethrowFromSystemServer();
+ }
+ }
+
+ public void addLmkWhiteList(@Nullable String jsonData) {
+ try {
+ mService.addLmkWhiteList(jsonData);
+ } catch (RemoteException e) {
+ e.rethrowFromSystemServer();
+ }
+ }
+
+ public void delLmkWhiteList(@Nullable String jsonData) {
+ try {
+ mService.delLmkWhiteList(jsonData);
+ } catch (RemoteException e) {
+ e.rethrowFromSystemServer();
+ }
+ }
+ public void mockNotifyMessage(@Nullable String pkg, int id, @NonNull Notification notification,int uid) {
+ try {
+ mService.mockNotifyMessage(pkg,id,notification,uid);
+ } catch (RemoteException e) {
+ e.rethrowFromSystemServer();
+ }
+ }
+
+}
diff --git a/frameworks/base/core/java/android/app/IAemManager.aidl b/frameworks/base/core/java/android/app/IAemManager.aidl
new file mode 100755
index 0000000000..db22c4fdc7
--- /dev/null
+++ b/frameworks/base/core/java/android/app/IAemManager.aidl
@@ -0,0 +1,18 @@
+package android.app;
+
+import android.app.Notification;
+
+/**
+ * System private API for talking with the activity manager service. This
+ * provides calls from the application back to the activity manager.
+ *
+ * {@hide}
+ */
+interface IAemManager {
+ void addLmkWhiteList(@nullable String jsonData);
+ void delLmkWhiteList(@nullable String jsonData);
+ String queryLmkWhiteList();
+ void clearLmkWhiteList();
+
+ void mockNotifyMessage(@nullable String pkg, int id,in Notification notification,int uid);
+}
diff --git a/frameworks/base/core/java/android/app/SystemServiceRegistry.java b/frameworks/base/core/java/android/app/SystemServiceRegistry.java
index 40192836e0..1ab79c6c69 100644
--- a/frameworks/base/core/java/android/app/SystemServiceRegistry.java
+++ b/frameworks/base/core/java/android/app/SystemServiceRegistry.java
@@ -1514,6 +1514,19 @@ public final class SystemServiceRegistry {
return new DisplayHashManager();
}
});
+ registerService(Context.ACTIVITY_SERVICE, ActivityManager.class,
+ new CachedServiceFetcher<ActivityManager>() {
+ @Override
+ public ActivityManager createService(ContextImpl ctx) {
+ return new ActivityManager(ctx.getOuterContext(), ctx.mMainThread.getHandler());
+ }});
+ //syd
+ registerService(Context.AEM_SERVICE, AemManager.class,
+ new CachedServiceFetcher<AemManager>() {
+ @Override
+ public AemManager createService(ContextImpl ctx) {
+ return AemManager.getInstance();
+ }});
registerService(Context.AMBIENT_CONTEXT_SERVICE, AmbientContextManager.class,
new CachedServiceFetcher<AmbientContextManager>() {
diff --git a/frameworks/base/core/java/android/content/Context.java b/frameworks/base/core/java/android/content/Context.java
index fce23cf681..f5245f3f06 100644
--- a/frameworks/base/core/java/android/content/Context.java
+++ b/frameworks/base/core/java/android/content/Context.java
@@ -3932,6 +3932,7 @@ public abstract class Context {
//@hide: ATTESTATION_VERIFICATION_SERVICE,
//@hide: SAFETY_CENTER_SERVICE,
DISPLAY_HASH_SERVICE,
+ AEM_SERVICE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface ServiceName {}
@@ -5763,6 +5764,17 @@ public abstract class Context {
*/
public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
+ /**
+ * Use with {@link #getSystemService(String)} to retrieve a {@link
+ * android.app.AemManager} for interacting with the status bar and quick settings.
+ *
+ * @see #getSystemService(String)
+ * @see android.app.AemManager
+ *
+ */
+ @SuppressLint("ServiceName")
+ public static final String AEM_SERVICE = "aemManager";
+
/**
* Use with {@link #getSystemService} to retrieve a
* {@link android.se.omapi.ISecureElementService}
diff --git a/frameworks/base/services/core/java/com/android/server/am/AemManagerService.java b/frameworks/base/services/core/java/com/android/server/am/AemManagerService.java
new file mode 100755
index 0000000000..4c06f1d57a
--- /dev/null
+++ b/frameworks/base/services/core/java/com/android/server/am/AemManagerService.java
@@ -0,0 +1,53 @@
+package com.android.server.am;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.app.ActivityManager;
+import android.app.IAemManager;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.os.RemoteException;
+import android.util.Log;
+
+public class AemManagerService extends IAemManager.Stub {
+ Context mContext;
+ ActivityManager am;
+ NotificationManager notificationManager;
+ public AemManagerService(Context context){
+ mContext = context;
+ am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ }
+
+ public Context getContext(){
+ return mContext;
+ }
+
+ @Override
+ public String queryLmkWhiteList() throws RemoteException {
+ return am.queryLmkWhiteList();
+ }
+
+ @Override
+ public void clearLmkWhiteList() throws RemoteException{
+ am.clearLmkWhiteList();
+ }
+
+ @Override
+ public void addLmkWhiteList(String jsonData) throws RemoteException{
+ am.addLmkWhiteList(jsonData);
+ }
+
+ @Override
+ public void delLmkWhiteList(String jsonData) throws RemoteException{
+ am.delLmkWhiteList(jsonData);
+ }
+
+ @Override
+ public void mockNotifyMessage(@Nullable String pkg, int id, @NonNull Notification notification,int uid) {
+ notificationManager.mockNotifyMessage(pkg, id, notification, uid);
+ }
+}
+
+
diff --git a/frameworks/base/services/java/com/android/server/SystemServer.java b/frameworks/base/services/java/com/android/server/SystemServer.java
index 2401ec3497..2bd46bac3d 100644
--- a/frameworks/base/services/java/com/android/server/SystemServer.java
+++ b/frameworks/base/services/java/com/android/server/SystemServer.java
@@ -105,6 +105,7 @@ import com.android.internal.util.EmergencyAffordanceManager;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.widget.ILockSettings;
import com.android.server.am.ActivityManagerService;
+import com.android.server.am.AemManagerService;
import com.android.server.ambientcontext.AmbientContextManagerService;
import com.android.server.appbinding.AppBindingService;
import com.android.server.art.ArtManagerLocal;
@@ -3061,6 +3062,15 @@ public final class SystemServer implements Dumpable {
}
t.traceEnd();
+ t.traceBegin("AemManagerService");
+ try {
+ ServiceManager.addService(Context.AEM_SERVICE,
+ new AemManagerService(context));
+ } catch (Throwable e) {
+ Slog.e(TAG, "Failure starting AemManagerService", e);
+ }
+ t.traceEnd();
+
t.traceEnd(); // startOtherServices
}
diff --git a/system/sepolicy/prebuilts/api/28.0/private/service_contexts b/system/sepolicy/prebuilts/api/28.0/private/service_contexts
index 5ec45a23ef..3c57817cc1 100644
--- a/system/sepolicy/prebuilts/api/28.0/private/service_contexts
+++ b/system/sepolicy/prebuilts/api/28.0/private/service_contexts
@@ -158,6 +158,7 @@ SurfaceFlinger u:object_r:surfaceflinger_service:s0
system_update u:object_r:system_update_service:s0
task u:object_r:task_service:s0
telecom u:object_r:telecom_service:s0
+AemManager u:object_r:AemManager_service:s0
telephony.registry u:object_r:registry_service:s0
textclassification u:object_r:textclassification_service:s0
textservices u:object_r:textservices_service:s0
diff --git a/system/sepolicy/prebuilts/api/28.0/public/service.te b/system/sepolicy/prebuilts/api/28.0/public/service.te
index 3526049f25..1bf428920a 100644
--- a/system/sepolicy/prebuilts/api/28.0/public/service.te
+++ b/system/sepolicy/prebuilts/api/28.0/public/service.te
@@ -106,6 +106,7 @@ type network_management_service, app_api_service, ephemeral_app_api_service, sys
type network_score_service, system_api_service, system_server_service, service_manager_type;
type network_time_update_service, system_server_service, service_manager_type;
type notification_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
+type AemManager_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
type oem_lock_service, system_api_service, system_server_service, service_manager_type;
type otadexopt_service, system_server_service, service_manager_type;
type overlay_service, system_api_service, system_server_service, service_manager_type;
diff --git a/system/sepolicy/prebuilts/api/29.0/private/service_contexts b/system/sepolicy/prebuilts/api/29.0/private/service_contexts
index 96d553bf49..c7a0867b79 100644
--- a/system/sepolicy/prebuilts/api/29.0/private/service_contexts
+++ b/system/sepolicy/prebuilts/api/29.0/private/service_contexts
@@ -188,6 +188,7 @@ suspend_control u:object_r:system_suspend_control_serv
system_update u:object_r:system_update_service:s0
task u:object_r:task_service:s0
telecom u:object_r:telecom_service:s0
+AemManager u:object_r:AemManager_service:s0
telephony.registry u:object_r:registry_service:s0
testharness u:object_r:testharness_service:s0
textclassification u:object_r:textclassification_service:s0
diff --git a/system/sepolicy/prebuilts/api/29.0/public/service.te b/system/sepolicy/prebuilts/api/29.0/public/service.te
index a2193d0edb..bb9a06d218 100644
--- a/system/sepolicy/prebuilts/api/29.0/public/service.te
+++ b/system/sepolicy/prebuilts/api/29.0/public/service.te
@@ -124,6 +124,7 @@ type network_score_service, system_api_service, system_server_service, service_m
type network_stack_service, system_server_service, service_manager_type;
type network_time_update_service, system_server_service, service_manager_type;
type notification_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
+type AemManager_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
type oem_lock_service, system_api_service, system_server_service, service_manager_type;
type otadexopt_service, system_server_service, service_manager_type;
type overlay_service, system_api_service, system_server_service, service_manager_type;
diff --git a/system/sepolicy/prebuilts/api/30.0/private/service_contexts b/system/sepolicy/prebuilts/api/30.0/private/service_contexts
index 5c6f1a4766..db3d1aeba3 100644
--- a/system/sepolicy/prebuilts/api/30.0/private/service_contexts
+++ b/system/sepolicy/prebuilts/api/30.0/private/service_contexts
@@ -213,6 +213,7 @@ task u:object_r:task_service:s0
telecom u:object_r:telecom_service:s0
telephony.registry u:object_r:registry_service:s0
telephony_ims u:object_r:radio_service:s0
+AemManager u:object_r:AemManager_service:s0
testharness u:object_r:testharness_service:s0
tethering u:object_r:tethering_service:s0
textclassification u:object_r:textclassification_service:s0
diff --git a/system/sepolicy/prebuilts/api/30.0/public/service.te b/system/sepolicy/prebuilts/api/30.0/public/service.te
index f27772eabb..a01f894b74 100644
--- a/system/sepolicy/prebuilts/api/30.0/public/service.te
+++ b/system/sepolicy/prebuilts/api/30.0/public/service.te
@@ -136,6 +136,7 @@ type network_score_service, system_api_service, system_server_service, service_m
type network_stack_service, system_server_service, service_manager_type;
type network_time_update_service, system_server_service, service_manager_type;
type notification_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
+type AemManager_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
type oem_lock_service, system_api_service, system_server_service, service_manager_type;
type otadexopt_service, system_server_service, service_manager_type;
type overlay_service, system_api_service, system_server_service, service_manager_type;
diff --git a/system/sepolicy/prebuilts/api/31.0/private/service_contexts b/system/sepolicy/prebuilts/api/31.0/private/service_contexts
index 3fd342b9be..6275bea280 100644
--- a/system/sepolicy/prebuilts/api/31.0/private/service_contexts
+++ b/system/sepolicy/prebuilts/api/31.0/private/service_contexts
@@ -266,6 +266,7 @@ task u:object_r:task_service:s0
telecom u:object_r:telecom_service:s0
telephony.registry u:object_r:registry_service:s0
telephony_ims u:object_r:radio_service:s0
+AemManager u:object_r:AemManager_service:s0
testharness u:object_r:testharness_service:s0
tethering u:object_r:tethering_service:s0
textclassification u:object_r:textclassification_service:s0
diff --git a/system/sepolicy/prebuilts/api/31.0/public/service.te b/system/sepolicy/prebuilts/api/31.0/public/service.te
index ba7837d562..072b615fd9 100644
--- a/system/sepolicy/prebuilts/api/31.0/public/service.te
+++ b/system/sepolicy/prebuilts/api/31.0/public/service.te
@@ -158,6 +158,7 @@ type network_score_service, system_api_service, system_server_service, service_m
type network_stack_service, system_server_service, service_manager_type;
type network_time_update_service, system_server_service, service_manager_type;
type notification_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
+type AemManager_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
type oem_lock_service, system_api_service, system_server_service, service_manager_type;
type otadexopt_service, system_server_service, service_manager_type;
type overlay_service, system_api_service, system_server_service, service_manager_type;
diff --git a/system/sepolicy/prebuilts/api/32.0/private/service_contexts b/system/sepolicy/prebuilts/api/32.0/private/service_contexts
index 3fd342b9be..6275bea280 100644
--- a/system/sepolicy/prebuilts/api/32.0/private/service_contexts
+++ b/system/sepolicy/prebuilts/api/32.0/private/service_contexts
@@ -266,6 +266,7 @@ task u:object_r:task_service:s0
telecom u:object_r:telecom_service:s0
telephony.registry u:object_r:registry_service:s0
telephony_ims u:object_r:radio_service:s0
+AemManager u:object_r:AemManager_service:s0
testharness u:object_r:testharness_service:s0
tethering u:object_r:tethering_service:s0
textclassification u:object_r:textclassification_service:s0
diff --git a/system/sepolicy/prebuilts/api/32.0/public/service.te b/system/sepolicy/prebuilts/api/32.0/public/service.te
index ba7837d562..072b615fd9 100644
--- a/system/sepolicy/prebuilts/api/32.0/public/service.te
+++ b/system/sepolicy/prebuilts/api/32.0/public/service.te
@@ -158,6 +158,7 @@ type network_score_service, system_api_service, system_server_service, service_m
type network_stack_service, system_server_service, service_manager_type;
type network_time_update_service, system_server_service, service_manager_type;
type notification_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
+type AemManager_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
type oem_lock_service, system_api_service, system_server_service, service_manager_type;
type otadexopt_service, system_server_service, service_manager_type;
type overlay_service, system_api_service, system_server_service, service_manager_type;
diff --git a/system/sepolicy/prebuilts/api/33.0/private/service_contexts b/system/sepolicy/prebuilts/api/33.0/private/service_contexts
index 72fa16629e..cd1951fa44 100644
--- a/system/sepolicy/prebuilts/api/33.0/private/service_contexts
+++ b/system/sepolicy/prebuilts/api/33.0/private/service_contexts
@@ -341,6 +341,7 @@ task u:object_r:task_service:s0
telecom u:object_r:telecom_service:s0
telephony.registry u:object_r:registry_service:s0
telephony_ims u:object_r:radio_service:s0
+AemManager u:object_r:AemManager_service:s0
testharness u:object_r:testharness_service:s0
tethering u:object_r:tethering_service:s0
textclassification u:object_r:textclassification_service:s0
diff --git a/system/sepolicy/prebuilts/api/33.0/public/service.te b/system/sepolicy/prebuilts/api/33.0/public/service.te
index e862b405fe..d213f7fbeb 100644
--- a/system/sepolicy/prebuilts/api/33.0/public/service.te
+++ b/system/sepolicy/prebuilts/api/33.0/public/service.te
@@ -171,6 +171,7 @@ type network_score_service, system_api_service, system_server_service, service_m
type network_stack_service, system_server_service, service_manager_type;
type network_time_update_service, system_server_service, service_manager_type;
type notification_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
+type AemManager_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
type oem_lock_service, system_api_service, system_server_service, service_manager_type;
type otadexopt_service, system_server_service, service_manager_type;
type overlay_service, system_api_service, system_server_service, service_manager_type;
diff --git a/system/sepolicy/private/service_contexts b/system/sepolicy/private/service_contexts
index 72fa16629e..cd1951fa44 100644
--- a/system/sepolicy/private/service_contexts
+++ b/system/sepolicy/private/service_contexts
@@ -341,6 +341,7 @@ task u:object_r:task_service:s0
telecom u:object_r:telecom_service:s0
telephony.registry u:object_r:registry_service:s0
telephony_ims u:object_r:radio_service:s0
+AemManager u:object_r:AemManager_service:s0
testharness u:object_r:testharness_service:s0
tethering u:object_r:tethering_service:s0
textclassification u:object_r:textclassification_service:s0
diff --git a/system/sepolicy/public/service.te b/system/sepolicy/public/service.te
index e862b405fe..d213f7fbeb 100644
--- a/system/sepolicy/public/service.te
+++ b/system/sepolicy/public/service.te
@@ -171,6 +171,7 @@ type network_score_service, system_api_service, system_server_service, service_m
type network_stack_service, system_server_service, service_manager_type;
type network_time_update_service, system_server_service, service_manager_type;
type notification_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
+type AemManager_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
type oem_lock_service, system_api_service, system_server_service, service_manager_type;
type otadexopt_service, system_server_service, service_manager_type;
type overlay_service, system_api_service, system_server_service, service_manager_type;
APP调用方法的时候,在工程下新建相同包名的文件夹及名称
包名:android.app
文件名:AemManager.java
文件内容:
package android.app;
import androidx.annotation.Nullable;
public class AemManager {
public static AemManager getInstance() {
throw new RuntimeException("API not supported!");
}
public String queryLmkWhiteList() {
throw new RuntimeException("API not supported!");
}
public void clearLmkWhiteList() {
throw new RuntimeException("API not supported!");
}
public void addLmkWhiteList(String json) {
throw new RuntimeException("API not supported!");
}
public void delLmkWhiteList(String json) {
throw new RuntimeException("API not supported!");
}
public void mockNotifyMessage(@Nullable String pkg, int id, Notification notification,int uid) {
throw new RuntimeException("API not supported!");
}
}
就可以在APP里面这样调用了
AemManager.getInstance().clearLmkWhiteList();