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

Commit 08bd9bdb authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "DO NOT MERGE: Cherry-pick misc fixes to AOSP"

parents 46e75a69 5b02a330
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import android.provider.Settings;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.UserIcons;
import com.android.settingslib.drawable.UserIconDrawable;
import com.android.settingslib.wrapper.LocationManagerWrapper;

import java.text.NumberFormat;

public class Utils {
@@ -69,8 +69,7 @@ public class Utils {
                intent, UserHandle.of(userId), android.Manifest.permission.WRITE_SECURE_SETTINGS);
        LocationManager locationManager =
                (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        LocationManagerWrapper wrapper = new LocationManagerWrapper(locationManager);
        wrapper.setLocationEnabledForUser(enabled, UserHandle.of(userId));
        locationManager.setLocationEnabledForUser(enabled, UserHandle.of(userId));
    }

    public static boolean updateLocationMode(Context context, int oldMode, int newMode, int userId,
+7 −17
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
@@ -28,9 +27,7 @@ import android.content.Context;
import android.os.ParcelUuid;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.R;
import com.android.settingslib.wrapper.BluetoothA2dpWrapper;

import java.util.ArrayList;
import java.util.Arrays;
@@ -43,7 +40,6 @@ public class A2dpProfile implements LocalBluetoothProfile {
    private Context mContext;

    private BluetoothA2dp mService;
    private BluetoothA2dpWrapper mServiceWrapper;
    private boolean mIsProfileReady;

    private final LocalBluetoothAdapter mLocalAdapter;
@@ -67,7 +63,6 @@ public class A2dpProfile implements LocalBluetoothProfile {
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            if (V) Log.d(TAG,"Bluetooth service connected");
            mService = (BluetoothA2dp) proxy;
            mServiceWrapper = new BluetoothA2dpWrapper(mService);
            // We just bound to the service, so refresh the UI for any connected A2DP devices.
            List<BluetoothDevice> deviceList = mService.getConnectedDevices();
            while (!deviceList.isEmpty()) {
@@ -110,11 +105,6 @@ public class A2dpProfile implements LocalBluetoothProfile {
                BluetoothProfile.A2DP);
    }

    @VisibleForTesting
    void setBluetoothA2dpWrapper(BluetoothA2dpWrapper wrapper) {
        mServiceWrapper = wrapper;
    }

    public boolean isConnectable() {
        return true;
    }
@@ -194,12 +184,12 @@ public class A2dpProfile implements LocalBluetoothProfile {
    }

    public boolean supportsHighQualityAudio(BluetoothDevice device) {
        int support = mServiceWrapper.supportsOptionalCodecs(device);
        int support = mService.supportsOptionalCodecs(device);
        return support == BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED;
    }

    public boolean isHighQualityAudioEnabled(BluetoothDevice device) {
        int enabled = mServiceWrapper.getOptionalCodecsEnabled(device);
        int enabled = mService.getOptionalCodecsEnabled(device);
        if (enabled != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN) {
            return enabled == BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED;
        } else if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED &&
@@ -210,8 +200,8 @@ public class A2dpProfile implements LocalBluetoothProfile {
            return true;
        }
        BluetoothCodecConfig codecConfig = null;
        if (mServiceWrapper.getCodecStatus(device) != null) {
            codecConfig = mServiceWrapper.getCodecStatus(device).getCodecConfig();
        if (mService.getCodecStatus(device) != null) {
            codecConfig = mService.getCodecStatus(device).getCodecConfig();
        }
        if (codecConfig != null)  {
            return !codecConfig.isMandatoryCodec();
@@ -224,7 +214,7 @@ public class A2dpProfile implements LocalBluetoothProfile {
        int prefValue = enabled
                ? BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED
                : BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED;
        mServiceWrapper.setOptionalCodecsEnabled(device, prefValue);
        mService.setOptionalCodecsEnabled(device, prefValue);
        if (getConnectionStatus(device) != BluetoothProfile.STATE_CONNECTED) {
            return;
        }
@@ -244,8 +234,8 @@ public class A2dpProfile implements LocalBluetoothProfile {
        // We want to get the highest priority codec, since that's the one that will be used with
        // this device, and see if it is high-quality (ie non-mandatory).
        BluetoothCodecConfig[] selectable = null;
        if (mServiceWrapper.getCodecStatus(device) != null) {
            selectable = mServiceWrapper.getCodecStatus(device).getCodecsSelectableCapabilities();
        if (mService.getCodecStatus(device) != null) {
            selectable = mService.getCodecStatus(device).getCodecsSelectableCapabilities();
            // To get the highest priority, we sort in reverse.
            Arrays.sort(selectable,
                    (a, b) -> {
+0 −70
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.settingslib.wrapper;

import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothDevice;

/**
 * This class replicates some methods of android.bluetooth.BluetoothA2dp that are new and not
 * yet available in our current version of Robolectric. It provides a thin wrapper to call the real
 * methods in production and a mock in tests.
 */
public class BluetoothA2dpWrapper {

    private BluetoothA2dp mService;

    public BluetoothA2dpWrapper(BluetoothA2dp service) {
        mService = service;
    }

    /**
     * @return the real {@code BluetoothA2dp} object
     */
    public BluetoothA2dp getService() {
        return mService;
    }

    /**
     * Wraps {@code BluetoothA2dp.getCodecStatus}
     */
    public BluetoothCodecStatus getCodecStatus(BluetoothDevice device) {
        return mService.getCodecStatus(device);
    }

    /**
     * Wraps {@code BluetoothA2dp.supportsOptionalCodecs}
     */
    public int supportsOptionalCodecs(BluetoothDevice device) {
        return mService.supportsOptionalCodecs(device);
    }

    /**
     * Wraps {@code BluetoothA2dp.getOptionalCodecsEnabled}
     */
    public int getOptionalCodecsEnabled(BluetoothDevice device) {
        return mService.getOptionalCodecsEnabled(device);
    }

    /**
     * Wraps {@code BluetoothA2dp.setOptionalCodecsEnabled}
     */
    public void setOptionalCodecsEnabled(BluetoothDevice device, int value) {
        mService.setOptionalCodecsEnabled(device, value);
    }
}
+0 −64
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.settingslib.wrapper;

import android.location.LocationManager;
import android.os.UserHandle;

/**
 * This class replicates some methods of android.location.LocationManager that are new and not
 * yet available in our current version of Robolectric. It provides a thin wrapper to call the real
 * methods in production and a mock in tests.
 */
public class LocationManagerWrapper {

    private LocationManager mLocationManager;

    public LocationManagerWrapper(LocationManager locationManager) {
        mLocationManager = locationManager;
    }

    /** Returns the real {@code LocationManager} object */
    public LocationManager getLocationManager() {
        return mLocationManager;
    }

    /** Wraps {@code LocationManager.isProviderEnabled} method */
    public boolean isProviderEnabled(String provider) {
        return mLocationManager.isProviderEnabled(provider);
    }

    /** Wraps {@code LocationManager.setProviderEnabledForUser} method */
    public void setProviderEnabledForUser(String provider, boolean enabled, UserHandle userHandle) {
        mLocationManager.setProviderEnabledForUser(provider, enabled, userHandle);
    }

    /** Wraps {@code LocationManager.isLocationEnabled} method */
    public boolean isLocationEnabled() {
        return mLocationManager.isLocationEnabled();
    }

    /** Wraps {@code LocationManager.isLocationEnabledForUser} method */
    public boolean isLocationEnabledForUser(UserHandle userHandle) {
        return mLocationManager.isLocationEnabledForUser(userHandle);
    }

    /** Wraps {@code LocationManager.setLocationEnabledForUser} method */
    public void setLocationEnabledForUser(boolean enabled, UserHandle userHandle) {
        mLocationManager.setLocationEnabledForUser(enabled, userHandle);
    }
}
+3 −5
Original line number Diff line number Diff line
@@ -41,8 +41,6 @@ import android.provider.Settings;
import android.provider.Settings.Secure;
import android.text.TextUtils;

import com.android.settingslib.wrapper.LocationManagerWrapper;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -63,7 +61,7 @@ import java.util.Map;
@RunWith(SettingsLibRobolectricTestRunner.class)
@Config(shadows = {
            UtilsTest.ShadowSecure.class,
            UtilsTest.ShadowLocationManagerWrapper.class})
            UtilsTest.ShadowLocationManager.class})
public class UtilsTest {
    private static final double[] TEST_PERCENTAGES = {0, 0.4, 0.5, 0.6, 49, 49.3, 49.8, 50, 100};
    private static final String PERCENTAGE_0 = "0%";
@@ -192,8 +190,8 @@ public class UtilsTest {
        }
    }

    @Implements(value = LocationManagerWrapper.class)
    public static class ShadowLocationManagerWrapper {
    @Implements(value = LocationManager.class)
    public static class ShadowLocationManager {

        @Implementation
        public void setLocationEnabledForUser(boolean enabled, UserHandle userHandle) {
Loading