Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c03929b5 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by Android (Google) Code Review
Browse files

Merge "Fix BackgroundDexOptServiceIntegrationTests"

parents b669c5c8 7804f7fa
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -9023,6 +9023,20 @@ public class PackageManagerService extends IPackageManager.Stub
        }
    }
    /**
     * Enforces that only the system UID or shell's UID can call a method exposed
     * via Binder.
     *
     * @param message used as message if SecurityException is thrown
     * @throws SecurityException if the caller is not system or shell
     */
    private static void enforceSystemOrShell(String message) {
        final int uid = Binder.getCallingUid();
        if (uid != Process.SYSTEM_UID && uid != Process.SHELL_UID) {
            throw new SecurityException(message);
        }
    }
    @Override
    public void performFstrimIfNeeded() {
        enforceSystemOrRoot("Only the system can request fstrim");
@@ -9504,7 +9518,13 @@ public class PackageManagerService extends IPackageManager.Stub
        if (getInstantAppPackageName(Binder.getCallingUid()) != null) {
            return false;
        }
        enforceSystemOrShell("runBackgroundDexoptJob");
        final long identity = Binder.clearCallingIdentity();
        try {
            return BackgroundDexOptService.runIdleOptimizationsNow(this, mContext, packageNames);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }
    List<PackageParser.Package> findSharedNonSystemLibraries(PackageParser.Package p) {
+13 −20
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@
package com.android.server.pm;

import android.app.AlarmManager;
import android.app.UiAutomation;
import android.content.Context;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.os.SystemProperties;
import android.os.storage.StorageManager;
import android.support.test.InstrumentationRegistry;
@@ -34,6 +36,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -141,27 +144,17 @@ public final class BackgroundDexOptServiceIntegrationTests {
    // Run the command and return the stdout.
    private static String runShellCommand(String cmd) throws IOException {
        Log.i(TAG, String.format("running command: '%s'", cmd));
        long startTime = System.nanoTime();
        Process p = Runtime.getRuntime().exec(cmd);
        int res;
        try {
            res = p.waitFor();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        String stdout = inputStreamToString(p.getInputStream());
        String stderr = inputStreamToString(p.getErrorStream());
        long elapsedTime = System.nanoTime() - startTime;
        Log.i(TAG, String.format("ran command: '%s' in %d ms with return code %d", cmd,
                TimeUnit.NANOSECONDS.toMillis(elapsedTime), res));
        Log.i(TAG, "stdout");
        Log.i(TAG, stdout);
        Log.i(TAG, "stderr");
        Log.i(TAG, stderr);
        if (res != 0) {
            throw new RuntimeException(String.format("failed command: '%s'", cmd));
        }
        return stdout;
        ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation()
                .executeShellCommand(cmd);
        byte[] buf = new byte[512];
        int bytesRead;
        FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
        StringBuilder stdout = new StringBuilder();
        while ((bytesRead = fis.read(buf)) != -1) {
            stdout.append(new String(buf, 0, bytesRead));
        }
        fis.close();
        return stdout.toString();
    }

    // Run the command and return the stdout split by lines.