Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UI blocking when retrieving apps #31

Merged
merged 2 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Become a [tester](https://play.google.com/apps/testing/com.razinj.context_launch
## Run

Install dependencies:

```shell
# NPM
npm ci
Expand All @@ -29,12 +29,23 @@ npm run android

## Build

Debug `APK`:
Debug `apk`:

```shell
cd android && ./gradlew assembleDebug
```

Release `apk` and `aab`

Before generating release builds, change the `versionCode` and `versionName` in `android/app/build.gradle`.

```shell
./gradlew assembleRelease # Release 'apk'
./gradlew bundleRelease # Release 'aab'
```

Or run the `build.sh` script.

## Tests

Only RN/Jest are implemented at the moment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,33 @@ public void onReceive(Context context, Intent intent) {

@ReactMethod
public void getApplications(Promise promise) {
PackageManager pm = reactContext.getPackageManager();
List<AppDetails> apps = new ArrayList<>();
List<PackageInfo> packages;

// Get installed packages
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packages = pm.getInstalledPackages(PackageManager.PackageInfoFlags.of(0));
} else {
packages = pm.getInstalledPackages(0);
}
new Thread(() -> {
PackageManager pm = reactContext.getPackageManager();
List<AppDetails> apps = new ArrayList<>();
List<PackageInfo> packages;

// Get installed packages
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packages = pm.getInstalledPackages(PackageManager.PackageInfoFlags.of(0));
} else {
packages = pm.getInstalledPackages(0);
}

// Filter and map to AppDetails
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
apps = packages.stream().filter(packageInfo -> Objects.nonNull(pm.getLaunchIntentForPackage(packageInfo.packageName))).map(packageInfo -> new AppDetails(packageInfo.packageName, packageInfo.applicationInfo.loadLabel(pm).toString(), Utils.getEncodedIcon(pm, packageInfo.packageName))).collect(Collectors.toList());
} else {
for (PackageInfo packageInfo : packages) {
if (Objects.isNull(pm.getLaunchIntentForPackage(packageInfo.packageName))) continue;
// Filter and map to AppDetails
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
apps = packages.stream().filter(packageInfo -> Objects.nonNull(pm.getLaunchIntentForPackage(packageInfo.packageName))).map(packageInfo -> new AppDetails(packageInfo.packageName, packageInfo.applicationInfo.loadLabel(pm).toString(), Utils.getEncodedIcon(pm, packageInfo.packageName))).collect(Collectors.toList());
} else {
for (PackageInfo packageInfo : packages) {
if (Objects.isNull(pm.getLaunchIntentForPackage(packageInfo.packageName))) {
continue;
}

apps.add(new AppDetails(packageInfo.packageName, packageInfo.applicationInfo.loadLabel(pm).toString(), Utils.getEncodedIcon(pm, packageInfo.packageName)));
apps.add(new AppDetails(packageInfo.packageName, packageInfo.applicationInfo.loadLabel(pm).toString(), Utils.getEncodedIcon(pm, packageInfo.packageName)));
}
}
}

promise.resolve(apps.toString());
promise.resolve(apps.toString());
}).start();
}

@ReactMethod
Expand Down
Loading