Skip to content

Commit

Permalink
Merge pull request #424 from SwissCovid/develop
Browse files Browse the repository at this point in the history
Version 2.4.0 Bugfixes
  • Loading branch information
simonroesch committed Mar 19, 2022
2 parents 005b485 + 7e56ff7 commit 4be7619
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 21 deletions.
10 changes: 10 additions & 0 deletions app/src/abnahme/java/ch/admin/bag/dp3t/debug/DebugFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.dpppt.android.sdk.internal.nearby.ExposureWindowMatchingWorker;

import ch.admin.bag.dp3t.R;
import ch.admin.bag.dp3t.contacts.HistoryFragment;
import ch.admin.bag.dp3t.networking.CertificatePinning;

public class DebugFragment extends Fragment {
Expand Down Expand Up @@ -62,6 +63,15 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

view.findViewById(R.id.debug_trigger_exposure_check)
.setOnClickListener(v -> ExposureWindowMatchingWorker.startMatchingWorker(v.getContext()));

View historyButton = view.findViewById(R.id.debug_history);
historyButton.setOnClickListener(v -> {
getParentFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_enter, R.anim.slide_exit, R.anim.slide_pop_enter, R.anim.slide_pop_exit)
.replace(R.id.main_fragment_container, HistoryFragment.newInstance())
.addToBackStack(HistoryFragment.class.getCanonicalName())
.commit();
});
}

}
20 changes: 15 additions & 5 deletions app/src/dev/java/ch/admin/bag/dp3t/debug/DebugFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import ch.admin.bag.dp3t.R;
import ch.admin.bag.dp3t.checkin.CrowdNotifierViewModel;
import ch.admin.bag.dp3t.checkin.models.SwissCovidAssociatedData;
import ch.admin.bag.dp3t.contacts.HistoryFragment;
import ch.admin.bag.dp3t.debug.model.DebugAppState;
import ch.admin.bag.dp3t.networking.CertificatePinning;
import ch.admin.bag.dp3t.storage.SecureStorage;
Expand Down Expand Up @@ -87,11 +88,11 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
private void setupSdkViews(View view) {
TextView statusText = view.findViewById(R.id.debug_sdk_state_text);
tracingViewModel.getTracingStatusLiveData().observe(getViewLifecycleOwner(), status -> {
statusText.setText(DebugUtils.formatStatusString(status, view.getContext()));
boolean isTracing = (status.isTracingEnabled()) && status.getErrors().size() == 0;
statusText.setBackgroundTintList(ColorStateList.valueOf(
isTracing ? getResources().getColor(R.color.status_green_bg, null)
: getResources().getColor(R.color.status_purple_bg, null)));
statusText.setText(DebugUtils.formatStatusString(status, view.getContext()));
boolean isTracing = (status.isTracingEnabled()) && status.getErrors().size() == 0;
statusText.setBackgroundTintList(ColorStateList.valueOf(
isTracing ? getResources().getColor(R.color.status_green_bg, null)
: getResources().getColor(R.color.status_purple_bg, null)));
});

view.findViewById(R.id.debug_button_reset).setOnClickListener(v -> {
Expand Down Expand Up @@ -132,6 +133,15 @@ private void setupSdkViews(View view) {

view.findViewById(R.id.debug_trigger_exposure_check)
.setOnClickListener(v -> ExposureWindowMatchingWorker.startMatchingWorker(v.getContext()));

View historyButton = view.findViewById(R.id.debug_history);
historyButton.setOnClickListener(v -> {
getParentFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_enter, R.anim.slide_exit, R.anim.slide_pop_enter, R.anim.slide_pop_exit)
.replace(R.id.main_fragment_container, HistoryFragment.newInstance())
.addToBackStack(HistoryFragment.class.getCanonicalName())
.commit();
});
}

private void setupStateOptions(View view) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/log/java/ch/admin/bag/dp3t/debug/DebugFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.dpppt.android.sdk.internal.nearby.ExposureWindowMatchingWorker;

import ch.admin.bag.dp3t.R;
import ch.admin.bag.dp3t.contacts.HistoryFragment;
import ch.admin.bag.dp3t.networking.CertificatePinning;

public class DebugFragment extends Fragment {
Expand Down Expand Up @@ -62,6 +63,15 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

view.findViewById(R.id.debug_trigger_exposure_check)
.setOnClickListener(v -> ExposureWindowMatchingWorker.startMatchingWorker(v.getContext()));

View historyButton = view.findViewById(R.id.debug_history);
historyButton.setOnClickListener(v -> {
getParentFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_enter, R.anim.slide_exit, R.anim.slide_pop_enter, R.anim.slide_pop_exit)
.replace(R.id.main_fragment_container, HistoryFragment.newInstance())
.addToBackStack(HistoryFragment.class.getCanonicalName())
.commit();
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
setupBottomNavigationView();
}

private static void setupDebugButton(View schwiizerchruez, FragmentManager fragmentManager) {
public static void setupDebugButton(View schwiizerchruez, FragmentManager fragmentManager) {
if (!DebugFragment.EXISTS) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void startKeyLoadWorker(Context context) {
}

public static void stop(Context context) {
WorkManager.getInstance(context).cancelAllWorkByTag(WORK_TAG);
WorkManager.getInstance(context).cancelUniqueWork(WORK_TAG);
}


Expand All @@ -59,6 +59,7 @@ public CrowdNotifierKeyLoadWorker(@NonNull Context context, @NonNull WorkerParam
@Override
public Result doWork() {
Log.d(LOG_TAG, "Started KeyLoadWorker");
DP3T.addWorkerStartedToHistory(getApplicationContext(), "key load worker");
if (DP3T.getStatus(getApplicationContext()).getInfectionStatus() == INFECTED) {
Log.d(LOG_TAG, "KeyLoadWorker: Network Request not executed");
return Result.success();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ch.admin.bag.dp3t.R
import ch.admin.bag.dp3t.TabbarHostFragment
import ch.admin.bag.dp3t.databinding.FragmentHibernatingInfoBinding
import ch.admin.bag.dp3t.html.HtmlFragment
import ch.admin.bag.dp3t.networking.models.InfoBoxModel
import ch.admin.bag.dp3t.util.AssetUtil
import ch.admin.bag.dp3t.util.UrlUtil

Expand All @@ -32,6 +31,9 @@ class HibernatingInfoFragment : Fragment() {
true
}

val schwiizerchruez = toolbar.findViewById<View>(R.id.schwiizerchruez)
TabbarHostFragment.setupDebugButton(schwiizerchruez, requireActivity().supportFragmentManager)

viewModel.isHibernatingModeEnabled.observe(viewLifecycleOwner) { isHibernatingModeEnabled ->
if (!isHibernatingModeEnabled) {
showHomeFragment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ConfigWorker(context: Context, workerParams: WorkerParameters) : Coroutine
}

fun stop(context: Context) {
WorkManager.getInstance(context).cancelAllWorkByTag(FakeWorker.WORK_TAG)
WorkManager.getInstance(context).cancelUniqueWork(WORK_NAME);
}

@Throws(IOException::class, ResponseError::class, SignatureException::class)
Expand Down
27 changes: 15 additions & 12 deletions app/src/main/java/ch/admin/bag/dp3t/viewmodel/TracingViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.dpppt.android.sdk.DP3T;
import org.dpppt.android.sdk.InfectionStatus;
import org.dpppt.android.sdk.TracingStatus;
import org.dpppt.android.sdk.internal.BroadcastHelper;
import org.dpppt.android.sdk.internal.history.HistoryEntry;
Expand All @@ -41,22 +43,12 @@
public class TracingViewModel extends AndroidViewModel {

private final MutableLiveData<TracingStatus> tracingStatusLiveData = new MutableLiveData<>();
private BroadcastReceiver tracingStatusBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
invalidateTracingStatus();
loadHistoryEntries();
}
};

private final MutableLiveData<Boolean> tracingEnabledLiveData = new MutableLiveData<>();
private final MutableLiveData<Pair<Boolean, Boolean>> exposedLiveData = new MutableLiveData<>();
private final MutableLiveData<Collection<TracingStatus.ErrorState>> errorsLiveData =
new MutableLiveData<>(Collections.emptyList());
private final MutableLiveData<TracingStatusInterface> appStatusLiveData = new MutableLiveData<>();

private TracingStatusInterface tracingStatusInterface = new TracingStatusWrapper();

private final MutableLiveData<Boolean> bluetoothEnabledLiveData = new MutableLiveData<>();
private BroadcastReceiver bluetoothReceiver = new BroadcastReceiver() {
@Override
Expand All @@ -67,8 +59,14 @@ public void onReceive(Context context, Intent intent) {
}
}
};

private final MutableLiveData<List<HistoryEntry>> historyMutableLiveData = new MutableLiveData<>();
private BroadcastReceiver tracingStatusBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
invalidateTracingStatus();
loadHistoryEntries();
}
};

public TracingViewModel(@NonNull Application application) {
super(application);
Expand Down Expand Up @@ -101,7 +99,12 @@ public void resetSdk() {
}

public void invalidateTracingStatus() {
TracingStatus status = DP3T.getStatus(getApplication());
TracingStatus status;
if (DP3T.isInitialized()) {
status = DP3T.getStatus(getApplication());
} else {
status = new TracingStatus(false, 0, InfectionStatus.HEALTHY, new ArrayList<>(), new ArrayList<>());
}
tracingStatusLiveData.setValue(status);
}

Expand Down
32 changes: 32 additions & 0 deletions app/src/main/res/layout/fragment_debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,38 @@

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
style="@style/NextStep.Card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_medium_large">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_medium_large"
android:layout_marginRight="@dimen/spacing_large"
android:layout_marginBottom="@dimen/spacing_large"
android:orientation="vertical">

<TextView
style="@style/NextStep.Text.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="History" />

<Button
android:id="@+id/debug_history"
style="@style/NextStep.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Worker History" />

</LinearLayout>

</androidx.cardview.widget.CardView>

</LinearLayout>

</ScrollView>
Expand Down

0 comments on commit 4be7619

Please sign in to comment.