improved app icon fetch
This commit is contained in:
parent
8d1352d3df
commit
cb102cbc6b
7 changed files with 43 additions and 39 deletions
|
@ -3,6 +3,7 @@ package deckers.thibault.aves.channel.calls
|
|||
import android.content.*
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
|
@ -103,6 +104,7 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
|
|||
var data: ByteArray? = null
|
||||
try {
|
||||
val iconResourceId = context.packageManager.getApplicationInfo(packageName, 0).icon
|
||||
if (iconResourceId != Resources.ID_NULL) {
|
||||
val uri = Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
|
||||
.authority(packageName)
|
||||
|
@ -124,6 +126,7 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
|
|||
Log.w(LOG_TAG, "failed to decode app icon for packageName=$packageName", e)
|
||||
}
|
||||
Glide.with(context).clear(target)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w(LOG_TAG, "failed to get app info for packageName=$packageName", e)
|
||||
return
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:aves/services/android_app_service.dart';
|
|||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:transparent_image/transparent_image.dart';
|
||||
|
||||
class AppIconImage extends ImageProvider<AppIconImageKey> {
|
||||
const AppIconImage({
|
||||
|
@ -39,10 +40,7 @@ class AppIconImage extends ImageProvider<AppIconImageKey> {
|
|||
Future<ui.Codec> _loadAsync(AppIconImageKey key, DecoderCallback decode) async {
|
||||
try {
|
||||
final bytes = await AndroidAppService.getAppIcon(key.packageName, key.size);
|
||||
if (bytes.isEmpty) {
|
||||
throw StateError('$packageName app icon loading failed');
|
||||
}
|
||||
return await decode(bytes);
|
||||
return await decode(bytes.isEmpty ? kTransparentImage : bytes);
|
||||
} catch (error) {
|
||||
debugPrint('$runtimeType _loadAsync failed with packageName=$packageName, error=$error');
|
||||
throw StateError('$packageName app icon decoding failed');
|
||||
|
|
|
@ -34,8 +34,8 @@ class AndroidAppService {
|
|||
'sizeDip': size,
|
||||
});
|
||||
if (result != null) return result as Uint8List;
|
||||
} on PlatformException catch (e, stack) {
|
||||
await reportService.recordError(e, stack);
|
||||
} on PlatformException catch (_, __) {
|
||||
// ignore, as some packages legitimately do not have icons
|
||||
}
|
||||
return Uint8List(0);
|
||||
}
|
||||
|
|
|
@ -274,6 +274,11 @@ class Constants {
|
|||
license: 'Apache 2.0',
|
||||
sourceUrl: 'https://github.com/DavBfr/dart_pdf',
|
||||
),
|
||||
Dependency(
|
||||
name: 'Transparent Image',
|
||||
license: 'MIT',
|
||||
sourceUrl: 'https://pub.dev/packages/transparent_image',
|
||||
),
|
||||
Dependency(
|
||||
name: 'Tuple',
|
||||
license: 'BSD 2-Clause',
|
||||
|
|
|
@ -168,9 +168,6 @@ class _OwnerPropState extends State<OwnerProp> {
|
|||
text: context.l10n.viewerInfoLabelOwner,
|
||||
style: InfoRowGroup.keyStyle,
|
||||
),
|
||||
// `com.android.shell` is the package reported
|
||||
// for images copied to the device by ADB for Test Driver
|
||||
if (ownerPackage != 'com.android.shell')
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Padding(
|
||||
|
|
|
@ -981,7 +981,7 @@ packages:
|
|||
source: hosted
|
||||
version: "0.3.19"
|
||||
transparent_image:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: transparent_image
|
||||
url: "https://pub.dartlang.org"
|
||||
|
|
|
@ -59,6 +59,7 @@ dependencies:
|
|||
streams_channel:
|
||||
git:
|
||||
url: git://github.com/deckerst/aves_streams_channel.git
|
||||
transparent_image:
|
||||
tuple:
|
||||
url_launcher:
|
||||
version:
|
||||
|
|
Loading…
Reference in a new issue