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

Commit 3e0270a7 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Automerger Merge Worker
Browse files

Merge "Fix Bluetooth crash when active user is switched" am: 818323fa

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1718530

Change-Id: I201dcb5fbe41df1a7e20ce19f0b17ad4aa44b30b
parents 81b528f1 818323fa
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -293,7 +293,7 @@ public class DatabaseManager {
     * {@link BluetoothProfile#PAN}, {@link BluetoothProfile#PBAP},
     * {@link BluetoothProfile#PBAP_CLIENT}, {@link BluetoothProfile#MAP},
     * {@link BluetoothProfile#MAP_CLIENT}, {@link BluetoothProfile#SAP},
     * {@link BluetoothProfile#HEARING_AID}
     * {@link BluetoothProfile#HEARING_AID}, {@link BluetoothProfile#LE_AUDIO}
     * @param newConnectionPolicy the connectionPolicy to set; one of
     * {@link BluetoothProfile.CONNECTION_POLICY_UNKNOWN},
     * {@link BluetoothProfile.CONNECTION_POLICY_FORBIDDEN},
@@ -349,7 +349,7 @@ public class DatabaseManager {
     * {@link BluetoothProfile#PAN}, {@link BluetoothProfile#PBAP},
     * {@link BluetoothProfile#PBAP_CLIENT}, {@link BluetoothProfile#MAP},
     * {@link BluetoothProfile#MAP_CLIENT}, {@link BluetoothProfile#SAP},
     * {@link BluetoothProfile#HEARING_AID}
     * {@link BluetoothProfile#HEARING_AID}, {@link BluetoothProfile#LE_AUDIO}
     * @return the profile connection policy of the device; one of
     * {@link BluetoothProfile.CONNECTION_POLICY_UNKNOWN},
     * {@link BluetoothProfile.CONNECTION_POLICY_FORBIDDEN},
+5 −0
Original line number Diff line number Diff line
@@ -110,6 +110,9 @@ class Metadata {
            case BluetoothProfile.HEARING_AID:
                profileConnectionPolicies.hearing_aid_connection_policy = connectionPolicy;
                break;
            case BluetoothProfile.LE_AUDIO:
                profileConnectionPolicies.le_audio_connection_policy = connectionPolicy;
                break;
            default:
                throw new IllegalArgumentException("invalid profile " + profile);
        }
@@ -141,6 +144,8 @@ class Metadata {
                return profileConnectionPolicies.sap_connection_policy;
            case BluetoothProfile.HEARING_AID:
                return profileConnectionPolicies.hearing_aid_connection_policy;
            case BluetoothProfile.LE_AUDIO:
                return profileConnectionPolicies.le_audio_connection_policy;
        }
        return BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
    }
+19 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import java.util.List;
/**
 * MetadataDatabase is a Room database stores Bluetooth persistence data
 */
@Database(entities = {Metadata.class}, version = 105)
@Database(entities = {Metadata.class}, version = 106)
public abstract class MetadataDatabase extends RoomDatabase {
    /**
     * The metadata database file name
@@ -58,6 +58,7 @@ public abstract class MetadataDatabase extends RoomDatabase {
                .addMigrations(MIGRATION_102_103)
                .addMigrations(MIGRATION_103_104)
                .addMigrations(MIGRATION_104_105)
                .addMigrations(MIGRATION_105_106)
                .allowMainThreadQueries()
                .build();
    }
@@ -330,4 +331,21 @@ public abstract class MetadataDatabase extends RoomDatabase {
            }
        }
    };

    @VisibleForTesting
    static final Migration MIGRATION_105_106 = new Migration(105, 106) {
        @Override
        public void migrate(SupportSQLiteDatabase database) {
            try {
                database.execSQL("ALTER TABLE metadata ADD COLUMN `le_audio_connection_policy` "
                        + "INTEGER DEFAULT 100");
            } catch (SQLException ex) {
                // Check if user has new schema, but is just missing the version update
                Cursor cursor = database.query("SELECT * FROM metadata");
                if (cursor == null || cursor.getColumnIndex("le_audio_connection_policy") == -1) {
                    throw ex;
                }
            }
        }
    };
}
+4 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ class ProfilePrioritiesEntity {
    public int sap_connection_policy;
    public int hearing_aid_connection_policy;
    public int map_client_connection_policy;
    public int le_audio_connection_policy;

    ProfilePrioritiesEntity() {
        a2dp_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
@@ -49,6 +50,7 @@ class ProfilePrioritiesEntity {
        sap_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
        hearing_aid_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
        map_client_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
        le_audio_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN;
    }

    public String toString() {
@@ -64,7 +66,8 @@ class ProfilePrioritiesEntity {
                .append("|MAP=").append(map_connection_policy)
                .append("|MAP_CLIENT=").append(map_client_connection_policy)
                .append("|SAP=").append(sap_connection_policy)
                .append("|HEARING_AID=").append(hearing_aid_connection_policy);
                .append("|HEARING_AID=").append(hearing_aid_connection_policy)
                .append("|LE_AUDIO=").append(le_audio_connection_policy);

        return builder.toString();
    }
+28 −0
Original line number Diff line number Diff line
@@ -994,6 +994,34 @@ public final class DatabaseManagerTest {
        }
    }

    @Test
    public void testDatabaseMigration_105_106() throws IOException {
        String testString = "TEST STRING";

        // Create a database with version 105
        SupportSQLiteDatabase db = testHelper.createDatabase(DB_NAME, 105);

        // insert a device to the database
        ContentValues device = new ContentValues();
        device.put("address", TEST_BT_ADDR);
        device.put("migrated", false);
        assertThat(db.insert("metadata", SQLiteDatabase.CONFLICT_IGNORE, device),
                CoreMatchers.not(-1));

        // Migrate database from 105 to 106
        db.close();
        db = testHelper.runMigrationsAndValidate(DB_NAME, 106, true,
                MetadataDatabase.MIGRATION_105_106);
        Cursor cursor = db.query("SELECT * FROM metadata");

        assertHasColumn(cursor, "le_audio_connection_policy", true);

        while (cursor.moveToNext()) {
            // Check the new columns was added with default value
            assertColumnIntData(cursor, "le_audio_connection_policy", 100);
        }
    }

    /**
     * Helper function to check whether the database has the expected column
     */
Loading