diff options
author | Jeff Sharkey <jsharkey@android.com> | 2014-07-10 12:10:25 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2014-07-11 16:54:49 -0700 |
commit | bb580670350b76fa2fcc5ee873f99b7970759cbf (patch) | |
tree | b4e22eeaaf299d9c5b2272a292fe9117e94bc0b3 /cmds/pm | |
parent | 4901d62f1629ef5b9fb4c821e5fafbbfde4b8a47 (diff) | |
download | frameworks_base-bb580670350b76fa2fcc5ee873f99b7970759cbf.zip frameworks_base-bb580670350b76fa2fcc5ee873f99b7970759cbf.tar.gz frameworks_base-bb580670350b76fa2fcc5ee873f99b7970759cbf.tar.bz2 |
Progress toward installer public API: callbacks.
Instead of surfacing all the existing cryptic error codes, we're
going to classify them into broad categories when surfacing through
public API. This change introduces InstallResultCallback and
UninstallResultCallback, and wires them up to existing AIDL
interfaces.
Also start defining general SessionObserver for apps interested
in general progress details, such as Launcher apps. Details about
active sessions are returned through new InstallSessionInfo objects.
Bug: 14975160
Change-Id: I068e2b0c30135f6340f59ae0fff93c321047f8f9
Diffstat (limited to 'cmds/pm')
-rw-r--r-- | cmds/pm/src/com/android/commands/pm/Pm.java | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java index 92e9290..6cca03b 100644 --- a/cmds/pm/src/com/android/commands/pm/Pm.java +++ b/cmds/pm/src/com/android/commands/pm/Pm.java @@ -27,10 +27,11 @@ import android.content.pm.IPackageDataObserver; import android.content.pm.IPackageDeleteObserver; import android.content.pm.IPackageInstaller; import android.content.pm.IPackageManager; +import android.content.pm.InstallSessionParams; import android.content.pm.InstrumentationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageInstaller; -import android.content.pm.PackageInstallerParams; +import android.content.pm.PackageInstaller.InstallResultCallback; import android.content.pm.PackageItemInfo; import android.content.pm.PackageManager; import android.content.pm.ParceledListSlice; @@ -768,6 +769,31 @@ public final class Pm { } } + class LocalInstallResultCallback extends InstallResultCallback { + boolean finished; + boolean success; + String msg; + + private void setResult(boolean success, String msg) { + synchronized (this) { + this.finished = true; + this.success = success; + this.msg = msg; + notifyAll(); + } + } + + @Override + public void onSuccess() { + setResult(true, null); + } + + @Override + public void onFailure(String msg) { + setResult(false, msg); + } + } + /** * Converts a failure code into a string by using reflection to find a matching constant * in PackageManager. @@ -989,7 +1015,7 @@ public final class Pm { private void runInstallCreate() throws RemoteException { String installerPackageName = null; - final PackageInstallerParams params = new PackageInstallerParams(); + final InstallSessionParams params = new InstallSessionParams(); params.installFlags = PackageManager.INSTALL_ALL_USERS; params.fullInstall = true; @@ -1084,21 +1110,21 @@ public final class Pm { try { session = new PackageInstaller.Session(mInstaller.openSession(sessionId)); - final LocalPackageInstallObserver observer = new LocalPackageInstallObserver(); - session.install(observer); + final LocalInstallResultCallback callback = new LocalInstallResultCallback(); + session.install(callback); - synchronized (observer) { - while (!observer.finished) { + synchronized (callback) { + while (!callback.finished) { try { - observer.wait(); + callback.wait(); } catch (InterruptedException e) { } } - if (observer.result != PackageManager.INSTALL_SUCCEEDED) { - throw new IllegalStateException( - "Failure [" + installFailureToString(observer) + "]"); + if (!callback.success) { + throw new IllegalStateException("Failure [" + callback.msg + "]"); } } + System.out.println("Success"); } finally { IoUtils.closeQuietly(session); |