Cleanup the evaluateBinding() method.

Small refactor to remove 1 level of nesting.

Test: build, run.
Change-Id: Ic46a65036b207ff73fefced914e0928de2f2b500
Merged-In: I38836ca9d18c5fcd3c6edf5931b58de3b08614ee
This commit is contained in:
Jeremy Joslin
2016-12-21 13:35:02 -08:00
parent 1471ad3ea7
commit e3d260d4e9

View File

@@ -147,37 +147,39 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
}
private void evaluateBinding(String scorerPackageName, boolean forceUnbind) {
if (mPackagesToWatch.contains(scorerPackageName)) {
if (!mPackagesToWatch.contains(scorerPackageName)) {
// Early exit when we don't care about the package that has changed.
return;
}
if (DBG) {
Log.d(TAG, "Evaluating binding for: " + scorerPackageName
+ ", forceUnbind=" + forceUnbind);
}
final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer();
if (activeScorer == null) {
// Package change has invalidated a scorer, this will also unbind any service
// connection.
if (DBG) Log.d(TAG, "No active scorers available.");
unbindFromScoringServiceIfNeeded();
} else if (activeScorer.packageName.equals(scorerPackageName)) {
// The active scoring service changed in some way.
if (DBG) {
Log.d(TAG, "Evaluating binding for: " + scorerPackageName
+ ", forceUnbind=" + forceUnbind);
}
final NetworkScorerAppData activeScorer =
mNetworkScorerAppManager.getActiveScorer();
if (activeScorer == null) {
// Package change has invalidated a scorer, this will also unbind any service
// connection.
if (DBG) Log.d(TAG, "No active scorers available.");
unbindFromScoringServiceIfNeeded();
} else if (activeScorer.packageName.equals(scorerPackageName)) {
// The active scoring service changed in some way.
if (DBG) {
Log.d(TAG, "Possible change to the active scorer: "
Log.d(TAG, "Possible change to the active scorer: "
+ activeScorer.packageName);
}
if (forceUnbind) {
unbindFromScoringServiceIfNeeded();
}
bindToScoringServiceIfNeeded(activeScorer);
} else {
// One of the scoring apps on the device has changed and we may no longer be
// bound to the correct scoring app. The logic in bindToScoringServiceIfNeeded()
// will sort that out to leave us bound to the most recent active scorer.
if (DBG) {
Log.d(TAG, "Binding to " + activeScorer.packageName + " if needed.");
}
bindToScoringServiceIfNeeded(activeScorer);
}
if (forceUnbind) {
unbindFromScoringServiceIfNeeded();
}
bindToScoringServiceIfNeeded(activeScorer);
} else {
// One of the scoring apps on the device has changed and we may no longer be
// bound to the correct scoring app. The logic in bindToScoringServiceIfNeeded()
// will sort that out to leave us bound to the most recent active scorer.
if (DBG) {
Log.d(TAG, "Binding to " + activeScorer.packageName + " if needed.");
}
bindToScoringServiceIfNeeded(activeScorer);
}
}
}