From 052d62d7736e313d736d341b1cbf1d9285345260 Mon Sep 17 00:00:00 2001 From: Saint-Theana Date: Mon, 25 Oct 2021 23:56:19 +0800 Subject: [PATCH] bump app version,delete gapps related code,fix possible boot block in gapps installed rom,reduce gradle warnnings to zero. --- app/build.gradle | 4 +- .../server/am/PreventRunningUtils.java | 5 +- .../piebridge/prevent/common/FileUtils.java | 19 - .../me/piebridge/prevent/common/GmsUtils.java | 144 ------ .../prevent/common/PackageUtils.java | 31 +- .../framework/ActivityManagerServiceHook.java | 45 +- .../prevent/framework/ActivityReceiver.java | 29 +- .../prevent/framework/IntentFilterHook.java | 18 +- .../prevent/framework/PreventRunning.java | 1 - .../prevent/framework/SystemHook.java | 72 +-- .../prevent/framework/SystemReceiver.java | 9 - .../util/ActivityManagerServiceUtils.java | 3 +- .../prevent/framework/util/HideApiUtils.java | 1 - .../framework/util/PreventListUtils.java | 2 +- .../prevent/framework/util/ReflectUtils.java | 4 +- .../framework/util/SafeActionUtils.java | 22 +- .../piebridge/prevent/ui/PreventActivity.java | 2 - .../piebridge/prevent/ui/PreventFragment.java | 2 +- .../prevent/ui/ScreenSlidePagerAdapter.java | 3 +- .../prevent/ui/UserGuideActivity.java | 423 ------------------ .../prevent/ui/util/DeprecatedUtils.java | 31 -- .../prevent/ui/util/PreventListUtils.java | 3 +- .../prevent/ui/util/PreventUtils.java | 3 +- 23 files changed, 48 insertions(+), 828 deletions(-) delete mode 100644 app/src/me/piebridge/prevent/common/GmsUtils.java delete mode 100644 app/src/me/piebridge/prevent/ui/UserGuideActivity.java delete mode 100644 app/src/me/piebridge/prevent/ui/util/DeprecatedUtils.java diff --git a/app/build.gradle b/app/build.gradle index b975b31..176a4d3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,9 +26,9 @@ android { defaultConfig { - versionCode 1 + versionCode 14 applicationId "me.piebridge.prevent" - versionName "3.1.2" + versionName "1.4" minSdkVersion 29 targetSdkVersion 30 maxSdkVersion 30 diff --git a/app/services/core/java/com/android/server/am/PreventRunningUtils.java b/app/services/core/java/com/android/server/am/PreventRunningUtils.java index cf0d66b..ed34ef5 100644 --- a/app/services/core/java/com/android/server/am/PreventRunningUtils.java +++ b/app/services/core/java/com/android/server/am/PreventRunningUtils.java @@ -137,10 +137,9 @@ public static void onVpnConnectionDisconnected() { private static ActivityRecord forToken(IBinder iBinder) { - if (Build.VERSION.SDK_INT >= 23) { + return ActivityRecord.forTokenLocked(iBinder); - } - return ActivityRecord.forToken(iBinder); + //return ActivityRecord.forToken(iBinder); } diff --git a/app/src/me/piebridge/prevent/common/FileUtils.java b/app/src/me/piebridge/prevent/common/FileUtils.java index bc7263a..6789c18 100644 --- a/app/src/me/piebridge/prevent/common/FileUtils.java +++ b/app/src/me/piebridge/prevent/common/FileUtils.java @@ -105,28 +105,9 @@ public static Set load(File file) { return packages; } - private static void loadExternal(Set packages, Context context) { - for (File file : ExternalFileUtils.getExternalFilesDirs(context)) { - if (file != null) { - packages.addAll(load(new File(file, PREVENT_LIST))); - if (!packages.isEmpty()) { - return; - } - } - } - if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { - File sdcard = Environment.getExternalStorageDirectory(); - if (sdcard != null) { - packages.addAll(load(new File(sdcard, PREVENT_LIST))); - } - } - } public static Set load(Context context, String prevent) { Set packages = load(new File(prevent)); - if (context != null && packages.isEmpty()) { - loadExternal(packages, context); - } return packages; } diff --git a/app/src/me/piebridge/prevent/common/GmsUtils.java b/app/src/me/piebridge/prevent/common/GmsUtils.java deleted file mode 100644 index 8d044dc..0000000 --- a/app/src/me/piebridge/prevent/common/GmsUtils.java +++ /dev/null @@ -1,144 +0,0 @@ -package me.piebridge.prevent.common; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.content.pm.ServiceInfo; -import android.os.Binder; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * Created by thom on 15/7/28. - */ -public class GmsUtils { - - private static final String GMS = "com.google.android.gms"; - private static final String GSF = "com.google.android.gsf"; - private static final String GSF_LOGIN = "com.google.android.gsf.login"; - private static final String GAPPS_PREFIX = "com.google.android."; - private static final String GAPPS_INPUTMETHOD_PREFIX = "com.google.android.inputmethod"; - private static final AtomicInteger GMS_COUNTER = new AtomicInteger(); - // https://developers.google.com/cloud-messaging/android/client - private static Collection GCM_ACTIONS = Arrays.asList( - "com.google.android.c2dm.intent.RECEIVE", - "com.google.android.c2dm.intent.REGISTRATION"); - private static final String GCM_ACTION_REGISTER = "com.google.android.c2dm.intent.REGISTER"; - private static final String GCM_ACTION_UNREGISTER = "com.google.android.c2dm.intent.UNREGISTER"; - private static Collection GMS_PACKAGES = Arrays.asList( - GMS, GSF, GSF_LOGIN - ); - private static Collection GAPPS = Arrays.asList( - "com.android.chrome", "com.android.facelock", "com.android.vending" - ); - private static Set GCM_REGISTERS = new HashSet(); - - private GmsUtils() { - - } - - public static boolean isGapps(String packageName) { - return packageName != null && (packageName.startsWith(GAPPS_PREFIX) || GAPPS.contains(packageName)); - } - - public static void increaseGmsCount(Context context, String packageName) { - if (!GMS.equals(packageName) && isGapps(packageName) && !PackageUtils.isLauncher(context.getPackageManager(), packageName)) { - int gmsCount = GMS_COUNTER.incrementAndGet(); - CommonLog.d("increase gms reference: " + gmsCount + ", package: " + packageName); - } - } - - public static void decreaseGmsCount(Context context, String packageName) { - if (!GMS.equals(packageName) && isGapps(packageName) && !PackageUtils.isLauncher(context.getPackageManager(), packageName)) { - int gmsCount = GMS_COUNTER.decrementAndGet(); - CommonLog.d("decrease gms reference: " + gmsCount + ", package: " + packageName); - } - } - - public static boolean isGcmAction(String sender, boolean isSystem, String action) { - return (isSystem || isGms(sender)) && GCM_ACTIONS.contains(action); - } - - public static boolean isGcmRegisterAction(String action) { - return GCM_ACTION_REGISTER.equals(action) || GCM_ACTION_UNREGISTER.equals(action); - } - - public static boolean isGmsRegister(Context context, ComponentName component) { - if (GCM_REGISTERS.isEmpty()) { - initGmsRegisters(context, GCM_ACTION_REGISTER); - initGmsRegisters(context, GCM_ACTION_UNREGISTER); - } - return GCM_REGISTERS.contains(component); - } - - private static void initGmsRegisters(Context context, String action) { - Intent intent = new Intent(); - intent.setAction(action); - intent.setPackage(GMS); - List intentServices = context.getPackageManager().queryIntentServices(intent, 0); - final int size = intentServices == null ? 0 : intentServices.size(); - for (int i = 0; i < size; ++i) { - ServiceInfo si = intentServices.get(i).serviceInfo; - if (GMS.equals(si.packageName) && GCM_REGISTERS.add(new ComponentName(si.packageName, si.name))) { - CommonLog.d("add gcm register/unregister: " + si.name); - } - } - } - - public static boolean isGms(String packageName) { - return packageName != null && GMS_PACKAGES.contains(packageName); - } - - public static Collection getGmsPackages() { - return GMS_PACKAGES; - } - - public static boolean isGappsCaller(Context context) { - try { - int callingUid = Binder.getCallingUid(); - if (callingUid < PackageUtils.FIRST_APPLICATION_UID) { - return false; - } - PackageManager pm = context.getPackageManager(); - return pm.getApplicationInfo(GMS, 0).uid == callingUid || isGapps(pm, callingUid); - } catch (PackageManager.NameNotFoundException e) { - CommonLog.v("cannot find gms", e); - } - return false; - } - - private static boolean isGapps(PackageManager pm, int callingUid) { - String[] packageNames = pm.getPackagesForUid(callingUid); - if (packageNames == null) { - return false; - } - for (String packageName : packageNames) { - if (isGapps(packageName)) { - return true; - } - } - return false; - } - - public static boolean canStopGms() { - int gmsCount = GMS_COUNTER.get(); - if (gmsCount != 0) { - CommonLog.d("cannot stop gms now, gms reference: " + gmsCount); - return false; - } else { - return true; - } - } - - public static boolean isInputMethod(String name) { - return name != null && name.startsWith(GAPPS_INPUTMETHOD_PREFIX); - } - -} diff --git a/app/src/me/piebridge/prevent/common/PackageUtils.java b/app/src/me/piebridge/prevent/common/PackageUtils.java index 531b412..77f3f21 100644 --- a/app/src/me/piebridge/prevent/common/PackageUtils.java +++ b/app/src/me/piebridge/prevent/common/PackageUtils.java @@ -93,7 +93,7 @@ private static boolean canPreventSystemPackage(PackageManager pm, ApplicationInf } if (isSystemSignaturePackage(pm, BuildConfig.APPLICATION_ID)) { // shouldn't happen, but for some abnormal rom - return GmsUtils.isGapps(appInfo.packageName); + return false; } else { return !isSystemSignaturePackage(pm, appInfo.packageName); } @@ -112,20 +112,10 @@ public static boolean equals(Object a, Object b) { // NOSONAR return (a == b) || (a != null && a.equals(b)); } - public static boolean isInputMethod(Context context, String pkg) { - List inputMethods = ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).getEnabledInputMethodList(); - int count = inputMethods == null ? 0 : inputMethods.size(); - for (int i = 0; i < count; i++) { - if (inputMethods.get(i).getPackageName().equals(pkg)) { - return true; - } - } - return false; - } - public static boolean isInputMethod(String name) { - if (GmsUtils.isGapps(name) && !GmsUtils.isInputMethod(name)) { - return false; + public static boolean isInputMethod(Context context,String name) { + if (inputMethodPackages.isEmpty()) { + initInputMethods(context); } return inputMethodPackages.contains(name); } @@ -143,17 +133,6 @@ public static void clearInputMethodPackages() { inputMethodPackages.clear(); } - public static boolean isImportPackage(Context context, String name) { - if (name == null) { - return false; - } - if (inputMethodPackages.isEmpty()) { - initInputMethods(context); - smsDefaultApplication = Settings.Secure.getString(context.getContentResolver(), "sms_default_application"); - } - return IMPORT_PACKAGES.contains(name) - || isInputMethod(name) - || name.equals(smsDefaultApplication); - } + } diff --git a/app/src/me/piebridge/prevent/framework/ActivityManagerServiceHook.java b/app/src/me/piebridge/prevent/framework/ActivityManagerServiceHook.java index 92e872e..c49a233 100644 --- a/app/src/me/piebridge/prevent/framework/ActivityManagerServiceHook.java +++ b/app/src/me/piebridge/prevent/framework/ActivityManagerServiceHook.java @@ -20,7 +20,6 @@ import me.piebridge.prevent.BuildConfig; import me.piebridge.prevent.common.Configuration; -import me.piebridge.prevent.common.GmsUtils; import me.piebridge.prevent.common.PackageUtils; import me.piebridge.prevent.framework.util.AccountUtils; import me.piebridge.prevent.framework.util.LogUtils; @@ -50,11 +49,9 @@ public static void setContext(Context context, Map preventPacka public static boolean hookStartProcessLocked(Context context, ApplicationInfo info, String hostingType, ComponentName hostingName, String sender) { String packageName = info.packageName; - if (mContext == null && context != null) { SystemHook.retrievePreventsIfNeeded(context); } - if (BuildConfig.DEBUG) { if (hostingName != null) { PreventLog.v("startProcessLocked, hostingName: " + hostingName.flattenToShortString() + ", hostingType: " + hostingType + ", sender: " + sender); @@ -62,16 +59,13 @@ public static boolean hookStartProcessLocked(Context context, ApplicationInfo in PreventLog.v("startProcessLocked, packageName: " + packageName + ", hostingType: " + hostingType + ", sender: " + sender); } } - if (mPreventPackages == null) { PreventLog.e("prevent list shouldn't be null"); return true; } - boolean prevents = Boolean.TRUE.equals(mPreventPackages.get(packageName)); if ("activity".equals(hostingType)) { SystemHook.cancelCheck(packageName); - SystemHook.updateRunningGapps(packageName, true); if (prevents) { // never block activity mPreventPackages.put(packageName, false); @@ -79,7 +73,6 @@ public static boolean hookStartProcessLocked(Context context, ApplicationInfo in } LogUtils.logStartProcess(packageName, hostingType, hostingName, sender); } - return !prevents || hookDependency(hostingName, hostingType, packageName, sender); } @@ -97,7 +90,6 @@ private static boolean hookDependency(ComponentName hostingName, String hostingT LogUtils.logStartProcess(true, packageName, hostingType, hostingName, sender); return false; } - SystemHook.checkRunningServices(packageName, false); LogUtils.logStartProcess(packageName, hostingType + "(should safe)", hostingName, sender); return true; @@ -118,12 +110,9 @@ private static boolean hookService(ComponentName hostingName, String hostingType if (SafeActionUtils.isSyncService(mContext, hostingName, sender)) { return hookSyncService(hostingName, hostingType, packageName, sender); } - if (SafeActionUtils.isAccountService(mContext, hostingName, sender)||PackageUtils.isInputMethod(mContext, packageName) ) { + if (SafeActionUtils.isAccountService(mContext, hostingName, sender) ) { return hookAccountService(hostingName, hostingType, packageName, sender); } - if (GmsUtils.isGms(packageName)) { - return hookGmsService(hostingName, hostingType, packageName, sender); - } if (cannotPrevent(sender, packageName, hostingName)) { SystemHook.checkRunningServices(packageName, true); LogUtils.logStartProcess(packageName, hostingType, hostingName, sender); @@ -140,7 +129,7 @@ private static boolean hookAccountService(ComponentName hostingName, String host if (settingsPackages.isEmpty()) { retrieveSettingsPackage(mContext.getPackageManager(), settingsPackages); } - if (isSettingPackageName(currentPackageName) ||PackageUtils.isInputMethod(mContext, packageName) ||(GmsUtils.isGapps(packageName) && GmsUtils.isGapps(currentPackageName))) { + if (isSettingPackageName(currentPackageName)) { handleSafeService(packageName); SystemHook.checkRunningServices(packageName, true); LogUtils.logStartProcess(packageName, hostingType + "(account)", hostingName, sender); @@ -167,17 +156,6 @@ private static boolean cannotPrevent(String sender, String packageName, Componen } } - private static boolean hookGmsService(ComponentName hostingName, String hostingType, String packageName, String sender) { - if (cannotPreventGms(hostingName, sender)) { - // only allow gapps to use gms - SystemHook.checkRunningServices(packageName, true); - LogUtils.logStartProcess(packageName, hostingType, hostingName, sender); - return true; - } else { - LogUtils.logStartProcess(true, packageName, hostingType, hostingName, sender); - return false; - } - } private static void retrieveSettingsPackage(PackageManager pm, Collection packages) { Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, @@ -191,22 +169,6 @@ private static void retrieveSettingsPackage(PackageManager pm, Collection activities = mActivityRecord.get(packageName); if(activities.contains(activityName)){ }else{ @@ -88,7 +87,7 @@ public void onLaunchActivity(Object activityRecord) { }else{ String activityName = ActivityRecordUtils.getActivityName(activityRecord); if(activityName!=null){ - List activities = new ArrayList(); + List activities = new ArrayList(); activities.add(activityName); mActivityRecord.put(packageName,activities); LogUtils.logActivity("start activity", packageName, 1); @@ -103,7 +102,6 @@ public boolean onDestroyActivity(Object activityRecord) { PreventLog.e("package " + packageName + " destroyed "); return false; } - if(mActivityRecord.containsKey(packageName)){ String activityName = ActivityRecordUtils.getActivityName(activityRecord); if(activityName!=null){ @@ -117,29 +115,33 @@ public boolean onDestroyActivity(Object activityRecord) { } } } - SystemHook.updateRunningGapps(packageName, false); if (mPreventPackages.containsKey(packageName)) { mPreventPackages.put(packageName, true); LogUtils.logForceStop("destroy activity", packageName, "if needed in " + SystemHook.TIME_DESTROY + "s"); SystemHook.checkForceStop(packageName, SystemHook.TIME_DESTROY); //SystemHook.checkRunningServices(packageName, SystemHook.TIME_DESTROY); - } else { + } + /*else { SystemHook.checkRunningServices(null, SystemHook.TIME_DESTROY); } - SystemHook.killNoFather(); + + */ + //SystemHook.killNoFather(); return true; } public void onDestroyActivity(String reason, String packageName) { - SystemHook.updateRunningGapps(packageName, false); if (mPreventPackages.containsKey(packageName)) { mPreventPackages.put(packageName, true); LogUtils.logForceStop(reason, packageName, "destroy in " + SystemHook.TIME_SUICIDE + "s"); - SystemHook.checkRunningServices(packageName, SystemHook.TIME_SUICIDE); - } else { + SystemHook.checkForceStop(packageName, SystemHook.TIME_SUICIDE); + } + /*else { SystemHook.checkRunningServices(null, SystemHook.TIME_SUICIDE < SystemHook.TIME_DESTROY ? SystemHook.TIME_DESTROY : SystemHook.TIME_SUICIDE); } - SystemHook.killNoFather(); + + */ + //SystemHook.killNoFather(); } public void onResumeActivity(Object activityRecord) { @@ -148,7 +150,6 @@ public void onResumeActivity(Object activityRecord) { return; } SystemHook.cancelCheck(packageName); - SystemHook.updateRunningGapps(packageName, true); if (Boolean.TRUE.equals(mPreventPackages.get(packageName))) { mPreventPackages.put(packageName, false); } @@ -338,10 +339,10 @@ public void onAppDied(Object processRecord) { if (!shouldStop(packageName, pid)) { return; } - SystemHook.updateRunningGapps(packageName, false); if (mPreventPackages.containsKey(packageName)) { mPreventPackages.put(packageName, true); - SystemHook.checkRunningServices(packageName, SystemHook.TIME_IMMEDIATE < SystemHook.TIME_DESTROY ? SystemHook.TIME_DESTROY : SystemHook.TIME_IMMEDIATE); + SystemHook.checkForceStop(packageName, SystemHook.TIME_DESTROY); + //SystemHook.checkRunningServices(packageName, SystemHook.TIME_IMMEDIATE < SystemHook.TIME_DESTROY ? SystemHook.TIME_DESTROY : SystemHook.TIME_IMMEDIATE); } } diff --git a/app/src/me/piebridge/prevent/framework/IntentFilterHook.java b/app/src/me/piebridge/prevent/framework/IntentFilterHook.java index 17e931b..abec2ff 100644 --- a/app/src/me/piebridge/prevent/framework/IntentFilterHook.java +++ b/app/src/me/piebridge/prevent/framework/IntentFilterHook.java @@ -13,7 +13,7 @@ import java.util.Map; import java.util.Set; -import me.piebridge.prevent.common.GmsUtils; + import me.piebridge.prevent.framework.util.AlarmManagerServiceUtils; import me.piebridge.prevent.framework.util.BroadcastFilterUtils; import me.piebridge.prevent.framework.util.LogUtils; @@ -78,11 +78,6 @@ private static boolean isSystemSender(String sender) { private static boolean isPrevent(String packageName, boolean receiver) { Boolean prevents = mPreventPackages.get(packageName); if (prevents == null) { - PackageManager pm = mContext.getPackageManager(); - if (receiver && GmsUtils.isGapps(packageName) && pm.getLaunchIntentForPackage(packageName) != null) { - PreventLog.d("allow " + packageName + " to use gms for next service"); - SystemHook.restoreLater(packageName); - } return false; } return prevents; @@ -99,9 +94,6 @@ private static boolean cannotPrevent(String packageName, String sender, boolean return false; } - private static boolean cannotPreventGms(String packageName, String sender) { - return GmsUtils.isGms(packageName) && (GmsUtils.isGapps(sender) || GmsUtils.isGappsCaller(mContext)); - } private static boolean isSafeReceiverAction(boolean isSystem, String action) { return isSystem && SafeActionUtils.isSafeAction(action); @@ -126,12 +118,7 @@ private static IntentFilterMatchResult hookReceiver(PackageParser.ActivityIntent return IntentFilterMatchResult.NONE; } boolean isSystem = isSystemSender(sender); - if (cannotPreventGms(packageName, sender)) { - LogUtils.logIntentFilter(false, sender, filter, action, packageName); - return IntentFilterMatchResult.NONE; - } else if (GmsUtils.isGcmAction(sender, isSystem, action)) { - return allowSafeIntent(filter, sender, action, packageName); - } else if (isSafeReceiverAction(isSystem, action)) { + if (isSafeReceiverAction(isSystem, action)) { LogUtils.logIntentFilter(false, sender, filter, action, packageName); return IntentFilterMatchResult.NONE; } @@ -143,7 +130,6 @@ private static IntentFilterMatchResult hookReceiver(PackageParser.ActivityIntent private static boolean isSafeServiceAction(String action) { return "android.content.SyncAdapter".equals(action) || AccountManager.ACTION_AUTHENTICATOR_INTENT.equals(action) - || GmsUtils.isGcmRegisterAction(action) || action.startsWith("android.nfc.cardemulation"); } diff --git a/app/src/me/piebridge/prevent/framework/PreventRunning.java b/app/src/me/piebridge/prevent/framework/PreventRunning.java index 11e6a90..290073d 100644 --- a/app/src/me/piebridge/prevent/framework/PreventRunning.java +++ b/app/src/me/piebridge/prevent/framework/PreventRunning.java @@ -27,7 +27,6 @@ public class PreventRunning implements PreventRunningHook { private final ThreadLocal mSender; - public PreventRunning() { mSender = new ThreadLocal(); PreventLog.i("prevent running " + BuildConfig.VERSION_NAME); diff --git a/app/src/me/piebridge/prevent/framework/SystemHook.java b/app/src/me/piebridge/prevent/framework/SystemHook.java index f36617a..bcc9eea 100644 --- a/app/src/me/piebridge/prevent/framework/SystemHook.java +++ b/app/src/me/piebridge/prevent/framework/SystemHook.java @@ -43,7 +43,6 @@ import me.piebridge.prevent.BuildConfig; import me.piebridge.prevent.common.Configuration; -import me.piebridge.prevent.common.GmsUtils; import me.piebridge.prevent.common.PackageUtils; import me.piebridge.prevent.common.PreventIntent; import me.piebridge.prevent.framework.util.AccountUtils; @@ -227,14 +226,10 @@ public static void checkRunningServices(final String packageName, final boolean synchronized (CHECKING_LOCK) { serviceFuture = serviceFutures.get(packageName); if (serviceFuture != null && serviceFuture.getDelay(TimeUnit.SECONDS) > 0) { - GmsUtils.decreaseGmsCount(mContext, packageName); serviceFuture.cancel(false); } - if (!GmsUtils.isGms(packageName)) { checkingWhiteList.add(packageName); - } } - GmsUtils.increaseGmsCount(mContext, packageName); serviceFuture = checkingExecutor.schedule(new CheckingRunningService(mContext, mPreventPackages) { @Override protected Collection preparePackageNames() { @@ -245,27 +240,21 @@ protected Collection preparePackageNames() { protected Collection prepareWhiteList() { return prepareServiceWhiteList(packageName, forcestop); } - }, GmsUtils.isGms(packageName) ? TIME_CHECK_GMS : TIME_CHECK_SERVICE, TimeUnit.SECONDS); + }, TIME_CHECK_SERVICE, TimeUnit.SECONDS); synchronized (CHECKING_LOCK) { serviceFutures.put(packageName, serviceFuture); } } private static Collection prepareServiceWhiteList(String packageName, boolean forcestop) { - GmsUtils.decreaseGmsCount(mContext, packageName); - if (!GmsUtils.isGms(packageName)) { synchronized (CHECKING_LOCK) { checkingWhiteList.remove(packageName); } - } - if (canStopGms()) { if (forcestop) { forceStopPackageIfNeeded(packageName); } return Collections.emptyList(); - } else { - return GmsUtils.getGmsPackages(); - } + } public static void cancelCheck(String packageName) { @@ -338,9 +327,6 @@ private static Collection prepareCheckingWhiteList() { synchronized (CHECKING_LOCK) { whiteList.addAll(checkingWhiteList); } - if (!canStopGms()) { - whiteList.addAll(GmsUtils.getGmsPackages()); - } return whiteList; } @@ -362,7 +348,7 @@ public void run() { return; } boolean a=forceStopPackage(packageName, false); - PreventLog.d("forceStopPackage"+packageName); + PreventLog.d("forceStopPackage "+packageName); }catch (Exception e) { e.printStackTrace(); } @@ -602,10 +588,10 @@ public static String getPackageNameFromUid(int uid) { } public static boolean isSystemPackage(String packageName) { - if (isFramework(packageName) || GmsUtils.isGms(packageName)) { + if (isFramework(packageName) ) { return true; } - if (packageName == null || GmsUtils.isGapps(packageName)) { + if (packageName == null ) { return false; } try { @@ -681,7 +667,7 @@ public static void setMethod(String method) { } public static boolean isUseAppStandby() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Configuration.getDefault().isUseAppStandby(); + return Configuration.getDefault().isUseAppStandby(); } public static void setNotSupported() { @@ -701,49 +687,8 @@ public static void setSupported(boolean supported) { SystemHook.supported = supported; } - public static void updateRunningGapps(String packageName, boolean added) { - if (mContext == null || packageName == null) { - return; - } - if (!added) { - resetSync(packageName); - } - PackageManager pm = mContext.getPackageManager(); - if (GmsUtils.isGapps(packageName) && pm.getLaunchIntentForPackage(packageName) != null) { - if (added) { - if (!runningGapps.contains(packageName)) { - PreventLog.d("add " + packageName + " to running gapps: " + runningGapps); - } - runningGapps.add(packageName); - } else { - if (runningGapps.contains(packageName)) { - PreventLog.d("remove " + packageName + " from running gapps: " + runningGapps); - checkRunningServices(null, SystemHook.TIME_CHECK_SERVICE); - } - runningGapps.remove(packageName); - } - } - } - public static boolean hasRunningGapps() { - Iterator it = runningGapps.iterator(); - int count = 0; - while (it.hasNext()) { - String packageName = it.next(); - int counter = systemReceiver.countCounter(packageName); - if (counter == 0) { - it.remove(); - } else if (counter > 1 || !PackageUtils.isLauncher(mContext.getPackageManager(), packageName)) { - count += 1; - } - } - if (count > 0) { - PreventLog.d("running gapps: " + runningGapps); - return true; - } else { - return false; - } - } + public static void restoreLater(final String packageName) { systemReceiver.cancelCheckLeaving(packageName); @@ -811,9 +756,6 @@ public static Context getContext() { return mContext; } - public static boolean canStopGms() { - return GmsUtils.canStopGms() && !SystemHook.hasRunningGapps(); - } public static void onActivityRequestAudioFocus(int uid, int pid, String clientId, String packageName) { expired = true; diff --git a/app/src/me/piebridge/prevent/framework/SystemReceiver.java b/app/src/me/piebridge/prevent/framework/SystemReceiver.java index 4649070..736aa46 100644 --- a/app/src/me/piebridge/prevent/framework/SystemReceiver.java +++ b/app/src/me/piebridge/prevent/framework/SystemReceiver.java @@ -30,7 +30,6 @@ import me.piebridge.prevent.BuildConfig; import me.piebridge.prevent.common.Configuration; -import me.piebridge.prevent.common.GmsUtils; import me.piebridge.prevent.common.PackageUtils; import me.piebridge.prevent.common.PreventIntent; import me.piebridge.prevent.common.TimeUtils; @@ -282,13 +281,6 @@ private void updateInactiveIfNeeded(Map> running) { private void handleGetPackages(String action) { Map preventPackages = new TreeMap(mPreventPackages); - if (!SystemHook.canStopGms()) { - for (String packageName : GmsUtils.getGmsPackages()) { - if (Boolean.TRUE.equals(preventPackages.get(packageName))) { - preventPackages.put(packageName, false); - } - } - } int size = preventPackages.size(); setResultCode(size); setResultData(new JSONObject(preventPackages).toString()); @@ -401,7 +393,6 @@ private Set getRunningServices(Context context) { private void handlePackageRestarted(String action, String packageName) { LogUtils.logRequestInfo(action, packageName, -1); removePackageCounters(packageName); - SystemHook.updateRunningGapps(packageName, false); if (mPreventPackages.containsKey(packageName)) { mPreventPackages.put(packageName, true); } diff --git a/app/src/me/piebridge/prevent/framework/util/ActivityManagerServiceUtils.java b/app/src/me/piebridge/prevent/framework/util/ActivityManagerServiceUtils.java index 0d91b7f..937083e 100644 --- a/app/src/me/piebridge/prevent/framework/util/ActivityManagerServiceUtils.java +++ b/app/src/me/piebridge/prevent/framework/util/ActivityManagerServiceUtils.java @@ -31,8 +31,7 @@ public class ActivityManagerServiceUtils { * ID of stack that occupies a dedicated region of the screen. */ public static final int DOCKED_STACK_ID = FREEFORM_WORKSPACE_STACK_ID + 1; - private ActivityManagerServiceUtils() { - + private ActivityManagerServiceUtils() { } public static Set getCurrentPackages() { diff --git a/app/src/me/piebridge/prevent/framework/util/HideApiUtils.java b/app/src/me/piebridge/prevent/framework/util/HideApiUtils.java index c01e5f5..f3bbb76 100644 --- a/app/src/me/piebridge/prevent/framework/util/HideApiUtils.java +++ b/app/src/me/piebridge/prevent/framework/util/HideApiUtils.java @@ -1,7 +1,6 @@ package me.piebridge.prevent.framework.util; import android.app.ActivityManager; -import android.app.ActivityManagerNative; import android.content.Context; import android.content.pm.PackageManager; import android.os.Process; diff --git a/app/src/me/piebridge/prevent/framework/util/PreventListUtils.java b/app/src/me/piebridge/prevent/framework/util/PreventListUtils.java index f49e206..ee22c5f 100644 --- a/app/src/me/piebridge/prevent/framework/util/PreventListUtils.java +++ b/app/src/me/piebridge/prevent/framework/util/PreventListUtils.java @@ -128,7 +128,7 @@ public static boolean notify(Context context, String action, String identifier) } String appName = ResourcesUtils.getString(resources, "app_name"); - Notification notification = new NotificationCompat.Builder(context) + Notification notification = new NotificationCompat.Builder(context,"default") .setAutoCancel(true) .setShowWhen(false) .setContentTitle(appName) diff --git a/app/src/me/piebridge/prevent/framework/util/ReflectUtils.java b/app/src/me/piebridge/prevent/framework/util/ReflectUtils.java index 109aba4..8bb351e 100644 --- a/app/src/me/piebridge/prevent/framework/util/ReflectUtils.java +++ b/app/src/me/piebridge/prevent/framework/util/ReflectUtils.java @@ -50,7 +50,7 @@ public static Object invoke(Object target, String name) { method.setAccessible(true); METHOD_CACHES.put(key, method); } - return method.invoke(target, null); + return method.invoke(target, (Object[]) null); } catch (NoSuchMethodException e) { PreventLog.e("cannot find method " + name + " in " + target.getClass()); } catch (InvocationTargetException e) { @@ -103,7 +103,7 @@ private static Method getMethod(Object target, String name, Class[] parameter try { return target.getClass().getMethod(name, parameterTypes); } catch (NoSuchMethodException e) { - Class superClass = target.getClass().getSuperclass(); + Class superClass = target.getClass().getSuperclass(); while (superClass != null) { try { return superClass.getMethod(name, parameterTypes); diff --git a/app/src/me/piebridge/prevent/framework/util/SafeActionUtils.java b/app/src/me/piebridge/prevent/framework/util/SafeActionUtils.java index ddcd98a..c74624a 100644 --- a/app/src/me/piebridge/prevent/framework/util/SafeActionUtils.java +++ b/app/src/me/piebridge/prevent/framework/util/SafeActionUtils.java @@ -21,7 +21,6 @@ import java.util.Map; import java.util.Set; -import me.piebridge.prevent.common.GmsUtils; import me.piebridge.prevent.framework.PreventLog; import me.piebridge.prevent.framework.SystemHook; @@ -138,7 +137,7 @@ public static boolean isSafeAction(String action) { if (action == null) { return false; } - if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action) || GmsUtils.isGcmAction(null, false, action)) { + if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action) ) { return true; } return !action.startsWith("android.intent.action") && !AppGlobals.getPackageManager().isProtectedBroadcast(action); @@ -164,7 +163,6 @@ public static void updateWidget(ComponentName component, boolean added) { public static boolean cannotPrevent(Context context, ComponentName cn) { String packageName = cn.getPackageName(); if (isSafeActionCache(safeActions, cn)) { - allowGmsIfNeeded(packageName); return true; } Collection actions = SAFE_PACKAGE_ACTIONS.get(packageName); @@ -174,19 +172,12 @@ public static boolean cannotPrevent(Context context, ComponentName cn) { for (String action : actions) { if (isActionService(context, cn, action)) { addSafeActions(safeActions, cn); - allowGmsIfNeeded(packageName); return true; } } return false; } - private static void allowGmsIfNeeded(String packageName) { - if (GmsUtils.isGapps(packageName)) { - PreventLog.d("allow " + packageName + " to use gms for next service"); - SystemHook.restoreLater(packageName); - } - } public static boolean isSafeAction(String packageName, String action) { Collection actions = SAFE_PACKAGE_ACTIONS.get(packageName); @@ -194,19 +185,12 @@ public static boolean isSafeAction(String packageName, String action) { } public static boolean isUnsafeService(ComponentName cn) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ServiceInfo si = AppGlobals.getPackageManager().getServiceInfo(cn, 0, 0); return si != null && (JobService.PERMISSION_BIND.equals(si.permission) || Manifest.permission.BIND_VOICE_INTERACTION.equals(si.permission)); - } else { - return false; - } } public static ComponentName getSearchWidgetProvider(Context context) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - return null; - } SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); ComponentName searchActivity; try { @@ -242,12 +226,8 @@ private static ComponentName getProviderInPackage(Context context, String packag } public static boolean isSafeService(ComponentName cn) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { ServiceInfo si = AppGlobals.getPackageManager().getServiceInfo(cn, 0, 0); return si != null && Manifest.permission.BIND_NFC_SERVICE.equals(si.permission); - } else { - return false; - } } public static boolean isSafeContentProvider(ComponentName component) { diff --git a/app/src/me/piebridge/prevent/ui/PreventActivity.java b/app/src/me/piebridge/prevent/ui/PreventActivity.java index 21a2983..1a14d9c 100644 --- a/app/src/me/piebridge/prevent/ui/PreventActivity.java +++ b/app/src/me/piebridge/prevent/ui/PreventActivity.java @@ -349,8 +349,6 @@ private boolean onClick(int id) { } savePackages(); setUnchecked(); - } else if (id == R.string.user_guide) { - startActivity(new Intent(this, UserGuideActivity.class)); } selections.clear(); checkSelection(); diff --git a/app/src/me/piebridge/prevent/ui/PreventFragment.java b/app/src/me/piebridge/prevent/ui/PreventFragment.java index 7f3e99f..cfb7aeb 100644 --- a/app/src/me/piebridge/prevent/ui/PreventFragment.java +++ b/app/src/me/piebridge/prevent/ui/PreventFragment.java @@ -11,7 +11,6 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; -import android.preference.PreferenceManager; import android.provider.Settings; import android.util.TypedValue; import android.view.ContextMenu; @@ -28,6 +27,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.widget.SwitchCompat; import androidx.fragment.app.Fragment; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; diff --git a/app/src/me/piebridge/prevent/ui/ScreenSlidePagerAdapter.java b/app/src/me/piebridge/prevent/ui/ScreenSlidePagerAdapter.java index 48e08af..5fdcaa7 100644 --- a/app/src/me/piebridge/prevent/ui/ScreenSlidePagerAdapter.java +++ b/app/src/me/piebridge/prevent/ui/ScreenSlidePagerAdapter.java @@ -7,6 +7,7 @@ import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentStatePagerAdapter; /** @@ -17,7 +18,7 @@ public class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { private final PreventFragment[] mFragments; public ScreenSlidePagerAdapter(FragmentManager fm) { - super(fm); + super(fm, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); mFragments = new PreventFragment[2]; } diff --git a/app/src/me/piebridge/prevent/ui/UserGuideActivity.java b/app/src/me/piebridge/prevent/ui/UserGuideActivity.java deleted file mode 100644 index 3cb4572..0000000 --- a/app/src/me/piebridge/prevent/ui/UserGuideActivity.java +++ /dev/null @@ -1,423 +0,0 @@ -package me.piebridge.prevent.ui; - -import android.Manifest; -import android.app.Activity; -import android.app.AlertDialog; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.os.Environment; -import android.os.Process; -import android.text.TextUtils; -import android.util.TypedValue; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.WindowManager; -import android.webkit.WebView; -import android.widget.ProgressBar; -import android.widget.RelativeLayout; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.core.app.ActivityCompat; - -import com.android.server.am.PreventRunning; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.File; -import java.io.IOException; -import java.util.Locale; - -import me.piebridge.prevent.BuildConfig; -import me.piebridge.prevent.R; -import me.piebridge.prevent.common.PreventIntent; -import me.piebridge.prevent.ui.util.ColorUtils; -import me.piebridge.prevent.ui.util.DeprecatedUtils; -import me.piebridge.prevent.ui.util.EmailUtils; -import me.piebridge.prevent.ui.util.FileUtils; - -/** - * Created by thom on 15/10/3. - */ -public class UserGuideActivity extends Activity implements View.OnClickListener { - - - private BroadcastReceiver receiver; - - private static final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 0x1; - - private String name; - private Integer version = null; - private String method = null; - - private String colorBackground; - private String colorText; - private String colorLink; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.about); - if (getActionBar() != null) { - getActionBar().setDisplayHomeAsUpEnabled(true); - } - - WebView webView = (WebView) findViewById(R.id.webview); - webView.setBackgroundColor(ColorUtils.resolveColor(this, android.R.attr.colorBackground)); - webView.setVerticalScrollBarEnabled(false); - webView.setHorizontalScrollBarEnabled(false); - String path; - if ("zh".equals(Locale.getDefault().getLanguage())) { - path = "about.zh.html"; - } else { - path = "about.en.html"; - } - try { - String template = FileUtils.readAsString(getAssets().open(path)); - resolveColors(); - String body = String.format(template, colorBackground, colorText, colorLink); - webView.loadDataWithBaseURL(null, body, "text/html; charset=utf-8", "UTF-8", null); - } catch (IOException e) { - webView.loadUrl("file:///android_asset/" + path); - UILog.d("cannot open " + path, e); - } - setView(R.id.alipay, "com.eg.android.AlipayGphone"); - if (hasPermission()) { - setView(R.id.wechat, "com.tencent.mm"); - } else { - findViewById(R.id.wechat).setVisibility(View.GONE); - } - if (!setView(R.id.paypal, "com.paypal.android.p2pmobile")) { - TextView paypal = (TextView) findViewById(R.id.paypal); - paypal.setClickable(true); - paypal.setOnClickListener(this); - paypal.setCompoundDrawablesWithIntrinsicBounds(null, cropDrawable(paypal.getCompoundDrawables()[1]), null, null); - } - retrieveInfo(); - } - - @Override - protected void onResume() { - super.onResume(); - } - - @Override - protected void onDestroy() { - deleteQrCodeIfNeeded(); - super.onDestroy(); - } - - private int getPixel(int dp) { - return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()); - } - - private Drawable cropDrawable(Drawable icon) { - int width = getPixel(0x20); - if (icon.getMinimumWidth() > width && icon instanceof BitmapDrawable) { - Bitmap bitmap = Bitmap.createScaledBitmap(((BitmapDrawable) icon).getBitmap(), width, width, false); - return new BitmapDrawable(getResources(), bitmap); - } - return icon; - } - - private boolean setView(int id, String packageName) { - TextView donate = (TextView) findViewById(id); - PackageManager pm = getPackageManager(); - try { - ApplicationInfo info = pm.getApplicationInfo(packageName, 0); - if (!info.enabled) { - return false; - } - CharSequence label = getLabel(pm, info); - donate.setContentDescription(label); - donate.setCompoundDrawablesWithIntrinsicBounds(null, cropDrawable(pm.getApplicationIcon(info)), null, null); - donate.setText(label); - donate.setClickable(true); - donate.setOnClickListener(this); - donate.setVisibility(View.VISIBLE); - return true; - } catch (PackageManager.NameNotFoundException e) { - UILog.d("cannot find package " + packageName, e); - return false; - } - } - - private CharSequence getLabel(PackageManager pm, ApplicationInfo info) throws PackageManager.NameNotFoundException { - CharSequence label = null; - if ("com.android.vending".equals(info.packageName)) { - Resources resources = pm.getResourcesForApplication(info); - int appName = resources.getIdentifier("app_name", "string", info.packageName); - if (appName > 0) { - label = resources.getText(appName); - } - } - if (TextUtils.isEmpty(label)) { - label = pm.getApplicationLabel(info); - } - return label; - } - - private File getQrCode() { - File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); - if (dir == null) { - return null; - } - if (!checkPermission()) { - return null; - } - File screenshots = new File(dir, "Screenshots"); - if (!screenshots.exists()) { - screenshots.mkdirs(); - } - return new File(screenshots, "pr_donate.png"); - } - - public int checkPermission(String permission) { - return checkPermission(permission, android.os.Process.myPid(), Process.myUid()); - } - - private boolean hasPermission() { - return checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED - || !ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); - } - - private boolean checkPermission() { - if (checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - return true; - } - if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); - } - return false; - } - - @Override - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { - if (requestCode == MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE) { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - donateViaWeChat(); - } else { - findViewById(R.id.wechat).setVisibility(View.GONE); - } - } - } - - private void refreshQrCode(File qrCode) { - Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); - mediaScanIntent.setData(Uri.fromFile(qrCode)); - sendBroadcast(mediaScanIntent); - } - - private void deleteQrCodeIfNeeded() { - File qrCode = getQrCode(); - if (qrCode != null && qrCode.exists()) { - qrCode.delete(); - refreshQrCode(qrCode); - } - } - - private boolean donateViaWeChat() { - File qrCode = getQrCode(); - if (qrCode == null) { - return false; - } - try { - FileUtils.dumpFile(getAssets().open("wechat.png"), qrCode); - } catch (IOException e) { - UILog.d("cannot dump wechat", e); - return false; - } - refreshQrCode(qrCode); - Intent intent = new Intent("com.tencent.mm.action.BIZSHORTCUT"); - intent.setPackage("com.tencent.mm"); - intent.putExtra("LauncherUI.From.Scaner.Shortcut", true); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - try { - startActivity(intent); - for (int i = 0; i < 0x3; ++i) { - Toast.makeText(this, R.string.select_qr_code, Toast.LENGTH_LONG).show(); - } - } catch (Throwable t) { // NOSONAR - } - return true; - } - - private boolean donateViaAlipay() { - - Intent intent = new Intent(); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.setData(Uri.parse(BuildConfig.DONATE_ALIPAY)); - try { - startActivity(intent); - } catch (Throwable t) { // NOSONAR - - } - return true; - } - - private boolean donateViaPayPal() { - - try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.DONATE_PAYPAL))); - } catch (Throwable t) { // NOSONAR - // do nothing - } - return true; - } - - @Override - public void onClick(View v) { - int id = v.getId(); - if (id == R.id.wechat) { - donateViaWeChat(); - } else if (id == R.id.alipay) { - donateViaAlipay(); - } else if (id == R.id.paypal) { - donateViaPayPal(); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - menu.clear(); - menu.add(Menu.NONE, R.string.version, Menu.NONE, R.string.version); - if (BuildConfig.RELEASE) { - menu.add(Menu.NONE, R.string.feedback, Menu.NONE, R.string.feedback); - } - menu.add(Menu.NONE, R.string.advanced_settings, Menu.NONE, R.string.advanced_settings); - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == android.R.id.home) { - finish(); - } else if (id == R.string.feedback) { - feedback(); - } else if (id == R.string.version) { - showVersionInfo(); - } else if (id == R.string.advanced_settings) { - startActivity(new Intent(this, AdvancedSettingsActivity.class)); - } - return true; - } - - private void feedback() { - EmailUtils.sendEmail(this, getString(R.string.feedback)); - } - - - - private void retrieveInfo() { - Intent intent = new Intent(); - intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); - intent.setAction(PreventIntent.ACTION_GET_INFO); - intent.setData(Uri.fromParts(PreventIntent.SCHEME, getPackageName(), null)); - UILog.i("sending get info broadcast"); - if (receiver == null) { - receiver = new HookReceiver(); - } - sendOrderedBroadcast(intent, PreventIntent.PERMISSION_SYSTEM, receiver, null, 0, null, null); - } - - private class HookReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (PreventIntent.ACTION_GET_INFO.equals(action)) { - handleInfo(); - } - } - - private void handleInfo() { - String info = getResultData(); - if (TextUtils.isEmpty(info)) { - return; - } - try { - JSONObject json = new JSONObject(info); - version = json.optInt("version"); - method = json.optString("method"); - name = json.optString("name"); - } catch (JSONException e) { - UILog.d("cannot get version from " + info, e); - } - } - } - - private String getVersionInfo(boolean showAppVersion) { - StringBuilder sb = new StringBuilder(); - showVersion(sb); - sb.append("Android: "); - sb.append(Locale.getDefault()); - sb.append("-"); - sb.append(Build.VERSION.RELEASE); - sb.append("\n"); - if (showAppVersion) { - sb.append(getString(R.string.app_name)); - sb.append(": "); - sb.append(BuildConfig.VERSION_NAME); - sb.append("\n"); - } - sb.append(Build.FINGERPRINT); - return sb.toString(); - } - - private void showVersion(StringBuilder sb) { - if (name != null && !BuildConfig.VERSION_NAME.equalsIgnoreCase(name)) { - sb.append("Active: "); - sb.append(name); - sb.append("\n"); - } - if (version != null) { - if (version == 0) { - method = "native"; - } - sb.append("Bridge: "); - sb.append(method); - sb.append(" v"); - sb.append(version); - if ("native".equalsIgnoreCase(method) && version < PreventRunning.VERSION) { - sb.append(" -> v"); - sb.append(PreventRunning.VERSION); - } - sb.append("\n"); - } - } - - private void showVersionInfo() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getString(R.string.app_name) + "(" + BuildConfig.VERSION_NAME + ")"); - builder.setMessage(getVersionInfo(false)); - builder.setIcon(R.drawable.ic_launcher); - builder.setPositiveButton(getString(android.R.string.copy), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - DeprecatedUtils.setClipboard(getBaseContext(), getVersionInfo(true)); - } - }); - builder.create().show(); - } - - private void resolveColors() { - colorBackground = ColorUtils.rgba(ColorUtils.resolveColor(this, android.R.attr.colorBackground)); - colorLink = ColorUtils.rgba(ColorUtils.resolveColor(this, android.R.attr.textColorLink)); - int textColorPrimary = ColorUtils.resolveColor(this, android.R.attr.textColorPrimary); - colorText = ColorUtils.rgba(ColorUtils.fixOpacity(textColorPrimary)); - } - -} diff --git a/app/src/me/piebridge/prevent/ui/util/DeprecatedUtils.java b/app/src/me/piebridge/prevent/ui/util/DeprecatedUtils.java deleted file mode 100644 index 38ac3d0..0000000 --- a/app/src/me/piebridge/prevent/ui/util/DeprecatedUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -package me.piebridge.prevent.ui.util; - -import android.content.Context; -import android.preference.Preference; -import android.preference.PreferenceActivity; - -/** - * Created by thom on 15/10/13. - */ -public class DeprecatedUtils { - - private DeprecatedUtils() { - - } - - @SuppressWarnings("deprecation") - public static void setClipboard(Context context, CharSequence content) { - ((android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE)).setText(content); - } - - @SuppressWarnings("deprecation") - public static void addPreferencesFromResource(PreferenceActivity activity, int preferencesResId) { - activity.addPreferencesFromResource(preferencesResId); - } - - @SuppressWarnings("deprecation") - public static Preference findPreference(PreferenceActivity activity, CharSequence key) { - return activity.findPreference(key); - } - -} diff --git a/app/src/me/piebridge/prevent/ui/util/PreventListUtils.java b/app/src/me/piebridge/prevent/ui/util/PreventListUtils.java index 888df32..7197cb9 100644 --- a/app/src/me/piebridge/prevent/ui/util/PreventListUtils.java +++ b/app/src/me/piebridge/prevent/ui/util/PreventListUtils.java @@ -4,7 +4,8 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Environment; -import android.preference.PreferenceManager; + +import androidx.preference.PreferenceManager; import java.io.File; import java.util.Set; diff --git a/app/src/me/piebridge/prevent/ui/util/PreventUtils.java b/app/src/me/piebridge/prevent/ui/util/PreventUtils.java index f2b61b4..ff29f96 100644 --- a/app/src/me/piebridge/prevent/ui/util/PreventUtils.java +++ b/app/src/me/piebridge/prevent/ui/util/PreventUtils.java @@ -8,9 +8,10 @@ import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; -import android.preference.PreferenceManager; import android.widget.Toast; +import androidx.preference.PreferenceManager; + import org.json.JSONException; import org.json.JSONObject;