Merge "Use 'cmd package list packages' to get the app uid." am: d7054da22b
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2128505 Change-Id: I714681ea5ce047d771d93b1f130daebc97cc1baf Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
19fb698c8d
1 changed files with 11 additions and 12 deletions
|
|
@ -34,8 +34,6 @@ import com.android.tradefed.testtype.IBuildReceiver;
|
|||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
abstract class HostsideNetworkTestCase extends DeviceTestCase implements IAbiReceiver,
|
||||
IBuildReceiver {
|
||||
|
|
@ -171,18 +169,19 @@ abstract class HostsideNetworkTestCase extends DeviceTestCase implements IAbiRec
|
|||
}
|
||||
}
|
||||
|
||||
private static final Pattern UID_PATTERN =
|
||||
Pattern.compile(".*userId=([0-9]+)$", Pattern.MULTILINE);
|
||||
|
||||
protected int getUid(String packageName) throws DeviceNotAvailableException {
|
||||
final String output = runCommand("dumpsys package " + packageName);
|
||||
final Matcher matcher = UID_PATTERN.matcher(output);
|
||||
while (matcher.find()) {
|
||||
final String match = matcher.group(1);
|
||||
return Integer.parseInt(match);
|
||||
final int currentUser = getDevice().getCurrentUser();
|
||||
final String uidLines = runCommand(
|
||||
"cmd package list packages -U --user " + currentUser + " " + packageName);
|
||||
for (String uidLine : uidLines.split("\n")) {
|
||||
if (uidLine.startsWith("package:" + packageName + " uid:")) {
|
||||
final String[] uidLineParts = uidLine.split(":");
|
||||
// 3rd entry is package uid
|
||||
return Integer.parseInt(uidLineParts[2].trim());
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Did not find regexp '" + UID_PATTERN + "' on adb output\n"
|
||||
+ output);
|
||||
throw new IllegalStateException("Failed to find the test app on the device; pkg="
|
||||
+ packageName + ", u=" + currentUser);
|
||||
}
|
||||
|
||||
protected String runCommand(String command) throws DeviceNotAvailableException {
|
||||
|
|
|
|||
Loading…
Reference in a new issue