am 40a3712a: Merge "Show version in dumped info"

* commit '40a3712a4c3e64fc074033ca8e20cc3a6175bcb6':
  Show version in dumped info
main
Satoshi Kataoka 2013-10-28 19:44:28 -07:00 committed by Android Git Automerger
commit 69a0b5374f
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); final Printer p = new PrintWriterPrinter(fout);
p.println("LatinIME state :"); p.println("LatinIME state :");
p.println(" VersionCode = " + ApplicationUtils.getVersionCode(this));
p.println(" VersionName = " + ApplicationUtils.getVersionName(this));
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1; final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
p.println(" Keyboard mode = " + keyboardMode); p.println(" Keyboard mode = " + keyboardMode);

View File

@ -62,4 +62,22 @@ public final class ApplicationUtils {
} }
return ""; 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;
}
} }