Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eeb2c7e7 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Work on issue #17628623: Need to update default preferred activities for YouTube

Improve the warning logs when setting up preferred activities
to help identify when there are issues and what they are.  Also
improve the algorithm a little to still apply permissions when
resetting them and there are additional third party apps, as long
as the additional app is something like another browser and the
preferred activity being set is more specific (has a better match).

And add an example of using manifest-based preferred activities
in to ActivityTest -- and yes it DOES work! :p

Change-Id: I1ff39e03a5df6526206e0c3882085396b355d814
parent 4c45b649
Loading
Loading
Loading
Loading
+40 −20
Original line number Original line Diff line number Diff line
@@ -2285,7 +2285,7 @@ final class Settings {
                Intent finalIntent = new Intent(intent);
                Intent finalIntent = new Intent(intent);
                finalIntent.setData(builder.build());
                finalIntent.setData(builder.build());
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                        scheme, ssp, null, null, null, userId);
                        scheme, ssp, null, null, userId);
                doScheme = false;
                doScheme = false;
            }
            }
            for (int iauth=0; iauth<tmpPa.countDataAuthorities(); iauth++) {
            for (int iauth=0; iauth<tmpPa.countDataAuthorities(); iauth++) {
@@ -2302,7 +2302,7 @@ final class Settings {
                    Intent finalIntent = new Intent(intent);
                    Intent finalIntent = new Intent(intent);
                    finalIntent.setData(builder.build());
                    finalIntent.setData(builder.build());
                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                            scheme, null, auth, path, null, userId);
                            scheme, null, auth, path, userId);
                    doAuth = doScheme = false;
                    doAuth = doScheme = false;
                }
                }
                if (doAuth) {
                if (doAuth) {
@@ -2314,7 +2314,7 @@ final class Settings {
                    Intent finalIntent = new Intent(intent);
                    Intent finalIntent = new Intent(intent);
                    finalIntent.setData(builder.build());
                    finalIntent.setData(builder.build());
                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                            scheme, null, auth, null, null, userId);
                            scheme, null, auth, null, userId);
                    doScheme = false;
                    doScheme = false;
                }
                }
            }
            }
@@ -2324,7 +2324,7 @@ final class Settings {
                Intent finalIntent = new Intent(intent);
                Intent finalIntent = new Intent(intent);
                finalIntent.setData(builder.build());
                finalIntent.setData(builder.build());
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                        scheme, null, null, null, null, userId);
                        scheme, null, null, null, userId);
            }
            }
            doNonData = false;
            doNonData = false;
        }
        }
