use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.
the class ApfFilter method installNewProgramLocked.
/**
* Generate and install a new filter program.
*/
@GuardedBy("this")
@VisibleForTesting
void installNewProgramLocked() {
purgeExpiredRasLocked();
ArrayList<Ra> rasToFilter = new ArrayList<>();
final byte[] program;
long programMinLifetime = Long.MAX_VALUE;
try {
// Step 1: Determine how many RA filters we can fit in the program.
ApfGenerator gen = beginProgramLocked();
for (Ra ra : mRas) {
ra.generateFilterLocked(gen);
// Stop if we get too big.
if (gen.programLengthOverEstimate() > mApfCapabilities.maximumApfProgramSize)
break;
rasToFilter.add(ra);
}
// Step 2: Actually generate the program
gen = beginProgramLocked();
for (Ra ra : rasToFilter) {
programMinLifetime = Math.min(programMinLifetime, ra.generateFilterLocked(gen));
}
// Execution will reach the end of the program if no filters match, which will pass the
// packet to the AP.
program = gen.generate();
} catch (IllegalInstructionException | IllegalStateException e) {
Log.e(TAG, "Failed to generate APF program.", e);
return;
}
mLastTimeInstalledProgram = currentTimeSeconds();
mLastInstalledProgramMinLifetime = programMinLifetime;
mLastInstalledProgram = program;
mNumProgramUpdates++;
if (VDBG) {
hexDump("Installing filter: ", program, program.length);
}
mIpManagerCallback.installPacketFilter(program);
int flags = ApfProgramEvent.flagsFor(mIPv4Address != null, mMulticastFilter);
mMetricsLog.log(new ApfProgramEvent(programMinLifetime, rasToFilter.size(), mRas.size(), program.length, flags));
}
use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.
the class Tethering method isTetherProvisioningRequired.
/**
* Check if the device requires a provisioning check in order to enable tethering.
*
* @return a boolean - {@code true} indicating tether provisioning is required by the carrier.
*/
@VisibleForTesting
protected boolean isTetherProvisioningRequired() {
String[] provisionApp = mContext.getResources().getStringArray(com.android.internal.R.array.config_mobile_hotspot_provision_app);
if (mSystemProperties.getBoolean(DISABLE_PROVISIONING_SYSPROP_KEY, false) || provisionApp == null) {
return false;
}
// Check carrier config for entitlement checks
final CarrierConfigManager configManager = (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
if (configManager != null && configManager.getConfig() != null) {
// we do have a CarrierConfigManager and it has a config.
boolean isEntitlementCheckRequired = configManager.getConfig().getBoolean(CarrierConfigManager.KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL);
if (!isEntitlementCheckRequired) {
return false;
}
}
return (provisionApp.length == 2);
}
use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.
the class IpConfigStore method writeConfig.
@VisibleForTesting
public static boolean writeConfig(DataOutputStream out, int configKey, IpConfiguration config) throws IOException {
boolean written = false;
try {
switch(config.ipAssignment) {
case STATIC:
out.writeUTF(IP_ASSIGNMENT_KEY);
out.writeUTF(config.ipAssignment.toString());
StaticIpConfiguration staticIpConfiguration = config.staticIpConfiguration;
if (staticIpConfiguration != null) {
if (staticIpConfiguration.ipAddress != null) {
LinkAddress ipAddress = staticIpConfiguration.ipAddress;
out.writeUTF(LINK_ADDRESS_KEY);
out.writeUTF(ipAddress.getAddress().getHostAddress());
out.writeInt(ipAddress.getPrefixLength());
}
if (staticIpConfiguration.gateway != null) {
out.writeUTF(GATEWAY_KEY);
// Default route.
out.writeInt(0);
// Have a gateway.
out.writeInt(1);
out.writeUTF(staticIpConfiguration.gateway.getHostAddress());
}
for (InetAddress inetAddr : staticIpConfiguration.dnsServers) {
out.writeUTF(DNS_KEY);
out.writeUTF(inetAddr.getHostAddress());
}
}
written = true;
break;
case DHCP:
out.writeUTF(IP_ASSIGNMENT_KEY);
out.writeUTF(config.ipAssignment.toString());
written = true;
break;
case UNASSIGNED:
/* Ignore */
break;
default:
loge("Ignore invalid ip assignment while writing");
break;
}
switch(config.proxySettings) {
case STATIC:
ProxyInfo proxyProperties = config.httpProxy;
String exclusionList = proxyProperties.getExclusionListAsString();
out.writeUTF(PROXY_SETTINGS_KEY);
out.writeUTF(config.proxySettings.toString());
out.writeUTF(PROXY_HOST_KEY);
out.writeUTF(proxyProperties.getHost());
out.writeUTF(PROXY_PORT_KEY);
out.writeInt(proxyProperties.getPort());
if (exclusionList != null) {
out.writeUTF(EXCLUSION_LIST_KEY);
out.writeUTF(exclusionList);
}
written = true;
break;
case PAC:
ProxyInfo proxyPacProperties = config.httpProxy;
out.writeUTF(PROXY_SETTINGS_KEY);
out.writeUTF(config.proxySettings.toString());
out.writeUTF(PROXY_PAC_FILE);
out.writeUTF(proxyPacProperties.getPacFileUrl().toString());
written = true;
break;
case NONE:
out.writeUTF(PROXY_SETTINGS_KEY);
out.writeUTF(config.proxySettings.toString());
written = true;
break;
case UNASSIGNED:
/* Ignore */
break;
default:
loge("Ignore invalid proxy settings while writing");
break;
}
if (written) {
out.writeUTF(ID_KEY);
out.writeInt(configKey);
}
} catch (NullPointerException e) {
loge("Failure in writing " + config + e);
}
out.writeUTF(EOS);
return written;
}
use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.
the class ShortcutService method injectIsActivityEnabledAndExported.
/**
* Return whether an activity is enabled and exported.
*/
@VisibleForTesting
boolean injectIsActivityEnabledAndExported(@NonNull ComponentName activity, @UserIdInt int userId) {
final long start = injectElapsedRealtime();
final long token = injectClearCallingIdentity();
try {
return queryActivities(new Intent(), activity.getPackageName(), activity, userId).size() > 0;
} finally {
injectRestoreCallingIdentity(token);
logDurationStat(Stats.IS_ACTIVITY_ENABLED, start);
}
}
use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.
the class ShortcutService method checkPackageChanges.
/**
* Called when a user is unlocked.
* - Check all known packages still exist, and otherwise perform cleanup.
* - If a package still exists, check the version code. If it's been updated, may need to
* update timestamps of its shortcuts.
*/
@VisibleForTesting
void checkPackageChanges(@UserIdInt int ownerUserId) {
if (DEBUG) {
Slog.d(TAG, "checkPackageChanges() ownerUserId=" + ownerUserId);
}
if (injectIsSafeModeEnabled()) {
Slog.i(TAG, "Safe mode, skipping checkPackageChanges()");
return;
}
final long start = injectElapsedRealtime();
try {
final ArrayList<PackageWithUser> gonePackages = new ArrayList<>();
synchronized (mLock) {
final ShortcutUser user = getUserShortcutsLocked(ownerUserId);
// Find packages that have been uninstalled.
user.forAllPackageItems(spi -> {
if (spi.getPackageInfo().isShadow()) {
return;
}
if (!isPackageInstalled(spi.getPackageName(), spi.getPackageUserId())) {
if (DEBUG) {
Slog.d(TAG, "Uninstalled: " + spi.getPackageName() + " user " + spi.getPackageUserId());
}
gonePackages.add(PackageWithUser.of(spi));
}
});
if (gonePackages.size() > 0) {
for (int i = gonePackages.size() - 1; i >= 0; i--) {
final PackageWithUser pu = gonePackages.get(i);
cleanUpPackageLocked(pu.packageName, ownerUserId, pu.userId, /* appStillExists = */
false);
}
}
rescanUpdatedPackagesLocked(ownerUserId, user.getLastAppScanTime(), /* forceRescan=*/
false);
}
} finally {
logDurationStat(Stats.CHECK_PACKAGE_CHANGES, start);
}
verifyStates();
}
Aggregations