Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55038c0a authored by Bartosz Fabianowski's avatar Bartosz Fabianowski
Browse files

Hide "Changes made by your organization's admin" when empty

The admin of a manged device can take a number actions that will be
listed in the "Changes made by your organization's admin" section of
Settings. If the admin has not taken any such actions, the section
will be empty and should be hidden. This is accomplished by having a
PreferenceController for the section that observes the state of the
PreferenceControllers inside it.

Bug: 35912953
Test: m RunSettingsRoboTests

Change-Id: Ia95754493ee6c5a19b4aa9731fd56fd558e61849
parent c62ce670
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -45,7 +45,8 @@
                    android:selectable="false"/>
    </PreferenceCategory>

    <PreferenceCategory android:title="@string/enterprise_privacy_exposure_changes_category">
    <PreferenceCategory android:title="@string/enterprise_privacy_exposure_changes_category"
                        android:key="exposure_changes_category">
        <Preference android:fragment="com.android.settings.enterprise.ApplicationListFragment$EnterpriseInstalledPackages"
                    android:key="number_enterprise_installed_packages"
                    android:title="@string/enterprise_privacy_enterprise_installed_packages"/>
+15 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ public abstract class DynamicAvailabilityPreferenceController extends Preference

    private Preference mPreference;
    private PreferenceScreen mScreen;
    private PreferenceAvailabilityObserver mAvailabilityObserver = null;

    public DynamicAvailabilityPreferenceController(Context context, Lifecycle lifecycle) {
        super(context);
@@ -37,6 +38,14 @@ public abstract class DynamicAvailabilityPreferenceController extends Preference
        }
    }

    public void setAvailabilityObserver(PreferenceAvailabilityObserver observer) {
        mAvailabilityObserver = observer;
    }

    public PreferenceAvailabilityObserver getAvailabilityObserver() {
        return mAvailabilityObserver;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        mScreen = screen;
@@ -56,4 +65,10 @@ public abstract class DynamicAvailabilityPreferenceController extends Preference
            mScreen.addPreference(mPreference);
        }
    }

    protected void notifyOnAvailabilityUpdate(boolean available) {
        if (mAvailabilityObserver != null) {
            mAvailabilityObserver.onPreferenceAvailabilityUpdated(getPreferenceKey(), available);
        }
    }
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.core;

/**
 * @deprecated This interface allows a {@link android.support.v7.preference.PreferenceGroup}'s
 * controller to observe the availability of the {@link android.support.v7.preference.Preference}s
 * inside it, hiding the group when all preferences become unavailable. In the future,
 * {@link android.support.v7.preference.PreferenceGroup} will have native support for that
 * functionality, removing the need for this interface.
 */
public interface PreferenceAvailabilityObserver {

    /**
     * Notifies the observer that the availability of the preference identified by {@code key} has
     * been updated.
     */
    void onPreferenceAvailabilityUpdated(String key, boolean available);
}
+3 −2
Original line number Diff line number Diff line
@@ -50,15 +50,15 @@ public abstract class AdminGrantedPermissionsPreferenceControllerBase
                true /* async */,
                (num) -> {
                    if (num == 0) {
                        preference.setVisible(false);
                        mHasApps = false;
                    } else {
                        preference.setVisible(true);
                        preference.setSummary(mContext.getResources().getQuantityString(
                                R.plurals.enterprise_privacy_number_packages_lower_bound,
                                num, num));
                        mHasApps = true;
                    }
                    preference.setVisible(mHasApps);
                    notifyOnAvailabilityUpdate(mHasApps);
                });
    }

@@ -80,6 +80,7 @@ public abstract class AdminGrantedPermissionsPreferenceControllerBase
        mFeatureProvider.calculateNumberOfAppsWithAdminGrantedPermissions(mPermissions,
                false /* async */, (num) -> haveAppsWithAdminGrantedPermissions[0] = num > 0);
        mHasApps = haveAppsWithAdminGrantedPermissions[0];
        notifyOnAvailabilityUpdate(mHasApps);
        return mHasApps;
    }

+3 −1
Original line number Diff line number Diff line
@@ -42,7 +42,9 @@ public class AlwaysOnVpnCurrentUserPreferenceController

    @Override
    public boolean isAvailable() {
        return mFeatureProvider.isAlwaysOnVpnSetInCurrentUser();
        final boolean available = mFeatureProvider.isAlwaysOnVpnSetInCurrentUser();
        notifyOnAvailabilityUpdate(available);
        return available;
    }

    @Override
Loading