Loading packages/PackageInstaller/src/com/android/packageinstaller/InstallStart.java +4 −15 Original line number Diff line number Diff line Loading @@ -51,7 +51,6 @@ import java.util.Arrays; public class InstallStart extends Activity { private static final String TAG = InstallStart.class.getSimpleName(); private static final String DOWNLOADS_AUTHORITY = "downloads"; private static final int DLG_INSTALL_APPS_RESTRICTED_FOR_USER = 1; private static final int DLG_UNKNOWN_SOURCES_RESTRICTED_FOR_USER = 2; Loading Loading @@ -103,6 +102,8 @@ public class InstallStart extends Activity { boolean isDocumentsManager = checkPermission(Manifest.permission.MANAGE_DOCUMENTS, -1, callingUid) == PackageManager.PERMISSION_GRANTED; boolean isSystemDownloadsProvider = PackageUtil.getSystemDownloadsProviderInfo( mPackageManager, callingUid) != null; boolean isTrustedSource = false; if (sourceInfo != null && sourceInfo.isPrivilegedApp()) { isTrustedSource = intent.getBooleanExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, false) || ( Loading @@ -111,7 +112,7 @@ public class InstallStart extends Activity { == PackageManager.PERMISSION_GRANTED); } if (!isTrustedSource && !isSystemDownloadsProvider(callingUid) && !isDocumentsManager if (!isTrustedSource && !isSystemDownloadsProvider && !isDocumentsManager && originatingUid != Process.INVALID_UID) { final int targetSdkVersion = getMaxTargetSdkVersionForUid(this, originatingUid); if (targetSdkVersion < 0) { Loading Loading @@ -241,17 +242,6 @@ public class InstallStart extends Activity { return null; } private boolean isSystemDownloadsProvider(int uid) { final ProviderInfo downloadProviderPackage = getPackageManager().resolveContentProvider( DOWNLOADS_AUTHORITY, 0); if (downloadProviderPackage == null) { // There seems to be no currently enabled downloads provider on the system. return false; } final ApplicationInfo appInfo = downloadProviderPackage.applicationInfo; return ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 && uid == appInfo.uid); } @NonNull private boolean canPackageQuery(int callingUid, Uri packageUri) { Loading Loading @@ -346,7 +336,6 @@ public class InstallStart extends Activity { * Create a new dialog. * * @param id The id of the dialog (determines dialog type) * * @return The dialog */ private DialogFragment createDialog(int id) { Loading packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java +9 −0 Original line number Diff line number Diff line Loading @@ -265,6 +265,15 @@ public class PackageInstallerActivity extends AlertActivity { } private String getPackageNameForUid(int sourceUid) { // If the sourceUid belongs to the system downloads provider, we explicitly return the // name of the Download Manager package. This is because its UID is shared with multiple // packages, resulting in uncertainty about which package will end up first in the list // of packages associated with this UID ApplicationInfo systemDownloadProviderInfo = PackageUtil.getSystemDownloadsProviderInfo( mPm, sourceUid); if (systemDownloadProviderInfo != null) { return systemDownloadProviderInfo.packageName; } String[] packagesForUid = mPm.getPackagesForUid(sourceUid); if (packagesForUid == null) { return null; Loading packages/PackageInstaller/src/com/android/packageinstaller/PackageUtil.java +25 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.content.DialogInterface; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; Loading @@ -48,7 +49,7 @@ import java.io.IOException; * used in the package installer application. */ public class PackageUtil { private static final String LOG_TAG = PackageUtil.class.getSimpleName(); private static final String LOG_TAG = "PackageInstaller"; public static final String PREFIX="com.android.packageinstaller."; public static final String INTENT_ATTR_INSTALL_STATUS = PREFIX+"installStatus"; Loading @@ -56,6 +57,7 @@ public class PackageUtil { public static final String INTENT_ATTR_PERMISSIONS_LIST=PREFIX+"PermissionsList"; //intent attribute strings related to uninstall public static final String INTENT_ATTR_PACKAGE_NAME=PREFIX+"PackageName"; private static final String DOWNLOADS_AUTHORITY = "downloads"; /** * Utility method to get package information for a given {@link File} Loading Loading @@ -245,4 +247,26 @@ public class PackageUtil { getActivity().finish(); } } /** * Determines if the UID belongs to the system downloads provider and returns the * {@link ApplicationInfo} of the provider * * @param uid UID of the caller * @return {@link ApplicationInfo} of the provider if a downloads provider exists, * it is a system app, and its UID matches with the passed UID, null otherwise. */ public static ApplicationInfo getSystemDownloadsProviderInfo(PackageManager pm, int uid) { final ProviderInfo providerInfo = pm.resolveContentProvider( DOWNLOADS_AUTHORITY, 0); if (providerInfo == null) { // There seems to be no currently enabled downloads provider on the system. return null; } ApplicationInfo appInfo = providerInfo.applicationInfo; if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 && uid == appInfo.uid) { return appInfo; } return null; } } Loading
packages/PackageInstaller/src/com/android/packageinstaller/InstallStart.java +4 −15 Original line number Diff line number Diff line Loading @@ -51,7 +51,6 @@ import java.util.Arrays; public class InstallStart extends Activity { private static final String TAG = InstallStart.class.getSimpleName(); private static final String DOWNLOADS_AUTHORITY = "downloads"; private static final int DLG_INSTALL_APPS_RESTRICTED_FOR_USER = 1; private static final int DLG_UNKNOWN_SOURCES_RESTRICTED_FOR_USER = 2; Loading Loading @@ -103,6 +102,8 @@ public class InstallStart extends Activity { boolean isDocumentsManager = checkPermission(Manifest.permission.MANAGE_DOCUMENTS, -1, callingUid) == PackageManager.PERMISSION_GRANTED; boolean isSystemDownloadsProvider = PackageUtil.getSystemDownloadsProviderInfo( mPackageManager, callingUid) != null; boolean isTrustedSource = false; if (sourceInfo != null && sourceInfo.isPrivilegedApp()) { isTrustedSource = intent.getBooleanExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, false) || ( Loading @@ -111,7 +112,7 @@ public class InstallStart extends Activity { == PackageManager.PERMISSION_GRANTED); } if (!isTrustedSource && !isSystemDownloadsProvider(callingUid) && !isDocumentsManager if (!isTrustedSource && !isSystemDownloadsProvider && !isDocumentsManager && originatingUid != Process.INVALID_UID) { final int targetSdkVersion = getMaxTargetSdkVersionForUid(this, originatingUid); if (targetSdkVersion < 0) { Loading Loading @@ -241,17 +242,6 @@ public class InstallStart extends Activity { return null; } private boolean isSystemDownloadsProvider(int uid) { final ProviderInfo downloadProviderPackage = getPackageManager().resolveContentProvider( DOWNLOADS_AUTHORITY, 0); if (downloadProviderPackage == null) { // There seems to be no currently enabled downloads provider on the system. return false; } final ApplicationInfo appInfo = downloadProviderPackage.applicationInfo; return ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 && uid == appInfo.uid); } @NonNull private boolean canPackageQuery(int callingUid, Uri packageUri) { Loading Loading @@ -346,7 +336,6 @@ public class InstallStart extends Activity { * Create a new dialog. * * @param id The id of the dialog (determines dialog type) * * @return The dialog */ private DialogFragment createDialog(int id) { Loading
packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java +9 −0 Original line number Diff line number Diff line Loading @@ -265,6 +265,15 @@ public class PackageInstallerActivity extends AlertActivity { } private String getPackageNameForUid(int sourceUid) { // If the sourceUid belongs to the system downloads provider, we explicitly return the // name of the Download Manager package. This is because its UID is shared with multiple // packages, resulting in uncertainty about which package will end up first in the list // of packages associated with this UID ApplicationInfo systemDownloadProviderInfo = PackageUtil.getSystemDownloadsProviderInfo( mPm, sourceUid); if (systemDownloadProviderInfo != null) { return systemDownloadProviderInfo.packageName; } String[] packagesForUid = mPm.getPackagesForUid(sourceUid); if (packagesForUid == null) { return null; Loading
packages/PackageInstaller/src/com/android/packageinstaller/PackageUtil.java +25 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.content.DialogInterface; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; Loading @@ -48,7 +49,7 @@ import java.io.IOException; * used in the package installer application. */ public class PackageUtil { private static final String LOG_TAG = PackageUtil.class.getSimpleName(); private static final String LOG_TAG = "PackageInstaller"; public static final String PREFIX="com.android.packageinstaller."; public static final String INTENT_ATTR_INSTALL_STATUS = PREFIX+"installStatus"; Loading @@ -56,6 +57,7 @@ public class PackageUtil { public static final String INTENT_ATTR_PERMISSIONS_LIST=PREFIX+"PermissionsList"; //intent attribute strings related to uninstall public static final String INTENT_ATTR_PACKAGE_NAME=PREFIX+"PackageName"; private static final String DOWNLOADS_AUTHORITY = "downloads"; /** * Utility method to get package information for a given {@link File} Loading Loading @@ -245,4 +247,26 @@ public class PackageUtil { getActivity().finish(); } } /** * Determines if the UID belongs to the system downloads provider and returns the * {@link ApplicationInfo} of the provider * * @param uid UID of the caller * @return {@link ApplicationInfo} of the provider if a downloads provider exists, * it is a system app, and its UID matches with the passed UID, null otherwise. */ public static ApplicationInfo getSystemDownloadsProviderInfo(PackageManager pm, int uid) { final ProviderInfo providerInfo = pm.resolveContentProvider( DOWNLOADS_AUTHORITY, 0); if (providerInfo == null) { // There seems to be no currently enabled downloads provider on the system. return null; } ApplicationInfo appInfo = providerInfo.applicationInfo; if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 && uid == appInfo.uid) { return appInfo; } return null; } }