56 lines
1.8 KiB
Java
56 lines
1.8 KiB
Java
package com.ttstd.dialer.receiver;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
|
|
import com.tencent.mmkv.MMKV;
|
|
import com.ttstd.dialer.config.CommonConfig;
|
|
import com.ttstd.dialer.manager.AppManager;
|
|
import com.ttstd.dialer.utils.Logger;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
|
|
public class AppChangedReceiver extends BroadcastReceiver {
|
|
private static final String TAG = "AppChangedReceiver";
|
|
|
|
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
|
|
|
// 创建一个单线程池用于处理应用变更事件
|
|
private static final ExecutorService sExecutor = Executors.newSingleThreadExecutor();
|
|
|
|
@Override
|
|
public void onReceive(final Context context, Intent intent) {
|
|
String action = intent.getAction();
|
|
Logger.e(TAG, "onReceive: " + "action = " + action);
|
|
if (TextUtils.isEmpty(action)) {
|
|
return;
|
|
}
|
|
String packageName = intent.getDataString().replace("package:", "");
|
|
switch (action) {
|
|
case Intent.ACTION_PACKAGE_ADDED:
|
|
Logger.e(TAG, "onReceive: added " + packageName);
|
|
break;
|
|
case Intent.ACTION_PACKAGE_REPLACED:
|
|
Logger.e(TAG, "onReceive: replaced " + packageName);
|
|
break;
|
|
case Intent.ACTION_PACKAGE_REMOVED:
|
|
Logger.e(TAG, "onReceive: removed " + packageName);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
sExecutor.execute(() -> {
|
|
try {
|
|
AppManager.getInstance().updateApp(packageName);
|
|
} catch (Exception e) {
|
|
Log.e(TAG, "onReceive: updateApp " + e.getMessage());
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|