Skip to content

Request to Merge #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: parent20290
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions lib/utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,38 @@ public static int getAppIconId(final String packageName) {
}
}


/**
* Return true if this is the first ever time that the application is installed on the device.
*
* @return true if this is the first ever time that the application is installed on the device.
*/
public static boolean isFirstTimeInstall(){
try {
Long firstInstallTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).firstInstallTime;
Long lastUpdateTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).lastUpdateTime;
return firstInstallTime == lastUpdateTime;
} catch (Exception e) {
return false;
}
Comment on lines +394 to +400
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Error Handling severity potentially major

Add logging to exception handling in isFirstTimeInstall().

Tell me more

In the isFirstTimeInstall() method, you're catching a general Exception, but not logging any information about it. Consider adding a log statement to capture the exception details for debugging purposes. For example: Log.e("AppUtils", "Error checking first time install", e);

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

Comment on lines +394 to +400
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Functionality

Redundant calls to getPackageManager() and getPackageInfo().

Tell me more

In both 'isFirstTimeInstall' and 'isAppUpgraded' methods, you're calling getPackageManager() and getPackageInfo() twice to get the firstInstallTime and lastUpdateTime. This is redundant and could impact performance. Consider retrieving the PackageInfo object once and then accessing both times from it. This will make the code more efficient.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

}

/**
* Return true if app was previously installed and this one is an update/upgrade to that one, returns false if this is a fresh installation and not an update/upgrade.
*
* @return true if app was previously installed and this one is an update/upgrade to that one, returns false if this is a fresh installation and not an update/upgrade.
*/
public static boolean isAppUpgraded(){
try {
Long firstInstallTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).firstInstallTime;
Long lastUpdateTime = Utils.getApp().getPackageManager().getPackageInfo(this.getAppPackageName(), 0).lastUpdateTime;
return firstInstallTime != lastUpdateTime;
} catch (Exception e) {
return false;
}
Comment on lines +409 to +415
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Error Handling severity potentially major

Add logging for exceptions in isAppUpgraded() method.

Tell me more

In the isAppUpgraded() method, you're catching a general Exception without logging any information about it. It's recommended to add a log statement to capture the exception details for debugging. For example: Log.e("AppUtils", "Error checking if app is upgraded", e);

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

}


/**
* Return the application's package name.
*
Expand Down