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

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

Merge "Move BT, NFC out of Conntection pref" into pi-dev

parents 671db847 b247311b
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -39,9 +39,24 @@
        settings:useAdminDisabledSummary="true"
        settings:controller="com.android.settings.connecteddevice.AddDevicePreferenceController"/>

    <com.android.settingslib.RestrictedSwitchPreference
        android:key="toggle_bluetooth_switch"
        android:title="@string/bluetooth_settings_title"
        android:icon="@drawable/ic_settings_bluetooth"
        android:summary="@string/bluetooth_pref_summary"
        settings:allowDividerAbove="true"
        settings:controller="com.android.settings.bluetooth.BluetoothSwitchPreferenceController"
        settings:userRestriction="no_bluetooth"
        settings:platform_slice="true"/>

    <SwitchPreference
        android:key="toggle_nfc"
        android:title="@string/nfc_quick_toggle_title"
        android:icon="@drawable/ic_nfc"
        android:summary="@string/nfc_quick_toggle_summary"/>

    <Preference
        android:fragment="com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment"
        android:key="connection_preferences"
        android:title="@string/connected_device_connections_title"
        settings:allowDividerAbove="true"/>
        android:title="@string/connected_device_connections_title"/>
</PreferenceScreen>
+1 −18
Original line number Diff line number Diff line
@@ -20,23 +20,6 @@
    android:key="connected_devices_advanced_screen"
    android:title="@string/connected_device_connections_title">

    <com.android.settingslib.RestrictedSwitchPreference
        android:key="toggle_bluetooth_switch"
        android:title="@string/bluetooth_settings_title"
        android:icon="@drawable/ic_settings_bluetooth"
        android:summary="@string/bluetooth_pref_summary"
        android:order="-7"
        settings:controller="com.android.settings.bluetooth.BluetoothSwitchPreferenceController"
        settings:userRestriction="no_bluetooth"
        settings:platform_slice="true"/>

    <SwitchPreference
        android:key="toggle_nfc"
        android:title="@string/nfc_quick_toggle_title"
        android:icon="@drawable/ic_nfc"
        android:summary="@string/nfc_quick_toggle_summary"
        android:order="-5"/>

    <com.android.settingslib.RestrictedPreference
        android:fragment="com.android.settings.nfc.AndroidBeam"
        android:key="android_beam_settings"
+8 −14
Original line number Diff line number Diff line
@@ -22,10 +22,8 @@ import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.bluetooth.BluetoothFilesPreferenceController;
import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
import com.android.settings.bluetooth.BluetoothSwitchPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.nfc.NfcPreferenceController;
import com.android.settings.nfc.AndroidBeamPreferenceController;
import com.android.settings.print.PrintSettingPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -70,21 +68,19 @@ public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment
    private static List<AbstractPreferenceController> buildControllers(Context context,
            Lifecycle lifecycle) {
        final List<AbstractPreferenceController> controllers = new ArrayList<>();
        final NfcPreferenceController nfcPreferenceController =
                new NfcPreferenceController(context);
        controllers.add(nfcPreferenceController);
        final BluetoothSwitchPreferenceController bluetoothPreferenceController =
                new BluetoothSwitchPreferenceController(context);
        controllers.add(bluetoothPreferenceController);

        final AndroidBeamPreferenceController beamPreferenceController =
                new AndroidBeamPreferenceController(context);
        controllers.add(beamPreferenceController);

        controllers.add(new BluetoothFilesPreferenceController(context));
        controllers.add(new BluetoothOnWhileDrivingPreferenceController(context));

        final PrintSettingPreferenceController printerController =
                new PrintSettingPreferenceController(context);
        if (lifecycle != null) {
            lifecycle.addObserver(beamPreferenceController);
            lifecycle.addObserver(printerController);
            lifecycle.addObserver(nfcPreferenceController);
            lifecycle.addObserver(bluetoothPreferenceController);
        }
        controllers.add(printerController);

@@ -109,10 +105,8 @@ public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment
                    final List<String> keys = super.getNonIndexableKeys(context);
                    PackageManager pm = context.getPackageManager();
                    if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
                        keys.add(NfcPreferenceController.KEY_TOGGLE_NFC);
                        keys.add(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
                        keys.add(AndroidBeamPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
                    }
                    keys.add(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);

                    return keys;
                }
+16 −0
Original line number Diff line number Diff line
@@ -17,11 +17,14 @@ package com.android.settings.connecteddevice;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.provider.SearchIndexableResource;
import android.support.annotation.VisibleForTesting;

import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.bluetooth.BluetoothSwitchPreferenceController;
import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.nfc.NfcPreferenceController;
@@ -73,6 +76,19 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
        controllers.add(new ConnectedDeviceGroupController(context, dashboardFragment, lifecycle));
        controllers.add(new SavedDeviceGroupController(context, dashboardFragment, lifecycle));

        final NfcPreferenceController nfcPreferenceController =
                new NfcPreferenceController(context);
        controllers.add(nfcPreferenceController);

        final BluetoothSwitchPreferenceController bluetoothPreferenceController =
                new BluetoothSwitchPreferenceController(context);
        controllers.add(bluetoothPreferenceController);

        if (lifecycle != null) {
            lifecycle.addObserver(nfcPreferenceController);
            lifecycle.addObserver(bluetoothPreferenceController);
        }

        return controllers;
    }

+84 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.nfc;

import android.content.Context;
import android.nfc.NfcAdapter;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.v7.preference.Preference;

import com.android.settings.R;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;

/**
 * AndroidBeanEnabler is a helper to manage the Android Beam preference. It turns on/off
 * Android Beam and ensures the summary of the preference reflects the current state.
 */
public class AndroidBeamEnabler extends BaseNfcEnabler {
    private final boolean mBeamDisallowedBySystem;
    private final RestrictedPreference mPreference;

    public AndroidBeamEnabler(Context context, RestrictedPreference preference) {
        super(context);

        mPreference = preference;

        mBeamDisallowedBySystem = RestrictedLockUtils.hasBaseUserRestriction(context,
                UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId());

        if (!isNfcAvailable()) {
            // NFC is not supported
            mPreference.setEnabled(false);
            return;
        }

        if (mBeamDisallowedBySystem) {
            mPreference.setEnabled(false);
        }
    }

    @Override
    protected void handleNfcStateChanged(int newState) {
        switch (newState) {
            case NfcAdapter.STATE_OFF:
                mPreference.setEnabled(false);
                mPreference.setSummary(R.string.android_beam_disabled_summary);
                break;
            case NfcAdapter.STATE_ON:
                if (mBeamDisallowedBySystem) {
                    mPreference.setDisabledByAdmin(null);
                    mPreference.setEnabled(false);
                } else {
                    mPreference.checkRestrictionAndSetDisabled(UserManager.DISALLOW_OUTGOING_BEAM);
                }
                if (mNfcAdapter.isNdefPushEnabled() && mPreference.isEnabled()) {
                    mPreference.setSummary(R.string.android_beam_on_summary);
                } else {
                    mPreference.setSummary(R.string.android_beam_off_summary);
                }
                break;
            case NfcAdapter.STATE_TURNING_ON:
                mPreference.setEnabled(false);
                break;
            case NfcAdapter.STATE_TURNING_OFF:
                mPreference.setEnabled(false);
                break;
        }
    }
}
Loading