microsoftconnect / intune-app-wrapping-tool-android

Use the Intune App Wrapping Tool for Android to enable Android apps to be managed by Microsoft Intune
28 stars 11 forks source link

Wrapping related to PackageManager does not work properly. #100

Open JosephNK opened 2 months ago

JosephNK commented 2 months ago

Questions to Ask Before Submission

  1. Does you app launch successfully without wrapping? yes
  2. Have you reviewed the prerequisites for App Wrapping? yes
  3. Does your issue have a solution in the Troubleshooting Guide? yes
  4. Have you checked the Microsoft Intune App SDK for Android repository for similar issues? yes
  5. Are you using the latest version of the App Wrapper? yes

Describe the bug: We are using flutter_inappwebview library. What we've seen here is that before wrapping, in debug and release, function values usually return a non-null value, which works fine. However, after wrapping it returns Null, which doesn't work properly.

To Reproduce Steps to reproduce the behavior:

Expected behavior: The function must return a non-Null value.

Screenshots and logs:

https://github.com/pichillilorenzo/flutter_inappwebview/blob/4c58653113573558ea5be880aca931e85b23da7e/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/chrome_custom_tabs/CustomTabsHelper.java#L50

...
... ... 

public static String getPackageNameToUse(Context context) {
    if (sPackageNameToUse != null) return sPackageNameToUse;

    PackageManager pm = context.getPackageManager();
    // Get default VIEW intent handler.
    Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    activityIntent.addCategory(Intent.CATEGORY_BROWSABLE);
    ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
    String defaultViewHandlerPackageName = null;
    if (defaultViewHandlerInfo != null) {
        defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
    }

    // Get all apps that can handle VIEW intents.
    int flags = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        flags |= PackageManager.MATCH_ALL;
    }
    List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, flags);
    List<String> packagesSupportingCustomTabs = new ArrayList<>();
    for (ResolveInfo info : resolvedActivityList) {
        Intent serviceIntent = new Intent();
        serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
        serviceIntent.setPackage(info.activityInfo.packageName);
        if (pm.resolveService(serviceIntent, 0) != null) {
            packagesSupportingCustomTabs.add(info.activityInfo.packageName);
        }
    }

    // Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
    // and service calls.
    if (packagesSupportingCustomTabs.isEmpty()) {
        sPackageNameToUse = null;
    } else if (packagesSupportingCustomTabs.size() == 1) {
        sPackageNameToUse = packagesSupportingCustomTabs.get(0);
    } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
            && !hasSpecializedHandlerIntents(context, activityIntent)
            && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
        sPackageNameToUse = defaultViewHandlerPackageName;
    } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
        sPackageNameToUse = STABLE_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
        sPackageNameToUse = BETA_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
        sPackageNameToUse = DEV_PACKAGE;
    } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
        sPackageNameToUse = LOCAL_PACKAGE;
    }
    return sPackageNameToUse;
}

... ...
...

Smartphone (please complete the following information):

Intune app wrapping tool (please complete the following information):

Additional context: No

mukeshk-ms commented 2 months ago

I am looking into this

JosephNK commented 1 week ago

I added an library link, but the issue is not a library issue. After creating a new Android project and writing only the code above, the return value is equally incorrect when wrapping.