Search in sources :

Example 81 with VisibleForTesting

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));
}
Also used : IllegalInstructionException(android.net.apf.ApfGenerator.IllegalInstructionException) ApfGenerator(android.net.apf.ApfGenerator) ArrayList(java.util.ArrayList) ApfProgramEvent(android.net.metrics.ApfProgramEvent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) GuardedBy(com.android.internal.annotations.GuardedBy)

Example 82 with VisibleForTesting

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);
}
Also used : CarrierConfigManager(android.telephony.CarrierConfigManager) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 83 with VisibleForTesting

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;
}
Also used : LinkAddress(android.net.LinkAddress) ProxyInfo(android.net.ProxyInfo) StaticIpConfiguration(android.net.StaticIpConfiguration) InetAddress(java.net.InetAddress) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 84 with VisibleForTesting

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);
    }
}
Also used : Intent(android.content.Intent) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 85 with VisibleForTesting

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();
}
Also used : PackageWithUser(com.android.server.pm.ShortcutUser.PackageWithUser) ArrayList(java.util.ArrayList) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.android.internal.annotations.VisibleForTesting)141 ArrayList (java.util.ArrayList)39 IOException (java.io.IOException)26 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)18 ComponentName (android.content.ComponentName)15 File (java.io.File)14 RemoteException (android.os.RemoteException)13 ArraySet (android.util.ArraySet)10 AtomicFile (android.util.AtomicFile)10 FileInputStream (java.io.FileInputStream)10 Locale (java.util.Locale)10 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)9 FileNotFoundException (java.io.FileNotFoundException)9 Notification (android.app.Notification)6 ErrnoException (android.system.ErrnoException)6 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)6 FileOutputStream (java.io.FileOutputStream)6 XmlSerializer (org.xmlpull.v1.XmlSerializer)6 ITransientNotification (android.app.ITransientNotification)5 UserInfo (android.content.pm.UserInfo)5