恢复浮窗权限,还有很多地方使用,需要统一处理

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2021-12-15 15:32:45 +08:00
parent 4cd08785fb
commit c88798fd98
7 changed files with 199 additions and 785 deletions

View File

@@ -24,6 +24,7 @@ import com.aispeech.lite.AuthType;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.cloud.commons.BuildConfig;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.eagle.core.utilcode.util.ToastUtils;
import com.mogo.tts.base.IMogoTTS;
import com.mogo.tts.base.IMogoTTSCallback;
import com.mogo.tts.base.MogoTTSConstants;
@@ -48,7 +49,7 @@ import java.util.concurrent.ConcurrentHashMap;
* <p>
* 描述
*/
@Route( path = MogoTTSConstants.API_PATH )
@Route(path = MogoTTSConstants.API_PATH)
public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsListener {
private static final String TAG = "PadTTS";
@@ -59,12 +60,12 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
private Context mContext;
public synchronized void release() {
Logger.d( TAG, "release" );
if ( mCmdMap != null && !mCmdMap.isEmpty() && mVoiceClient != null ) {
for ( String cmd : mCmdMap.keySet() ) {
Logger.d(TAG, "release");
if (mCmdMap != null && !mCmdMap.isEmpty() && mVoiceClient != null) {
for (String cmd : mCmdMap.keySet()) {
try {
mVoiceClient.unRegisterCustomWakeupCmd( cmd );
} catch ( Exception e ) {
mVoiceClient.unRegisterCustomWakeupCmd(cmd);
} catch (Exception e) {
e.printStackTrace();
}
}
@@ -83,13 +84,13 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
private VoiceClient mVoiceClient;
private MogoVoiceManager mogoVoiceManager;
// 免唤醒指令
private Map< String, List< IMogoTTSCallback > > mCmdMap = new HashMap<>();
private Map<String, List<IMogoTTSCallback>> mCmdMap = new HashMap<>();
// 问答指令
private Map< String, IMogoTTSCallback > mQAndAMap = new HashMap<>();
private Map<String, IMogoTTSCallback> mQAndAMap = new HashMap<>();
// 单独的语音播放
private Map< String, IMogoTTSCallback > mSpeakVoiceMap = new HashMap<>();
private Map<String, IMogoTTSCallback> mSpeakVoiceMap = new HashMap<>();
private Map< String, String[] > mCacheUnWakeupCommands = new ConcurrentHashMap<>();
private Map<String, String[]> mCacheUnWakeupCommands = new ConcurrentHashMap<>();
private static final String TTS_BACK_RES_ZHILING = "zhilingf_common_back_ce_local.v2.1.0.bin";
private int audioRecorderType = DUILiteConfig.TYPE_COMMON_MIC;
@@ -101,13 +102,13 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
public static final String TTS_BACK_RES_GUODGM = "tts/guodgm_common_back_ce_local.v2.1.0.bin";
private AILocalTTSEngine mEngine;
private AILocalTTSIntent mAILocalTTSIntent;
private String[] mBackResBinArray = new String[]{TTS_BACK_RES_ZHILING,TTS_BACK_RES_GUODGM};
private String[] mBackResBinArray = new String[]{TTS_BACK_RES_ZHILING, TTS_BACK_RES_GUODGM};
// 单独的语音播放
private boolean mHasAuth;
private void initFlushStatus() {
if ( !mHasFlush ) {
mHasFlush = isVoiceServiceReady( mContext );
if (!mHasFlush) {
mHasFlush = isVoiceServiceReady(mContext);
}
}
@@ -127,7 +128,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
.setSavedDirPath("/sdcard/aispeech/aecPcmFile/")//设置echo前后音频保存路径
.create();
if (BuildConfig.DEBUG){
if (BuildConfig.DEBUG) {
DUILiteSDK.openLog();//开启日志需要在sdk init 之前调用
}
@@ -137,9 +138,9 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
.setProductKey("1fe5930844b488a8d32d9ef7717be7dc")
.setProductSecret("f601ecc407986b548ac8ab2a9144162e")
.setAuthConfig(onlineBuilder.create())//授权配置
// .setRecorderConfig(recorderConfig)//设置录音配置
// .setUploadConfig(uploadConfig)//设置日志上传配置
// .setTtsCacheDir("/sdcard/speech/cache") //设置tts cache文件存放目录
// .setRecorderConfig(recorderConfig)//设置录音配置
// .setUploadConfig(uploadConfig)//设置日志上传配置
// .setTtsCacheDir("/sdcard/speech/cache") //设置tts cache文件存放目录
.setEchoConfig(echoConfig)
.create(), new DUILiteSDK.InitListener() {
@Override
@@ -152,7 +153,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
@Override
public void error(String errorCode, final String errorInfo) {
Logger.e(TAG, "error code : " + errorCode + " , error info :" + errorInfo);
// throw new IllegalStateException("授权失败,请检查授权配置");
// throw new IllegalStateException("授权失败,请检查授权配置");
}
});
@@ -163,6 +164,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
Logger.d(TAG, "core version is: " + core_version);
} catch (Exception e) {
e.printStackTrace();
ToastUtils.showShort("PadTTS 模块初始化异常");
}
}
@@ -216,10 +218,10 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
/**
* 初始化
*/
private void initSpeech( Context context ) {
private void initSpeech(Context context) {
Logger.d(TAG, "initSpeech");
mogoVoiceManager = MogoVoiceManagerImpl.getInstance();
mogoVoiceManager.init( context, new OnConnStatusListener() {
mogoVoiceManager.init(context, new OnConnStatusListener() {
@Override
public void onSuccess() {
mInitReady = true;
@@ -229,7 +231,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
public void onFailed() {
}
} );
});
}
/**
@@ -243,78 +245,78 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
}
@Override
public void onCmdSelected( String cmd ) {
if ( !mCmdMap.containsKey( cmd ) ) {
public void onCmdSelected(String cmd) {
if (!mCmdMap.containsKey(cmd)) {
return;
}
Logger.d( TAG, "received command: %s", cmd );
Logger.d(TAG, "received command: %s", cmd);
Iterator< IMogoTTSCallback > iterator = null;
Iterator<IMogoTTSCallback> iterator = null;
try {
List< IMogoTTSCallback > cmdCallBacks = mCmdMap.get( cmd );
iterator = new ArrayList<>( cmdCallBacks ).iterator();
} catch ( Exception e ) {
List<IMogoTTSCallback> cmdCallBacks = mCmdMap.get(cmd);
iterator = new ArrayList<>(cmdCallBacks).iterator();
} catch (Exception e) {
e.printStackTrace();
}
while ( iterator != null && iterator.hasNext() ) {
while (iterator != null && iterator.hasNext()) {
IMogoTTSCallback callBack = iterator.next();
if ( callBack != null ) {
callBack.onCmdSelected( cmd );
if (callBack != null) {
callBack.onCmdSelected(cmd);
}
}
}
@Override
public void onCmdAction( String speakText ) {
if ( !TextUtils.isEmpty( mLastQAndASpeakText ) ) {
IMogoTTSCallback cmdCallBack = mQAndAMap.remove( mLastQAndASpeakText );
if ( cmdCallBack != null ) {
cmdCallBack.onCmdAction( speakText );
public void onCmdAction(String speakText) {
if (!TextUtils.isEmpty(mLastQAndASpeakText)) {
IMogoTTSCallback cmdCallBack = mQAndAMap.remove(mLastQAndASpeakText);
if (cmdCallBack != null) {
cmdCallBack.onCmdAction(speakText);
}
}
}
@Override
public void onCmdCancel( String speakText ) {
if ( !TextUtils.isEmpty( mLastQAndASpeakText ) ) {
IMogoTTSCallback cmdCallBack = mQAndAMap.remove( mLastQAndASpeakText );
if ( cmdCallBack != null ) {
cmdCallBack.onCmdCancel( speakText );
public void onCmdCancel(String speakText) {
if (!TextUtils.isEmpty(mLastQAndASpeakText)) {
IMogoTTSCallback cmdCallBack = mQAndAMap.remove(mLastQAndASpeakText);
if (cmdCallBack != null) {
cmdCallBack.onCmdCancel(speakText);
}
}
}
@Override
public void onSpeakEnd( String speakText ) {
if ( mQAndAMap.containsKey( speakText ) ) {
public void onSpeakEnd(String speakText) {
if (mQAndAMap.containsKey(speakText)) {
mLastQAndASpeakText = speakText;
IMogoTTSCallback cmdCallBack = mQAndAMap.get( speakText );
if ( cmdCallBack != null ) {
cmdCallBack.onSpeakEnd( speakText );
IMogoTTSCallback cmdCallBack = mQAndAMap.get(speakText);
if (cmdCallBack != null) {
cmdCallBack.onSpeakEnd(speakText);
return;
}
}
IMogoTTSCallback callBack = mSpeakVoiceMap.remove( speakText );
if ( callBack != null ) {
callBack.onSpeakEnd( speakText );
IMogoTTSCallback callBack = mSpeakVoiceMap.remove(speakText);
if (callBack != null) {
callBack.onSpeakEnd(speakText);
}
}
@Override
public void onSpeakSelectTimeOut( String speakText ) {
if ( mQAndAMap.containsKey( speakText ) ) {
if ( TextUtils.equals( speakText, mLastQAndASpeakText ) ) {
public void onSpeakSelectTimeOut(String speakText) {
if (mQAndAMap.containsKey(speakText)) {
if (TextUtils.equals(speakText, mLastQAndASpeakText)) {
mLastQAndASpeakText = null;
}
IMogoTTSCallback cmdCallBack = mQAndAMap.remove( speakText );
if ( cmdCallBack != null ) {
cmdCallBack.onSpeakSelectTimeOut( speakText );
IMogoTTSCallback cmdCallBack = mQAndAMap.remove(speakText);
if (cmdCallBack != null) {
cmdCallBack.onSpeakSelectTimeOut(speakText);
return;
}
}
IMogoTTSCallback callBack = mSpeakVoiceMap.remove( speakText );
if ( callBack != null ) {
callBack.onSpeakSelectTimeOut( speakText );
IMogoTTSCallback callBack = mSpeakVoiceMap.remove(speakText);
if (callBack != null) {
callBack.onSpeakSelectTimeOut(speakText);
}
}
@@ -323,7 +325,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
*
* @param text
*/
public void speakTTSVoice( String text, IMogoTTSCallback callBack ) {
public void speakTTSVoice(String text, IMogoTTSCallback callBack) {
speakTTSVoice(text);
// try {
// initFlushStatus();
@@ -341,11 +343,11 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
*
* @param text
*/
public void speakTTSVoice( String text ) {
Logger.d( TAG, "speakTTSVoice");
public void speakTTSVoice(String text) {
Logger.d(TAG, "speakTTSVoice");
if (mEngine != null && mHasAuth) {
// 合成并播放
mEngine.speak(text,"1024",mAILocalTTSIntent);
mEngine.speak(text, "1024", mAILocalTTSIntent);
// 合成音频不播放同时输出实时pcm音频,音频回调在onSynthesizeDataArrived接口
// mEngine.synthesize(mAILocalTTSIntent, text, "1024");
}
@@ -357,14 +359,14 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
* @param text 播报内容
* @param type 播报策略
*/
public void speakTTSVoice( String text, PreemptType type, IMogoTTSCallback callBack ) {
public void speakTTSVoice(String text, PreemptType type, IMogoTTSCallback callBack) {
try {
initFlushStatus();
if ( mHasFlush ) {
mSpeakVoiceMap.put( text, callBack );
if (mHasFlush) {
mSpeakVoiceMap.put(text, callBack);
VoiceClient.PreemptType preemptType = VoiceClient.PreemptType.PREEMPT_TYPE_NONE;
if ( type != null ) {
switch ( type ) {
if (type != null) {
switch (type) {
case PREEMPT_TYPE_NEXT:
preemptType = VoiceClient.PreemptType.PREEMPT_TYPE_NEXT;
break;
@@ -382,7 +384,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
speakTTSVoice(text);
// mVoiceClient.speakTypeText( text, preemptType );
}
} catch ( Exception e ) {
} catch (Exception e) {
e.printStackTrace();
}
}
@@ -392,10 +394,10 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
*
* @param tts 播报内容
*/
public void speakQAndACmd( String tts, IMogoTTSCallback callBack ) {
public void speakQAndACmd(String tts, IMogoTTSCallback callBack) {
initFlushStatus();
if ( mHasFlush ) {
mQAndAMap.put( tts, callBack );
if (mHasFlush) {
mQAndAMap.put(tts, callBack);
speakTTSVoice(tts);
// mVoiceClient.speakTtsAndRegistCmd( tts );
}
@@ -408,10 +410,10 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
* @param okCmds 确认命令唤醒词
* @param cancelCmds 取消命令唤醒词
*/
public void speakQAndACmd( String tts, String[] okCmds, String[] cancelCmds, IMogoTTSCallback callBack ) {
public void speakQAndACmd(String tts, String[] okCmds, String[] cancelCmds, IMogoTTSCallback callBack) {
initFlushStatus();
if ( mHasFlush ) {
mQAndAMap.put( tts, callBack );
if (mHasFlush) {
mQAndAMap.put(tts, callBack);
speakTTSVoice(tts);
// mVoiceClient.speakTtsAndRegistCmd( tts, okCmds, cancelCmds );
}
@@ -424,19 +426,19 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
* @param cmdWords
* @param callBack
*/
public void registerUnWakeupCommand( String cmd, String[] cmdWords, IMogoTTSCallback callBack ) {
if ( !mCmdMap.containsKey( cmd ) ) {
mCmdMap.put( cmd, new ArrayList<>() );
public void registerUnWakeupCommand(String cmd, String[] cmdWords, IMogoTTSCallback callBack) {
if (!mCmdMap.containsKey(cmd)) {
mCmdMap.put(cmd, new ArrayList<>());
}
mCmdMap.get( cmd ).add( callBack );
mCmdMap.get(cmd).add(callBack);
initFlushStatus();
if ( mHasFlush ) {
mVoiceClient.registerCustomWakeupCmd( cmd, cmdWords );
mCacheUnWakeupCommands.remove( cmd );
if (mHasFlush) {
mVoiceClient.registerCustomWakeupCmd(cmd, cmdWords);
mCacheUnWakeupCommands.remove(cmd);
}
Logger.i( TAG, "cache un wakeup command2. %s", cmd );
mCacheUnWakeupCommands.put( cmd, cmdWords );
Logger.i(TAG, "cache un wakeup command2. %s", cmd);
mCacheUnWakeupCommands.put(cmd, cmdWords);
}
/**
@@ -445,14 +447,14 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
* @param cmd
* @param cmdWords
*/
private void registerUnWakeupCommand( String cmd, String[] cmdWords ) {
private void registerUnWakeupCommand(String cmd, String[] cmdWords) {
initFlushStatus();
if ( mHasFlush ) {
mVoiceClient.registerCustomWakeupCmd( cmd, cmdWords );
mCacheUnWakeupCommands.remove( cmd );
if (mHasFlush) {
mVoiceClient.registerCustomWakeupCmd(cmd, cmdWords);
mCacheUnWakeupCommands.remove(cmd);
}
Logger.i( TAG, "cache un wakeup command. %s", cmd );
mCacheUnWakeupCommands.put( cmd, cmdWords );
Logger.i(TAG, "cache un wakeup command. %s", cmd);
mCacheUnWakeupCommands.put(cmd, cmdWords);
}
/**
@@ -460,14 +462,14 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
*
* @param cmd
*/
public synchronized void unregisterUnWakeupCommand( String cmd ) {
mCmdMap.remove( cmd );
public synchronized void unregisterUnWakeupCommand(String cmd) {
mCmdMap.remove(cmd);
try {
mVoiceClient.unRegisterCustomWakeupCmd( cmd );
} catch ( Exception e ) {
mVoiceClient.unRegisterCustomWakeupCmd(cmd);
} catch (Exception e) {
e.printStackTrace();
}
mCacheUnWakeupCommands.remove( cmd );
mCacheUnWakeupCommands.remove(cmd);
}
/**
@@ -475,88 +477,88 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
*
* @param cmd
*/
public synchronized void unregisterUnWakeupCommand( String cmd, IMogoTTSCallback callBack ) {
if ( mCmdMap.containsKey( cmd ) ) {
List< IMogoTTSCallback > callBacks = mCmdMap.get( cmd );
if ( callBacks != null ) {
callBacks.remove( callBack );
public synchronized void unregisterUnWakeupCommand(String cmd, IMogoTTSCallback callBack) {
if (mCmdMap.containsKey(cmd)) {
List<IMogoTTSCallback> callBacks = mCmdMap.get(cmd);
if (callBacks != null) {
callBacks.remove(callBack);
}
if ( callBacks.isEmpty() ) {
mCmdMap.remove( cmd );
if (callBacks.isEmpty()) {
mCmdMap.remove(cmd);
try {
mVoiceClient.unRegisterCustomWakeupCmd( cmd );
} catch ( Exception e ) {
mVoiceClient.unRegisterCustomWakeupCmd(cmd);
} catch (Exception e) {
e.printStackTrace();
}
mCacheUnWakeupCommands.remove( cmd );
mCacheUnWakeupCommands.remove(cmd);
}
}
}
public static void startAssistant( Context context ) {
startAssistant( context, 1 );
public static void startAssistant(Context context) {
startAssistant(context, 1);
}
/**
* @param context
* @param status window_start_cancel 0 - 结束, 1 - 显示, 2 - 未激活调试进入
*/
public static void startAssistant( Context context, int status ) {
public static void startAssistant(Context context, int status) {
Logger.w(TAG, "startAssistant status = %d", status);
final Intent intent = new Intent();
intent.setFlags( Intent.FLAG_INCLUDE_STOPPED_PACKAGES );
intent.setAction( "pvetec.intent.action.txz.switch" );
intent.putExtra( "window_start_cancel", status );
intent.putExtra( "extra_switch_type", "window_start_cancel" );
Logger.d( TAG, "status = %d", status );
context.sendBroadcast( intent );
intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
intent.setAction("pvetec.intent.action.txz.switch");
intent.putExtra("window_start_cancel", status);
intent.putExtra("extra_switch_type", "window_start_cancel");
Logger.d(TAG, "status = %d", status);
context.sendBroadcast(intent);
}
public synchronized void flush() {
if ( mCacheUnWakeupCommands.isEmpty() ) {
if (mCacheUnWakeupCommands.isEmpty()) {
return;
}
mHasFlush = true;
Logger.d( TAG, "flush cache voice command when voice service ready." );
final Map< String, String[] > tmp = new HashMap<>( mCacheUnWakeupCommands );
for ( String cmd : tmp.keySet() ) {
registerUnWakeupCommand( cmd, tmp.get( cmd ) );
Logger.d(TAG, "flush cache voice command when voice service ready.");
final Map<String, String[]> tmp = new HashMap<>(mCacheUnWakeupCommands);
for (String cmd : tmp.keySet()) {
registerUnWakeupCommand(cmd, tmp.get(cmd));
}
}
private boolean isVoiceServiceReady( Context context ) {
if ( isProcessRunning( context, getPackageUid( context, "com.zhidao.speech" ) )) {
Logger.d( TAG, "pad txz is voiceServiceReady" );
private boolean isVoiceServiceReady(Context context) {
if (isProcessRunning(context, getPackageUid(context, "com.zhidao.speech"))) {
Logger.d(TAG, "pad txz is voiceServiceReady");
return true;
} else if ( isProcessRunning( context, getPackageUid( context, "com.txznet.txz" ) )
&& isProcessRunning( context, getPackageUid( context, "com.txznet.adapter" ) ) ) {
Logger.d( TAG, "txz is voiceServiceReady" );
} else if (isProcessRunning(context, getPackageUid(context, "com.txznet.txz"))
&& isProcessRunning(context, getPackageUid(context, "com.txznet.adapter"))) {
Logger.d(TAG, "txz is voiceServiceReady");
return true;
}
return true;
}
public void speakTTSAndDuck( String text ) {
speakTTSAndDuck( text, null );
public void speakTTSAndDuck(String text) {
speakTTSAndDuck(text, null);
}
public void speakTTSAndDuck( String text, IMogoTTSCallback callBack ) {
public void speakTTSAndDuck(String text, IMogoTTSCallback callBack) {
try {
if ( mInitReady ) {
mSpeakVoiceMap.put( text, callBack );
mogoVoiceManager.toSpeak( text, -3, this );
if (mInitReady) {
mSpeakVoiceMap.put(text, callBack);
mogoVoiceManager.toSpeak(text, -3, this);
}
} catch ( Exception e ) {
} catch (Exception e) {
e.printStackTrace();
}
}
public void shutUp( String ttsId, String text ) {
public void shutUp(String ttsId, String text) {
try {
mSpeakVoiceMap.remove( text );
mogoVoiceManager.shutUp( ttsId );
} catch ( Exception e ) {
mSpeakVoiceMap.remove(text);
mogoVoiceManager.shutUp(ttsId);
} catch (Exception e) {
e.printStackTrace();
}
}
@@ -569,44 +571,44 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
mVoiceClient.breakOffSpeak();
}
public void clearTTSCallback( String text ) {
public void clearTTSCallback(String text) {
try {
mSpeakVoiceMap.remove( text );
} catch ( Exception e ) {
mSpeakVoiceMap.remove(text);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onTtsStart( String ttsId, String text ) {
IMogoTTSCallback callBack = mSpeakVoiceMap.get( text );
if ( callBack != null ) {
callBack.onTTSStart( ttsId, text );
public void onTtsStart(String ttsId, String text) {
IMogoTTSCallback callBack = mSpeakVoiceMap.get(text);
if (callBack != null) {
callBack.onTTSStart(ttsId, text);
}
}
@Override
public void onTtsFinish( String ttsId, String text ) {
IMogoTTSCallback callBack = mSpeakVoiceMap.remove( text );
if ( callBack != null ) {
callBack.onTTSEnd( ttsId, text );
public void onTtsFinish(String ttsId, String text) {
IMogoTTSCallback callBack = mSpeakVoiceMap.remove(text);
if (callBack != null) {
callBack.onTTSEnd(ttsId, text);
}
}
@Override
public void onTtsError( String ttsId, String text ) {
IMogoTTSCallback callBack = mSpeakVoiceMap.remove( text );
if ( callBack != null ) {
callBack.onTTSError( ttsId, text );
public void onTtsError(String ttsId, String text) {
IMogoTTSCallback callBack = mSpeakVoiceMap.remove(text);
if (callBack != null) {
callBack.onTTSError(ttsId, text);
}
}
@Override
public void init( Context context ) {
if ( context != null ) {
public void init(Context context) {
if (context != null) {
mContext = context.getApplicationContext();
mVoiceClient = new VoiceClient( mContext );
mVoiceClient.setCallBack( this );
mVoiceClient = new VoiceClient(mContext);
mVoiceClient.setCallBack(this);
initFlushStatus();
initTtsConfig();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@@ -622,20 +624,20 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
}
@Override
public void startAIAssist( Context context ) {
startAssistant( context, 1 );
public void startAIAssist(Context context) {
startAssistant(context, 1);
}
@Override
public void startAIAssist( Context context, int status ) {
public void startAIAssist(Context context, int status) {
Logger.w(TAG, "startAIAssist status = %d", status);
final Intent intent = new Intent();
intent.setFlags( Intent.FLAG_INCLUDE_STOPPED_PACKAGES );
intent.setAction( "pvetec.intent.action.txz.switch" );
intent.putExtra( "window_start_cancel", status );
intent.putExtra( "extra_switch_type", "window_start_cancel" );
Logger.d( TAG, "status = %d", status );
context.sendBroadcast( intent );
intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
intent.setAction("pvetec.intent.action.txz.switch");
intent.putExtra("window_start_cancel", status);
intent.putExtra("extra_switch_type", "window_start_cancel");
Logger.d(TAG, "status = %d", status);
context.sendBroadcast(intent);
}
private static class AILocalTTSListenerImpl implements AITTSListener {
@@ -688,29 +690,30 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack, OnTtsList
}
}
public static boolean isProcessRunning( Context context, int uid ) {
if ( context == null ) {
public static boolean isProcessRunning(Context context, int uid) {
if (context == null) {
return false;
}
ActivityManager am = ( ActivityManager ) context.getSystemService( Context.ACTIVITY_SERVICE );
List< ActivityManager.RunningServiceInfo > runningServiceInfos = am.getRunningServices( 200 );
if ( runningServiceInfos.size() > 0 ) {
for ( ActivityManager.RunningServiceInfo appProcess : runningServiceInfos ) {
if ( uid == appProcess.uid ) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> runningServiceInfos = am.getRunningServices(200);
if (runningServiceInfos.size() > 0) {
for (ActivityManager.RunningServiceInfo appProcess : runningServiceInfos) {
if (uid == appProcess.uid) {
return true;
}
}
}
return false;
}
//获取已安装应用的 uid-1 表示未安装此应用或程序异常
public static int getPackageUid( Context context, String packageName ) {
public static int getPackageUid(Context context, String packageName) {
try {
ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo( packageName, 0 );
if ( applicationInfo != null ) {
ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(packageName, 0);
if (applicationInfo != null) {
return applicationInfo.uid;
}
} catch ( Exception e ) {
} catch (Exception e) {
return -1;
}
return -1;