Merge "Hidden API blacklisting killswitch."

This commit is contained in:
Treehugger Robot
2018-02-16 11:50:20 +00:00
committed by Gerrit Code Review
5 changed files with 60 additions and 4 deletions

View File

@@ -10386,6 +10386,14 @@ public final class Settings {
public static final String STORAGE_SETTINGS_CLOBBER_THRESHOLD = public static final String STORAGE_SETTINGS_CLOBBER_THRESHOLD =
"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 * Settings to backup. This is here so that it's in the same place as the settings
* keys and easy to update. * keys and easy to update.

View File

@@ -335,6 +335,7 @@ message GlobalSettingsProto {
SettingProto uninstalled_instant_app_min_cache_period = 290; SettingProto uninstalled_instant_app_min_cache_period = 290;
SettingProto uninstalled_instant_app_max_cache_period = 291; SettingProto uninstalled_instant_app_max_cache_period = 291;
SettingProto unused_static_shared_lib_min_cache_period = 292; SettingProto unused_static_shared_lib_min_cache_period = 292;
SettingProto hidden_api_blacklist_exemptions = 293;
} }
message SecureSettingsProto { message SecureSettingsProto {

View File

@@ -413,7 +413,8 @@ public class SettingsBackupTest {
Settings.Global.WTF_IS_FATAL, Settings.Global.WTF_IS_FATAL,
Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE,
Settings.Global.ZEN_MODE_CONFIG_ETAG, 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 = private static final Set<String> BACKUP_BLACKLISTED_SECURE_SETTINGS =
newHashSet( newHashSet(

View File

@@ -923,6 +923,9 @@ class SettingsProtoDumpUtil {
dumpSetting(s, p, dumpSetting(s, p,
Settings.Global.CONTACTS_DATABASE_WAL_ENABLED, Settings.Global.CONTACTS_DATABASE_WAL_ENABLED,
GlobalSettingsProto.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, dumpSetting(s, p,
Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION, Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION,
GlobalSettingsProto.MULTI_SIM_VOICE_CALL_SUBSCRIPTION); GlobalSettingsProto.MULTI_SIM_VOICE_CALL_SUBSCRIPTION);

View File

@@ -1738,6 +1738,9 @@ public class ActivityManagerService extends IActivityManager.Stub
final ActivityManagerConstants mConstants; final ActivityManagerConstants mConstants;
// Encapsulates the global setting "hidden_api_blacklist_exemptions"
final HiddenApiBlacklist mHiddenApiBlacklist;
PackageManagerInternal mPackageManagerInt; PackageManagerInternal mPackageManagerInt;
// VoiceInteraction session ID that changes for each new request except when // 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 @VisibleForTesting
public ActivityManagerService(Injector injector) { public ActivityManagerService(Injector injector) {
mInjector = injector; mInjector = injector;
@@ -2716,6 +2755,7 @@ public class ActivityManagerService extends IActivityManager.Stub
mUiHandler = injector.getUiHandler(null); mUiHandler = injector.getUiHandler(null);
mUserController = null; mUserController = null;
mVrController = null; mVrController = null;
mHiddenApiBlacklist = null;
} }
// Note: This method is invoked on the main thread but may need to attach various // 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().addMonitor(this);
Watchdog.getInstance().addThread(mHandler); Watchdog.getInstance().addThread(mHandler);
} }
@@ -3891,9 +3933,9 @@ public class ActivityManagerService extends IActivityManager.Stub
runtimeFlags |= Zygote.ONLY_USE_SYSTEM_OAT_FILES; runtimeFlags |= Zygote.ONLY_USE_SYSTEM_OAT_FILES;
} }
if (!app.info.isAllowedToUseHiddenApi()) { if (!app.info.isAllowedToUseHiddenApi() && !mHiddenApiBlacklist.isDisabled()) {
// This app is not allowed to use undocumented and private APIs. // This app is not allowed to use undocumented and private APIs, or blacklisting is
// Set up its runtime with the appropriate flag. // enabled. Set up its runtime with the appropriate flag.
runtimeFlags |= Zygote.ENABLE_HIDDEN_API_CHECKS; 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); NETWORK_ACCESS_TIMEOUT_MS, NETWORK_ACCESS_TIMEOUT_DEFAULT_MS);
final boolean supportsLeanbackOnly = final boolean supportsLeanbackOnly =
mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK_ONLY); mContext.getPackageManager().hasSystemFeature(FEATURE_LEANBACK_ONLY);
mHiddenApiBlacklist.registerObserver();
// Transfer any global setting for forcing RTL layout, into a System Property // Transfer any global setting for forcing RTL layout, into a System Property
SystemProperties.set(DEVELOPMENT_FORCE_RTL, forceRtl ? "1":"0"); SystemProperties.set(DEVELOPMENT_FORCE_RTL, forceRtl ? "1":"0");