Search in sources :

Example 46 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by AOSPA.

the class AccountManagerService method getPreNDatabaseName.

@VisibleForTesting
String getPreNDatabaseName(int userId) {
    File systemDir = Environment.getDataSystemDirectory();
    File databaseFile = new File(Environment.getUserSystemDirectory(userId), PRE_N_DATABASE_NAME);
    if (userId == 0) {
        // Migrate old file, if it exists, to the new location.
        // Make sure the new file doesn't already exist. A dummy file could have been
        // accidentally created in the old location, causing the new one to become corrupted
        // as well.
        File oldFile = new File(systemDir, PRE_N_DATABASE_NAME);
        if (oldFile.exists() && !databaseFile.exists()) {
            // Check for use directory; create if it doesn't exist, else renameTo will fail
            File userDir = Environment.getUserSystemDirectory(userId);
            if (!userDir.exists()) {
                if (!userDir.mkdirs()) {
                    throw new IllegalStateException("User dir cannot be created: " + userDir);
                }
            }
            if (!oldFile.renameTo(databaseFile)) {
                throw new IllegalStateException("User dir cannot be migrated: " + databaseFile);
            }
        }
    }
    return databaseFile.getPath();
}
Also used : File(java.io.File) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 47 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by AOSPA.

the class NetworkMonitor method sendHttpProbe.

/**
     * Do a URL fetch on a known web server to see if we get the data we expect.
     * @return a CaptivePortalProbeResult inferred from the HTTP response.
     */
@VisibleForTesting
protected CaptivePortalProbeResult sendHttpProbe(URL url, int probeType) {
    HttpURLConnection urlConnection = null;
    int httpResponseCode = 599;
    String redirectUrl = null;
    final Stopwatch probeTimer = new Stopwatch().start();
    try {
        urlConnection = (HttpURLConnection) mNetworkAgentInfo.network.openConnection(url);
        urlConnection.setInstanceFollowRedirects(probeType == ValidationProbeEvent.PROBE_PAC);
        urlConnection.setConnectTimeout(SOCKET_TIMEOUT_MS);
        urlConnection.setReadTimeout(SOCKET_TIMEOUT_MS);
        urlConnection.setUseCaches(false);
        final String userAgent = getCaptivePortalUserAgent(mContext);
        if (userAgent != null) {
            urlConnection.setRequestProperty("User-Agent", userAgent);
        }
        // Time how long it takes to get a response to our request
        long requestTimestamp = SystemClock.elapsedRealtime();
        httpResponseCode = urlConnection.getResponseCode();
        redirectUrl = urlConnection.getHeaderField("location");
        // Time how long it takes to get a response to our request
        long responseTimestamp = SystemClock.elapsedRealtime();
        validationLog(ValidationProbeEvent.getProbeName(probeType) + " " + url + " time=" + (responseTimestamp - requestTimestamp) + "ms" + " ret=" + httpResponseCode + " headers=" + urlConnection.getHeaderFields());
        // proxy server.
        if (httpResponseCode == 200) {
            if (probeType == ValidationProbeEvent.PROBE_PAC) {
                validationLog("PAC fetch 200 response interpreted as 204 response.");
                httpResponseCode = 204;
            } else if (urlConnection.getContentLengthLong() == 0) {
                // Consider 200 response with "Content-length=0" to not be a captive portal.
                // There's no point in considering this a captive portal as the user cannot
                // sign-in to an empty page. Probably the result of a broken transparent proxy.
                // See http://b/9972012.
                validationLog("200 response with Content-length=0 interpreted as 204 response.");
                httpResponseCode = 204;
            } else if (urlConnection.getContentLengthLong() == -1) {
                // response. Do not use available() as it is unreliable. See http://b/33498325.
                if (urlConnection.getInputStream().read() == -1) {
                    validationLog("Empty 200 response interpreted as 204 response.");
                    httpResponseCode = 204;
                }
            }
        }
    } catch (IOException e) {
        validationLog("Probably not a portal: exception " + e);
        if (httpResponseCode == 599) {
        // TODO: Ping gateway and DNS server and log results.
        }
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
    }
    logValidationProbe(probeTimer.stop(), probeType, httpResponseCode);
    return new CaptivePortalProbeResult(httpResponseCode, redirectUrl, url.toString());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Stopwatch(android.net.util.Stopwatch) IOException(java.io.IOException) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 48 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by AOSPA.

the class NetworkStatsObservers method getHandlerLooperLocked.

@VisibleForTesting
protected Looper getHandlerLooperLocked() {
    HandlerThread handlerThread = new HandlerThread(TAG);
    handlerThread.start();
    return handlerThread.getLooper();
}
Also used : HandlerThread(android.os.HandlerThread) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 49 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by crdroidandroid.

the class ResourcesManager method getDisplayMetrics.

/**
     * Protected so that tests can override and returns something a fixed value.
     */
@VisibleForTesting
@NonNull
protected DisplayMetrics getDisplayMetrics(int displayId, DisplayAdjustments da) {
    DisplayMetrics dm = new DisplayMetrics();
    final Display display = getAdjustedDisplay(displayId, da);
    if (display != null) {
        display.getMetrics(dm);
    } else {
        dm.setToDefaults();
    }
    return dm;
}
Also used : DisplayMetrics(android.util.DisplayMetrics) Display(android.view.Display) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) NonNull(android.annotation.NonNull)

Example 50 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by crdroidandroid.

the class InputMethodUtils method parseInputMethodsAndSubtypesString.

/**
     * Parses the setting stored input methods and subtypes string value.
     *
     * @param inputMethodsAndSubtypesString The input method subtypes value stored in settings.
     * @return Map from input method ID to set of input method subtypes IDs.
     */
@VisibleForTesting
public static ArrayMap<String, ArraySet<String>> parseInputMethodsAndSubtypesString(@Nullable final String inputMethodsAndSubtypesString) {
    final ArrayMap<String, ArraySet<String>> imeMap = new ArrayMap<>();
    if (TextUtils.isEmpty(inputMethodsAndSubtypesString)) {
        return imeMap;
    }
    final SimpleStringSplitter typeSplitter = new SimpleStringSplitter(INPUT_METHOD_SEPARATOR);
    final SimpleStringSplitter subtypeSplitter = new SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATOR);
    List<Pair<String, ArrayList<String>>> allImeSettings = InputMethodSettings.buildInputMethodsAndSubtypeList(inputMethodsAndSubtypesString, typeSplitter, subtypeSplitter);
    for (Pair<String, ArrayList<String>> ime : allImeSettings) {
        ArraySet<String> subtypes = new ArraySet<>();
        if (ime.second != null) {
            subtypes.addAll(ime.second);
        }
        imeMap.put(ime.first, subtypes);
    }
    return imeMap;
}
Also used : ArraySet(android.util.ArraySet) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) SimpleStringSplitter(android.text.TextUtils.SimpleStringSplitter) Pair(android.util.Pair) 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