improved app icon fetch

This commit is contained in:
Thibault Deckers 2021-08-16 10:42:50 +09:00
parent 8d1352d3df
commit cb102cbc6b
7 changed files with 43 additions and 39 deletions

View file

@ -3,6 +3,7 @@ package deckers.thibault.aves.channel.calls
import android.content.* import android.content.*
import android.content.pm.ApplicationInfo import android.content.pm.ApplicationInfo
import android.content.res.Configuration import android.content.res.Configuration
import android.content.res.Resources
import android.net.Uri import android.net.Uri
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
@ -103,6 +104,7 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
var data: ByteArray? = null var data: ByteArray? = null
try { try {
val iconResourceId = context.packageManager.getApplicationInfo(packageName, 0).icon val iconResourceId = context.packageManager.getApplicationInfo(packageName, 0).icon
if (iconResourceId != Resources.ID_NULL) {
val uri = Uri.Builder() val uri = Uri.Builder()
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
.authority(packageName) .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) Log.w(LOG_TAG, "failed to decode app icon for packageName=$packageName", e)
} }
Glide.with(context).clear(target) Glide.with(context).clear(target)
}
} catch (e: Exception) { } catch (e: Exception) {
Log.w(LOG_TAG, "failed to get app info for packageName=$packageName", e) Log.w(LOG_TAG, "failed to get app info for packageName=$packageName", e)
return return

View file

@ -4,6 +4,7 @@ import 'package:aves/services/android_app_service.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:transparent_image/transparent_image.dart';
class AppIconImage extends ImageProvider<AppIconImageKey> { class AppIconImage extends ImageProvider<AppIconImageKey> {
const AppIconImage({ const AppIconImage({
@ -39,10 +40,7 @@ class AppIconImage extends ImageProvider<AppIconImageKey> {
Future<ui.Codec> _loadAsync(AppIconImageKey key, DecoderCallback decode) async { Future<ui.Codec> _loadAsync(AppIconImageKey key, DecoderCallback decode) async {
try { try {
final bytes = await AndroidAppService.getAppIcon(key.packageName, key.size); final bytes = await AndroidAppService.getAppIcon(key.packageName, key.size);
if (bytes.isEmpty) { return await decode(bytes.isEmpty ? kTransparentImage : bytes);
throw StateError('$packageName app icon loading failed');
}
return await decode(bytes);
} catch (error) { } catch (error) {
debugPrint('$runtimeType _loadAsync failed with packageName=$packageName, error=$error'); debugPrint('$runtimeType _loadAsync failed with packageName=$packageName, error=$error');
throw StateError('$packageName app icon decoding failed'); throw StateError('$packageName app icon decoding failed');

View file

@ -34,8 +34,8 @@ class AndroidAppService {
'sizeDip': size, 'sizeDip': size,
}); });
if (result != null) return result as Uint8List; if (result != null) return result as Uint8List;
} on PlatformException catch (e, stack) { } on PlatformException catch (_, __) {
await reportService.recordError(e, stack); // ignore, as some packages legitimately do not have icons
} }
return Uint8List(0); return Uint8List(0);
} }

View file

@ -274,6 +274,11 @@ class Constants {
license: 'Apache 2.0', license: 'Apache 2.0',
sourceUrl: 'https://github.com/DavBfr/dart_pdf', sourceUrl: 'https://github.com/DavBfr/dart_pdf',
), ),
Dependency(
name: 'Transparent Image',
license: 'MIT',
sourceUrl: 'https://pub.dev/packages/transparent_image',
),
Dependency( Dependency(
name: 'Tuple', name: 'Tuple',
license: 'BSD 2-Clause', license: 'BSD 2-Clause',

View file

@ -168,9 +168,6 @@ class _OwnerPropState extends State<OwnerProp> {
text: context.l10n.viewerInfoLabelOwner, text: context.l10n.viewerInfoLabelOwner,
style: InfoRowGroup.keyStyle, 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( WidgetSpan(
alignment: PlaceholderAlignment.middle, alignment: PlaceholderAlignment.middle,
child: Padding( child: Padding(

View file

@ -981,7 +981,7 @@ packages:
source: hosted source: hosted
version: "0.3.19" version: "0.3.19"
transparent_image: transparent_image:
dependency: transitive dependency: "direct main"
description: description:
name: transparent_image name: transparent_image
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"

View file

@ -59,6 +59,7 @@ dependencies:
streams_channel: streams_channel:
git: git:
url: git://github.com/deckerst/aves_streams_channel.git url: git://github.com/deckerst/aves_streams_channel.git
transparent_image:
tuple: tuple:
url_launcher: url_launcher:
version: version: