Merge "Show version in dumped info"

This commit is contained in:
Satoshi Kataoka 2013-10-29 02:43:08 +00:00 committed by Android (Google) Code Review
commit 40a3712a4c
2 changed files with 20 additions and 0 deletions

View file

@ -3276,6 +3276,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final Printer p = new PrintWriterPrinter(fout);
p.println("LatinIME state :");
p.println(" VersionCode = " + ApplicationUtils.getVersionCode(this));
p.println(" VersionName = " + ApplicationUtils.getVersionName(this));
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
p.println(" Keyboard mode = " + keyboardMode);

View file

@ -62,4 +62,22 @@ public final class ApplicationUtils {
}
return "";
}
/**
* A utility method to get the application's PackageInfo.versionCode
* @return the application's PackageInfo.versionCode
*/
public static int getVersionCode(final Context context) {
try {
if (context == null) {
return 0;
}
final String packageName = context.getPackageName();
final PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
return info.versionCode;
} catch (final NameNotFoundException e) {
Log.e(TAG, "Could not find version info.", e);
}
return 0;
}
}