@@ -2340,28 +2340,27 @@ final class Settings {
                        builder.scheme(scheme);
                        builder.scheme(scheme);
                        finalIntent.setDataAndType(builder.build(), mimeType);
                        finalIntent.setDataAndType(builder.build(), mimeType);
                        applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                        applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                                scheme, null, null, null, mimeType, userId);
                                scheme, null, null, null, userId);
                    }
                    }
                }
                }
            } else {
            } else {
                Intent finalIntent = new Intent(intent);
                Intent finalIntent = new Intent(intent);
                finalIntent.setType(mimeType);
                finalIntent.setType(mimeType);
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
                        null, null, null, null, mimeType, userId);
                        null, null, null, null, userId);
            }
            }
            doNonData = false;
            doNonData = false;
        }
        }


        if (doNonData) {
        if (doNonData) {
            applyDefaultPreferredActivityLPw(service, intent, flags, cn,
            applyDefaultPreferredActivityLPw(service, intent, flags, cn,
                    null, null, null, null, null, userId);
                    null, null, null, null, userId);
        }
        }
    }
    }


    private void applyDefaultPreferredActivityLPw(PackageManagerService service,
    private void applyDefaultPreferredActivityLPw(PackageManagerService service,
            Intent intent, int flags, ComponentName cn, String scheme, PatternMatcher ssp,
            Intent intent, int flags, ComponentName cn, String scheme, PatternMatcher ssp,
            IntentFilter.AuthorityEntry auth, PatternMatcher path, String mimeType,
            IntentFilter.AuthorityEntry auth, PatternMatcher path, int userId) {
            int userId) {
        List<ResolveInfo> ri = service.mActivities.queryIntent(intent,
        List<ResolveInfo> ri = service.mActivities.queryIntent(intent,
                intent.getType(), flags, 0);
                intent.getType(), flags, 0);
        if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Queried " + intent
        if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Queried " + intent
@@ -2369,19 +2368,24 @@ final class Settings {
        int match = 0;
        int match = 0;
        if (ri != null && ri.size() > 1) {
        if (ri != null && ri.size() > 1) {
            boolean haveAct = false;
            boolean haveAct = false;
            boolean haveNonSys = false;
            ComponentName haveNonSys = null;
            ComponentName[] set = new ComponentName[ri.size()];
            ComponentName[] set = new ComponentName[ri.size()];
            for (int i=0; i<ri.size(); i++) {
            for (int i=0; i<ri.size(); i++) {
                ActivityInfo ai = ri.get(i).activityInfo;
                ActivityInfo ai = ri.get(i).activityInfo;
                set[i] = new ComponentName(ai.packageName, ai.name);
                set[i] = new ComponentName(ai.packageName, ai.name);
                if ((ai.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
                if ((ai.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
                    if (ri.get(i).match >= match) {
                        // If any of the matches are not system apps, then
                        // If any of the matches are not system apps, then
                        // there is a third party app that is now an option...
                        // there is a third party app that is now an option...
                        // so don't set a default since we don't want to hide it.
                        // so don't set a default since we don't want to hide it.
                        // Only do this if the match of this one is at least as good
                        // as what we have found as the built-in app; if it isn't
                        // as good, the user won't want it anyway, right?
                        if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
                        if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
                                + ai.packageName + "/" + ai.name + ": non-system!");
                                + ai.packageName + "/" + ai.name + ": non-system!");
                    haveNonSys = true;
                        haveNonSys = set[i];
                        break;
                        break;
                    }
                } else if (cn.getPackageName().equals(ai.packageName)
                } else if (cn.getPackageName().equals(ai.packageName)
                        && cn.getClassName().equals(ai.name)) {
                        && cn.getClassName().equals(ai.name)) {
                    if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
                    if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
@@ -2393,7 +2397,7 @@ final class Settings {
                            + ai.packageName + "/" + ai.name + ": skipped");
                            + ai.packageName + "/" + ai.name + ": skipped");
                }
                }
            }
            }
            if (haveAct && !haveNonSys) {
            if (haveAct && haveNonSys == null) {
                IntentFilter filter = new IntentFilter();
                IntentFilter filter = new IntentFilter();
                if (intent.getAction() != null) {
                if (intent.getAction() != null) {
                    filter.addAction(intent.getAction());
                    filter.addAction(intent.getAction());
@@ -2427,9 +2431,25 @@ final class Settings {
                }
                }
                PreferredActivity pa = new PreferredActivity(filter, match, set, cn, true);
                PreferredActivity pa = new PreferredActivity(filter, match, set, cn, true);
                editPreferredActivitiesLPw(userId).addFilter(pa);
                editPreferredActivitiesLPw(userId).addFilter(pa);
            } else if (!haveNonSys) {
            } else if (haveNonSys == null) {
                Slog.w(TAG, "No component found for default preferred activity " + cn);
                StringBuilder sb = new StringBuilder();
                sb.append("No component ");
                sb.append(cn.flattenToShortString());
                sb.append(" found setting preferred ");
                sb.append(intent);
                sb.append("; possible matches are ");
                for (int i=0; i<set.length; i++) {
                    if (i > 0) sb.append(", ");
                    sb.append(set[i].flattenToShortString());
                }
                Slog.w(TAG, sb.toString());
            } else {
                Slog.i(TAG, "Not setting preferred " + intent + "; found third party match "
                        + haveNonSys.flattenToShortString());
            }
            }
        } else {
            Slog.w(TAG, "No potential matches found for " + intent + " while setting preferred "
                    + cn.flattenToShortString());
        }
        }
    }
    }


+14 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,20 @@
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" android:host="www.angryredplanet.com"
                        android:pathPrefix="" />
            </intent-filter>
            <preferred>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" android:host="www.angryredplanet.com"
                        android:pathPrefix="" />
            </preferred>
        </activity>
        </activity>
        <activity android:name="SpamActivity" android:label="Spam!"
        <activity android:name="SpamActivity" android:label="Spam!"
                android:documentLaunchMode="always">
                android:documentLaunchMode="always">