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

Commit 1327bbcf authored by xiaowang's avatar xiaowang Committed by Xiaoyang Wang
Browse files

Fix null reference used for synchronization

Fix null reference used for mSearchScanCallback synchronization.
Also just printing RuntimeException rather than new Throwable()

Bug: 228228740
Test: compile
Change-Id: Ibf24040f517c8a6f3b15486ff7ddf301b3ad9552
parent 15c83448
Loading
Loading
Loading
Loading
+19 −18
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ public class BassClientService extends ProfileService {
    private static BassClientService sService;

    private final Map<BluetoothDevice, BassClientStateMachine> mStateMachines = new HashMap<>();
    private final Object mSearchScanCallbackLock = new Object();

    private HandlerThread mStateMachinesThread;
    private HandlerThread mCallbackHandlerThread;
@@ -619,7 +620,7 @@ public class BassClientService extends ProfileService {
            Log.e(TAG, "startLeScan: cannot get BluetoothLeScanner");
            return;
        }
        synchronized (mSearchScanCallback) {
        synchronized (mSearchScanCallbackLock) {
            if (mSearchScanCallback != null) {
                Log.e(TAG, "LE Scan has already started");
                mCallbacks.notifySearchStartFailed(BluetoothStatusCodes.ERROR_UNKNOWN);
@@ -685,7 +686,7 @@ public class BassClientService extends ProfileService {
            Log.e(TAG, "startLeScan: cannot get BluetoothLeScanner");
            return;
        }
        synchronized (mSearchScanCallback) {
        synchronized (mSearchScanCallbackLock) {
            if (mSearchScanCallback == null) {
                Log.e(TAG, "Scan not started yet");
                mCallbacks.notifySearchStopFailed(BluetoothStatusCodes.ERROR_UNKNOWN);
@@ -702,7 +703,7 @@ public class BassClientService extends ProfileService {
     * @return true if a search has been started by this application
     */
    public boolean isSearchInProgress() {
        synchronized (mSearchScanCallback) {
        synchronized (mSearchScanCallbackLock) {
            return mSearchScanCallback != null;
        }
    }
@@ -1047,7 +1048,7 @@ public class BassClientService extends ProfileService {
                }
                return service.getConnectionState(sink);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
                return BluetoothProfile.STATE_DISCONNECTED;
            }
        }
@@ -1062,7 +1063,7 @@ public class BassClientService extends ProfileService {
                }
                return service.getDevicesMatchingConnectionStates(states);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
                return Collections.emptyList();
            }
        }
@@ -1077,7 +1078,7 @@ public class BassClientService extends ProfileService {
                }
                return service.getConnectedDevices();
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
                return Collections.emptyList();
            }
        }
@@ -1092,7 +1093,7 @@ public class BassClientService extends ProfileService {
                }
                return service.setConnectionPolicy(device, connectionPolicy);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
                return false;
            }
        }
@@ -1107,7 +1108,7 @@ public class BassClientService extends ProfileService {
                }
                return service.getConnectionPolicy(device);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
                return BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
            }
        }
@@ -1122,7 +1123,7 @@ public class BassClientService extends ProfileService {
                }
                service.registerCallback(cb);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
            }
        }

@@ -1136,7 +1137,7 @@ public class BassClientService extends ProfileService {
                }
                service.unregisterCallback(cb);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
            }
        }

@@ -1150,7 +1151,7 @@ public class BassClientService extends ProfileService {
                }
                service.startSearchingForSources(filters);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
            }
        }

@@ -1164,7 +1165,7 @@ public class BassClientService extends ProfileService {
                }
                service.stopSearchingForSources();
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
            }
        }

@@ -1178,7 +1179,7 @@ public class BassClientService extends ProfileService {
                }
                return service.isSearchInProgress();
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
                return false;
            }
        }
@@ -1195,7 +1196,7 @@ public class BassClientService extends ProfileService {
                }
                service.addSource(sink, sourceMetadata, isGroupOp);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
            }
        }

@@ -1210,7 +1211,7 @@ public class BassClientService extends ProfileService {
                }
                service.modifySource(sink, sourceId, updatedMetadata);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
            }
        }

@@ -1224,7 +1225,7 @@ public class BassClientService extends ProfileService {
                }
                service.removeSource(sink, sourceId);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
            }
        }

@@ -1238,7 +1239,7 @@ public class BassClientService extends ProfileService {
                }
                return service.getAllSources(sink);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
                return Collections.emptyList();
            }
        }
@@ -1253,7 +1254,7 @@ public class BassClientService extends ProfileService {
                }
                return service.getMaximumSourceCapacity(sink);
            } catch (RuntimeException e) {
                Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
                Log.e(TAG, "Exception happened", e);
                return 0;
            }
        }