New command to get device config
Change-Id: I7172a3a150fd83e2382ca3e4e4a0188758189f14
This commit is contained in:
@@ -32,6 +32,7 @@ import android.content.IIntentReceiver;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
import android.os.Binder;
|
||||
@@ -45,6 +46,8 @@ import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.util.AndroidException;
|
||||
import android.view.IWindowManager;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.internal.os.BaseCommand;
|
||||
|
||||
import dalvik.system.VMRuntime;
|
||||
@@ -123,6 +126,7 @@ public class Am extends BaseCommand {
|
||||
" am stack info <STACK_ID>\n" +
|
||||
" am lock-task <TASK_ID>\n" +
|
||||
" am lock-task stop\n" +
|
||||
" am get-config\n" +
|
||||
"\n" +
|
||||
"am start: start an Activity. Options are:\n" +
|
||||
" -D: enable debugging\n" +
|
||||
@@ -229,6 +233,9 @@ public class Am extends BaseCommand {
|
||||
"\n" +
|
||||
"am lock-task: bring <TASK_ID> to the front and don't allow other tasks to run\n" +
|
||||
"\n" +
|
||||
"am get-config: retrieve the configuration and any recent configurations\n" +
|
||||
" of the device\n" +
|
||||
"\n" +
|
||||
"<INTENT> specifications include these flags and arguments:\n" +
|
||||
" [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]\n" +
|
||||
" [-c <CATEGORY> [-c <CATEGORY>] ...]\n" +
|
||||
@@ -323,6 +330,8 @@ public class Am extends BaseCommand {
|
||||
runStack();
|
||||
} else if (op.equals("lock-task")) {
|
||||
runLockTask();
|
||||
} else if (op.equals("get-config")) {
|
||||
runGetConfig();
|
||||
} else {
|
||||
showError("Error: unknown command '" + op + "'");
|
||||
}
|
||||
@@ -909,8 +918,7 @@ public class Am extends BaseCommand {
|
||||
}
|
||||
}
|
||||
|
||||
if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher, connection, userId,
|
||||
abi)) {
|
||||
if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher, connection, userId, abi)) {
|
||||
throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString());
|
||||
}
|
||||
|
||||
@@ -1699,4 +1707,23 @@ public class Am extends BaseCommand {
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private void runGetConfig() throws Exception {
|
||||
try {
|
||||
Configuration config = mAm.getConfiguration();
|
||||
if (config == null) {
|
||||
System.err.println("Activity manager has no configuration");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("config: " + Configuration.resourceQualifierString(config));
|
||||
System.out.print("abi: " + Build.CPU_ABI);
|
||||
if (!Build.CPU_ABI2.isEmpty()) {
|
||||
System.out.print("," + Build.CPU_ABI2);
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,14 @@
|
||||
package android.content.res;
|
||||
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import java.text.Format;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@@ -1306,4 +1309,240 @@ public final class Configuration implements Parcelable, Comparable<Configuration
|
||||
private static int getScreenLayoutNoDirection(int screenLayout) {
|
||||
return screenLayout&~SCREENLAYOUT_LAYOUTDIR_MASK;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static String localeToResourceQualifier(Locale locale) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean l = (locale.getLanguage().length() != 0);
|
||||
boolean c = (locale.getCountry().length() != 0);
|
||||
boolean s = (locale.getScript().length() != 0);
|
||||
boolean v = (locale.getVariant().length() != 0);
|
||||
|
||||
if (l) {
|
||||
sb.append(locale.getLanguage());
|
||||
if (c) {
|
||||
sb.append("-r").append(locale.getCountry());
|
||||
if (s) {
|
||||
sb.append("-s").append(locale.getScript());
|
||||
if (v) {
|
||||
sb.append("-v").append(locale.getVariant());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a string representation of the configuration that can be parsed
|
||||
* by build tools (like AAPT).
|
||||
*
|
||||
*
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static String resourceQualifierString(Configuration config) {
|
||||
ArrayList<String> parts = new ArrayList<String>();
|
||||
|
||||
if (config.mcc != 0) {
|
||||
parts.add(config.mcc + "mcc");
|
||||
if (config.mnc != 0) {
|
||||
parts.add(config.mnc + "mnc");
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.locale.getLanguage().isEmpty()) {
|
||||
parts.add(localeToResourceQualifier(config.locale));
|
||||
}
|
||||
|
||||
switch (config.screenLayout & Configuration.SCREENLAYOUT_LAYOUTDIR_MASK) {
|
||||
case Configuration.SCREENLAYOUT_LAYOUTDIR_LTR:
|
||||
parts.add("ldltr");
|
||||
break;
|
||||
case Configuration.SCREENLAYOUT_LAYOUTDIR_RTL:
|
||||
parts.add("ldrtl");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (config.smallestScreenWidthDp != 0) {
|
||||
parts.add("sw" + config.smallestScreenWidthDp + "dp");
|
||||
}
|
||||
|
||||
if (config.screenWidthDp != 0) {
|
||||
parts.add("w" + config.screenWidthDp + "dp");
|
||||
}
|
||||
|
||||
if (config.screenHeightDp != 0) {
|
||||
parts.add("h" + config.screenHeightDp + "dp");
|
||||
}
|
||||
|
||||
switch (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) {
|
||||
case Configuration.SCREENLAYOUT_SIZE_SMALL:
|
||||
parts.add("small");
|
||||
break;
|
||||
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
|
||||
parts.add("normal");
|
||||
break;
|
||||
case Configuration.SCREENLAYOUT_SIZE_LARGE:
|
||||
parts.add("large");
|
||||
break;
|
||||
case Configuration.SCREENLAYOUT_SIZE_XLARGE:
|
||||
parts.add("xlarge");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (config.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK) {
|
||||
case Configuration.SCREENLAYOUT_LONG_YES:
|
||||
parts.add("long");
|
||||
break;
|
||||
case Configuration.SCREENLAYOUT_LONG_NO:
|
||||
parts.add("notlong");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (config.orientation) {
|
||||
case Configuration.ORIENTATION_LANDSCAPE:
|
||||
parts.add("land");
|
||||
break;
|
||||
case Configuration.ORIENTATION_PORTRAIT:
|
||||
parts.add("port");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (config.uiMode & Configuration.UI_MODE_TYPE_MASK) {
|
||||
case Configuration.UI_MODE_TYPE_APPLIANCE:
|
||||
parts.add("appliance");
|
||||
break;
|
||||
case Configuration.UI_MODE_TYPE_DESK:
|
||||
parts.add("desk");
|
||||
break;
|
||||
case Configuration.UI_MODE_TYPE_TELEVISION:
|
||||
parts.add("television");
|
||||
break;
|
||||
case Configuration.UI_MODE_TYPE_CAR:
|
||||
parts.add("car");
|
||||
break;
|
||||
case Configuration.UI_MODE_TYPE_WATCH:
|
||||
parts.add("watch");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (config.uiMode & Configuration.UI_MODE_NIGHT_MASK) {
|
||||
case Configuration.UI_MODE_NIGHT_YES:
|
||||
parts.add("night");
|
||||
break;
|
||||
case Configuration.UI_MODE_NIGHT_NO:
|
||||
parts.add("notnight");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (config.densityDpi) {
|
||||
case 0:
|
||||
break;
|
||||
case 120:
|
||||
parts.add("ldpi");
|
||||
break;
|
||||
case 160:
|
||||
parts.add("mdpi");
|
||||
break;
|
||||
case 213:
|
||||
parts.add("tvdpi");
|
||||
break;
|
||||
case 240:
|
||||
parts.add("hdpi");
|
||||
break;
|
||||
case 320:
|
||||
parts.add("xhdpi");
|
||||
break;
|
||||
default:
|
||||
parts.add(config.densityDpi + "dpi");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (config.touchscreen) {
|
||||
case Configuration.TOUCHSCREEN_NOTOUCH:
|
||||
parts.add("notouch");
|
||||
break;
|
||||
case Configuration.TOUCHSCREEN_FINGER:
|
||||
parts.add("finger");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (config.keyboardHidden) {
|
||||
case Configuration.KEYBOARDHIDDEN_NO:
|
||||
parts.add("keysexposed");
|
||||
break;
|
||||
case Configuration.KEYBOARDHIDDEN_YES:
|
||||
parts.add("keyshidden");
|
||||
break;
|
||||
case Configuration.KEYBOARDHIDDEN_SOFT:
|
||||
parts.add("keyssoft");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (config.keyboard) {
|
||||
case Configuration.KEYBOARD_NOKEYS:
|
||||
parts.add("nokeys");
|
||||
break;
|
||||
case Configuration.KEYBOARD_QWERTY:
|
||||
parts.add("qwerty");
|
||||
break;
|
||||
case Configuration.KEYBOARD_12KEY:
|
||||
parts.add("12key");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (config.navigationHidden) {
|
||||
case Configuration.NAVIGATIONHIDDEN_NO:
|
||||
parts.add("navexposed");
|
||||
break;
|
||||
case Configuration.NAVIGATIONHIDDEN_YES:
|
||||
parts.add("navhidden");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (config.navigation) {
|
||||
case Configuration.NAVIGATION_NONAV:
|
||||
parts.add("nonav");
|
||||
break;
|
||||
case Configuration.NAVIGATION_DPAD:
|
||||
parts.add("dpad");
|
||||
break;
|
||||
case Configuration.NAVIGATION_TRACKBALL:
|
||||
parts.add("trackball");
|
||||
break;
|
||||
case Configuration.NAVIGATION_WHEEL:
|
||||
parts.add("wheel");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
parts.add("v" + Build.VERSION.SDK_INT);
|
||||
return TextUtils.join("-", parts);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user