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

Commit 6c6c0e11 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Refactor SoundSettings to use more preference controller."

parents 276e3b7a 6c2cf0db
Loading
Loading
Loading
Loading
+39 −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.notification;

import android.content.Context;
import android.media.RingtoneManager;

public class AlarmRingtonePreferenceController extends RingtonePreferenceControllerBase {

    private static final String KEY_ALARM_RINGTONE = "alarm_ringtone";

    public AlarmRingtonePreferenceController(Context context) {
        super(context);
    }

    @Override
    public String getPreferenceKey() {
        return KEY_ALARM_RINGTONE;
    }

    @Override
    public int getRingtoneType() {
        return RingtoneManager.TYPE_ALARM;
    }
}
+99 −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.notification;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.v7.preference.Preference;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.accounts.AccountRestrictionHelper;
import com.android.settings.core.PreferenceController;
import com.android.settingslib.RestrictedPreference;

/**
 * Base class for preference controller that handles preference that enforce adjust volume
 * restriction
 */
public class EmergencyBroadcastPreferenceController extends PreferenceController {

    private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings";

    private AccountRestrictionHelper mHelper;
    private UserManager mUserManager;
    private PackageManager mPm;
    private boolean mCellBroadcastAppLinkEnabled;

    public EmergencyBroadcastPreferenceController(Context context) {
        this(context, new AccountRestrictionHelper(context));
    }

    @VisibleForTesting
    EmergencyBroadcastPreferenceController(Context context, AccountRestrictionHelper helper) {
        super(context);
        mHelper = helper;
        mUserManager = UserManager.get(context);
        mPm = mContext.getPackageManager();
        // Enable link to CMAS app settings depending on the value in config.xml.
        mCellBroadcastAppLinkEnabled = isCellBroadcastAppLinkEnabled();
    }

    @Override
    public void updateState(Preference preference) {
        if (!(preference instanceof RestrictedPreference)) {
            return;
        }
        ((RestrictedPreference) preference).checkRestrictionAndSetDisabled(
            UserManager.DISALLOW_CONFIG_CELL_BROADCASTS);
    }

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        return false;
    }

    @Override
    public String getPreferenceKey() {
        return KEY_CELL_BROADCAST_SETTINGS;
    }

    @Override
    public boolean isAvailable() {
        return mUserManager.isAdminUser() && mCellBroadcastAppLinkEnabled
            && !mHelper.hasBaseUserRestriction(
                UserManager.DISALLOW_CONFIG_CELL_BROADCASTS, UserHandle.myUserId());
    }

    private boolean isCellBroadcastAppLinkEnabled() {
        boolean enabled = mContext.getResources().getBoolean(
            com.android.internal.R.bool.config_cellBroadcastAppLinks);
        if (enabled) {
            try {
                if (mPm.getApplicationEnabledSetting("com.android.cellbroadcastreceiver")
                    == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
                    enabled = false;  // CMAS app disabled
                }
            } catch (IllegalArgumentException ignored) {
                enabled = false;  // CMAS app not installed
            }
        }
        return enabled;
    }

}
 No newline at end of file
+39 −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.notification;

import android.content.Context;
import android.media.RingtoneManager;

public class NotificationRingtonePreferenceController extends RingtonePreferenceControllerBase {

    private static final String KEY_NOTIFICATION_RINGTONE = "notification_ringtone";

    public NotificationRingtonePreferenceController(Context context) {
        super(context);
    }

    @Override
    public String getPreferenceKey() {
        return KEY_NOTIFICATION_RINGTONE;
    }

    @Override
    public int getRingtoneType() {
        return RingtoneManager.TYPE_NOTIFICATION;
    }
}
+45 −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.notification;

import android.content.Context;
import android.media.RingtoneManager;
import com.android.settings.Utils;

public class PhoneRingtonePreferenceController extends RingtonePreferenceControllerBase {

    private static final String KEY_PHONE_RINGTONE = "ringtone";

    public PhoneRingtonePreferenceController(Context context) {
        super(context);
    }

    @Override
    public String getPreferenceKey() {
        return KEY_PHONE_RINGTONE;
    }

    @Override
    public boolean isAvailable() {
        return Utils.isVoiceCapable(mContext);
    }

    @Override
    public int getRingtoneType() {
        return RingtoneManager.TYPE_RINGTONE;
    }
}
+55 −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.notification;

import android.content.Context;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v7.preference.Preference;

import com.android.settings.core.PreferenceController;

public abstract class RingtonePreferenceControllerBase extends PreferenceController {

    public RingtonePreferenceControllerBase(Context context) {
        super(context);
    }

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        return false;
    }

    @Override
    public boolean isAvailable() {
        return true;
    }

    @Override
    public void updateState(Preference preference) {
        Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(mContext, getRingtoneType());
        final CharSequence summary = Ringtone.getTitle(
            mContext, ringtoneUri, false /* followSettingsUri */, true /* allowRemote */);
        if (summary != null) {
            preference.setSummary(summary);
        }
    }

    public abstract int getRingtoneType();

}
Loading