summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/content/pm/IPackageInstallerSession.aidl3
-rw-r--r--core/java/android/content/pm/InstallSessionParams.java27
-rw-r--r--core/java/android/content/pm/PackageInstaller.java61
-rw-r--r--core/java/android/os/FileBridge.java4
-rw-r--r--core/java/android/util/ExceptionUtils.java42
5 files changed, 111 insertions, 26 deletions
diff --git a/core/java/android/content/pm/IPackageInstallerSession.aidl b/core/java/android/content/pm/IPackageInstallerSession.aidl
index f881acd..d6775d4 100644
--- a/core/java/android/content/pm/IPackageInstallerSession.aidl
+++ b/core/java/android/content/pm/IPackageInstallerSession.aidl
@@ -21,7 +21,8 @@ import android.os.ParcelFileDescriptor;
/** {@hide} */
interface IPackageInstallerSession {
- void updateProgress(int progress);
+ void setClientProgress(int progress);
+ void addClientProgress(int progress);
ParcelFileDescriptor openWrite(String name, long offsetBytes, long lengthBytes);
diff --git a/core/java/android/content/pm/InstallSessionParams.java b/core/java/android/content/pm/InstallSessionParams.java
index f683523..43e3314 100644
--- a/core/java/android/content/pm/InstallSessionParams.java
+++ b/core/java/android/content/pm/InstallSessionParams.java
@@ -21,6 +21,8 @@ import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
+import com.android.internal.util.IndentingPrintWriter;
+
/** {@hide} */
public class InstallSessionParams implements Parcelable {
@@ -37,6 +39,8 @@ public class InstallSessionParams implements Parcelable {
/** {@hide} */
public long deltaSize = -1;
/** {@hide} */
+ public int progressMax = 100;
+ /** {@hide} */
public String packageName;
/** {@hide} */
public Bitmap icon;
@@ -59,6 +63,7 @@ public class InstallSessionParams implements Parcelable {
installLocation = source.readInt();
signatures = (Signature[]) source.readParcelableArray(null);
deltaSize = source.readLong();
+ progressMax = source.readInt();
packageName = source.readString();
icon = source.readParcelable(null);
title = source.readString();
@@ -87,6 +92,10 @@ public class InstallSessionParams implements Parcelable {
this.deltaSize = deltaSize;
}
+ public void setProgressMax(int progressMax) {
+ this.progressMax = progressMax;
+ }
+
public void setPackageName(String packageName) {
this.packageName = packageName;
}
@@ -107,6 +116,23 @@ public class InstallSessionParams implements Parcelable {
this.referrerUri = referrerUri;
}
+ /** {@hide} */
+ public void dump(IndentingPrintWriter pw) {
+ pw.printPair("fullInstall", fullInstall);
+ pw.printHexPair("installFlags", installFlags);
+ pw.printPair("installLocation", installLocation);
+ pw.printPair("signatures", (signatures != null));
+ pw.printPair("deltaSize", deltaSize);
+ pw.printPair("progressMax", progressMax);
+ pw.printPair("packageName", packageName);
+ pw.printPair("icon", (icon != null));
+ pw.printPair("title", title);
+ pw.printPair("originatingUri", originatingUri);
+ pw.printPair("referrerUri", referrerUri);
+ pw.printPair("abiOverride", abiOverride);
+ pw.println();
+ }
+
@Override
public int describeContents() {
return 0;
@@ -119,6 +145,7 @@ public class InstallSessionParams implements Parcelable {
dest.writeInt(installLocation);
dest.writeParcelableArray(signatures, flags);
dest.writeLong(deltaSize);
+ dest.writeInt(progressMax);
dest.writeString(packageName);
dest.writeParcelable(icon, flags);
dest.writeString(title != null ? title.toString() : null);
diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java
index 9d756f7..401be06 100644
--- a/core/java/android/content/pm/PackageInstaller.java
+++ b/core/java/android/content/pm/PackageInstaller.java
@@ -23,8 +23,10 @@ import android.os.Bundle;
import android.os.FileBridge;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
+import android.util.ExceptionUtils;
import java.io.Closeable;
+import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
@@ -64,9 +66,12 @@ public class PackageInstaller {
observer.packageInstalled(packageName, null, returnCode);
}
- public int createSession(InstallSessionParams params) {
+ public int createSession(InstallSessionParams params) throws IOException {
try {
return mInstaller.createSession(mInstallerPackageName, params, mUserId);
+ } catch (RuntimeException e) {
+ ExceptionUtils.maybeUnwrapIOException(e);
+ throw e;
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
@@ -136,8 +141,7 @@ public class PackageInstaller {
public abstract void onFinished(int sessionId, boolean success);
}
- public void registerObserver(SessionObserver observer) {
- // TODO: consider restricting to current launcher app
+ public void registerSessionObserver(SessionObserver observer) {
try {
mInstaller.registerObserver(observer.getBinder(), mUserId);
} catch (RemoteException e) {
@@ -145,7 +149,7 @@ public class PackageInstaller {
}
}
- public void unregisterObserver(SessionObserver observer) {
+ public void unregisterSessionObserver(SessionObserver observer) {
try {
mInstaller.unregisterObserver(observer.getBinder(), mUserId);
} catch (RemoteException e) {
@@ -173,9 +177,18 @@ public class PackageInstaller {
mSession = session;
}
- public void updateProgress(int progress) {
+ public void setProgress(int progress) {
try {
- mSession.updateProgress(progress);
+ mSession.setClientProgress(progress);
+ } catch (RemoteException e) {
+ throw e.rethrowAsRuntimeException();
+ }
+ }
+
+ /** {@hide} */
+ public void addProgress(int progress) {
+ try {
+ mSession.addClientProgress(progress);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
@@ -187,19 +200,31 @@ public class PackageInstaller {
* {@link OutputStream#flush()} to ensure bytes have been written to
* disk.
*/
- public OutputStream openWrite(String splitName, long offsetBytes, long lengthBytes) {
+ public OutputStream openWrite(String splitName, long offsetBytes, long lengthBytes)
+ throws IOException {
try {
final ParcelFileDescriptor clientSocket = mSession.openWrite(splitName,
offsetBytes, lengthBytes);
return new FileBridge.FileBridgeOutputStream(clientSocket.getFileDescriptor());
+ } catch (RuntimeException e) {
+ ExceptionUtils.maybeUnwrapIOException(e);
+ throw e;
} catch (RemoteException e) {
- throw e.rethrowAsRuntimeException();
+ throw new IOException(e);
}
}
- public void install(InstallResultCallback callback) {
+ public void fsync(OutputStream out) throws IOException {
+ if (out instanceof FileBridge.FileBridgeOutputStream) {
+ ((FileBridge.FileBridgeOutputStream) out).fsync();
+ } else {
+ throw new IllegalArgumentException("Unrecognized stream");
+ }
+ }
+
+ public void commit(CommitResultCallback callback) {
try {
- mSession.install(new InstallResultCallbackDelegate(callback).getBinder());
+ mSession.install(new CommitResultCallbackDelegate(callback).getBinder());
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
@@ -246,16 +271,8 @@ public class PackageInstaller {
}
}
- public static abstract class InstallResultCallback {
- /**
- * The session installed successfully.
- */
+ public static abstract class CommitResultCallback {
public abstract void onSuccess();
-
- /**
- * General unclassified failure. You may be interested in overriding
- * more granular classifications.
- */
public abstract void onFailure(String msg);
/**
@@ -300,10 +317,10 @@ public class PackageInstaller {
}
}
- private static class InstallResultCallbackDelegate extends PackageInstallObserver {
- private final InstallResultCallback target;
+ private static class CommitResultCallbackDelegate extends PackageInstallObserver {
+ private final CommitResultCallback target;
- public InstallResultCallbackDelegate(InstallResultCallback target) {
+ public CommitResultCallbackDelegate(CommitResultCallback target) {
this.target = target;
}
diff --git a/core/java/android/os/FileBridge.java b/core/java/android/os/FileBridge.java
index 691afdd..1e1ad9e 100644
--- a/core/java/android/os/FileBridge.java
+++ b/core/java/android/os/FileBridge.java
@@ -31,7 +31,6 @@ import libcore.io.Streams;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.OutputStream;
-import java.io.SyncFailedException;
import java.nio.ByteOrder;
import java.util.Arrays;
@@ -144,8 +143,7 @@ public class FileBridge extends Thread {
}
}
- @Override
- public void flush() throws IOException {
+ public void fsync() throws IOException {
writeCommandAndBlock(CMD_FSYNC, "fsync()");
}
diff --git a/core/java/android/util/ExceptionUtils.java b/core/java/android/util/ExceptionUtils.java
new file mode 100644
index 0000000..6aae84d
--- /dev/null
+++ b/core/java/android/util/ExceptionUtils.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.util;
+
+import java.io.IOException;
+
+/**
+ * Utility methods for proxying richer exceptions across Binder calls.
+ *
+ * @hide
+ */
+public class ExceptionUtils {
+ // TODO: longer term these should be replaced with first-class
+ // Parcel.read/writeException() and AIDL support, but for now do this using
+ // a nasty hack.
+
+ private static final String PREFIX_IO = "\u2603";
+
+ public static RuntimeException wrap(IOException e) {
+ throw new IllegalStateException(PREFIX_IO + e.getMessage());
+ }
+
+ public static void maybeUnwrapIOException(RuntimeException e) throws IOException {
+ if ((e instanceof IllegalStateException) && e.getMessage().startsWith(PREFIX_IO)) {
+ throw new IOException(e.getMessage().substring(PREFIX_IO.length()));
+ }
+ }
+}