Search in sources :

Example 1 with InstallSourceInfo

use of android.content.pm.InstallSourceInfo in project android_packages_apps_Settings by omnirom.

the class InstantAppButtonsPreferenceControllerTest method setUp.

@Before
public void setUp() throws PackageManager.NameNotFoundException {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    when(mContext.getPackageManager()).thenReturn(mPackageManager);
    final PackageInfo packageInfo = mock(PackageInfo.class);
    packageInfo.applicationInfo = mAppInfo;
    when(mFragment.getPackageInfo()).thenReturn(packageInfo);
    mPreferenceManager = new PreferenceManager(mContext);
    mScreen = mPreferenceManager.createPreferenceScreen(mContext);
    when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
    final View buttons = View.inflate(RuntimeEnvironment.application, R.layout.instant_app_buttons, null);
    mLaunchButton = buttons.findViewById(R.id.launch);
    mInstallButton = buttons.findViewById(R.id.install);
    mClearAppButton = buttons.findViewById(R.id.clear_data);
    mController = spy(new InstantAppButtonsPreferenceController(mContext, mFragment, TEST_AIA_PACKAGE_NAME, null));
    when(mPreference.getKey()).thenReturn("instant_app_buttons");
    mScreen.addPreference(mPreference);
    when(mPreference.findViewById(R.id.instant_app_button_container)).thenReturn(buttons);
    final InstallSourceInfo installSourceInfo = mock(InstallSourceInfo.class);
    when(mPackageManager.getInstallSourceInfo(TEST_AIA_PACKAGE_NAME)).thenReturn(installSourceInfo);
    when(installSourceInfo.getInstallingPackageName()).thenReturn(TEST_INSTALLER_PACKAGE_NAME);
}
Also used : PackageInfo(android.content.pm.PackageInfo) InstallSourceInfo(android.content.pm.InstallSourceInfo) PreferenceManager(androidx.preference.PreferenceManager) View(android.view.View) Before(org.junit.Before)

Example 2 with InstallSourceInfo

use of android.content.pm.InstallSourceInfo in project quickstart-android by firebase.

the class CustomKeySamples method getInstallSource.

/**
 * Retrieve the install source and return it as a string.
 *
 * Supressed deprecation warning because that code path is only used below API level R.
 */
public String getInstallSource() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        try {
            InstallSourceInfo info = context.getPackageManager().getInstallSourceInfo(context.getPackageName());
            String originating = info.getOriginatingPackageName() == null ? "None" : info.getOriginatingPackageName();
            String installing = info.getInstallingPackageName() == null ? "None" : info.getInstallingPackageName();
            String initiating = info.getInitiatingPackageName() == null ? "None" : info.getInitiatingPackageName();
            // source.
            return "Originating: " + originating + ", Installing: " + installing + ", Initiating: " + initiating;
        } catch (PackageManager.NameNotFoundException e) {
            return "Unknown";
        }
    }
    String installerPackageName = context.getPackageManager().getInstallerPackageName(context.getPackageName());
    return installerPackageName == null ? "None" : installerPackageName;
}
Also used : PackageManager(android.content.pm.PackageManager) InstallSourceInfo(android.content.pm.InstallSourceInfo)

Example 3 with InstallSourceInfo

use of android.content.pm.InstallSourceInfo in project android_packages_apps_Settings by omnirom.

the class AppStoreUtil method getInstallerPackageName.

// Returns the package name of the app that we consider to be the user-visible 'installer'
// of given packageName, if one is available.
public static String getInstallerPackageName(Context context, String packageName) {
    String installerPackageName;
    try {
        InstallSourceInfo source = context.getPackageManager().getInstallSourceInfo(packageName);
        // By default, use the installing package name.
        installerPackageName = source.getInstallingPackageName();
        // Use the recorded originating package name only if the initiating package is a system
        // app (eg. Package Installer). The originating package is not verified by the platform,
        // so we choose to ignore this when supplied by a non-system app.
        String originatingPackageName = source.getOriginatingPackageName();
        String initiatingPackageName = source.getInitiatingPackageName();
        if (originatingPackageName != null && initiatingPackageName != null) {
            ApplicationInfo ai = context.getPackageManager().getApplicationInfo(initiatingPackageName, 0);
            if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                installerPackageName = originatingPackageName;
            }
        }
    } catch (NameNotFoundException e) {
        Log.e(LOG_TAG, "Exception while retrieving the package installer of " + packageName, e);
        installerPackageName = null;
    }
    return installerPackageName;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) InstallSourceInfo(android.content.pm.InstallSourceInfo)

Aggregations

InstallSourceInfo (android.content.pm.InstallSourceInfo)3 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 View (android.view.View)1 PreferenceManager (androidx.preference.PreferenceManager)1 Before (org.junit.Before)1