Search in sources :

Example 16 with UserAppInfo

use of com.android.settings.applications.UserAppInfo in project android_packages_apps_Settings by LineageOS.

the class EnterpriseSetDefaultAppsListPreferenceController method buildAppList.

/**
 * Builds data for UI. Updates mUsers and mApps so that they contain non-empty list.
 */
private void buildAppList() {
    mUsers = new ArrayList<>();
    mApps = new ArrayList<>();
    for (UserHandle user : mUserFeatureProvider.getUserProfiles()) {
        boolean hasDefaultsForUser = false;
        EnumMap<EnterpriseDefaultApps, List<ApplicationInfo>> userMap = null;
        for (EnterpriseDefaultApps typeOfDefault : EnterpriseDefaultApps.values()) {
            List<UserAppInfo> apps = mApplicationFeatureProvider.findPersistentPreferredActivities(user.getIdentifier(), typeOfDefault.getIntents());
            if (apps.isEmpty()) {
                continue;
            }
            if (!hasDefaultsForUser) {
                hasDefaultsForUser = true;
                mUsers.add(apps.get(0).userInfo);
                userMap = new EnumMap<>(EnterpriseDefaultApps.class);
                mApps.add(userMap);
            }
            ArrayList<ApplicationInfo> applicationInfos = new ArrayList<>();
            for (UserAppInfo userAppInfo : apps) {
                applicationInfos.add(userAppInfo.appInfo);
            }
            userMap.put(typeOfDefault, applicationInfos);
        }
    }
    new Handler(mContext.getMainLooper()).post(() -> {
        updateUi();
    });
}
Also used : EnterpriseDefaultApps(com.android.settings.applications.EnterpriseDefaultApps) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) Handler(android.os.Handler) UserHandle(android.os.UserHandle) UserAppInfo(com.android.settings.applications.UserAppInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with UserAppInfo

use of com.android.settings.applications.UserAppInfo in project android_packages_apps_Settings by LineageOS.

the class EnterpriseSetDefaultAppsListPreferenceControllerTest method testMultipleAppsForOneTypeOfDefault.

@Test
public void testMultipleAppsForOneTypeOfDefault() {
    final UserInfo user = new UserInfo(USER_ID, "main", UserInfo.FLAG_ADMIN);
    final ApplicationInfo appInfo1 = ApplicationTestUtils.buildInfo(APP_UID, APP_1, 0, 0);
    final ApplicationInfo appInfo2 = ApplicationTestUtils.buildInfo(APP_UID, APP_2, 0, 0);
    when(mFeatureFactory.userFeatureProvider.getUserProfiles()).thenReturn(Arrays.asList(new UserHandle(USER_ID)));
    when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
    when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(anyInt(), any())).thenReturn(Collections.emptyList());
    when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(eq(USER_ID), eq(EnterpriseDefaultApps.BROWSER.getIntents()))).thenReturn(Arrays.asList(new UserAppInfo(user, appInfo1)));
    when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(eq(USER_ID), eq(EnterpriseDefaultApps.PHONE.getIntents()))).thenReturn(Arrays.asList(new UserAppInfo(user, appInfo1), new UserAppInfo(user, appInfo2)));
    new EnterpriseSetDefaultAppsListPreferenceController(mContext, mFragment, mPackageManager);
    ShadowApplication.runBackgroundTasks();
    ArgumentCaptor<Preference> apps = ArgumentCaptor.forClass(Preference.class);
    verify(mScreen, times(2)).addPreference(apps.capture());
    assertThat(apps.getAllValues().get(0).getTitle()).isEqualTo(BROWSER_TITLE);
    assertThat(apps.getAllValues().get(0).getSummary()).isEqualTo(APP_1);
    assertThat(apps.getAllValues().get(1).getTitle()).isEqualTo(PHONE_TITLE);
    assertThat(apps.getAllValues().get(1).getSummary()).isEqualTo(APP_1 + ", " + APP_2);
}
Also used : Preference(android.support.v7.preference.Preference) UserHandle(android.os.UserHandle) UserAppInfo(com.android.settings.applications.UserAppInfo) ApplicationInfo(android.content.pm.ApplicationInfo) UserInfo(android.content.pm.UserInfo) Test(org.junit.Test)

Example 18 with UserAppInfo

use of com.android.settings.applications.UserAppInfo in project android_packages_apps_Settings by DirtyUnicorns.

the class EnterpriseSetDefaultAppsPreferenceControllerTest method setEnterpriseSetDefaultApps.

