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

Commit 22cd72d8 authored by Hani Kazmi's avatar Hani Kazmi
Browse files

[AAPM} Catch exceptions thrown by AdvancedProtectionHooks.

This is to prevent a single hook from crashing the entire service.

Bug: 352420507  
Change-Id: I591688c6bb22f6a738b5219830037ab8bf941266
Test: AdvancedProtectionManagerTest
Flag: android.security.aapm_api
parent 3802103d
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -80,13 +80,25 @@ public class AdvancedProtectionService extends IAdvancedProtectionService.Stub

    private void initFeatures(boolean enabled) {
        if (android.security.Flags.aapmFeatureDisableInstallUnknownSources()) {
          try {
            mHooks.add(new DisallowInstallUnknownSourcesAdvancedProtectionHook(mContext, enabled));
          } catch (Exception e) {
            Slog.e(TAG, "Failed to initialize DisallowInstallUnknownSources", e);
          }
        }
        if (android.security.Flags.aapmFeatureMemoryTaggingExtension()) {
          try {
            mHooks.add(new MemoryTaggingExtensionHook(mContext, enabled));
          } catch (Exception e) {
            Slog.e(TAG, "Failed to initialize MemoryTaggingExtension", e);
          }
        }
        if (android.security.Flags.aapmFeatureDisableCellular2g()) {
          try {
            mHooks.add(new DisallowCellular2GAdvancedProtectionHook(mContext, enabled));
          } catch (Exception e) {
            Slog.e(TAG, "Failed to initialize DisallowCellular2g", e);
          }
        }
    }

@@ -278,9 +290,14 @@ public class AdvancedProtectionService extends IAdvancedProtectionService.Stub

            for (int i = 0; i < mHooks.size(); i++) {
                AdvancedProtectionHook feature = mHooks.get(i);
                try {
                    if (feature.isAvailable()) {
                        feature.onAdvancedProtectionChanged(enabled);
                    }
                } catch (Exception e) {
                    Slog.e(TAG, "Failed to call hook for feature "
                            + feature.getFeature().getId(), e);
                }
            }
            synchronized (mCallbacks) {
                for (int i = 0; i < mCallbacks.size(); i++) {