Skip to content

Commit

Permalink
bump app version,delete gapps related code,fix possible boot block in…
Browse files Browse the repository at this point in the history
… gapps installed rom,reduce gradle warnnings to zero.
  • Loading branch information
Saint-Theana authored and Saint-Theana committed Oct 25, 2021
1 parent 64635f0 commit 052d62d
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 828 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
19 changes: 0 additions & 19 deletions app/src/me/piebridge/prevent/common/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,9 @@ public static Set<String> load(File file) {
return packages;
}

private static void loadExternal(Set<String> 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<String> load(Context context, String prevent) {
Set<String> packages = load(new File(prevent));
if (context != null && packages.isEmpty()) {
loadExternal(packages, context);
}
return packages;
}

Expand Down
144 changes: 0 additions & 144 deletions app/src/me/piebridge/prevent/common/GmsUtils.java

This file was deleted.

31 changes: 5 additions & 26 deletions app/src/me/piebridge/prevent/common/PackageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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<InputMethodInfo> 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);
}
Expand All @@ -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);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,36 +49,30 @@ public static void setContext(Context context, Map<String, Boolean> 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);
} else {
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);
prevents = false;
}
LogUtils.logStartProcess(packageName, hostingType, hostingName, sender);
}

return !prevents || hookDependency(hostingName, hostingType, packageName, sender);
}

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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<String> packages) {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Expand All @@ -191,22 +169,6 @@ private static void retrieveSettingsPackage(PackageManager pm, Collection<String
}
}

private static boolean cannotPreventGms(ComponentName component, String sender) {
if (GmsUtils.isGmsRegister(mContext, component)) {
return true;
}
PackageManager pm = mContext.getPackageManager();
if (settingsPackages.isEmpty()) {
retrieveSettingsPackage(pm, settingsPackages);
}
if (settingsPackages.contains(sender)) {
return true;
}
if (!GmsUtils.isGapps(sender)) {
return false;
}
return pm.getLaunchIntentForPackage(sender) == null || SystemHook.hasRunningActivity(sender);
}

private static boolean cannotPrevent(String sender, String packageName) {
if (SystemHook.isFramework(packageName)) {
Expand Down Expand Up @@ -263,8 +225,7 @@ private static void handleSafeService(String packageName) {
}

public static boolean onCleanUpRemovedTask(final String packageName) {
SystemHook.updateRunningGapps(packageName, false);
if (PackageUtils.isInputMethod(mContext, packageName)) {
if (PackageUtils.isInputMethod(mContext,packageName)) {
PreventLog.i("" + packageName + " is input method so will not be cleaned");
return false;
}
Expand Down
Loading

0 comments on commit 052d62d

Please sign in to comment.