Skip to content
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 1.0.0

- **BREAKING**: Raised the minimum Dart SDK version to 3.12.0.
- **BREAKING**: Platform implementations must implement the new abstract query methods and accept `packageNamePrefix` in their `listApps` override.
- Added `isAppInstalled`, `isSystemApp`, `isAppEnabled`, and `isAppLaunchable` to query app state without loading full app metadata.
- Added `getAppIcon` to retrieve an app icon separately as PNG bytes.
- Added `getInstallSourceInfo` and the `AppInstallSourceInfo` model with `installingPackageName`, `initiatingPackageName`, `originatingPackageName`, `packageSource`, and `updateOwnerPackageName`.
- Deprecated `getInstallerStore`. Use `getInstallSourceInfo` and its `installingPackageName` field instead.
- Added the optional `packageNamePrefix` filter to `listApps`. Matching is case-sensitive; null or empty disables the filter.
- Updated package topics and directed issue reports to the main `flutter_device_apps` repository.

## 0.7.0
- Expanded `AppInfo` with additional Android raw metadata fields: `uid`, `apkPath`, `apkSizeBytes`, `dataPath`, and `isOnExternalStorage`.
- Updated `AppInfo` unit tests to cover parsing and null-safety behavior for the new fields.
Expand Down
26 changes: 17 additions & 9 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ linter:
avoid_init_to_null: true
avoid_js_rounded_ints: true
avoid_multiple_declarations_per_line: true
avoid_null_checks_in_equality_operators: true
avoid_print: true
avoid_private_typedef_functions: true
avoid_redundant_argument_values: true
avoid_renaming_method_parameters: true
avoid_return_types_on_setters: true
Expand Down Expand Up @@ -84,7 +82,7 @@ linter:
no_leading_underscores_for_local_identifiers: true
no_literal_bool_comparisons: true
no_logic_in_create_state: true
no_runtimeType_toString: true
no_runtimeType_tostring: true
no_self_assignments: true
no_wildcard_variable_uses: true
non_constant_identifier_names: true
Expand Down Expand Up @@ -148,7 +146,6 @@ linter:
type_init_formals: true
type_literal_in_constant_pattern: true
unawaited_futures: true
unnecessary_await_in_return: true
unnecessary_brace_in_string_interps: true
unnecessary_breaks: true
unnecessary_const: true
Expand Down Expand Up @@ -178,7 +175,6 @@ linter:
use_enums: true
use_full_hex_values_for_flutter_colors: true
use_function_type_syntax_for_parameters: true
use_if_null_to_convert_nulls_to_bools: true
use_is_even_rather_than_modulo: true
use_late_for_private_fields_and_variables: true
use_named_constants: true
Expand All @@ -199,23 +195,29 @@ linter:
unnecessary_library_name: true
use_truncating_division: true
strict_top_level_inference: true
unnecessary_async: true
unnecessary_async: false
unnecessary_underscores: true
unsafe_variance: true
simplify_variable_pattern: true
specify_nonobvious_property_types: true
switch_on_type: true
unnecessary_ignore: true
unnecessary_unawaited: true
use_null_aware_elements: true
public_member_api_docs: true
simple_directive_paths: true
var_with_no_type_annotation: true
empty_container_bodies: true
initialize_in_field_declaration: true
unnecessary_primary_constructor_body: true
use_declaring_parameters: true
migrate_design_widgets: true
###-------------------------------------------------------
omit_local_variable_types: false
use_setters_to_change_properties: false
use_key_in_widget_constructors: false
unnecessary_final: false
prefer_expression_function_bodies: false
prefer_null_aware_method_calls: false
prefer_final_parameters: false
prefer_if_elements_to_conditional_expressions: false
prefer_double_quotes: false
avoid_catches_without_on_clauses: false
Expand All @@ -232,9 +234,15 @@ linter:
flutter_style_todos: false
eol_at_end_of_file: false
lines_longer_than_80_chars: false
one_member_abstracts: false
public_member_api_docs: false
use_build_context_synchronously: false
do_not_use_environment: false
omit_obvious_local_variable_types: false
unintended_html_in_doc_comment: false
omit_obvious_property_types: false
unnecessary_type_name_in_constructor: false
async_return_with_no_await: false
no_raw_types: false
unnecessary_const_in_enum_constructor: false
no_dynamic_casts: false
remove_deprecations_in_breaking_versions: false
29 changes: 13 additions & 16 deletions lib/flutter_device_apps_app_change_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ class AppChangeEvent {
/// Creates an [AppChangeEvent] with the specified properties.
///
/// All parameters are optional and represent the details of the app change.
const AppChangeEvent({
this.packageName,
this.type,
this.isReplacing,
});
const AppChangeEvent({this.packageName, this.type, this.isReplacing});

/// Creates an [AppChangeEvent] from a map of key-value pairs.
///
Expand All @@ -30,8 +26,9 @@ class AppChangeEvent {
factory AppChangeEvent.fromMap(Map<String, Object?> m) {
final String? pkg = m['packageName']?.toString();
final String? t = m['type']?.toString();
final bool? replacing =
m['isReplacing'] != null ? bool.tryParse(m['isReplacing']!.toString()) : null;
final bool? replacing = m['isReplacing'] != null
? bool.tryParse(m['isReplacing']!.toString())
: null;

return AppChangeEvent(
packageName: pkg,
Expand All @@ -53,15 +50,15 @@ class AppChangeEvent {
///
/// Useful for serialization to platform channels or other data formats.
Map<String, Object?> toMap() => {
'packageName': packageName,
'type': type?.name,
'isReplacing': isReplacing,
};
'packageName': packageName,
'type': type?.name,
'isReplacing': isReplacing,
};

static AppChangeType? _parseType(String raw) => switch (raw) {
'installed' => AppChangeType.installed,
'removed' => AppChangeType.removed,
'updated' => AppChangeType.updated,
_ => null,
};
'installed' => AppChangeType.installed,
'removed' => AppChangeType.removed,
'updated' => AppChangeType.updated,
_ => null,
};
}
160 changes: 141 additions & 19 deletions lib/flutter_device_apps_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,31 @@ class AppInfo {
/// The map typically comes from platform-specific implementations.
/// Handles type conversion and null safety for various data types.
factory AppInfo.fromMap(Map<String, Object?> m) {
final int? firstInstallTime =
m['firstInstallTime'] != null ? int.tryParse(m['firstInstallTime']!.toString()) : null;
final DateTime? firstInstallTimeDate =
firstInstallTime != null ? DateTime.fromMillisecondsSinceEpoch(firstInstallTime) : null;

final int? lastUpdateTime =
m['lastUpdateTime'] != null ? int.tryParse(m['lastUpdateTime']!.toString()) : null;
final DateTime? lastUpdateTimeDate =
lastUpdateTime != null ? DateTime.fromMillisecondsSinceEpoch(lastUpdateTime) : null;
final int? firstInstallTime = m['firstInstallTime'] != null
? int.tryParse(m['firstInstallTime']!.toString())
: null;
final DateTime? firstInstallTimeDate = firstInstallTime != null
? DateTime.fromMillisecondsSinceEpoch(firstInstallTime)
: null;

final int? lastUpdateTime = m['lastUpdateTime'] != null
? int.tryParse(m['lastUpdateTime']!.toString())
: null;
final DateTime? lastUpdateTimeDate = lastUpdateTime != null
? DateTime.fromMillisecondsSinceEpoch(lastUpdateTime)
: null;

final int? category = m['category'] != null ? int.tryParse(m['category']!.toString()) : null;
final int? targetSdkVersion =
m['targetSdkVersion'] != null ? int.tryParse(m['targetSdkVersion']!.toString()) : null;
final int? minSdkVersion =
m['minSdkVersion'] != null ? int.tryParse(m['minSdkVersion']!.toString()) : null;
final int? targetSdkVersion = m['targetSdkVersion'] != null
? int.tryParse(m['targetSdkVersion']!.toString())
: null;
final int? minSdkVersion = m['minSdkVersion'] != null
? int.tryParse(m['minSdkVersion']!.toString())
: null;
final bool? enabled = m['enabled'] != null ? bool.tryParse(m['enabled']!.toString()) : null;
final int? installLocation =
m['installLocation'] != null ? int.tryParse(m['installLocation']!.toString()) : null;
final int? installLocation = m['installLocation'] != null
? int.tryParse(m['installLocation']!.toString())
: null;

return AppInfo(
packageName: m['packageName']?.toString(),
Expand All @@ -72,8 +79,9 @@ class AppInfo {
firstInstallTime: firstInstallTimeDate,
lastUpdateTime: lastUpdateTimeDate,
isSystem: m['isSystem'] != null ? bool.tryParse(m['isSystem']!.toString()) : null,
iconBytes:
m['iconBytes'] is List<int> ? Uint8List.fromList(m['iconBytes']! as List<int>) : null,
iconBytes: m['iconBytes'] is List<int>
? Uint8List.fromList(m['iconBytes']! as List<int>)
: null,
category: category,
targetSdkVersion: targetSdkVersion,
minSdkVersion: minSdkVersion,
Expand Down Expand Up @@ -145,6 +153,50 @@ class AppInfo {
final int? installLocation;
}

/// Information about how an app was installed.
class AppInstallSourceInfo {
/// Creates installation source information with optional platform metadata.
const AppInstallSourceInfo({
this.installingPackageName,
this.initiatingPackageName,
this.originatingPackageName,
this.packageSource,
this.updateOwnerPackageName,
});

/// Creates installation source information from a platform map.
factory AppInstallSourceInfo.fromMap(Map<String, Object?> m) => AppInstallSourceInfo(
installingPackageName: m['installingPackageName']?.toString(),
initiatingPackageName: m['initiatingPackageName']?.toString(),
originatingPackageName: m['originatingPackageName']?.toString(),
packageSource: m['packageSource'] != null ? int.tryParse(m['packageSource']!.toString()) : null,
updateOwnerPackageName: m['updateOwnerPackageName']?.toString(),
);

/// The installer of record, or null when unavailable.
///
/// This value can be changed after installation. Null does not establish
/// whether an app was sideloaded.
final String? installingPackageName;

/// The package that requested installation (Android API 30+).
final String? initiatingPackageName;

/// The package on whose behalf installation was requested (Android API 30+).
///
/// Supplied by the installer and not verified by Android. Access is restricted
/// by Android permissions, so this value is usually null for ordinary apps.
final String? originatingPackageName;

/// Raw Android PackageInstaller.PACKAGE_SOURCE_* value (API 33+).
///
/// Null on older Android versions. Zero means the source is unspecified.
final int? packageSource;

/// The package owning updates (Android API 34+), or null when unavailable.
final String? updateOwnerPackageName;
}

/// Base class every platform implementation must extend.
abstract class FlutterDeviceAppsPlatform extends PlatformInterface {
/// Creates a [FlutterDeviceAppsPlatform] with the provided [token].
Expand All @@ -168,15 +220,50 @@ abstract class FlutterDeviceAppsPlatform extends PlatformInterface {
}

/// Lists installed apps.
///
/// [packageNamePrefix] filters package names with a case-sensitive prefix
/// before loading app metadata and icons. Null or empty disables this filter.
Future<List<AppInfo>> listApps({
bool includeSystem = false,
bool onlyLaunchable = true,
bool includeIcons = false,
String? packageNamePrefix,
});

/// Gets details for a single app.
Future<AppInfo?> getApp(String packageName, {bool includeIcon = false});

/// Gets the app icon as PNG bytes without loading the full app metadata.
///
/// Returns null when the package is missing, not visible, or its icon resources
/// cannot be loaded. Returns Android's default icon if no icon is defined.
Future<Uint8List?> getAppIcon(String packageName);

/// Whether [packageName] is installed and visible to the calling app.
///
/// Includes disabled apps and apps without a launcher entry. Returns false
/// when the package is missing or hidden by Android package visibility rules.
Future<bool> isAppInstalled(String packageName);

/// Whether [packageName] is a system app, using the same flag as [AppInfo.isSystem].
///
/// Returns null when the package is missing or hidden by Android package
/// visibility rules. Includes disabled apps and apps without a launcher entry.
Future<bool?> isSystemApp(String packageName);

/// Whether [packageName] is enabled, using the same value as [AppInfo.enabled].
///
/// Returns null when the package is missing or hidden by Android package
/// visibility rules. An enabled app may still have no launchable activity.
Future<bool?> isAppEnabled(String packageName);

/// Whether Android provides a launch intent for [packageName], as in [openApp].
///
/// Does not open the app. Returns false when the package is missing, not
/// visible, or has no suitable entry activity. True does not guarantee that
/// a subsequent launch will succeed.
Future<bool> isAppLaunchable(String packageName);

/// Gets the requested permissions for a specific app.
///
/// Implementations should return the Android PackageInfo.requestedPermissions
Expand Down Expand Up @@ -207,10 +294,19 @@ abstract class FlutterDeviceAppsPlatform extends PlatformInterface {
/// Returns true if the app was successfully uninstalled, false otherwise.
Future<bool> uninstallApp(String packageName);

/// Gets installation source information without loading full app metadata.
///
/// Returns null when the package is missing or not visible. On Android before
/// API 30, only installingPackageName is available. A returned model can have
/// null fields when Android does not provide the corresponding information.
Future<AppInstallSourceInfo?> getInstallSourceInfo(String packageName);

/// Gets the installer store for the specified package name.
///
/// Platform implementations should return the installer store for the given package.
/// Returns the installer store name or null if not available.
// Newly deprecated; retain the method for backwards compatibility.
@Deprecated('Use getInstallSourceInfo() and its installingPackageName instead.')
Future<String?> getInstallerStore(String packageName);
}

Expand All @@ -223,13 +319,33 @@ class _UnimplementedPlatform extends FlutterDeviceAppsPlatform {
bool includeSystem = false,
bool onlyLaunchable = true,
bool includeIcons = false,
}) =>
Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));
String? packageNamePrefix,
}) => Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));

@override
Future<AppInfo?> getApp(String packageName, {bool includeIcon = false}) =>
Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));

@override
Future<Uint8List?> getAppIcon(String packageName) =>
Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));

@override
Future<bool> isAppInstalled(String packageName) =>
Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));

@override
Future<bool?> isSystemApp(String packageName) =>
Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));

@override
Future<bool?> isAppEnabled(String packageName) =>
Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));

@override
Future<bool> isAppLaunchable(String packageName) =>
Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));

@override
Future<List<String>?> getRequestedPermissions(String packageName) =>
Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));
Expand All @@ -251,6 +367,12 @@ class _UnimplementedPlatform extends FlutterDeviceAppsPlatform {
Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));

@override
Future<AppInstallSourceInfo?> getInstallSourceInfo(String packageName) =>
Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));

@override
// Newly deprecated; retain the method for backwards compatibility.
@Deprecated('Use getInstallSourceInfo() and its installingPackageName instead.')
Future<String?> getInstallerStore(String packageName) =>
Future.error(UnsupportedError('FlutterDeviceAppsPlatform not implemented'));
}
Loading