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

Commit 7d9ad18c authored by Joanne Chung's avatar Joanne Chung
Browse files

Handle permission grant for TextClassifierService.

The trust TextClassifierServices are defined in config.xml, and the first
one package is the default system TextClassifier service. Grant permissions
to default TextClassifier Service.

Bug: 141111813
Bug: 146391636
Test: Manual. Use dumpsys pm to check package runtime permissions.
Test: atest GtsPermissionTestCases:com.google.android.permission.gts.\
DefaultPermissionGrantPolicyTest#testDefaultGrantsWithRemoteExceptions

Change-Id: Iff2dec1e44515d97cc38bb336d19d5df29f1c097
parent 97a17d56
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -3490,13 +3490,14 @@
         set to empty string), a default textclassifier will be loaded in the calling app's process.
         See android.view.textclassifier.TextClassificationManager.
    -->
    <!-- TODO(b/144896755) remove the config -->
    <string name="config_defaultTextClassifierPackage" translatable="false"></string>

    <!-- A list of the default system textclassifier service package name. Only one of the packages
         will be activated and the fist package is the default system textclassifier service. OS
         only tries to bind the first trusted service and the others can be selected via device
         config. These services must be trusted, as they can be activated without explicit consent
         of the user. Example: "com.android.textclassifier"
    <!-- A list of supported system textClassifier service package names. Only one of the packages
         will be activated. The first package in the list is the default system textClassifier
         service. OS only tries to bind and grant permissions to the first trusted service and the
         others can be selected via device config. These services must be trusted, as they can be
         activated without explicit consent of the user. Example: "com.android.textclassifier"
    -->
    <string-array name="config_defaultTextClassifierPackages" translatable="false">
        <item>android.ext.services</item>
+7 −5
Original line number Diff line number Diff line
@@ -726,10 +726,12 @@ public final class DefaultPermissionGrantPolicy {
                userId, STORAGE_PERMISSIONS);

        // TextClassifier Service
        String textClassifierPackageName =
                mContext.getPackageManager().getSystemTextClassifierPackageName();
        if (!TextUtils.isEmpty(textClassifierPackageName)) {
            grantPermissionsToSystemPackage(textClassifierPackageName, userId,
        final String[] packages = mContext.getPackageManager().getSystemTextClassifierPackages();
        if (packages.length > 0) {
            // We have a list of supported system TextClassifier package names, the first one
            // package is the default system TextClassifier service. Grant permissions to default
            // TextClassifier Service.
            grantPermissionsToSystemPackage(packages[0], userId,
                    COARSE_BACKGROUND_LOCATION_PERMISSIONS, CONTACTS_PERMISSIONS);
        }

@@ -998,7 +1000,7 @@ public final class DefaultPermissionGrantPolicy {
    private void revokeRuntimePermissions(String packageName, Set<String> permissions,
            boolean systemFixed, int userId) {
        PackageInfo pkg = getSystemPackageInfo(packageName);
        if (ArrayUtils.isEmpty(pkg.requestedPermissions)) {
        if (pkg == null || ArrayUtils.isEmpty(pkg.requestedPermissions)) {
            return;
        }
        Set<String> revokablePermissions = new ArraySet<>(Arrays.asList(pkg.requestedPermissions));