-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PackageUtils and fix ReportActivity
- PackageUtils has been added to get various package related info. This will be used to get info based on Context objects instead of using BuildConfig which wouldn't have been available across termux plugins. - Support for getting Context objects of all termux plugin apps have been added to TermuxUtils. - Support for showing more details for the app has been added for ReportActivity. This will also allow app info of Termux app to be generated when TermuxUtils.getAppInfoMarkdownString() is called by a termux plugin so that both are shown so that devs/users can more easily detect compatibility issues. - ReportActivity has been fixed to also include report and device info instead of just the ExecutionCommand info when copying and sharing. - Moved the generation of markdown for ReportInfo to its own class and added creationTimestamp field. - Increased markdown headings size for some cases.
- Loading branch information
1 parent
d7ea770
commit 15eb56d
Showing
8 changed files
with
346 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
app/src/main/java/com/termux/app/utils/PackageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.termux.app.utils; | ||
|
||
import android.content.Context; | ||
import android.content.pm.ApplicationInfo; | ||
import android.content.pm.PackageInfo; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class PackageUtils { | ||
|
||
/** | ||
* Get the {@link Context} for the package name. | ||
* | ||
* @param context The {@link Context} to use to get the {@link Context} of the {@code packageName}. | ||
* @return Returns the {@link Context}. This will {@code null} if an exception is raised. | ||
*/ | ||
public static Context getContextForPackage(@NonNull final Context context, String packageName) { | ||
try { | ||
return context.createPackageContext(packageName, Context.CONTEXT_RESTRICTED); | ||
} catch (Exception e) { | ||
Logger.logStackTraceWithMessage("Failed to get \"" + packageName + "\" package context.", e); | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Get the {@link PackageInfo} for the package associated with the {@code context}. | ||
* | ||
* @param context The {@link Context} for the package. | ||
* @return Returns the {@link PackageInfo}. This will be {@code null} if an exception is raised. | ||
*/ | ||
public static PackageInfo getPackageInfoForPackage(@NonNull final Context context) { | ||
try { | ||
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0); | ||
} catch (final Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Get the app name for the package associated with the {@code context}. | ||
* | ||
* @param context The {@link Context} for the package. | ||
* @return Returns the {@code android:name} attribute. | ||
*/ | ||
public static String getAppNameForPackage(@NonNull final Context context) { | ||
return context.getApplicationInfo().loadLabel(context.getPackageManager()).toString(); | ||
} | ||
|
||
/** | ||
* Get the package name for the package associated with the {@code context}. | ||
* | ||
* @param context The {@link Context} for the package. | ||
* @return Returns the package name. | ||
*/ | ||
public static String getPackageNameForPackage(@NonNull final Context context) { | ||
return context.getApplicationInfo().packageName; | ||
} | ||
|
||
/** | ||
* Get the {@code targetSdkVersion} for the package associated with the {@code context}. | ||
* | ||
* @param context The {@link Context} for the package. | ||
* @return Returns the {@code targetSdkVersion}. | ||
*/ | ||
public static int getTargetSDKForPackage(@NonNull final Context context) { | ||
return context.getApplicationInfo().targetSdkVersion; | ||
} | ||
|
||
/** | ||
* Get the {@code versionName} for the package associated with the {@code context}. | ||
* | ||
* @param context The {@link Context} for the package. | ||
* @return Returns the {@code versionName}. This will be {@code null} if an exception is raised. | ||
*/ | ||
public static Boolean isAppForPackageADebugBuild(@NonNull final Context context) { | ||
return ( 0 != ( context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE ) ); | ||
} | ||
|
||
/** | ||
* Get the {@code versionCode} for the package associated with the {@code context}. | ||
* | ||
* @param context The {@link Context} for the package. | ||
* @return Returns the {@code versionCode}. This will be {@code null} if an exception is raised. | ||
*/ | ||
public static Integer getVersionCodeForPackage(@NonNull final Context context) { | ||
try { | ||
return getPackageInfoForPackage(context).versionCode; | ||
} catch (final Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Get the {@code versionName} for the package associated with the {@code context}. | ||
* | ||
* @param context The {@link Context} for the package. | ||
* @return Returns the {@code versionName}. This will be {@code null} if an exception is raised. | ||
*/ | ||
public static String getVersionNameForPackage(@NonNull final Context context) { | ||
try { | ||
return getPackageInfoForPackage(context).versionName; | ||
} catch (final Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.