Search in sources :

Example 71 with BufferedWriter

use of java.io.BufferedWriter in project android_frameworks_base by ParanoidAndroid.

the class WindowManagerService method viewServerWindowCommand.

/**
     * Sends a command to a target window. The result of the command, if any, will be
     * written in the output stream of the specified socket.
     *
     * The parameters must follow this syntax:
     * windowHashcode extra
     *
     * Where XX is the length in characeters of the windowTitle.
     *
     * The first parameter is the target window. The window with the specified hashcode
     * will be the target. If no target can be found, nothing happens. The extra parameters
     * will be delivered to the target window and as parameters to the command itself.
     *
     * @param client The remote client to sent the result, if any, to.
     * @param command The command to execute.
     * @param parameters The command parameters.
     *
     * @return True if the command was successfully delivered, false otherwise. This does
     *         not indicate whether the command itself was successful.
     */
boolean viewServerWindowCommand(Socket client, String command, String parameters) {
    if (isSystemSecure()) {
        return false;
    }
    boolean success = true;
    Parcel data = null;
    Parcel reply = null;
    BufferedWriter out = null;
    // Any uncaught exception will crash the system process
    try {
        // Find the hashcode of the window
        int index = parameters.indexOf(' ');
        if (index == -1) {
            index = parameters.length();
        }
        final String code = parameters.substring(0, index);
        int hashCode = (int) Long.parseLong(code, 16);
        // Extract the command's parameter after the window description
        if (index < parameters.length()) {
            parameters = parameters.substring(index + 1);
        } else {
            parameters = "";
        }
        final WindowState window = findWindow(hashCode);
        if (window == null) {
            return false;
        }
        data = Parcel.obtain();
        data.writeInterfaceToken("android.view.IWindow");
        data.writeString(command);
        data.writeString(parameters);
        data.writeInt(1);
        ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
        reply = Parcel.obtain();
        final IBinder binder = window.mClient.asBinder();
        // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
        binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
        reply.readException();
        if (!client.isOutputShutdown()) {
            out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
            out.write("DONE\n");
            out.flush();
        }
    } catch (Exception e) {
        Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
        success = false;
    } finally {
        if (data != null) {
            data.recycle();
        }
        if (reply != null) {
            reply.recycle();
        }
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
            }
        }
    }
    return success;
}
Also used : IBinder(android.os.IBinder) Parcel(android.os.Parcel) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Point(android.graphics.Point) RemoteException(android.os.RemoteException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NoSuchElementException(java.util.NoSuchElementException) BufferedWriter(java.io.BufferedWriter)

Example 72 with BufferedWriter

use of java.io.BufferedWriter in project android_frameworks_base by ParanoidAndroid.

the class WindowManagerService method viewServerGetFocusedWindow.

// TODO(multidisplay): Extend to multiple displays.
/**
     * Returns the focused window in the following format:
     * windowHashCodeInHexadecimal windowName
     *
     * @param client The remote client to send the listing to.
     * @return False if an error occurred, true otherwise.
     */
boolean viewServerGetFocusedWindow(Socket client) {
    if (isSystemSecure()) {
        return false;
    }
    boolean result = true;
    WindowState focusedWindow = getFocusedWindow();
    BufferedWriter out = null;
    // Any uncaught exception will crash the system process
    try {
        OutputStream clientStream = client.getOutputStream();
        out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
        if (focusedWindow != null) {
            out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
            out.write(' ');
            out.append(focusedWindow.mAttrs.getTitle());
        }
        out.write('\n');
        out.flush();
    } catch (Exception e) {
        result = false;
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                result = false;
            }
        }
    }
    return result;
}
Also used : OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NoSuchElementException(java.util.NoSuchElementException) BufferedWriter(java.io.BufferedWriter)

Example 73 with BufferedWriter

use of java.io.BufferedWriter in project android_frameworks_base by ParanoidAndroid.

the class FsUtils method saveTestListToStorage.

