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

Commit 0e19d242 authored by Tony Mak's avatar Tony Mak
Browse files

Home default setting should not shown in managed profile settings

Each default preference needs to have its corresponding
PreferenceAvailabilityProvider to provide us the availability of it.
If no corresponding provider is found, it is considered to be not
available. So it encourages other developers who will add new default app
preference later to consider the availability of it.

Bug:27143673
Change-Id: I073b7122dddc579504f397c5de2bdd4df3826269
parent 6b00d3fe
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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;

import android.content.Context;

/**
 * Interface for classes whose instances can provide the availability of the preference.
 */
public interface PreferenceAvailabilityProvider {
    /**
     * @return the availability of the preference. Please make sure the availability in managed
     * profile is taken into account.
     */
    boolean isAvailable(Context context);
}
+8 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.UserHandle;
import android.util.AttributeSet;

import com.android.settings.AppListPreference;
import com.android.settings.PreferenceAvailabilityProvider;

import java.util.ArrayList;
import java.util.List;
@@ -72,4 +73,11 @@ public class DefaultBrowserPreference extends AppListPreference {

        return result;
    }

    public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
        @Override
        public boolean isAvailable(Context context) {
            return true;
        }
    }
}
+12 −11
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.util.ArraySet;
import android.util.AttributeSet;

import com.android.settings.AppListPreference;
import com.android.settings.PreferenceAvailabilityProvider;
import com.android.settings.Utils;

import java.util.List;
@@ -51,11 +52,8 @@ public class DefaultEmergencyPreference extends AppListPreference {
    public DefaultEmergencyPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContentResolver = context.getContentResolver();

        if (isAvailable(context)) {
        load();
    }
    }

    @Override
    protected boolean persistString(String value) {
@@ -135,13 +133,7 @@ public class DefaultEmergencyPreference extends AppListPreference {
        return packages;
    }

    public static boolean isAvailable(Context context) {
        return isCapable(context)
                && context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null
                && !Utils.isManagedProfile(UserManager.get(context)) ;
    }

    public static boolean isCapable(Context context) {
    private static boolean isCapable(Context context) {
        return TelephonyManager.EMERGENCY_ASSISTANCE_ENABLED
                && context.getResources().getBoolean(
                com.android.internal.R.bool.config_voice_capable);
@@ -151,4 +143,13 @@ public class DefaultEmergencyPreference extends AppListPreference {
        return info.applicationInfo != null
                && (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
    }

    public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
        @Override
        public boolean isAvailable(Context context) {
            return isCapable(context)
                    && context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null
                    && !Utils.isManagedProfile(UserManager.get(context));
        }
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -26,8 +26,11 @@ import android.content.pm.UserInfo;
import android.os.Build;
import android.os.UserManager;
import android.util.AttributeSet;

import com.android.settings.AppListPreference;
import com.android.settings.PreferenceAvailabilityProvider;
import com.android.settings.R;
import com.android.settings.Utils;

import java.util.ArrayList;
import java.util.List;
@@ -115,4 +118,10 @@ public class DefaultHomePreference extends AppListPreference {
        return false;
    }

    public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
        @Override
        public boolean isAvailable(Context context) {
            return !Utils.isManagedProfile(UserManager.get(context));
        }
    }
}
+6 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.util.Slog;
import java.util.ArrayList;
import java.util.List;

import com.android.settings.PreferenceAvailabilityProvider;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.notification.ManagedServiceSettings;
@@ -111,7 +112,10 @@ public class DefaultNotificationAssistantPreference extends AppListPreference {
        return c;
    }

    public static boolean isAvailable(Context context) {
    public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
        @Override
        public boolean isAvailable(Context context) {
            return !Utils.isManagedProfile(UserManager.get(context));
        }
    }
}
Loading