Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processing PowerInfo broadcast async #1229

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ class PowerInfoReceiver extends android.content.BroadcastReceiver {
}

public final void onReceive(android.content.Context context, android.content.Intent intent) {
final int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
final boolean isCharging =
m_parent.executeTask(new FutureTask<>(() -> {
final int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
final boolean isCharging =
status == BatteryManager.BATTERY_STATUS_CHARGING
|| status == BatteryManager.BATTERY_STATUS_FULL;
boolean isLow = false;
if (Build.VERSION.SDK_INT >= 28) {
isLow = intent.getBooleanExtra(BatteryManager.EXTRA_BATTERY_LOW, false);
}
m_parent.onPowerChange(isCharging, isLow);
boolean isLow = false;
if (Build.VERSION.SDK_INT >= 28) {
isLow = intent.getBooleanExtra(BatteryManager.EXTRA_BATTERY_LOW, false);
}
m_parent.onPowerChange(isCharging, isLow);
}, true));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.isA;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -230,7 +231,7 @@ public void canInstantiate() throws java.io.IOException, PackageManager.NameNotF
/* Stubby should not attempt to access the CONNECTIVITY_SERVICE */
verify(mockContext, times(0)).getSystemService(Context.CONNECTIVITY_SERVICE);
verify(mockContext, times(1)).registerReceiver(isA(BroadcastReceiver.class), isA(IntentFilter.class));
verify(mockIntent, times(1)).getIntExtra(BatteryManager.EXTRA_STATUS, -1);
verify(mockIntent, timeout(5000).times(1)).getIntExtra(BatteryManager.EXTRA_STATUS, -1);
verify(mockManager, times(0)).registerDefaultNetworkCallback(any(ConnectivityManager.NetworkCallback.class));
assertNull(callback);
assertEquals(previousDispatch, dispatchCount.get());
Expand Down
Loading