Search in sources :

Example 1 with SessionInfo

use of android.content.pm.PackageInstaller.SessionInfo in project platform_frameworks_base by android.

the class PackageInstallerService method getMySessions.

@Override
public ParceledListSlice<SessionInfo> getMySessions(String installerPackageName, int userId) {
    mPm.enforceCrossUserPermission(Binder.getCallingUid(), userId, true, false, "getMySessions");
    mAppOps.checkPackage(Binder.getCallingUid(), installerPackageName);
    final List<SessionInfo> result = new ArrayList<>();
    synchronized (mSessions) {
        for (int i = 0; i < mSessions.size(); i++) {
            final PackageInstallerSession session = mSessions.valueAt(i);
            if (Objects.equals(session.installerPackageName, installerPackageName) && session.userId == userId) {
                result.add(session.generateInfo());
            }
        }
    }
    return new ParceledListSlice<>(result);
}
Also used : IPackageInstallerSession(android.content.pm.IPackageInstallerSession) ArrayList(java.util.ArrayList) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) ParceledListSlice(android.content.pm.ParceledListSlice)

Example 2 with SessionInfo

use of android.content.pm.PackageInstaller.SessionInfo in project platform_frameworks_base by android.

the class PackageInstallerService method getAllSessions.

@Override
public ParceledListSlice<SessionInfo> getAllSessions(int userId) {
    mPm.enforceCrossUserPermission(Binder.getCallingUid(), userId, true, false, "getAllSessions");
    final List<SessionInfo> result = new ArrayList<>();
    synchronized (mSessions) {
        for (int i = 0; i < mSessions.size(); i++) {
            final PackageInstallerSession session = mSessions.valueAt(i);
            if (session.userId == userId) {
                result.add(session.generateInfo());
            }
        }
    }
    return new ParceledListSlice<>(result);
}
Also used : IPackageInstallerSession(android.content.pm.IPackageInstallerSession) ArrayList(java.util.ArrayList) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) ParceledListSlice(android.content.pm.ParceledListSlice)

Example 3 with SessionInfo

use of android.content.pm.PackageInstaller.SessionInfo in project platform_frameworks_base by android.

the class PackageManagerShellCommand method doWriteSplit.

private int doWriteSplit(int sessionId, String inPath, long sizeBytes, String splitName, boolean logSuccess) throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    if (sizeBytes <= 0) {
        pw.println("Error: must specify a APK size");
        return 1;
    }
    if (inPath != null && !"-".equals(inPath)) {
        pw.println("Error: APK content must be streamed");
        return 1;
    }
    inPath = null;
    final SessionInfo info = mInterface.getPackageInstaller().getSessionInfo(sessionId);
    PackageInstaller.Session session = null;
    InputStream in = null;
    OutputStream out = null;
    try {
        session = new PackageInstaller.Session(mInterface.getPackageInstaller().openSession(sessionId));
        if (inPath != null) {
            in = new FileInputStream(inPath);
        } else {
            in = new SizedInputStream(getRawInputStream(), sizeBytes);
        }
        out = session.openWrite(splitName, 0, sizeBytes);
        int total = 0;
        byte[] buffer = new byte[65536];
        int c;
        while ((c = in.read(buffer)) != -1) {
            total += c;
            out.write(buffer, 0, c);
            if (info.sizeBytes > 0) {
                final float fraction = ((float) c / (float) info.sizeBytes);
                session.addProgress(fraction);
            }
        }
        session.fsync(out);
        if (logSuccess) {
            pw.println("Success: streamed " + total + " bytes");
        }
        return 0;
    } catch (IOException e) {
        pw.println("Error: failed to write; " + e.getMessage());
        return 1;
    } finally {
        IoUtils.closeQuietly(out);
        IoUtils.closeQuietly(in);
        IoUtils.closeQuietly(session);
    }
}
Also used : SizedInputStream(com.android.internal.util.SizedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) PackageInstaller(android.content.pm.PackageInstaller) SizedInputStream(com.android.internal.util.SizedInputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PrintWriter(java.io.PrintWriter)

Example 4 with SessionInfo

use of android.content.pm.PackageInstaller.SessionInfo in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerShellCommand method doWriteSplit.

private int doWriteSplit(int sessionId, String inPath, long sizeBytes, String splitName, boolean logSuccess) throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    if (sizeBytes <= 0) {
        pw.println("Error: must specify a APK size");
        return 1;
    }
    if (inPath != null && !"-".equals(inPath)) {
        pw.println("Error: APK content must be streamed");
        return 1;
    }
    inPath = null;
    final SessionInfo info = mInterface.getPackageInstaller().getSessionInfo(sessionId);
    PackageInstaller.Session session = null;
    InputStream in = null;
    OutputStream out = null;
    try {
        session = new PackageInstaller.Session(mInterface.getPackageInstaller().openSession(sessionId));
        if (inPath != null) {
            in = new FileInputStream(inPath);
        } else {
            in = new SizedInputStream(getRawInputStream(), sizeBytes);
        }
        out = session.openWrite(splitName, 0, sizeBytes);
        int total = 0;
        byte[] buffer = new byte[65536];
        int c;
        while ((c = in.read(buffer)) != -1) {
            total += c;
            out.write(buffer, 0, c);
            if (info.sizeBytes > 0) {
                final float fraction = ((float) c / (float) info.sizeBytes);
                session.addProgress(fraction);
            }
        }
        session.fsync(out);
        if (logSuccess) {
            pw.println("Success: streamed " + total + " bytes");
        }
        return 0;
    } catch (IOException e) {
        pw.println("Error: failed to write; " + e.getMessage());
        return 1;
    } finally {
        IoUtils.closeQuietly(out);
        IoUtils.closeQuietly(in);
        IoUtils.closeQuietly(session);
    }
}
Also used : SizedInputStream(com.android.internal.util.SizedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) PackageInstaller(android.content.pm.PackageInstaller) SizedInputStream(com.android.internal.util.SizedInputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PrintWriter(java.io.PrintWriter)

Example 5 with SessionInfo

use of android.content.pm.PackageInstaller.SessionInfo in project android_frameworks_base by DirtyUnicorns.

the class PackageInstallerService method getAllSessions.

@Override
public ParceledListSlice<SessionInfo> getAllSessions(int userId) {
    mPm.enforceCrossUserPermission(Binder.getCallingUid(), userId, true, false, "getAllSessions");
    final List<SessionInfo> result = new ArrayList<>();
    synchronized (mSessions) {
        for (int i = 0; i < mSessions.size(); i++) {
            final PackageInstallerSession session = mSessions.valueAt(i);
            if (session.userId == userId) {
                result.add(session.generateInfo());
            }
        }
    }
    return new ParceledListSlice<>(result);
}
Also used : IPackageInstallerSession(android.content.pm.IPackageInstallerSession) ArrayList(java.util.ArrayList) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) ParceledListSlice(android.content.pm.ParceledListSlice)

Aggregations

SessionInfo (android.content.pm.PackageInstaller.SessionInfo)24 IPackageInstallerSession (android.content.pm.IPackageInstallerSession)10 ParceledListSlice (android.content.pm.ParceledListSlice)10 ArrayList (java.util.ArrayList)10 PackageInstaller (android.content.pm.PackageInstaller)9 SizedInputStream (com.android.internal.util.SizedInputStream)9 FileInputStream (java.io.FileInputStream)9 IOException (java.io.IOException)9 InputStream (java.io.InputStream)9 OutputStream (java.io.OutputStream)9 IPackageInstaller (android.content.pm.IPackageInstaller)5 File (java.io.File)5 PrintWriter (java.io.PrintWriter)4