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

Commit 46656fa2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Hidden API blacklisting killswitch."

parents f50d9fbd fe1eebec
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");