Add Broadcast action and query API for AudioSource.HOTWORD.

- Add ACTION_HOTWORD_INPUT_CHANGED broadcast action and related extras.
- Add getCurrentHotwordPackageName() API to SettingsManager to query the
  current package name of the application that controls the HOTWORD
  input.
- Rename SettingsManager to PartnerInterface.

Change-Id: I5987499cd32908c47a7e8e95d644c483dc32914c
This commit is contained in:
Matt Garnes
2015-09-05 14:25:07 -07:00
committed by Raj Yengisetty
parent a458122384
commit eabd575721
10 changed files with 143 additions and 56 deletions

View File

@@ -53,14 +53,14 @@ public final class CMContextConstants {
/**
* Use with {@link android.content.Context#getSystemService} to retrieve a
* {@link cyanogenmod.app.SettingsManager} changing system settings.
* {@link cyanogenmod.app.PartnerInterface} interact with system settings.
*
* @see android.content.Context#getSystemService
* @see cyanogenmod.app.SettingsManager
* @see cyanogenmod.app.PartnerInterface
*
* @hide
*/
public static final String CM_SETTINGS_SERVICE = "cmsettings";
public static final String CM_PARTNER_INTERFACE = "cmpartnerinterface";
/**
* Use with {@link android.content.Context#getSystemService} to retrieve a

View File

@@ -18,11 +18,12 @@
package cyanogenmod.app;
/** {@hide} */
interface ISettingsManager
interface IPartnerInterface
{
void setAirplaneModeEnabled(boolean enabled);
void setMobileDataEnabled(boolean enabled);
boolean setZenMode(int mode);
void shutdown();
void reboot();
String getCurrentHotwordPackageName();
}

View File

@@ -24,10 +24,10 @@ import android.util.Log;
/**
* <p>
* The SettingsManager allows applications to modify a subset of system settings.
* The PartnerInterface allows applications to interact with a subset of system settings.
* </p>
*/
public class SettingsManager {
public class PartnerInterface {
/**
* Turn off zen mode. This restores the original ring and interruption
* settings that the user had set before zen mode was enabled.
@@ -53,7 +53,7 @@ public class SettingsManager {
*/
public static final int ZEN_MODE_NO_INTERRUPTIONS = 2;
private static ISettingsManager sService;
private static IPartnerInterface sService;
private Context mContext;
@@ -70,11 +70,11 @@ public class SettingsManager {
public static final String MODIFY_SOUND_SETTINGS_PERMISSION =
"cyanogenmod.permission.MODIFY_SOUND_SETTINGS";
private static final String TAG = "SettingsManager";
private static final String TAG = "PartnerInterface";
private static SettingsManager sSettingsManagerInstance;
private static PartnerInterface sPartnerInterfaceInstance;
private SettingsManager(Context context) {
private PartnerInterface(Context context) {
Context appContext = context.getApplicationContext();
if (appContext != null) {
mContext = appContext;
@@ -85,25 +85,25 @@ public class SettingsManager {
}
/**
* Get or create an instance of the {@link cyanogenmod.app.SettingsManager}
* Get or create an instance of the {@link cyanogenmod.app.PartnerInterface}
* @param context
* @return {@link SettingsManager}
* @return {@link PartnerInterface}
*/
public static SettingsManager getInstance(Context context) {
if (sSettingsManagerInstance == null) {
sSettingsManagerInstance = new SettingsManager(context);
public static PartnerInterface getInstance(Context context) {
if (sPartnerInterfaceInstance == null) {
sPartnerInterfaceInstance = new PartnerInterface(context);
}
return sSettingsManagerInstance;
return sPartnerInterfaceInstance;
}
/** @hide */
static public ISettingsManager getService() {
static public IPartnerInterface getService() {
if (sService != null) {
return sService;
}
IBinder b = ServiceManager.getService(CMContextConstants.CM_SETTINGS_SERVICE);
IBinder b = ServiceManager.getService(CMContextConstants.CM_PARTNER_INTERFACE);
if (b != null) {
sService = ISettingsManager.Stub.asInterface(b);
sService = IPartnerInterface.Stub.asInterface(b);
return sService;
} else {
return null;
@@ -122,7 +122,7 @@ public class SettingsManager {
return;
}
try {
getService().setAirplaneModeEnabled(enabled);
sService.setAirplaneModeEnabled(enabled);
} catch (RemoteException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
@@ -140,7 +140,7 @@ public class SettingsManager {
return;
}
try {
getService().setMobileDataEnabled(enabled);
sService.setMobileDataEnabled(enabled);
} catch (RemoteException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
@@ -165,7 +165,7 @@ public class SettingsManager {
return false;
}
try {
return getService().setZenMode(mode);
return sService.setZenMode(mode);
} catch (RemoteException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
@@ -183,7 +183,7 @@ public class SettingsManager {
return;
}
try {
getService().shutdown();
sService.shutdown();
} catch (RemoteException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
@@ -200,9 +200,26 @@ public class SettingsManager {
return;
}
try {
getService().reboot();
sService.reboot();
} catch (RemoteException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
}
/**
* Retrieves the package name of the application that currently holds the
* {@link cyanogenmod.media.MediaRecorder.AudioSource#HOTWORD} input.
* @return The package name or null if no application currently holds the HOTWORD input.
*/
public String getCurrentHotwordPackageName() {
if (sService == null) {
return null;
}
try {
return sService.getCurrentHotwordPackageName();
} catch (RemoteException e) {
Log.e(TAG, e.getLocalizedMessage(), e);
}
return null;
}
}

View File

@@ -26,7 +26,47 @@ public class MediaRecorder {
public static final String CAPTURE_AUDIO_HOTWORD_PERMISSION
= "android.permission.CAPTURE_AUDIO_HOTWORD";
public class AudioSource {
/**
* <p>Broadcast Action: The state of the HOTWORD audio input has changed.:</p>
* <ul>
* <li><em>state</em> - A String value indicating the state of the input.
* {@link #EXTRA_HOTWORD_INPUT_STATE}. The value will be one of:
* {@link android.media.AudioRecord#RECORDSTATE_RECORDING} or
* {@link android.media.AudioRecord#RECORDSTATE_STOPPED}.
* </li>
* <li><em>package</em> - A String value indicating the package name of the application
* that currently holds the HOTWORD input.
* {@link #EXTRA_CURRENT_PACKAGE_NAME}
* </li>
* </ul>
*
* <p class="note">This is a protected intent that can only be sent
* by the system. It can only be received by packages that hold
* {@link android.Manifest.permission#CAPTURE_AUDIO_HOTWORD}.
*/
//@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_HOTWORD_INPUT_CHANGED
= "com.cyanogenmod.intent.action.HOTWORD_INPUT_CHANGED";
/**
* Extra for {@link #ACTION_HOTWORD_INPUT_CHANGED} that provides the package name of the
* app in that controlled the HOTWORD input when the state changed. Can be reused for other
* purposes.
*/
public static final String EXTRA_CURRENT_PACKAGE_NAME =
"com.cyanogenmod.intent.extra.CURRENT_PACKAGE_NAME";
/**
* Extra for {@link #ACTION_HOTWORD_INPUT_CHANGED} that provides the state of
* the input when the broadcast action was sent.
* @hide
*/
public static final String EXTRA_HOTWORD_INPUT_STATE =
"com.cyanogenmod.intent.extra.HOTWORD_INPUT_STATE";
public static class AudioSource {
/**
* Audio source for preemptible, low-priority software hotword detection
* It presents the same gain and pre processing tuning as

View File

@@ -99,7 +99,7 @@ public class Build {
* <li>Hardware Abstraction Framework Access via
* {@link cyanogenmod.hardware.CMHardwareManager} (Not for use by 3rd parties)
* <li>MSIM API via {@link cyanogenmod.app.CMTelephonyManager}
* <li>Settings interface for partners via {@link cyanogenmod.app.SettingsManager}
* <li>Interface for partners via {@link cyanogenmod.app.PartnerInterface}
* <li>Introductory Settings Provider {@link cyanogenmod.providers.CMSettings}
* <li>AlarmClock API via {@link cyanogenmod.alarmclock.CyanogenModAlarmClock}
* </ul>