-
-
Notifications
You must be signed in to change notification settings - Fork 3k
manager: introduce webui package manager api #2928
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7736d1d
manager: introduce webui package manager api
KOWX712 a30e2d6
merge all list packages funtion into listPackages
KOWX712 d51d13e
Update manager/app/src/main/java/me/weishu/kernelsu/ui/webui/WebViewI…
KOWX712 e425502
drop getPackagesIcons
KOWX712 05ec455
remove @RequiresApi(Build.VERSION_CODES.P)
KOWX712 040322d
Replace the HashMap-based cache with an LruCache to prevent memory leaks
KOWX712 e3670a2
Update manager/app/src/main/java/me/weishu/kernelsu/ui/webui/AppIconU…
KOWX712 8a8b2c6
Fix data race by adding synchronization
KOWX712 b383275
Update manager/app/src/main/java/me/weishu/kernelsu/ui/webui/AppIconU…
KOWX712 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
manager/app/src/main/java/me/weishu/kernelsu/ui/webui/AppIconUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package me.weishu.kernelsu.ui.webui; | ||
|
|
||
| import android.content.Context; | ||
| import android.graphics.Bitmap; | ||
| import android.graphics.Canvas; | ||
| import android.graphics.drawable.BitmapDrawable; | ||
| import android.graphics.drawable.Drawable; | ||
| import android.util.LruCache; | ||
| import me.weishu.kernelsu.ui.viewmodel.SuperUserViewModel; | ||
|
|
||
| public class AppIconUtil { | ||
| // Limit cache size to 200 icons | ||
| private static final int CACHE_SIZE = 200; | ||
| private static final LruCache<String, Bitmap> iconCache = new LruCache<>(CACHE_SIZE); | ||
|
|
||
| public static synchronized Bitmap loadAppIconSync(Context context, String packageName, int sizePx) { | ||
| Bitmap cached = iconCache.get(packageName); | ||
| if (cached != null) return cached; | ||
|
|
||
| try { | ||
| Drawable drawable = SuperUserViewModel.getAppIconDrawable(context, packageName); | ||
KOWX712 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (drawable == null) { | ||
| return null; | ||
| } | ||
| Bitmap raw = drawableToBitmap(drawable, sizePx); | ||
| Bitmap icon = Bitmap.createScaledBitmap(raw, sizePx, sizePx, true); | ||
KOWX712 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (raw != icon) raw.recycle(); | ||
| iconCache.put(packageName, icon); | ||
| return icon; | ||
| } catch (Exception e) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private static Bitmap drawableToBitmap(Drawable drawable, int size) { | ||
| if (drawable instanceof BitmapDrawable) return ((BitmapDrawable) drawable).getBitmap(); | ||
|
|
||
| int width = drawable.getIntrinsicWidth() > 0 ? drawable.getIntrinsicWidth() : size; | ||
| int height = drawable.getIntrinsicHeight() > 0 ? drawable.getIntrinsicHeight() : size; | ||
|
|
||
| Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); | ||
| Canvas canvas = new Canvas(bmp); | ||
| drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); | ||
| drawable.draw(canvas); | ||
| return bmp; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.