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

Commit 259015ac authored by Matías Hernández's avatar Matías Hernández Committed by Android (Google) Code Review
Browse files

Merge "Disallow invalid CPS/ConfigurationActivity when creating or udpating...

Merge "Disallow invalid CPS/ConfigurationActivity when creating or udpating AutomaticZenRule" into main
parents b56f987a b7a49adb
Loading
Loading
Loading
Loading
+27 −3
Original line number Diff line number Diff line
@@ -266,6 +266,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.LauncherApps;
import android.content.pm.ModuleInfo;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManagerInternal;
@@ -6451,8 +6452,8 @@ public class NotificationManagerService extends SystemService {
            enforceUserOriginOnlyFromSystem(fromUser, "addAutomaticZenRule");
            UserHandle zenUser = getCallingZenUser();
            // If the calling app is the system (from any user), take the package name from the
            // rule's owner rather than from the caller's package.
            // Allow the system (and crucially, Settings) to choose an arbitrary package as owner;
            // otherwise forcibly use the calling package.
            String rulePkg = pkg;
            if (isCallingAppIdSystem()) {
                if (automaticZenRule.getOwner() != null) {
@@ -6500,12 +6501,35 @@ public class NotificationManagerService extends SystemService {
            if (!isImplicitRuleUpdateFromSystem
                    && rule.getOwner() == null
                    && rule.getConfigurationActivity() == null) {
                throw new NullPointerException(
                throw new IllegalArgumentException(
                        "Rule must have a ConditionProviderService and/or configuration "
                                + "activity");
            }
            Objects.requireNonNull(rule.getConditionId(), "ConditionId is null");
            // If supplied, both CPS and ConfigurationActivity must be accessible to the calling
            // package. Skip check when the caller is the system: for additions we trust ourselves,
            // and for updates we don't want to block updating a rule in Settings even if the owner
            // package has changed its manifest so that some component is gone.
            if (Flags.strictZenRuleComponentValidation() && !isCallerSystemOrSystemUi()) {
                if (rule.getOwner() != null) {
                    PackageItemInfo ownerInfo = mZenModeHelper.getServiceInfo(rule.getOwner());
                    if (ownerInfo == null) {
                        throw new IllegalArgumentException(
                                "Lacking enabled ConditionProviderService " + rule.getOwner());
                    }
                }
                if (rule.getConfigurationActivity() != null) {
                    PackageItemInfo activityInfo = mZenModeHelper.getActivityInfo(
                            rule.getConfigurationActivity());
                    if (activityInfo == null) {
                        throw new IllegalArgumentException(
                                "Lacking enabled ConfigurationActivity "
                                        + rule.getConfigurationActivity());
                    }
                }
            }
            if (isCallerSystemOrSystemUi()) {
                return; // System callers can use any type.
            }
+2 −2
Original line number Diff line number Diff line
@@ -1095,7 +1095,7 @@ public class ZenModeHelper {
        }
    }

    private ServiceInfo getServiceInfo(ComponentName owner) {
    ServiceInfo getServiceInfo(ComponentName owner) {
        Intent queryIntent = new Intent();
        queryIntent.setComponent(owner);
        List<ResolveInfo> installedServices = mPm.queryIntentServicesAsUser(
@@ -1114,7 +1114,7 @@ public class ZenModeHelper {
        return null;
    }

    private ActivityInfo getActivityInfo(ComponentName configActivity) {
    ActivityInfo getActivityInfo(ComponentName configActivity) {
        Intent queryIntent = new Intent();
        queryIntent.setComponent(configActivity);
        List<ResolveInfo> installedComponents = mPm.queryIntentActivitiesAsUser(
+7 −0
Original line number Diff line number Diff line
@@ -170,6 +170,13 @@ flag {
  }
}

flag {
  name: "strict_zen_rule_component_validation"
  namespace: "systemui"
  description: "Properly validate both CPS and configActivity in both add and update paths"
  bug: "420605963"
}

flag {
  name: "managed_services_concurrent_multiuser"
  namespace: "systemui"
+1 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ filegroup {
    name: "shared-srcs",
    srcs: [
        "src/android/app/ExampleActivity.java",
        "src/android/app/ExampleConditionProviderService.java",
        "src/android/app/NotificationSystemUtil.java",
        "src/com/android/frameworks/tests/uiservices/DummyProvider.java",
        "src/com/android/internal/logging/InstanceIdSequenceFake.java",
+10 −1
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@
    <uses-permission android:name="android.permission.MANAGE_USERS" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
    <uses-permission android:name="android.permission.ACCESS_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.STATUS_BAR_SERVICE" />
    <uses-permission android:name="android.permission.ACCESS_VOICE_INTERACTION_SERVICE" />
    <uses-permission android:name="android.permission.DEVICE_POWER" />
    <uses-permission android:name="android.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY" />
@@ -47,6 +46,16 @@

        <activity android:name="android.app.ExampleActivity" />

        <service
            android:name="android.app.ExampleConditionProviderService"
            android:exported="true"
            android:label="Example Condition Provider"
            android:permission="android.permission.BIND_CONDITION_PROVIDER_SERVICE">
            <intent-filter>
                <action android:name="android.service.notification.ConditionProviderService" />
            </intent-filter>
        </service>

    </application>

    <instrumentation
Loading