Search in sources :

Example 36 with VisibleForTesting

use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppButtonsPreferenceController method refreshUi.

@VisibleForTesting
boolean refreshUi() {
    if (mPackageName == null) {
        return false;
    }
    retrieveAppEntry();
    if (mAppEntry == null || mPackageInfo == null) {
        return false;
    }
    // Get list of "home" apps and trace through any meta-data references
    List<ResolveInfo> homeActivities = new ArrayList<>();
    mPm.getHomeActivities(homeActivities);
    mHomePackages.clear();
    for (int i = 0, size = homeActivities.size(); i < size; i++) {
        ResolveInfo ri = homeActivities.get(i);
        final String activityPkg = ri.activityInfo.packageName;
        mHomePackages.add(activityPkg);
        // Also make sure to include anything proxying for the home app
        final Bundle metadata = ri.activityInfo.metaData;
        if (metadata != null) {
            final String metaPkg = metadata.getString(ActivityManager.META_HOME_ALTERNATE);
            if (signaturesMatch(metaPkg, activityPkg)) {
                mHomePackages.add(metaPkg);
            }
        }
    }
    updateOpenButton();
    updateUninstallButton();
    updateForceStopButton();
    return true;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 37 with VisibleForTesting

use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppButtonsPreferenceController method updateForceStopButton.

@VisibleForTesting
void updateForceStopButton() {
    if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
        // User can't force stop device admin.
        Log.w(TAG, "User can't force stop device admin");
        updateForceStopButtonInner(false);
    } else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_STOPPED) == 0) {
        // If the app isn't explicitly stopped, then always show the
        // force stop button.
        Log.w(TAG, "App is not explicitly stopped");
        updateForceStopButtonInner(true);
    } else {
        Intent intent = new Intent(Intent.ACTION_QUERY_PACKAGE_RESTART, Uri.fromParts("package", mAppEntry.info.packageName, null));
        intent.putExtra(Intent.EXTRA_PACKAGES, new String[] { mAppEntry.info.packageName });
        intent.putExtra(Intent.EXTRA_UID, mAppEntry.info.uid);
        intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(mAppEntry.info.uid));
        Log.d(TAG, "Sending broadcast to query restart status for " + mAppEntry.info.packageName);
        mActivity.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null, mCheckKillProcessesReceiver, null, Activity.RESULT_CANCELED, null, null);
    }
}
Also used : Intent(android.content.Intent) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 38 with VisibleForTesting

use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppButtonsPreferenceController method uninstallPkg.

@VisibleForTesting
void uninstallPkg(String packageName, boolean allUsers, boolean andDisable) {
    stopListeningToPackageRemove();
    // Create new intent to launch Uninstaller activity
    Uri packageUri = Uri.parse("package:" + packageName);
    Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
    uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, allUsers);
    mMetricsFeatureProvider.action(mActivity, SettingsEnums.ACTION_SETTINGS_UNINSTALL_APP);
    mFragment.startActivityForResult(uninstallIntent, mRequestUninstall);
    mDisableAfterUninstall = andDisable;
}
Also used : Intent(android.content.Intent) Uri(android.net.Uri) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 39 with VisibleForTesting

use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppButtonsPreferenceController method updateUninstallButton.

