正在查看: 万能钥匙 v1.1.23 应用的 GuardServiceAction.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 万能钥匙 v1.1.23 应用的 GuardServiceAction.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.sdk.plus.action.guard;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.IBinder;
import android.text.TextUtils;
import com.sdk.plus.WakedType;
import com.sdk.plus.WkWus;
import com.sdk.plus.bean.GuardTypeBean;
import com.sdk.plus.config.Consts;
import com.sdk.plus.config.CoreRuntimeInfo;
import com.sdk.plus.config.DynamicConfig;
import com.sdk.plus.config.RuntimeInfo;
import com.sdk.plus.log.WusLog;
import com.sdk.plus.utils.WusUtils;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class GuardServiceAction {
public static final String TAG = "WUS_GSA";
private static GuardServiceAction instance;
private volatile boolean isEnhService = false;
private HashMap<String, String> guardIntentInfoMap = new HashMap<>();
private Map<String, GuardType> pmPkgGuardMap = new HashMap();
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
public static class GuardResult {
private String guardServiceName;
private boolean guardSuccess;
private int type;
private GuardResult(int i, boolean z, String str) {
this.type = i;
this.guardSuccess = z;
this.guardServiceName = str;
}
}
private GuardServiceAction() {
}
private void bindService(Intent intent) {
WkWus.bindService(CoreRuntimeInfo.context, intent, new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
}
}, 1);
}
private List<String> filterGuardList(Map<String, List<String>> map, List<String> list, int i, boolean z) {
ArrayList<String> arrayList = new ArrayList();
if (map != null && !map.isEmpty()) {
if (!"none".equalsIgnoreCase(DynamicConfig.guardIntentInfo) && !TextUtils.isEmpty(DynamicConfig.guardIntentInfo)) {
try {
if (this.guardIntentInfoMap == null) {
this.guardIntentInfoMap = new HashMap<>();
}
this.guardIntentInfoMap.clear();
String[] split = DynamicConfig.guardIntentInfo.split(",");
if (split != null && split.length > 0) {
for (String str : split) {
String[] split2 = str.split(":");
if (split2 != null && split2.length == 3) {
this.guardIntentInfoMap.put(split2[0], split2[1] + ":" + split2[2]);
}
}
}
} catch (Throwable th) {
WusLog.e(th);
}
}
if (list != null && !list.isEmpty()) {
WusLog.log(TAG, "remove all running, running = " + list.toString());
Iterator<Map.Entry<String, List<String>>> it = map.entrySet().iterator();
while (it.hasNext()) {
if (list.contains(it.next().getKey())) {
it.remove();
}
}
}
WusLog.log(TAG, "after remove running, guardList = " + map.toString());
if (!DynamicConfig.guardBlackList.equals("none")) {
ArrayList arrayList2 = new ArrayList(Arrays.asList(DynamicConfig.guardBlackList.split(",")));
Iterator<Map.Entry<String, List<String>>> it2 = map.entrySet().iterator();
while (it2.hasNext()) {
if (GuardUtils.isInBlackList(it2.next().getKey(), arrayList2)) {
it2.remove();
}
}
}
WusLog.log(TAG, "after remove blacklist, guardList = " + map.toString());
List<String> pMGuardBlackList = getPMGuardBlackList(i, z);
if (pMGuardBlackList != null && !pMGuardBlackList.isEmpty()) {
Iterator<Map.Entry<String, List<String>>> it3 = map.entrySet().iterator();
while (it3.hasNext()) {
if (pMGuardBlackList.contains(it3.next().getKey())) {
it3.remove();
}
}
}
WusLog.log(TAG, "after remove pm blacklist pkgs, guardList = " + map.toString());
if (!TextUtils.isEmpty(DynamicConfig.guardWhiteList) && !DynamicConfig.guardWhiteList.equals("none") && !map.isEmpty()) {
ArrayList<String> arrayList3 = new ArrayList(Arrays.asList(DynamicConfig.guardWhiteList.split(",")));
WusLog.log(TAG, "white list = " + arrayList3.toString());
if (!arrayList3.isEmpty()) {
for (String str2 : arrayList3) {
if (map.containsKey(str2)) {
arrayList.add(str2);
}
}
}
}
if (!map.isEmpty()) {
ArrayList arrayList4 = new ArrayList(map.keySet());
for (String str3 : arrayList) {
if (arrayList4.contains(str3)) {
arrayList4.remove(str3);
}
}
Collections.shuffle(arrayList4);
arrayList.addAll(arrayList4);
}
WusLog.log(TAG, "after add all whitelist, guardList = " + arrayList.toString());
}
return arrayList;
}
private String getGuardService(List<String> list) {
String str = RuntimeInfo.GUARD_SERVICE_NAME;
if (list != null && !list.isEmpty()) {
if (list.contains(Consts.DEFAULT_WAKEUP_SERVICE)) {
this.isEnhService = true;
if (list.size() == 1) {
return list.get(0);
}
for (String str2 : list) {
if (!str2.equals(Consts.DEFAULT_WAKEUP_SERVICE) && !str2.equals(RuntimeInfo.GUARD_SERVICE_NAME)) {
return str2;
}
}
return Consts.DEFAULT_WAKEUP_SERVICE;
}
if (list.size() == 1) {
return list.get(0);
}
for (String str3 : list) {
if (!str3.equals(RuntimeInfo.GUARD_SERVICE_NAME)) {
return str3;
}
}
}
return str;
}
private Map<String, List<String>> getHasServiceAppList(List<String> list, List<String> list2, boolean z) {
Map<String, List<String>> guardMap = GuardHelper.getInstance().getGuardMap();
if (!guardMap.isEmpty()) {
List<ActivityManager.RunningServiceInfo> runningServices = WkWus.getRunningServices(2000);
if (runningServices != null && !runningServices.isEmpty()) {
WusLog.log(TAG, "rsi " + runningServices.size());
for (Map.Entry<String, List<String>> entry : guardMap.entrySet()) {
String key = entry.getKey();
Iterator<String> it = entry.getValue().iterator();
while (true) {
if (!it.hasNext()) {
break;
}
if (WusUtils.isServiceRunning(it.next(), key, runningServices) && !list.contains(key)) {
list.add(key);
break;
}
}
}
} else {
WusLog.log(TAG, "rsi empty.");
return guardMap;
}
}
return guardMap;
}
public static synchronized GuardServiceAction getInstance() {
GuardServiceAction guardServiceAction;
synchronized (GuardServiceAction.class) {
try {
if (instance == null) {
instance = new GuardServiceAction();
}
guardServiceAction = instance;
} catch (Throwable th) {
throw th;
}
}
return guardServiceAction;
}
private List<String> getPMGuardBlackList(int i, boolean z) {
if (TextUtils.isEmpty(DynamicConfig.guardPMBlacklist)) {
WusLog.log(TAG, "pMBlacklist is empty or null");
return null;
}
String[] split = DynamicConfig.guardPMBlacklist.split(",");
if (split.length == 0) {
WusLog.log(TAG, "pMBlacklist is empty or null");
return null;
}
String phoneBrand = WusUtils.getPhoneBrand();
if (TextUtils.isEmpty(phoneBrand)) {
return null;
}
ArrayList arrayList = new ArrayList();
this.pmPkgGuardMap.clear();
int length = split.length;
char c = 0;
int i2 = 0;
while (i2 < length) {
String str = split[i2];
if (!TextUtils.isEmpty(str)) {
String[] split2 = str.split(":");
String str2 = split2[1];
if (split2.length == 4 && phoneBrand.equalsIgnoreCase(split2[c]) && !TextUtils.isEmpty(str2) && !arrayList.contains(str2)) {
if (WusUtils.checkApp(str2)) {
boolean parseBoolean = Boolean.parseBoolean(split2[2]);
boolean parseBoolean2 = Boolean.parseBoolean(split2[3]);
WusLog.log(TAG, "brand = " + phoneBrand + "|pkg = " + str2 + "|aEnable = " + parseBoolean + "|sEnable = " + parseBoolean2);
if (!parseBoolean || !parseBoolean2) {
if (!parseBoolean && !parseBoolean2) {
arrayList.add(str2);
} else if (i == 2 && !parseBoolean2) {
WusLog.log(TAG, "guard type = " + i + "|pkg = " + str2 + " matched, in pm black list ###");
arrayList.add(str2);
} else if (i == 1) {
if (parseBoolean) {
Intent intent = new Intent();
intent.setClassName(str2, RuntimeInfo.GUARD_ACTIVITY_NEW);
boolean isActivityExist = WusUtils.isActivityExist(intent);
intent.setClassName(str2, RuntimeInfo.GUARD_ACTIVITY);
if (isActivityExist || WusUtils.isActivityExist(intent)) {
this.pmPkgGuardMap.put(str2, GuardType.GACTIVITY);
} else {
arrayList.add(str2);
WusLog.log(TAG, "getPMGuardBlackList-> " + str2 + " activitySet = false, add to pMGuardBlackList");
}
} else if (z) {
this.pmPkgGuardMap.put(str2, GuardType.SERVICE);
} else {
arrayList.add(str2);
}
}
}
} else {
WusLog.log(TAG, "pkg = " + str2 + " not install");
}
}
}
i2++;
c = 0;
}
WusLog.log(TAG, "PMGuardBlack-> = " + arrayList.toString());
return arrayList;
}
private void guard(int i, List<String> list, boolean z) {
if (WkWus.canWake()) {
try {
ArrayList arrayList = new ArrayList();
Map<String, List<String>> hasServiceAppList = getHasServiceAppList(arrayList, list, z);
if (hasServiceAppList.size() <= 0) {
WusLog.log(TAG, "hasServiceAppList size <= 0");
return;
}
if (i == 2 && !z) {
GuardResultHandle.saveData2Look("none", i, this.simpleDateFormat.format(new Date()), 3);
}
startSDK(arrayList, hasServiceAppList, i, false, z);
} catch (Throwable th) {
WusLog.e(th);
}
}
}
private boolean isBindService(String str) {
try {
if (TextUtils.isEmpty(DynamicConfig.bindServiceWhiteList) || "none".equalsIgnoreCase(DynamicConfig.bindServiceWhiteList)) {
return false;
}
if ("*".equals(DynamicConfig.bindServiceWhiteList)) {
return true;
}
List asList = Arrays.asList(DynamicConfig.bindServiceWhiteList.split(","));
if (asList == null || asList.isEmpty()) {
return false;
}
return asList.contains(str);
} catch (Throwable th) {
WusLog.e(th);
return false;
}
}
private void queryEnhProvider(String str) {
String str2 = RuntimeInfo.dynamicProviderMap.get(str);
Cursor cursor = null;
if (!TextUtils.isEmpty(str2) && GuardUtils.getProviders(str, str2)) {
try {
ContentResolver contentResolver = CoreRuntimeInfo.context.getContentResolver();
Uri parse = Uri.parse("content://com.sdk.plus." + str + "/*");
if (parse == null) {
return;
}
WusLog.log(TAG, "dyn pd.");
if (WkWus.canWakePackage(str)) {
cursor = WkWus.query(contentResolver, parse, null, null, null, null);
WkWus.onStartWake(WakedType.FROM_PROVIDER, str);
}
if (cursor != null) {
cursor.close();
}
} catch (Throwable th) {
try {
WusLog.e(th);
if (cursor != null) {
cursor.close();
}
} finally {
}
}
} else {
if (!GuardUtils.getProviders(str, Consts.DEFAULT_WAKEUP_PROVIDER)) {
return;
}
try {
ContentResolver contentResolver2 = CoreRuntimeInfo.context.getContentResolver();
Uri parse2 = Uri.parse("content://com.sdk.plus." + str + "/*");
if (parse2 == null) {
return;
}
WusLog.log(TAG, "enh pd.");
if (WkWus.canWakePackage(str)) {
cursor = WkWus.query(contentResolver2, parse2, null, null, null, null);
WkWus.onStartWake(WakedType.FROM_PROVIDER, str);
}
if (cursor != null) {
cursor.close();
}
} catch (Throwable th2) {
try {
WusLog.e(th2);
if (cursor != null) {
cursor.close();
}
} finally {
}
}
}
}
private void saveResultAndCheck(String str, int i, String str2, String str3) {
try {
GuardResultHandle.saveData2Look(str, i, str3, 0);
String str4 = str.split(",")[0];
String str5 = str.split(",")[1];
WusLog.log("WUS_GSA_guard", "success start " + str4);
WusLog.log("WUS_GSA_guard", "success start service " + str4);
ArrayList arrayList = new ArrayList();
arrayList.add(str2);
HashMap hashMap = new HashMap();
hashMap.put(GuardResultHandle.GUARD_PACKNAME, str4);
hashMap.put(GuardResultHandle.GUARD_SERVICENAME, str5);
hashMap.put(GuardResultHandle.GUARD_DATATIME, str3);
hashMap.put(GuardResultHandle.GUARD_CHECKLIST, arrayList);
GuardResultHandle.checkServiceTimer(hashMap, 0, i);
} catch (Throwable th) {
WusLog.e(th);
WusLog.log(TAG, "saveResultAndCheck exception = " + th.getMessage());
}
}
private Intent setGuardIntentInfo(String str, Intent intent) {
String[] split;
if (intent == null) {
return null;
}
try {
HashMap<String, String> hashMap = this.guardIntentInfoMap;
if (hashMap != null && !hashMap.isEmpty() && this.guardIntentInfoMap.containsKey(str)) {
String str2 = this.guardIntentInfoMap.get(str);
if (!TextUtils.isEmpty(str2) && (split = str2.split(":")) != null && split.length == 2) {
String str3 = split[0];
String str4 = split[1];
if ("pkg".equals(str3) && "*".equals(str4)) {
str4 = CoreRuntimeInfo.context.getPackageName();
intent.putExtra("pkg", str4);
} else {
intent.putExtra(str3, str4);
}
WusLog.log(TAG, "intent info " + str3 + " " + str4);
}
}
return intent;
} catch (Throwable th) {
WusLog.e(th);
return null;
}
}
private boolean startGActivity(String str, Intent intent) {
try {
if (WkWus.canWakePackage(str)) {
intent.setFlags(268435456);
CoreRuntimeInfo.context.startActivity(intent);
WkWus.onStartWake(WakedType.FROM_ACTIVITY, str);
}
WusLog.log(TAG, "type = start by activity, pkg = " + str);
return true;
} catch (Exception e) {
WusLog.log(TAG, e.getMessage());
WusLog.e(e);
return false;
}
}
private boolean startGTService(java.lang.String r10, java.lang.String r11, boolean r12) throws java.lang.Throwable {
throw new UnsupportedOperationException("Method not decompiled: com.sdk.plus.action.guard.GuardServiceAction.startGTService(java.lang.String, java.lang.String, boolean):boolean");
}
private GuardResult startGuard(int i, String str, List<String> list, boolean z, String str2, String str3) {
Intent intent;
boolean z2 = false;
this.isEnhService = false;
String guardService = getGuardService(list);
if (TextUtils.isEmpty(guardService)) {
return new GuardResult(i, z2, guardService);
}
try {
GuardType guardType = this.pmPkgGuardMap.get(str);
boolean z3 = true;
char c = 1;
char c2 = 1;
char c3 = 1;
if (i == 1 && GuardUtils.isPmWhiteListNotEmpty() && !GuardUtils.isInPmWhiteList(str)) {
if (!z) {
WusLog.log(TAG, str + " not a and s, return.");
return new GuardResult(i, z2, guardService);
}
WusLog.log(TAG, str + " not in pm white list, switch to service.");
i = 2;
}
if (i == 1) {
WusLog.log(TAG, "start aGuard pkg = " + str);
if (guardType != null && guardType != GuardType.GACTIVITY) {
WusLog.log(TAG, "start aGuard, pkg = " + str + "|not support act");
}
if (guardType == null || guardType == GuardType.GACTIVITY) {
Intent intent2 = new Intent();
if (!DynamicConfig.dynamicActivityEnable) {
intent = null;
} else if (DynamicConfig.isDynamicActivityListFromLocal) {
WusLog.log(TAG, "d-a from local.");
intent = GuardUtils.handleGuardDynamicActivityFromLocal(str);
} else {
WusLog.log(TAG, "d-a from config.");
intent = GuardUtils.handleGuardDynamicActivityFromConfig(str, this.isEnhService);
}
if (intent != null) {
i = 3;
WusLog.log(TAG, "in DA mode.");
intent2 = intent;
} else {
intent2.setClassName(str, RuntimeInfo.GUARD_ACTIVITY_NEW);
}
Intent guardIntentInfo = setGuardIntentInfo(str, intent2);
if (WusUtils.isActivityExist(guardIntentInfo) && startGActivity(str, guardIntentInfo)) {
GuardUtils.sleepThread();
WusLog.log(TAG, "MA or DA guard success. ");
return new GuardResult(i, z3, guardService);
}
if (this.isEnhService) {
guardIntentInfo.setClassName(str, Consts.DEFAULT_WAKEUP_ACTIVITY);
} else {
guardIntentInfo.setClassName(str, RuntimeInfo.GUARD_ACTIVITY);
}
try {
if (WusUtils.isActivityExist(guardIntentInfo) && startGActivity(str, guardIntentInfo)) {
GuardUtils.sleepThread();
WusLog.log(TAG, "GA or EnhA guard success. ");
return new GuardResult(c3 == true ? 1 : 0, c2 == true ? 1 : 0, guardService);
}
i = 1;
} catch (Throwable th) {
th = th;
i = 1;
WusLog.e(th);
WusLog.log(TAG, "startGuard exception = " + th.getMessage());
GuardResultHandle.saveData2Look(str2, i, str3, 2);
return new GuardResult(i, z2, guardService);
}
}
WusLog.log(TAG, "aGuard failed, useServiceGuard = " + z);
if (!z) {
return new GuardResult(i, z2, guardService);
}
i = 2;
}
if (i == 2 && WkWus.canWakeThanActivity()) {
WusLog.log(TAG, "start sGuard = " + str);
if (guardType != null && guardType != GuardType.SERVICE) {
WusLog.log(TAG, "start sGuard = " + str + "|not support service, return");
}
if ((guardType == null || guardType == GuardType.SERVICE) && startGTService(str, guardService, this.isEnhService)) {
i = 6;
}
}
return new GuardResult(i, c == true ? 1 : 0, guardService);
} catch (Throwable th2) {
th = th2;
}
}
private void startSDK(List<String> list, Map<String, List<String>> map, int i, boolean z, boolean z2) {
String str;
boolean z3 = z;
if (i == 1) {
try {
if (Build.VERSION.SDK_INT >= 24 && list != null) {
list.clear();
}
} catch (Throwable th) {
WusLog.e(th);
WusLog.log(TAG, " startSDK " + th.getMessage());
return;
}
}
WusLog.log(TAG, "guard cnt = " + DynamicConfig.guardCount + ", running cnt = " + list.size() + ", has cnt = " + map.size() + ", type = " + i + ", useService = " + z3);
if (GuardUtils.checkNeedGuard(list.size(), map.size())) {
List<String> filterGuardList = filterGuardList(map, list, i, z3);
if (filterGuardList.isEmpty()) {
return;
}
int min = Math.min(DynamicConfig.guardCount - (list.size() > 0 ? list.size() - 1 : 0), filterGuardList.size());
WusLog.log(TAG, "need guard cnt = " + min + " #######");
if (min <= 0) {
return;
}
String format = this.simpleDateFormat.format(new Date());
int i2 = 0;
for (String str2 : filterGuardList) {
List<String> list2 = map.get(str2);
if (list2 == null || list2.isEmpty() || TextUtils.isEmpty(str2) || str2.equals(CoreRuntimeInfo.pkgName)) {
str = format;
WusLog.log(TAG, "pkg = " + str2 + " service is empty");
} else {
String appid = GuardUtils.getAppid(str2);
if (TextUtils.isEmpty(appid)) {
WusLog.log(TAG, "guard pkg = " + str2 + ", appid is empty, ignore this ###");
str = format;
} else {
String str3 = str2 + "," + appid;
GuardResultHandle.putGuardDataListMD5(str3);
str = format;
GuardResult startGuard = startGuard(i, str2, list2, z3, str3, str);
if (startGuard.guardSuccess) {
saveResultAndCheck(str3, startGuard.type, startGuard.guardServiceName, str);
i2++;
WusLog.log(TAG, "has guard cnt = " + i2);
if (i2 >= min) {
return;
}
}
}
}
z3 = z;
format = str;
}
}
}
public synchronized void firstStartSdkGuard() {
throw new UnsupportedOperationException("Method not decompiled: com.sdk.plus.action.guard.GuardServiceAction.firstStartSdkGuard():void");
}
public synchronized void startGuardGActivity() {
try {
WusLog.log(TAG, "start aGuard ~~~");
GuardTypeBean checkGuardAvailable = GuardUtils.checkGuardAvailable(GuardType.GACTIVITY, false);
if (checkGuardAvailable.aEnable) {
WusLog.log(TAG, "start aGuard, aEnable = true, guard a.");
guard(1, null, false);
} else if (checkGuardAvailable.sEnable && GuardUtils.isExecServiceGuard()) {
WusLog.log(TAG, "start aGuard, aEnable = false, sEnable = true, guard s.");
guard(2, null, false);
} else {
WusLog.log(TAG, "start aGuard, aEnable = false, sEnable = false, return.");
}
} catch (Throwable th) {
throw th;
}
}
public synchronized void startPushService() {
WusLog.log(TAG, "start sGuard ~~~");
if (GuardUtils.checkGuardAvailable(GuardType.SERVICE, false).sEnable && GuardUtils.isExecServiceGuard()) {
guard(2, null, false);
return;
}
WusLog.log(TAG, "start sGuard, available = false");
}
}