From 8dcfefd652fa2c5612b3acbc4bf842d2dfb1cf21 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Thu, 15 May 2014 18:12:59 +0100 Subject: Support an ABI flag for instrumentation. Allows us to choose what ABI a process uses when launching it with "adb shell am instrument", for eg. adb shell am instrument --abi arm64-v8a component/runner Note that we only perform very basic validation of the ABI. In general, there is no guarantee that the app will launch with the instruction set we choose, for eg. if it has native libraries that are for a different ABI. bug: 14453227 Change-Id: Ifb7e89b53675080dc87941091ee5ac360f218d7f --- cmds/am/src/com/android/commands/am/Am.java | 31 +++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'cmds/am') diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index 0344d26..ffe7ac9 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -33,6 +33,7 @@ import android.content.pm.IPackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Binder; +import android.os.Build; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.RemoteException; @@ -43,6 +44,8 @@ import android.util.AndroidException; import android.view.IWindowManager; import com.android.internal.os.BaseCommand; +import dalvik.system.VMRuntime; + import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; @@ -91,7 +94,11 @@ public class Am extends BaseCommand { " am broadcast [--user | all | current] \n" + " am instrument [-r] [-e ] [-p ] [-w]\n" + " [--user | current]\n" + - " [--no-window-animation] \n" + + " [--no-window-animation]\n" + + " [--abi ]\n : Launch the instrumented process with the " + + " selected ABI. This assumes that the process supports the" + + " selected ABI." + + " \n" + " am profile start [--user current] \n" + " am profile stop [--user current] []\n" + " am dumpheap [--user current] [-n] \n" + @@ -813,6 +820,7 @@ public class Am extends BaseCommand { Bundle args = new Bundle(); String argKey = null, argValue = null; IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window")); + String abi = null; String opt; while ((opt=nextOption()) != null) { @@ -831,6 +839,8 @@ public class Am extends BaseCommand { no_window_animation = true; } else if (opt.equals("--user")) { userId = parseUserArg(nextArgRequired()); + } else if (opt.equals("--abi")) { + abi = nextArgRequired(); } else { System.err.println("Error: Unknown option: " + opt); return; @@ -861,7 +871,24 @@ public class Am extends BaseCommand { wm.setAnimationScale(1, 0.0f); } - if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher, connection, userId)) { + if (abi != null) { + final String[] supportedAbis = Build.SUPPORTED_ABIS; + boolean matched = false; + for (String supportedAbi : supportedAbis) { + if (supportedAbi.equals(abi)) { + matched = true; + break; + } + } + + if (!matched) { + throw new AndroidException( + "INSTRUMENTATION_FAILED: Unsupported instruction set " + abi); + } + } + + if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher, connection, userId, + abi)) { throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString()); } -- cgit v1.1