@VisibleForTesting
void updateUninstallButton() {
    final boolean isBundled = (mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
    boolean enabled = true;
    if (isBundled) {
        enabled = handleDisableable();
    } else {
        if ((mPackageInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0 && mUserManager.getUsers().size() >= 2) {
            // When we have multiple users, there is a separate menu
            // to uninstall for all users.
            enabled = false;
        }
    }
    // We do this here so the text of the button is still set correctly.
    if (isBundled && mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
        enabled = false;
    }
    // will clear data on all users.
    if (Utils.isProfileOrDeviceOwner(mUserManager, mDpm, mPackageInfo.packageName)) {
        enabled = false;
    }
    // Don't allow uninstalling the device provisioning package.
    if (Utils.isDeviceProvisioningPackage(mContext.getResources(), mAppEntry.info.packageName)) {
        enabled = false;
    }
    // If the uninstall intent is already queued, disable the uninstall button
    if (mDpm.isUninstallInQueue(mPackageName)) {
        enabled = false;
    }
    // uninstallation of the now-not-default one.
    if (enabled && mHomePackages.contains(mPackageInfo.packageName)) {
        if (isBundled) {
            enabled = false;
        } else {
            ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
            ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);
            if (currentDefaultHome == null) {
                // No preferred default, so permit uninstall only when
                // there is more than one candidate
                enabled = (mHomePackages.size() > 1);
            } else {
                // There is an explicit default home app -- forbid uninstall of
                // that one, but permit it for installed-but-inactive ones.
                enabled = !mPackageInfo.packageName.equals(currentDefaultHome.getPackageName());
            }
        }
    }
    if (mAppsControlDisallowedBySystem) {
        enabled = false;
    }
    // system/vendor, they can never be uninstalled. :-(
    if (mAppEntry.info.isResourceOverlay()) {
        if (isBundled) {
            enabled = false;
        } else {
            String pkgName = mAppEntry.info.packageName;
            UserHandle user = UserHandle.getUserHandleForUid(mAppEntry.info.uid);
            OverlayInfo overlayInfo = mOverlayManager.getOverlayInfo(pkgName, user);
            if (overlayInfo != null && overlayInfo.isEnabled()) {
                ApplicationsState.AppEntry targetEntry = mState.getEntry(overlayInfo.targetPackageName, UserHandle.getUserId(mAppEntry.info.uid));
                if (targetEntry != null) {
                    enabled = false;
                }
            }
        }
    }
    mButtonsPref.setButton2Enabled(enabled);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ApplicationsState(com.android.settingslib.applications.ApplicationsState) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) OverlayInfo(android.content.om.OverlayInfo) ComponentName(android.content.ComponentName) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 40 with VisibleForTesting

use of androidx.annotation.VisibleForTesting in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ManageApplications method createHeader.

@VisibleForTesting
void createHeader() {
    final Activity activity = getActivity();
    final FrameLayout pinnedHeader = mRootView.findViewById(R.id.pinned_header);
    mSpinnerHeader = activity.getLayoutInflater().inflate(R.layout.apps_filter_spinner, pinnedHeader, false);
    mFilterSpinner = mSpinnerHeader.findViewById(R.id.filter_spinner);
    mFilterAdapter = new FilterSpinnerAdapter(this);
    mFilterSpinner.setAdapter(mFilterAdapter);
    mFilterSpinner.setOnItemSelectedListener(this);
    pinnedHeader.addView(mSpinnerHeader, 0);
    final AppFilterRegistry appFilterRegistry = AppFilterRegistry.getInstance();
    mFilterAdapter.enableFilter(appFilterRegistry.getDefaultFilterType(mListType));
    if (mListType == LIST_TYPE_MAIN) {
        if (UserManager.get(getActivity()).getUserProfiles().size() > 1) {
            mFilterAdapter.enableFilter(FILTER_APPS_PERSONAL);
            mFilterAdapter.enableFilter(FILTER_APPS_WORK);
        }
    }
    if (mListType == LIST_TYPE_NOTIFICATION) {
        mFilterAdapter.enableFilter(FILTER_APPS_RECENT);
        mFilterAdapter.enableFilter(FILTER_APPS_FREQUENT);
        mFilterAdapter.enableFilter(FILTER_APPS_BLOCKED);
        mFilterAdapter.disableFilter(FILTER_APPS_ALL);
    }
    if (mListType == LIST_TYPE_HIGH_POWER) {
        mFilterAdapter.enableFilter(FILTER_APPS_POWER_WHITELIST_ALL);
    }
    AppFilter compositeFilter = getCompositeFilter(mListType, mStorageType, mVolumeUuid);
    if (mIsWorkOnly) {
        final AppFilter workFilter = appFilterRegistry.get(FILTER_APPS_WORK).getFilter();
        compositeFilter = new CompoundFilter(compositeFilter, workFilter);
    }
    if (compositeFilter != null) {
        mApplications.setCompositeFilter(compositeFilter);
    }
}
Also used : AppFilter(com.android.settingslib.applications.ApplicationsState.AppFilter) FrameLayout(android.widget.FrameLayout) PreferenceFrameLayout(android.preference.PreferenceFrameLayout) GamesStorageActivity(com.android.settings.Settings.GamesStorageActivity) UsageAccessSettingsActivity(com.android.settings.Settings.UsageAccessSettingsActivity) WriteSettingsActivity(com.android.settings.Settings.WriteSettingsActivity) HighPowerApplicationsActivity(com.android.settings.Settings.HighPowerApplicationsActivity) SettingsActivity(com.android.settings.SettingsActivity) StorageUseActivity(com.android.settings.Settings.StorageUseActivity) OverlaySettingsActivity(com.android.settings.Settings.OverlaySettingsActivity) MoviesStorageActivity(com.android.settings.Settings.MoviesStorageActivity) ManageExternalSourcesActivity(com.android.settings.Settings.ManageExternalSourcesActivity) Activity(android.app.Activity) CompoundFilter(com.android.settingslib.applications.ApplicationsState.CompoundFilter) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

VisibleForTesting (androidx.annotation.VisibleForTesting)385 Intent (android.content.Intent)36 ArrayList (java.util.ArrayList)36 Context (android.content.Context)34 Bundle (android.os.Bundle)30 Uri (android.net.Uri)18 View (android.view.View)18 Preference (androidx.preference.Preference)18 TextView (android.widget.TextView)16 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)16 MetricsFeatureProvider (com.android.settingslib.core.instrumentation.MetricsFeatureProvider)16 SuppressLint (android.annotation.SuppressLint)15 Activity (android.app.Activity)14 RemoteException (android.os.RemoteException)14 SubscriptionInfo (android.telephony.SubscriptionInfo)12 ImageView (android.widget.ImageView)12 BluetoothDevice (android.bluetooth.BluetoothDevice)11 ComponentName (android.content.ComponentName)11 Drawable (android.graphics.drawable.Drawable)11 SharedPreferences (android.content.SharedPreferences)10