Loading Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -341,6 +341,7 @@ LOCAL_SRC_FILES += \ media/java/android/media/IAudioRoutesObserver.aidl \ media/java/android/media/IMediaHTTPConnection.aidl \ media/java/android/media/IMediaHTTPService.aidl \ media/java/android/media/IMediaResourceMonitor.aidl \ media/java/android/media/IMediaRouterClient.aidl \ media/java/android/media/IMediaRouterService.aidl \ media/java/android/media/IMediaScannerListener.aidl \ Loading core/java/android/content/Intent.java +46 −0 Original line number Diff line number Diff line Loading @@ -3033,6 +3033,24 @@ public class Intent implements Parcelable, Cloneable { */ public static final String ACTION_GLOBAL_BUTTON = "android.intent.action.GLOBAL_BUTTON"; /** * Broadcast Action: Sent when media resource is granted. * <p> * {@link #EXTRA_PACKAGES} specifies the packages on the process holding the media resource * granted. * </p> * <p class="note"> * This is a protected intent that can only be sent by the system. * </p> * <p class="note"> * This requires the RECEIVE_MEDIA_RESOURCE_USAGE permission. * </p> * * @hide */ public static final String ACTION_MEDIA_RESOURCE_GRANTED = "android.intent.action.MEDIA_RESOURCE_GRANTED"; /** * Activity Action: Allow the user to select and return one or more existing * documents. When invoked, the system will display the various Loading Loading @@ -4077,6 +4095,34 @@ public class Intent implements Parcelable, Cloneable { * Optional boolean extra indicating whether quiet mode has been switched on or off. */ public static final String EXTRA_QUIET_MODE = "android.intent.extra.QUIET_MODE"; /** * Used as an int extra field in {@link android.content.Intent#ACTION_MEDIA_RESOURCE_GRANTED} * intents to specify the resource type granted. Possible values are * {@link android.content.Intent#EXTRA_MEDIA_RESOURCE_TYPE_VIDEO_CODEC} or * {@link android.content.Intent#EXTRA_MEDIA_RESOURCE_TYPE_AUDIO_CODEC}. * * @hide */ public static final String EXTRA_MEDIA_RESOURCE_TYPE = "android.intent.extra.MEDIA_RESOURCE_TYPE"; /** * Used as an int value for {@link android.content.Intent#EXTRA_MEDIA_RESOURCE_TYPE} * to represent that a video codec is allowed to use. * * @hide */ public static final int EXTRA_MEDIA_RESOURCE_TYPE_VIDEO_CODEC = 0; /** * Used as an int value for {@link android.content.Intent#EXTRA_MEDIA_RESOURCE_TYPE} * to represent that a audio codec is allowed to use. * * @hide */ public static final int EXTRA_MEDIA_RESOURCE_TYPE_AUDIO_CODEC = 1; // --------------------------------------------------------------------- // --------------------------------------------------------------------- // Intent flags (see mFlags variable). Loading core/res/AndroidManifest.xml +7 −0 Original line number Diff line number Diff line Loading @@ -384,6 +384,7 @@ <protected-broadcast android:name="com.android.server.device_idle.STEP_LIGHT_IDLE_STATE" /> <protected-broadcast android:name="com.android.server.Wifi.action.TOGGLE_PNO" /> <protected-broadcast android:name="intent.action.ACTION_RF_BAND_INFO" /> <protected-broadcast android:name="android.intent.action.MEDIA_RESOURCE_GRANTED" /> <protected-broadcast android:name="android.app.action.INTERRUPTION_FILTER_CHANGED" /> <protected-broadcast android:name="android.app.action.INTERRUPTION_FILTER_CHANGED_INTERNAL" /> Loading Loading @@ -2821,6 +2822,12 @@ <permission android:name="android.permission.ACCESS_EPHEMERAL_APPS" android:protectionLevel="signature" /> <!-- Allows receiving the usage of media resource e.g. video/audio codec and graphic memory. @hide --> <permission android:name="android.permission.RECEIVE_MEDIA_RESOURCE_USAGE" android:protectionLevel="signature|privileged" /> <application android:process="system" android:persistent="true" android:hasCode="false" Loading media/java/android/media/IMediaResourceMonitor.aidl 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * Copyright 2016 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.media; /** {@hide} */ interface IMediaResourceMonitor { oneway void notifyResourceGranted(in int pid, String type, String subType, long value); } services/core/java/com/android/server/media/MediaResourceMonitorService.java 0 → 100644 +103 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 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.media; import android.app.ActivityManager; import android.app.ActivityManagerNative; import android.content.Context; import android.content.Intent; import android.media.IMediaResourceMonitor; import android.os.Binder; import android.os.RemoteException; import android.os.UserHandle; import android.util.Log; import android.util.Slog; import com.android.server.SystemService; import java.util.List; /** This class provides a system service that monitors media resource usage. */ public class MediaResourceMonitorService extends SystemService { private static final String TAG = "MediaResourceMonitorService"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final String SERVICE_NAME = "media_resource_monitor"; /* * Resource types. Should be in sync with: * frameworks/av/media/libmedia/MediaResource.cpp */ private static final String RESOURCE_AUDIO_CODEC = "audio-codec"; private static final String RESOURCE_VIDEO_CODEC = "video-codec"; private final MediaResourceMonitorImpl mMediaResourceMonitorImpl; public MediaResourceMonitorService(Context context) { super(context); mMediaResourceMonitorImpl = new MediaResourceMonitorImpl(); } @Override public void onStart() { publishBinderService(SERVICE_NAME, mMediaResourceMonitorImpl); } class MediaResourceMonitorImpl extends IMediaResourceMonitor.Stub { @Override public void notifyResourceGranted(int pid, String type, String subType, long value) throws RemoteException { if (DEBUG) { Slog.d(TAG, "notifyResourceGranted(pid=" + pid + ", type=" + type + ", subType=" + subType + ", value=" + value + ")"); } final long identity = Binder.clearCallingIdentity(); try { String pkgNames[] = getPackageNamesFromPid(pid); Integer resourceType = null; if (RESOURCE_AUDIO_CODEC.equals(subType)) { resourceType = Intent.EXTRA_MEDIA_RESOURCE_TYPE_AUDIO_CODEC; } else if (RESOURCE_VIDEO_CODEC.equals(subType)) { resourceType = Intent.EXTRA_MEDIA_RESOURCE_TYPE_VIDEO_CODEC; } if (pkgNames != null && resourceType != null) { Intent intent = new Intent(Intent.ACTION_MEDIA_RESOURCE_GRANTED); intent.putExtra(Intent.EXTRA_PACKAGES, pkgNames); intent.putExtra(Intent.EXTRA_MEDIA_RESOURCE_TYPE, resourceType); getContext().sendBroadcastAsUser(intent, new UserHandle(ActivityManager.getCurrentUser()), android.Manifest.permission.RECEIVE_MEDIA_RESOURCE_USAGE); } } finally { Binder.restoreCallingIdentity(identity); } } private String[] getPackageNamesFromPid(int pid) { try { for (ActivityManager.RunningAppProcessInfo proc : ActivityManagerNative.getDefault().getRunningAppProcesses()) { if (proc.pid == pid) { return proc.pkgList; } } } catch (RemoteException e) { Slog.w(TAG, "ActivityManager.getRunningAppProcesses() failed"); } return null; } } } Loading
Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -341,6 +341,7 @@ LOCAL_SRC_FILES += \ media/java/android/media/IAudioRoutesObserver.aidl \ media/java/android/media/IMediaHTTPConnection.aidl \ media/java/android/media/IMediaHTTPService.aidl \ media/java/android/media/IMediaResourceMonitor.aidl \ media/java/android/media/IMediaRouterClient.aidl \ media/java/android/media/IMediaRouterService.aidl \ media/java/android/media/IMediaScannerListener.aidl \ Loading
core/java/android/content/Intent.java +46 −0 Original line number Diff line number Diff line Loading @@ -3033,6 +3033,24 @@ public class Intent implements Parcelable, Cloneable { */ public static final String ACTION_GLOBAL_BUTTON = "android.intent.action.GLOBAL_BUTTON"; /** * Broadcast Action: Sent when media resource is granted. * <p> * {@link #EXTRA_PACKAGES} specifies the packages on the process holding the media resource * granted. * </p> * <p class="note"> * This is a protected intent that can only be sent by the system. * </p> * <p class="note"> * This requires the RECEIVE_MEDIA_RESOURCE_USAGE permission. * </p> * * @hide */ public static final String ACTION_MEDIA_RESOURCE_GRANTED = "android.intent.action.MEDIA_RESOURCE_GRANTED"; /** * Activity Action: Allow the user to select and return one or more existing * documents. When invoked, the system will display the various Loading Loading @@ -4077,6 +4095,34 @@ public class Intent implements Parcelable, Cloneable { * Optional boolean extra indicating whether quiet mode has been switched on or off. */ public static final String EXTRA_QUIET_MODE = "android.intent.extra.QUIET_MODE"; /** * Used as an int extra field in {@link android.content.Intent#ACTION_MEDIA_RESOURCE_GRANTED} * intents to specify the resource type granted. Possible values are * {@link android.content.Intent#EXTRA_MEDIA_RESOURCE_TYPE_VIDEO_CODEC} or * {@link android.content.Intent#EXTRA_MEDIA_RESOURCE_TYPE_AUDIO_CODEC}. * * @hide */ public static final String EXTRA_MEDIA_RESOURCE_TYPE = "android.intent.extra.MEDIA_RESOURCE_TYPE"; /** * Used as an int value for {@link android.content.Intent#EXTRA_MEDIA_RESOURCE_TYPE} * to represent that a video codec is allowed to use. * * @hide */ public static final int EXTRA_MEDIA_RESOURCE_TYPE_VIDEO_CODEC = 0; /** * Used as an int value for {@link android.content.Intent#EXTRA_MEDIA_RESOURCE_TYPE} * to represent that a audio codec is allowed to use. * * @hide */ public static final int EXTRA_MEDIA_RESOURCE_TYPE_AUDIO_CODEC = 1; // --------------------------------------------------------------------- // --------------------------------------------------------------------- // Intent flags (see mFlags variable). Loading
core/res/AndroidManifest.xml +7 −0 Original line number Diff line number Diff line Loading @@ -384,6 +384,7 @@ <protected-broadcast android:name="com.android.server.device_idle.STEP_LIGHT_IDLE_STATE" /> <protected-broadcast android:name="com.android.server.Wifi.action.TOGGLE_PNO" /> <protected-broadcast android:name="intent.action.ACTION_RF_BAND_INFO" /> <protected-broadcast android:name="android.intent.action.MEDIA_RESOURCE_GRANTED" /> <protected-broadcast android:name="android.app.action.INTERRUPTION_FILTER_CHANGED" /> <protected-broadcast android:name="android.app.action.INTERRUPTION_FILTER_CHANGED_INTERNAL" /> Loading Loading @@ -2821,6 +2822,12 @@ <permission android:name="android.permission.ACCESS_EPHEMERAL_APPS" android:protectionLevel="signature" /> <!-- Allows receiving the usage of media resource e.g. video/audio codec and graphic memory. @hide --> <permission android:name="android.permission.RECEIVE_MEDIA_RESOURCE_USAGE" android:protectionLevel="signature|privileged" /> <application android:process="system" android:persistent="true" android:hasCode="false" Loading
media/java/android/media/IMediaResourceMonitor.aidl 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * Copyright 2016 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.media; /** {@hide} */ interface IMediaResourceMonitor { oneway void notifyResourceGranted(in int pid, String type, String subType, long value); }
services/core/java/com/android/server/media/MediaResourceMonitorService.java 0 → 100644 +103 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 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.media; import android.app.ActivityManager; import android.app.ActivityManagerNative; import android.content.Context; import android.content.Intent; import android.media.IMediaResourceMonitor; import android.os.Binder; import android.os.RemoteException; import android.os.UserHandle; import android.util.Log; import android.util.Slog; import com.android.server.SystemService; import java.util.List; /** This class provides a system service that monitors media resource usage. */ public class MediaResourceMonitorService extends SystemService { private static final String TAG = "MediaResourceMonitorService"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final String SERVICE_NAME = "media_resource_monitor"; /* * Resource types. Should be in sync with: * frameworks/av/media/libmedia/MediaResource.cpp */ private static final String RESOURCE_AUDIO_CODEC = "audio-codec"; private static final String RESOURCE_VIDEO_CODEC = "video-codec"; private final MediaResourceMonitorImpl mMediaResourceMonitorImpl; public MediaResourceMonitorService(Context context) { super(context); mMediaResourceMonitorImpl = new MediaResourceMonitorImpl(); } @Override public void onStart() { publishBinderService(SERVICE_NAME, mMediaResourceMonitorImpl); } class MediaResourceMonitorImpl extends IMediaResourceMonitor.Stub { @Override public void notifyResourceGranted(int pid, String type, String subType, long value) throws RemoteException { if (DEBUG) { Slog.d(TAG, "notifyResourceGranted(pid=" + pid + ", type=" + type + ", subType=" + subType + ", value=" + value + ")"); } final long identity = Binder.clearCallingIdentity(); try { String pkgNames[] = getPackageNamesFromPid(pid); Integer resourceType = null; if (RESOURCE_AUDIO_CODEC.equals(subType)) { resourceType = Intent.EXTRA_MEDIA_RESOURCE_TYPE_AUDIO_CODEC; } else if (RESOURCE_VIDEO_CODEC.equals(subType)) { resourceType = Intent.EXTRA_MEDIA_RESOURCE_TYPE_VIDEO_CODEC; } if (pkgNames != null && resourceType != null) { Intent intent = new Intent(Intent.ACTION_MEDIA_RESOURCE_GRANTED); intent.putExtra(Intent.EXTRA_PACKAGES, pkgNames); intent.putExtra(Intent.EXTRA_MEDIA_RESOURCE_TYPE, resourceType); getContext().sendBroadcastAsUser(intent, new UserHandle(ActivityManager.getCurrentUser()), android.Manifest.permission.RECEIVE_MEDIA_RESOURCE_USAGE); } } finally { Binder.restoreCallingIdentity(identity); } } private String[] getPackageNamesFromPid(int pid) { try { for (ActivityManager.RunningAppProcessInfo proc : ActivityManagerNative.getDefault().getRunningAppProcesses()) { if (proc.pid == pid) { return proc.pkgList; } } } catch (RemoteException e) { Slog.w(TAG, "ActivityManager.getRunningAppProcesses() failed"); } return null; } } }