Skip to content

Commit

Permalink
MidiManagerAndroid: use PackageManager to detect MIDI feature support
Browse files Browse the repository at this point in the history
Existing code just checks Android version to know if the system supports
Android MIDI API, but reality is it depends on products.

This patch introduces an additional check to ask PackageManager.
This is expected to work always because cts would requre MIDI tests
to pass if it says FEATURE_MIDI is supported on the device.

See aosp-master/cts/tests/tests/midi/src/android/midi/cts/MidiEchoTest.java

Bug: 486584, 683027, 761897
Change-Id: Idb3ca57c3179220957dd16126f24570e2b45f299
Reviewed-on: https://chromium-review.googlesource.com/643246
Commit-Queue: Takashi Toyoshima <[email protected]>
Reviewed-by: Yutaka Hirano <[email protected]>
Cr-Commit-Position: refs/heads/master@{#499575}
  • Loading branch information
toyoshim authored and Commit Bot committed Sep 5, 2017
1 parent 3c87c67 commit cb9d4e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions media/midi/java/src/org/chromium/midi/MidiManagerAndroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.PackageManager;
import android.media.midi.MidiDevice;
import android.media.midi.MidiDeviceInfo;
import android.media.midi.MidiManager;
Expand Down Expand Up @@ -53,6 +54,15 @@ class MidiManagerAndroid {
*/
private final long mNativeManagerPointer;

/**
* Checks if Android MIDI is supported on the device.
*/
@CalledByNative
static boolean hasSystemFeatureMidi() {
return ContextUtils.getApplicationContext().getPackageManager().hasSystemFeature(
PackageManager.FEATURE_MIDI);
}

/**
* A creation function called by C++.
* @param nativeManagerPointer The native pointer to a midi::MidiManagerAndroid object.
Expand Down
9 changes: 7 additions & 2 deletions media/midi/midi_manager_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ bool IsMidiManagerAndroidEnabled() {
return false;

auto sdk_version = base::android::BuildInfo::GetInstance()->sdk_int();
if (sdk_version < base::android::SDK_VERSION_MARSHMALLOW)
return false;

bool has_midi = Java_MidiManagerAndroid_hasSystemFeatureMidi(
base::android::AttachCurrentThread());

// If the feature is enabled, check the RequredAndroidVersion param. If the
// param is provided and the value is "NOUGAT", use MidiManagerAndroid on N
Expand All @@ -41,11 +46,11 @@ bool IsMidiManagerAndroidEnabled() {
if (base::GetFieldTrialParamValueByFeature(features::kMidiManagerAndroid,
"RequiredAndroidVersion") ==
"NOUGAT") {
return sdk_version >= base::android::SDK_VERSION_NOUGAT;
return has_midi && sdk_version >= base::android::SDK_VERSION_NOUGAT;
}

// Otherwise, allow to use MidiManagerAndroid on M and later versions.
return sdk_version >= base::android::SDK_VERSION_MARSHMALLOW;
return has_midi && sdk_version >= base::android::SDK_VERSION_MARSHMALLOW;
}

} // namespace
Expand Down

0 comments on commit cb9d4e9

Please sign in to comment.