public static void saveTestListToStorage(File file, int start, List<String> testList) {
    try {
        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        for (String line : testList.subList(start, testList.size())) {
            writer.write(line + '\n');
        }
        writer.flush();
        writer.close();
    } catch (IOException e) {
        Log.e(LOG_TAG, "failed to write test list", e);
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 74 with BufferedWriter

use of java.io.BufferedWriter in project android_frameworks_base by ParanoidAndroid.

the class RsBenchRS method saveTestResults.

private void saveTestResults() {
    String state = Environment.getExternalStorageState();
    if (!Environment.MEDIA_MOUNTED.equals(state)) {
        Log.v(TAG, "sdcard is read only");
        return;
    }
    File sdCard = Environment.getExternalStorageDirectory();
    if (!sdCard.canWrite()) {
        Log.v(TAG, "ssdcard is read only");
        return;
    }
    File resultFile = new File(sdCard, "rsbench_result" + mCurrentLoop + ".csv");
    resultFile.setWritable(true, false);
    try {
        BufferedWriter results = new BufferedWriter(new FileWriter(resultFile));
        for (int i = 0; i < mLocalTestResults.length; i++) {
            results.write(mTestNames[i] + ", " + mLocalTestResults[i] + ",\n");
        }
        results.close();
        Log.v(TAG, "Saved results in: " + resultFile.getAbsolutePath());
    } catch (IOException e) {
        Log.v(TAG, "Unable to write result file " + e.getMessage());
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 75 with BufferedWriter

use of java.io.BufferedWriter in project android_frameworks_base by ParanoidAndroid.

the class WritePreloadedClassFile method main.

public static void main(String[] args) throws IOException, ClassNotFoundException {
    if (args.length != 1) {
        System.err.println("Usage: WritePreloadedClassFile [compiled log]");
        System.exit(-1);
    }
    String rootFile = args[0];
    Root root = Root.fromFile(rootFile);
    // No classes are preloaded to start.
    for (LoadedClass loadedClass : root.loadedClasses.values()) {
        loadedClass.preloaded = false;
    }
    // Open preloaded-classes file for output.
    Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(Policy.PRELOADED_CLASS_FILE), Charset.forName("US-ASCII")));
    out.write("# Classes which are preloaded by" + " com.android.internal.os.ZygoteInit.\n");
    out.write("# Automatically generated by frameworks/base/tools/preload/" + WritePreloadedClassFile.class.getSimpleName() + ".java.\n");
    out.write("# MIN_LOAD_TIME_MICROS=" + MIN_LOAD_TIME_MICROS + "\n");
    out.write("# MIN_PROCESSES=" + MIN_PROCESSES + "\n");
    /*
         * The set of classes to preload. We preload a class if:
         *
         *  a) it's loaded in the bootclasspath (i.e., is a system class)
         *  b) it takes > MIN_LOAD_TIME_MICROS us to load, and
         *  c) it's loaded by more than one process, or it's loaded by an
         *     application (i.e., not a long running service)
         */
    Set<LoadedClass> toPreload = new TreeSet<LoadedClass>();
    // the memory associated with these classes will be shared.
    for (LoadedClass loadedClass : root.loadedClasses.values()) {
        Set<String> names = loadedClass.processNames();
        if (!Policy.isPreloadable(loadedClass)) {
            continue;
        }
        if (names.size() >= MIN_PROCESSES || (loadedClass.medianTimeMicros() > MIN_LOAD_TIME_MICROS && names.size() > 1)) {
            toPreload.add(loadedClass);
        }
    }
    int initialSize = toPreload.size();
    System.out.println(initialSize + " classses were loaded by more than one app.");
    // services).
    for (Proc proc : root.processes.values()) {
        if (proc.fromZygote() && !Policy.isService(proc.name)) {
            for (Operation operation : proc.operations) {
                LoadedClass loadedClass = operation.loadedClass;
                if (shouldPreload(loadedClass)) {
                    toPreload.add(loadedClass);
                }
            }
        }
    }
    System.out.println("Added " + (toPreload.size() - initialSize) + " more to speed up applications.");
    System.out.println(toPreload.size() + " total classes will be preloaded.");
    // Make classes that were implicitly loaded by the zygote explicit.
    // This adds minimal overhead but avoid confusion about classes not
    // appearing in the list.
    addAllClassesFrom("zygote", root, toPreload);
    for (LoadedClass loadedClass : toPreload) {
        out.write(loadedClass.name + "\n");
    }
    out.close();
    // Update data to reflect LoadedClass.preloaded changes.
    for (LoadedClass loadedClass : toPreload) {
        loadedClass.preloaded = true;
    }
    root.toFile(rootFile);
}
Also used : BufferedWriter(java.io.BufferedWriter) TreeSet(java.util.TreeSet) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

BufferedWriter (java.io.BufferedWriter)4214 FileWriter (java.io.FileWriter)2181 File (java.io.File)1879 IOException (java.io.IOException)1847 OutputStreamWriter (java.io.OutputStreamWriter)1344 BufferedReader (java.io.BufferedReader)747 FileOutputStream (java.io.FileOutputStream)656 ArrayList (java.util.ArrayList)386 FileReader (java.io.FileReader)376 InputStreamReader (java.io.InputStreamReader)349 PrintWriter (java.io.PrintWriter)324 Writer (java.io.Writer)324 Test (org.junit.Test)286 FileNotFoundException (java.io.FileNotFoundException)217 OutputStream (java.io.OutputStream)213 HashMap (java.util.HashMap)200 Path (java.nio.file.Path)177 InputStream (java.io.InputStream)171 FileInputStream (java.io.FileInputStream)158 StringWriter (java.io.StringWriter)143