Skip to content

Commit

Permalink
Exposing packageName and versionCode in getDeviceInfo()
Browse files Browse the repository at this point in the history
Ticket: medic/cht-core#6741

This commit will:
- Add more info to getDeviceInfo() method that will be used in about page, new properties are: packageName and versionCode.
  • Loading branch information
latin-panda authored Jun 11, 2021
1 parent c968045 commit 615d947
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.app.DatePickerDialog;
import android.content.pm.PackageInfo;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
Expand Down Expand Up @@ -223,11 +224,15 @@ public String getDeviceInfo() {
return jsonError("ConnectivityManager not set. Cannot retrieve network info.");
}

String versionName = parent.getPackageManager()
.getPackageInfo(parent.getPackageName(), 0)
.versionName;
PackageInfo packageInfo = parent
.getPackageManager()
.getPackageInfo(parent.getPackageName(), 0);
long versionCode = Build.VERSION.SDK_INT < Build.VERSION_CODES.P ? (long)packageInfo.versionCode : packageInfo.getLongVersionCode();

JSONObject appObject = new JSONObject();
appObject.put("version", versionName);
appObject.put("version", packageInfo.versionName);
appObject.put("packageName", packageInfo.packageName);
appObject.put("versionCode", versionCode);

String androidVersion = Build.VERSION.RELEASE;
int osApiLevel = Build.VERSION.SDK_INT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.app.DatePickerDialog;
import android.content.pm.PackageInfo;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
Expand Down Expand Up @@ -235,11 +236,15 @@ public String getDeviceInfo() {
return jsonError("ConnectivityManager not set. Cannot retrieve network info.");
}

String versionName = parent.getPackageManager()
.getPackageInfo(parent.getPackageName(), 0)
.versionName;
PackageInfo packageInfo = parent
.getPackageManager()
.getPackageInfo(parent.getPackageName(), 0);
long versionCode = Build.VERSION.SDK_INT < Build.VERSION_CODES.P ? (long)packageInfo.versionCode : packageInfo.getLongVersionCode();

JSONObject appObject = new JSONObject();
appObject.put("version", versionName);
appObject.put("version", packageInfo.versionName);
appObject.put("packageName", packageInfo.packageName);
appObject.put("versionCode", versionCode);

String androidVersion = Build.VERSION.RELEASE;
int osApiLevel = Build.VERSION.SDK_INT;
Expand Down

0 comments on commit 615d947

Please sign in to comment.