Make the MIDI Manager optional, enabled by "android.software.midi" feature
Change-Id: I76d442ea28beea4b9e2876bfef501d8f61403702
This commit is contained in:
@@ -9146,6 +9146,7 @@ package android.content.pm {
|
||||
field public static final java.lang.String FEATURE_LOCATION_NETWORK = "android.hardware.location.network";
|
||||
field public static final java.lang.String FEATURE_MANAGED_USERS = "android.software.managed_users";
|
||||
field public static final java.lang.String FEATURE_MICROPHONE = "android.hardware.microphone";
|
||||
field public static final java.lang.String FEATURE_MIDI = "android.software.midi";
|
||||
field public static final java.lang.String FEATURE_NFC = "android.hardware.nfc";
|
||||
field public static final java.lang.String FEATURE_NFC_HOST_CARD_EMULATION = "android.hardware.nfc.hce";
|
||||
field public static final java.lang.String FEATURE_OPENGLES_EXTENSION_PACK = "android.hardware.opengles.aep";
|
||||
|
||||
@@ -9394,6 +9394,7 @@ package android.content.pm {
|
||||
field public static final java.lang.String FEATURE_LOCATION_NETWORK = "android.hardware.location.network";
|
||||
field public static final java.lang.String FEATURE_MANAGED_USERS = "android.software.managed_users";
|
||||
field public static final java.lang.String FEATURE_MICROPHONE = "android.hardware.microphone";
|
||||
field public static final java.lang.String FEATURE_MIDI = "android.software.midi";
|
||||
field public static final java.lang.String FEATURE_NFC = "android.hardware.nfc";
|
||||
field public static final java.lang.String FEATURE_NFC_HOST_CARD_EMULATION = "android.hardware.nfc.hce";
|
||||
field public static final java.lang.String FEATURE_OPENGLES_EXTENSION_PACK = "android.hardware.opengles.aep";
|
||||
|
||||
@@ -1600,6 +1600,12 @@ public abstract class PackageManager {
|
||||
@SdkConstant(SdkConstantType.FEATURE)
|
||||
public static final String FEATURE_GAMEPAD = "android.hardware.gamepad";
|
||||
|
||||
/**
|
||||
* Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
|
||||
* The device has a full implementation of the android.media.midi.* APIs.
|
||||
*/
|
||||
@SdkConstant(SdkConstantType.FEATURE)
|
||||
public static final String FEATURE_MIDI = "android.software.midi";
|
||||
|
||||
/**
|
||||
* Action to external storage service to clean out removed apps.
|
||||
|
||||
@@ -24,6 +24,7 @@ services := \
|
||||
appwidget \
|
||||
backup \
|
||||
devicepolicy \
|
||||
midi \
|
||||
net \
|
||||
print \
|
||||
restrictions \
|
||||
|
||||
@@ -124,6 +124,8 @@ public final class SystemServer {
|
||||
"com.android.server.print.PrintManagerService";
|
||||
private static final String USB_SERVICE_CLASS =
|
||||
"com.android.server.usb.UsbService$Lifecycle";
|
||||
private static final String MIDI_SERVICE_CLASS =
|
||||
"com.android.server.midi.MidiService$Lifecycle";
|
||||
private static final String WIFI_SERVICE_CLASS =
|
||||
"com.android.server.wifi.WifiService";
|
||||
private static final String WIFI_P2P_SERVICE_CLASS =
|
||||
@@ -810,6 +812,11 @@ public final class SystemServer {
|
||||
}
|
||||
|
||||
if (!disableNonCoreServices) {
|
||||
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)) {
|
||||
// Start MIDI Manager service
|
||||
mSystemServiceManager.startService(MIDI_SERVICE_CLASS);
|
||||
}
|
||||
|
||||
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)
|
||||
|| mPackageManager.hasSystemFeature(
|
||||
PackageManager.FEATURE_USB_ACCESSORY)) {
|
||||
@@ -827,16 +834,6 @@ public final class SystemServer {
|
||||
}
|
||||
}
|
||||
|
||||
if (!disableNonCoreServices) {
|
||||
try {
|
||||
Slog.i(TAG, "MIDI Service");
|
||||
ServiceManager.addService(Context.MIDI_SERVICE,
|
||||
new MidiService(context));
|
||||
} catch (Throwable e) {
|
||||
reportWtf("starting MIDI Service", e);
|
||||
}
|
||||
}
|
||||
|
||||
mSystemServiceManager.startService(TwilightService.class);
|
||||
|
||||
mSystemServiceManager.startService(JobSchedulerService.class);
|
||||
|
||||
12
services/midi/Android.mk
Normal file
12
services/midi/Android.mk
Normal file
@@ -0,0 +1,12 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := services.midi
|
||||
|
||||
LOCAL_SRC_FILES += \
|
||||
$(call all-java-files-under,java)
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := services.core
|
||||
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY)
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server;
|
||||
package com.android.server.midi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -40,6 +40,7 @@ import android.util.Log;
|
||||
import com.android.internal.content.PackageMonitor;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
import com.android.internal.util.XmlUtils;
|
||||
import com.android.server.SystemService;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
@@ -51,6 +52,21 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class MidiService extends IMidiManager.Stub {
|
||||
|
||||
public static class Lifecycle extends SystemService {
|
||||
private MidiService mMidiService;
|
||||
|
||||
public Lifecycle(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mMidiService = new MidiService(getContext());
|
||||
publishBinderService(Context.MIDI_SERVICE, mMidiService);
|
||||
}
|
||||
}
|
||||
|
||||
private static final String TAG = "MidiService";
|
||||
|
||||
private final Context mContext;
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.server.usb;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.hardware.usb.UsbConstants;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
@@ -55,6 +56,7 @@ public final class UsbAlsaManager {
|
||||
|
||||
private final Context mContext;
|
||||
private IAudioService mAudioService;
|
||||
private final boolean mHasMidiFeature;
|
||||
|
||||
private final AlsaCardsParser mCardsParser = new AlsaCardsParser();
|
||||
private final AlsaDevicesParser mDevicesParser = new AlsaDevicesParser();
|
||||
@@ -126,6 +128,7 @@ public final class UsbAlsaManager {
|
||||
|
||||
/* package */ UsbAlsaManager(Context context) {
|
||||
mContext = context;
|
||||
mHasMidiFeature = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI);
|
||||
|
||||
// initial scan
|
||||
mCardsParser.scan();
|
||||
@@ -389,7 +392,7 @@ public final class UsbAlsaManager {
|
||||
// mDevicesParser.scan()
|
||||
|
||||
boolean hasMidi = mDevicesParser.hasMIDIDevices(addedCard);
|
||||
if (hasMidi) {
|
||||
if (hasMidi && mHasMidiFeature) {
|
||||
int device = mDevicesParser.getDefaultDeviceNum(addedCard);
|
||||
AlsaDevice alsaDevice = waitForAlsaDevice(addedCard, device, AlsaDevice.TYPE_MIDI);
|
||||
if (alsaDevice != null) {
|
||||
@@ -459,6 +462,10 @@ public final class UsbAlsaManager {
|
||||
}
|
||||
|
||||
/* package */ void setPeripheralMidiState(boolean enabled, int card, int device) {
|
||||
if (!mHasMidiFeature) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabled && mPeripheralMidiDevice == null) {
|
||||
Bundle properties = new Bundle();
|
||||
Resources r = mContext.getResources();
|
||||
|
||||
Reference in New Issue
Block a user