private void setEnterpriseSetDefaultApps(Intent[] intents, int number) {
    final ApplicationInfo appInfo = new ApplicationInfo();
    appInfo.packageName = "app";
    for (int i = 0; i < number; i++) {
        final List<UserAppInfo> apps = new ArrayList<>(number);
        apps.add(new UserAppInfo(new UserInfo(i, "user." + i, UserInfo.FLAG_ADMIN), appInfo));
        when(mFeatureFactory.applicationFeatureProvider.findPersistentPreferredActivities(eq(i), argThat(matchesIntents(intents)))).thenReturn(apps);
    }
}
Also used : UserAppInfo(com.android.settings.applications.UserAppInfo) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo)

Example 19 with UserAppInfo

use of com.android.settings.applications.UserAppInfo in project android_packages_apps_Settings by DirtyUnicorns.

the class EnterpriseSetDefaultAppsListPreferenceController method buildAppList.

/**
 * Builds data for UI. Updates mUsers and mApps so that they contain non-empty list.
 */
private void buildAppList() {
    mUsers = new ArrayList<>();
    mApps = new ArrayList<>();
    for (UserHandle user : mUserFeatureProvider.getUserProfiles()) {
        boolean hasDefaultsForUser = false;
        EnumMap<EnterpriseDefaultApps, List<ApplicationInfo>> userMap = null;
        for (EnterpriseDefaultApps typeOfDefault : EnterpriseDefaultApps.values()) {
            List<UserAppInfo> apps = mApplicationFeatureProvider.findPersistentPreferredActivities(user.getIdentifier(), typeOfDefault.getIntents());
            if (apps.isEmpty()) {
                continue;
            }
            if (!hasDefaultsForUser) {
                hasDefaultsForUser = true;
                mUsers.add(apps.get(0).userInfo);
                userMap = new EnumMap<>(EnterpriseDefaultApps.class);
                mApps.add(userMap);
            }
            ArrayList<ApplicationInfo> applicationInfos = new ArrayList<>();
            for (UserAppInfo userAppInfo : apps) {
                applicationInfos.add(userAppInfo.appInfo);
            }
            userMap.put(typeOfDefault, applicationInfos);
        }
    }
    new Handler(mContext.getMainLooper()).post(() -> {
        updateUi();
    });
}
Also used : EnterpriseDefaultApps(com.android.settings.applications.EnterpriseDefaultApps) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) Handler(android.os.Handler) UserHandle(android.os.UserHandle) UserAppInfo(com.android.settings.applications.UserAppInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with UserAppInfo

use of com.android.settings.applications.UserAppInfo in project android_packages_apps_Settings by DirtyUnicorns.

the class ApplicationListPreferenceController method onListOfAppsResult.

@Override
public void onListOfAppsResult(List<UserAppInfo> result) {
    final PreferenceScreen screen = mParent.getPreferenceScreen();
    if (screen == null) {
        return;
    }
    final Context prefContext = mParent.getPreferenceManager().getContext();
    for (int position = 0; position < result.size(); position++) {
        final UserAppInfo item = result.get(position);
        final Preference preference = new Preference(prefContext);
        preference.setLayoutResource(R.layout.preference_app);
        preference.setTitle(item.appInfo.loadLabel(mPm));
        preference.setIcon(item.appInfo.loadIcon(mPm));
        preference.setOrder(position);
        preference.setSelectable(false);
        screen.addPreference(preference);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) UserAppInfo(com.android.settings.applications.UserAppInfo)

Aggregations

UserAppInfo (com.android.settings.applications.UserAppInfo)28 ApplicationInfo (android.content.pm.ApplicationInfo)21 UserInfo (android.content.pm.UserInfo)14 UserHandle (android.os.UserHandle)14 ArrayList (java.util.ArrayList)14 Preference (android.support.v7.preference.Preference)10 Context (android.content.Context)7 EnterpriseDefaultApps (com.android.settings.applications.EnterpriseDefaultApps)7 List (java.util.List)7 Test (org.junit.Test)7 Handler (android.os.Handler)5 PreferenceScreen (android.support.v7.preference.PreferenceScreen)5 Preference (androidx.preference.Preference)4 IconDrawableFactory (android.util.IconDrawableFactory)2 PreferenceScreen (androidx.preference.PreferenceScreen)2 AppPreference (com.android.settingslib.widget.AppPreference)1 AppPreference (com.android.settingslib.widget.apppreference.AppPreference)1