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

Commit b5f5ffbe authored by Fan Zhang's avatar Fan Zhang
Browse files

Remove DynamicAvailabilityPreferenceController.

- This class is over complex to use, and get in the way of show/hide
  pref when availability change.
- The function from DynamicAvailabilityPreferenceController can be done
  with PreferenceCategoryController.

Bug: 68956750
Bug: 32953042
Test: robotests
Change-Id: Ia7b7e214c072b8c77f5de3d959fdb1dc79217f76
parent 2260321f
Loading
Loading
Loading
Loading
+0 −75
Original line number Original line 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;

import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;

import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnResume;

public abstract class DynamicAvailabilityPreferenceController extends AbstractPreferenceController
        implements PreferenceControllerMixin, LifecycleObserver, OnResume {

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

    public DynamicAvailabilityPreferenceController(Context context, Lifecycle lifecycle) {
        super(context);
        if (lifecycle != null) {
            lifecycle.addObserver(this);
        }
    }

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

    public PreferenceAvailabilityObserver getAvailabilityObserver() {
        return mAvailabilityObserver;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        mScreen = screen;
        mPreference = screen.findPreference(getPreferenceKey());
        super.displayPreference(screen);
    }

    @Override
    public void onResume() {
        if (!isAvailable()) {
            removePreference(mScreen, getPreferenceKey());
            return;
        }

        updateState(mPreference);
        if (mScreen.findPreference(getPreferenceKey()) == null) {
            mScreen.addPreference(mPreference);
        }
    }

    protected void notifyOnAvailabilityUpdate(boolean available) {
        if (mAvailabilityObserver != null) {
            mAvailabilityObserver.onPreferenceAvailabilityUpdated(getPreferenceKey(), available);
        }
    }
}
+0 −33
Original line number Original line 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);
}
+2 −6
Original line number Original line Diff line number Diff line
@@ -17,18 +17,14 @@ package com.android.settings.enterprise;
import android.Manifest;
import android.Manifest;
import android.content.Context;
import android.content.Context;


import com.android.settingslib.core.lifecycle.Lifecycle;

public class AdminGrantedCameraPermissionPreferenceController extends
public class AdminGrantedCameraPermissionPreferenceController extends
        AdminGrantedPermissionsPreferenceControllerBase {
        AdminGrantedPermissionsPreferenceControllerBase {


    private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_CAMERA_ACCESS_PACKAGES
    private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_CAMERA_ACCESS_PACKAGES
            = "enterprise_privacy_number_camera_access_packages";
            = "enterprise_privacy_number_camera_access_packages";


    public AdminGrantedCameraPermissionPreferenceController(Context context, Lifecycle lifecycle,
    public AdminGrantedCameraPermissionPreferenceController(Context context, boolean async) {
            boolean async) {
        super(context, async, new String[] {Manifest.permission.CAMERA});
        super(context, lifecycle, async, new String[] {Manifest.permission.CAMERA},
                Manifest.permission_group.CAMERA);
    }
    }


    @Override
    @Override
+3 −6
Original line number Original line Diff line number Diff line
@@ -17,18 +17,15 @@ package com.android.settings.enterprise;
import android.Manifest;
import android.Manifest;
import android.content.Context;
import android.content.Context;


import com.android.settingslib.core.lifecycle.Lifecycle;

public class AdminGrantedLocationPermissionsPreferenceController extends
public class AdminGrantedLocationPermissionsPreferenceController extends
        AdminGrantedPermissionsPreferenceControllerBase {
        AdminGrantedPermissionsPreferenceControllerBase {


    private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_LOCATION_ACCESS_PACKAGES
    private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_LOCATION_ACCESS_PACKAGES
            = "enterprise_privacy_number_location_access_packages";
            = "enterprise_privacy_number_location_access_packages";


    public AdminGrantedLocationPermissionsPreferenceController(Context context, Lifecycle lifecycle,
    public AdminGrantedLocationPermissionsPreferenceController(Context context, boolean async) {
            boolean async) {
        super(context, async, new String[] {Manifest.permission.ACCESS_COARSE_LOCATION,
        super(context, lifecycle, async, new String[] {Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.ACCESS_FINE_LOCATION});
                Manifest.permission.ACCESS_FINE_LOCATION}, Manifest.permission_group.LOCATION);
    }
    }


    @Override
    @Override
+2 −6
Original line number Original line Diff line number Diff line
@@ -17,18 +17,14 @@ package com.android.settings.enterprise;
import android.Manifest;
import android.Manifest;
import android.content.Context;
import android.content.Context;


import com.android.settingslib.core.lifecycle.Lifecycle;

public class AdminGrantedMicrophonePermissionPreferenceController extends
public class AdminGrantedMicrophonePermissionPreferenceController extends
        AdminGrantedPermissionsPreferenceControllerBase {
        AdminGrantedPermissionsPreferenceControllerBase {


    private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_MICROPHONE_ACCESS_PACKAGES
    private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_MICROPHONE_ACCESS_PACKAGES
            = "enterprise_privacy_number_microphone_access_packages";
            = "enterprise_privacy_number_microphone_access_packages";


    public AdminGrantedMicrophonePermissionPreferenceController(Context context,
    public AdminGrantedMicrophonePermissionPreferenceController(Context context, boolean async) {
            Lifecycle lifecycle, boolean async) {
        super(context, async, new String[] {Manifest.permission.RECORD_AUDIO});
        super(context, lifecycle, async, new String[] {Manifest.permission.RECORD_AUDIO},
                Manifest.permission_group.MICROPHONE);
    }
    }


    @Override
    @Override
Loading