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

Commit fe1eebec authored by Mathew Inwood's avatar Mathew Inwood
Browse files

Hidden API blacklisting killswitch.

Just support "*" for now, meaning disable all API blacklisting for all
apps.

Test: Manually verified by:
- installing test app that accesses hidden API
- manually blacklist the API
- $ adb shell settings put global hidden_api_blacklist_exemptions \\*

This is a cherry pick of change I9a41a104742c9aaaf3a753e7b0f3a1106e37d4d3
from internal master.

Merged-In: I9a41a104742c9aaaf3a753e7b0f3a1106e37d4d3
Change-Id: Ibb2a1d054c1b099fc6093e37f24b2ed421a2313c
parent f50d9fbd
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -10386,6 +10386,14 @@ public final class Settings {
        public static final String STORAGE_SETTINGS_CLOBBER_THRESHOLD =
                "storage_settings_clobber_threshold";

        /**
         * Exemptions to the hidden API blacklist.
         *
         * @hide
         */
        public static final String HIDDEN_API_BLACKLIST_EXEMPTIONS =
                "hidden_api_blacklist_exemptions";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+1 −0
Original line number Diff line number Diff line
@@ -335,6 +335,7 @@ message GlobalSettingsProto {
    SettingProto uninstalled_instant_app_min_cache_period = 290;
    SettingProto uninstalled_instant_app_max_cache_period = 291;
    SettingProto unused_static_shared_lib_min_cache_period = 292;
    SettingProto hidden_api_blacklist_exemptions = 293;
}

message SecureSettingsProto {
+2 −1
Original line number Diff line number Diff line
@@ -413,7 +413,8 @@ public class SettingsBackupTest {
                    Settings.Global.WTF_IS_FATAL,
                    Settings.Global.ZEN_MODE,
                    Settings.Global.ZEN_MODE_CONFIG_ETAG,
                    Settings.Global.ZEN_MODE_RINGER_LEVEL);
                    Settings.Global.ZEN_MODE_RINGER_LEVEL,
                    Settings.Global.HIDDEN_API_BLACKLIST_EXEMPTIONS);

    private static final Set<String> BACKUP_BLACKLISTED_SECURE_SETTINGS =
             newHashSet(
+3 −0
Original line number Diff line number Diff line
@@ -923,6 +923,9 @@ class SettingsProtoDumpUtil {
        dumpSetting(s, p,
                Settings.Global.CONTACTS_DATABASE_WAL_ENABLED,
                GlobalSettingsProto.CONTACTS_DATABASE_WAL_ENABLED);
        dumpSetting(s, p,
                Settings.Global.HIDDEN_API_BLACKLIST_EXEMPTIONS,
                GlobalSettingsProto.HIDDEN_API_BLACKLIST_EXEMPTIONS);
        dumpSetting(s, p,
                Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION,
                GlobalSettingsProto.MULTI_SIM_VOICE_CALL_SUBSCRIPTION);
+46 −3
Original line number Diff line number Diff line
@@ -1738,6 +1738,9 @@ public class ActivityManagerService extends IActivityManager.Stub
    final ActivityManagerConstants mConstants;
    // Encapsulates the global setting "hidden_api_blacklist_exemptions"
    final HiddenApiBlacklist mHiddenApiBlacklist;
    PackageManagerInternal mPackageManagerInt;
    // VoiceInteraction session ID that changes for each new request except when
@@ -2687,6 +2690,42 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    /**
     * Encapsulates the globla setting "hidden_api_blacklist_exemptions", including tracking the
     * latest value via a content observer.
     */
    static class HiddenApiBlacklist extends ContentObserver {
        private final Context mContext;
        private boolean mBlacklistDisabled;
        public HiddenApiBlacklist(Handler handler, Context context) {
            super(handler);
            mContext = context;
        }
        public void registerObserver() {
            mContext.getContentResolver().registerContentObserver(
                    Settings.Global.getUriFor(Settings.Global.HIDDEN_API_BLACKLIST_EXEMPTIONS),
                    false,
                    this);
            update();
        }
        private void update() {
            mBlacklistDisabled = "*".equals(Settings.Global.getString(mContext.getContentResolver(),
                    Settings.Global.HIDDEN_API_BLACKLIST_EXEMPTIONS));
        }
        boolean isDisabled() {
            return mBlacklistDisabled;
        }
        public void onChange(boolean selfChange) {
            update();
        }
    }
    @VisibleForTesting
    public ActivityManagerService(Injector injector) {
        mInjector = injector;
@@ -2716,6 +2755,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mUiHandler = injector.getUiHandler(null);
        mUserController = null;
        mVrController = null;
        mHiddenApiBlacklist = null;
    }
    // Note: This method is invoked on the main thread but may need to attach various
@@ -2848,6 +2888,8 @@ public class ActivityManagerService extends IActivityManager.Stub
            }
        };
        mHiddenApiBlacklist = new HiddenApiBlacklist(mHandler, mContext);
        Watchdog.getInstance().addMonitor(this);
        Watchdog.getInstance().addThread(mHandler);
    }
@@ -3891,9 +3933,9 @@ public class ActivityManagerService extends IActivityManager.Stub
                runtimeFlags |= Zygote.ONLY_USE_SYSTEM_OAT_FILES;
            }
            if (!app.info.isAllowedToUseHiddenApi()) {
                // This app is not allowed to use undocumented and private APIs.
                // Set up its runtime with the appropriate flag.
            if (!app.info.isAllowedToUseHiddenApi() && !mHiddenApiBlacklist.isDisabled()) {
                // This app is not allowed to use undocumented and private APIs, or blacklisting is
                // enabled. Set up its runtime with the appropriate flag.
                runtimeFlags |= Zygote.ENABLE_HIDDEN_API_CHECKS;
            }
@@ -14165,6 +14207,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                NETWORK_ACCESS_TIMEOUT_MS, NETWORK_ACCESS_TIMEOUT_DEFAULT_MS);
        final boolean supportsLeanbackOnly =
                mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK_ONLY);
        mHiddenApiBlacklist.registerObserver();
        // Transfer any global setting for forcing RTL layout, into a System Property
        SystemProperties.set(DEVELOPMENT_FORCE_RTL, forceRtl ? "1":"0");