[core] [app] Filter out apps without any process for the scope list (#181)

* Filter out apps without any process for the scope list

* Bump ver

Co-authored-by: LoveSy <shana@zju.edu.cn>
This commit is contained in:
tehcneko 2021-02-23 22:28:13 +08:00 committed by GitHub
parent 9ab6529e91
commit 128f3d8937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 186 additions and 16 deletions

View File

@ -63,10 +63,10 @@ public class ConfigManager {
} }
} }
public static List<PackageInfo> getInstalledPackagesFromAllUsers(int flags) { public static List<PackageInfo> getInstalledPackagesFromAllUsers(int flags, boolean filterNoProcess) {
List<PackageInfo> list = new ArrayList<>(); List<PackageInfo> list = new ArrayList<>();
try { try {
list.addAll(LSPosedManagerServiceClient.getInstalledPackagesFromAllUsers(flags)); list.addAll(LSPosedManagerServiceClient.getInstalledPackagesFromAllUsers(flags, filterNoProcess));
} catch (RemoteException | NullPointerException e) { } catch (RemoteException | NullPointerException e) {
Log.e(App.TAG, Log.getStackTraceString(e)); Log.e(App.TAG, Log.getStackTraceString(e));
} }

View File

@ -127,7 +127,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
enabled = ModuleUtil.getInstance().isModuleEnabled(modulePackageName); enabled = ModuleUtil.getInstance().isModuleEnabled(modulePackageName);
activity.runOnUiThread(() -> masterSwitch.setChecked(enabled)); activity.runOnUiThread(() -> masterSwitch.setChecked(enabled));
List<PackageInfo> appList = ConfigManager.getInstalledPackagesFromAllUsers(PackageManager.GET_META_DATA); List<PackageInfo> appList = ConfigManager.getInstalledPackagesFromAllUsers(PackageManager.GET_META_DATA, true);
checkedList.clear(); checkedList.clear();
recommendedList.clear(); recommendedList.clear();
searchList.clear(); searchList.clear();
@ -181,6 +181,9 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
if (info.packageName.equals(BuildConfig.APPLICATION_ID)) { if (info.packageName.equals(BuildConfig.APPLICATION_ID)) {
return true; return true;
} }
if (info.packageName.equals("android")) {
return false;
}
if (checkedList.contains(app)) { if (checkedList.contains(app)) {
return false; return false;
} }

View File

@ -43,9 +43,9 @@ public class LSPosedManagerServiceClient {
} }
public static List<PackageInfo> getInstalledPackagesFromAllUsers(int flags) throws RemoteException, NullPointerException { public static List<PackageInfo> getInstalledPackagesFromAllUsers(int flags, boolean filterNoProcess) throws RemoteException, NullPointerException {
ensureService(); ensureService();
ParceledListSlice<PackageInfo> parceledListSlice = service.getInstalledPackagesFromAllUsers(flags); ParceledListSlice<PackageInfo> parceledListSlice = service.getInstalledPackagesFromAllUsers(flags, false);
// //
return parceledListSlice.getList(); return parceledListSlice.getList();
} }

View File

@ -85,7 +85,7 @@ public final class ModuleUtil {
} }
Map<String, InstalledModule> modules = new HashMap<>(); Map<String, InstalledModule> modules = new HashMap<>();
for (PackageInfo pkg : ConfigManager.getInstalledPackagesFromAllUsers(PackageManager.GET_META_DATA)) { for (PackageInfo pkg : ConfigManager.getInstalledPackagesFromAllUsers(PackageManager.GET_META_DATA, false)) {
ApplicationInfo app = pkg.applicationInfo; ApplicationInfo app = pkg.applicationInfo;
if (!app.enabled || app.uid / 100000 != 0) if (!app.enabled || app.uid / 100000 != 0)
continue; continue;

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2015 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingStart"
android:background="@drawable/item_background"
android:clipToPadding="false"
android:baselineAligned="false">
<include layout="@layout/image_frame" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem"
android:ellipsize="marquee" />
<TextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignLeft="@android:id/title"
android:layout_alignStart="@android:id/title"
android:layout_gravity="start"
android:textAlignment="viewStart"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="10"
style="@style/PreferenceSummaryTextStyle" />
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<LinearLayout
android:id="@android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="end|center_vertical"
android:paddingLeft="16dp"
android:paddingStart="16dp"
android:paddingRight="0dp"
android:paddingEnd="0dp"
android:orientation="vertical" />
</LinearLayout>

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2015 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:gravity="center_vertical"
android:paddingStart="?android:listPreferredItemPaddingLeft"
android:paddingEnd="24dp"
android:background="@drawable/item_background"
android:clipToPadding="false"
android:baselineAligned="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:gravity="center_vertical">
<include layout="@layout/image_frame" />
<View
android:id="@android:id/empty"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:visibility="invisible" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="16dp"
android:paddingBottom="16dp">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearance"
android:textIsSelectable="false"
android:textSize="16sp"
android:ellipsize="marquee" />
<TextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignLeft="@android:id/title"
android:layout_alignStart="@android:id/title"
android:layout_gravity="start"
android:textAlignment="viewStart"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="10"
style="@style/PreferenceSummaryTextStyle" />
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<LinearLayout
android:id="@android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="end|center_vertical"
android:paddingLeft="16dp"
android:paddingStart="16dp"
android:paddingRight="0dp"
android:paddingEnd="0dp"
android:orientation="vertical" />
</LinearLayout>
</LinearLayout>

View File

@ -28,8 +28,11 @@ import android.app.ActivityThread;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.os.Process; import android.os.Process;
import androidx.annotation.Keep;
import io.github.lsposed.lspd.util.Utils; import io.github.lsposed.lspd.util.Utils;
@Keep
public class ModuleLogger { public class ModuleLogger {
static SimpleDateFormat logDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss", Locale.getDefault()); static SimpleDateFormat logDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss", Locale.getDefault());
static int fd = -1; static int fd = -1;

View File

@ -23,18 +23,15 @@ import android.content.pm.PackageInfo;
import android.os.IBinder; import android.os.IBinder;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Log;
import java.util.List; import java.util.List;
import de.robv.android.xposed.XposedBridge; import de.robv.android.xposed.XposedBridge;
import io.github.lsposed.lspd.Application;
import io.github.lsposed.lspd.BuildConfig; import io.github.lsposed.lspd.BuildConfig;
import io.github.lsposed.lspd.ILSPManagerService; import io.github.lsposed.lspd.ILSPManagerService;
import io.github.lsposed.lspd.Application;
import io.github.lsposed.lspd.utils.ParceledListSlice; import io.github.lsposed.lspd.utils.ParceledListSlice;
import static io.github.lsposed.lspd.service.ServiceManager.TAG;
public class LSPManagerService extends ILSPManagerService.Stub { public class LSPManagerService extends ILSPManagerService.Stub {
LSPManagerService() { LSPManagerService() {
@ -61,8 +58,8 @@ public class LSPManagerService extends ILSPManagerService.Stub {
} }
@Override @Override
public ParceledListSlice<PackageInfo> getInstalledPackagesFromAllUsers(int flags) throws RemoteException { public ParceledListSlice<PackageInfo> getInstalledPackagesFromAllUsers(int flags, boolean filterNoProcess) throws RemoteException {
return PackageService.getInstalledPackagesFromAllUsers(flags); return PackageService.getInstalledPackagesFromAllUsers(flags, filterNoProcess);
} }
@Override @Override

View File

@ -33,7 +33,9 @@ import android.util.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import io.github.lsposed.lspd.Application; import io.github.lsposed.lspd.Application;
import io.github.lsposed.lspd.utils.ParceledListSlice; import io.github.lsposed.lspd.utils.ParceledListSlice;
@ -79,13 +81,18 @@ public class PackageService {
return pm.getPackagesForUid(uid); return pm.getPackagesForUid(uid);
} }
public static ParceledListSlice<PackageInfo> getInstalledPackagesFromAllUsers(int flags) throws RemoteException { public static ParceledListSlice<PackageInfo> getInstalledPackagesFromAllUsers(int flags, boolean filterNoProcess) throws RemoteException {
ArrayList<PackageInfo> res = new ArrayList<>(); List<PackageInfo> res = new ArrayList<>();
IPackageManager pm = getPackageManager(); IPackageManager pm = getPackageManager();
if (pm == null) return ParceledListSlice.emptyList(); if (pm == null) return ParceledListSlice.emptyList();
if (filterNoProcess) flags = PackageManager.MATCH_DISABLED_COMPONENTS |
PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.GET_ACTIVITIES | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
PackageManager.GET_SERVICES | PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS | flags;
for (int userId : UserService.getUsers()) { for (int userId : UserService.getUsers()) {
res.addAll(pm.getInstalledPackages(flags, userId).getList()); res.addAll(pm.getInstalledPackages(flags, userId).getList());
} }
if (filterNoProcess)
res = res.stream().filter(pkgInfo -> !fetchProcesses(pkgInfo).isEmpty()).collect(Collectors.toList());
return new ParceledListSlice<>(res); return new ParceledListSlice<>(res);
} }

View File

@ -20,4 +20,4 @@ androidMinSdkVersion=26
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
android.prefabVersion=1.1.2 android.prefabVersion=1.1.2
versionName=v1.0.0 versionName=v1.0.1

View File

@ -5,7 +5,7 @@ import io.github.lsposed.lspd.Application;
interface ILSPManagerService { interface ILSPManagerService {
ParceledListSlice<PackageInfo> getInstalledPackagesFromAllUsers(int flags) = 2; ParceledListSlice<PackageInfo> getInstalledPackagesFromAllUsers(int flags, boolean filterNoProcess) = 2;
String[] enabledModules() = 3; String[] enabledModules() = 3;