Add logic to log interaction of RAC warning dialog.

Bug: 326618987
Test: make, atest EuiccRacConnectivityDialogFragmentTest
Change-Id: Iccec9245da27d525cfb3d74504ab86859e152a6e
Merged-In: Iccec9245da27d525cfb3d74504ab86859e152a6e
(cherry picked from commit ea0453e5f6)
This commit is contained in:
Rafael Higuera Silva
2024-04-05 18:58:26 +00:00
parent 844d2f4c67
commit 268fa16d5b
3 changed files with 121 additions and 6 deletions

View File

@@ -43,6 +43,9 @@ public class EraseEuiccDataDialogFragment extends InstrumentedDialogFragment imp
"com.android.settings.network";
public static void show(ResetDashboardFragment host) {
if (host.getActivity() == null) {
return;
}
final EraseEuiccDataDialogFragment dialog = new EraseEuiccDataDialogFragment();
dialog.setTargetFragment(host, 0 /* requestCode */);
final FragmentManager manager = host.getActivity().getSupportFragmentManager();

View File

@@ -33,14 +33,25 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.system.ResetDashboardFragment;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.ObservableDialogFragment;
public class EuiccRacConnectivityDialogFragment extends InstrumentedDialogFragment
implements DialogInterface.OnClickListener {
public class EuiccRacConnectivityDialogFragment extends ObservableDialogFragment
implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
public static final String TAG = "EuiccRacConnectivityDlg";
private static final int METRICS_TAG =
SettingsEnums.ACTION_RESET_ESIMS_RAC_CONNECTIVITY_WARNING;
private static final int METRICS_CANCEL_VALUE = 0;
private static final int METRICS_CONTINUE_VALUE = 1;
private MetricsFeatureProvider mMetricsFeatureProvider;
static void show(ResetDashboardFragment host) {
if (host.getActivity() == null) {
return;
}
final EuiccRacConnectivityDialogFragment dialog = new EuiccRacConnectivityDialogFragment();
dialog.setTargetFragment(host, /* requestCode= */ 0);
final FragmentManager manager = host.getActivity().getSupportFragmentManager();
@@ -48,8 +59,9 @@ public class EuiccRacConnectivityDialogFragment extends InstrumentedDialogFragme
}
@Override
public int getMetricsCategory() {
return SettingsEnums.RESET_EUICC;
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
}
@NonNull
@@ -62,7 +74,7 @@ public class EuiccRacConnectivityDialogFragment extends InstrumentedDialogFragme
new AlertDialog.Builder(getContext())
.setOnDismissListener(this)
// Return is on the right side
.setPositiveButton(R.string.wifi_warning_return_button, null)
.setPositiveButton(R.string.wifi_warning_return_button, this)
// Continue is on the left side
.setNegativeButton(R.string.wifi_warning_continue_button, this);
@@ -109,7 +121,24 @@ public class EuiccRacConnectivityDialogFragment extends InstrumentedDialogFragme
// Positions of the buttons have been switch:
// negative button = left button = the button to continue
if (which == DialogInterface.BUTTON_NEGATIVE) {
logMetrics(METRICS_CONTINUE_VALUE);
EraseEuiccDataDialogFragment.show(((ResetDashboardFragment) fragment));
} else {
logMetrics(METRICS_CANCEL_VALUE);
}
}
@Override
public void onCancel(@NonNull DialogInterface dialog) {
final Fragment fragment = getTargetFragment();
if (!(fragment instanceof ResetDashboardFragment)) {
Log.e(TAG, "getTargetFragment return unexpected type");
return;
}
logMetrics(METRICS_CANCEL_VALUE);
}
private void logMetrics(int value) {
mMetricsFeatureProvider.action(getActivity(), METRICS_TAG, value);
}
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network;
import static org.mockito.Mockito.verify;
import android.app.settings.SettingsEnums;
import android.content.DialogInterface;
import com.android.settings.system.ResetDashboardFragment;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.androidx.fragment.FragmentController;
@RunWith(RobolectricTestRunner.class)
public class EuiccRacConnectivityDialogFragmentTest {
private static final int CONTINUE_VALUE = 1;
private static final int CANCEL_VALUE = 0;
private EuiccRacConnectivityDialogFragment mRacDialogFragment;
private FakeFeatureFactory mFeatureFactory;
@Mock private DialogInterface mDialogInterface;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mRacDialogFragment = new EuiccRacConnectivityDialogFragment();
FragmentController.setupFragment(mRacDialogFragment);
mRacDialogFragment.setTargetFragment(new ResetDashboardFragment(), /* requestCode= */ 0);
}
@Test
public void dialogAction_continue_intentResetESIMS_metricsLogged() {
mRacDialogFragment.onClick(mDialogInterface, DialogInterface.BUTTON_NEGATIVE);
verify(mFeatureFactory.metricsFeatureProvider)
.action(
mRacDialogFragment.getActivity(),
SettingsEnums.ACTION_RESET_ESIMS_RAC_CONNECTIVITY_WARNING,
CONTINUE_VALUE);
}
@Test
public void dialogAction_backCancel_intentResetESIMS_metricsLogged() {
mRacDialogFragment.onCancel(mDialogInterface);
verify(mFeatureFactory.metricsFeatureProvider)
.action(
mRacDialogFragment.getActivity(),
SettingsEnums.ACTION_RESET_ESIMS_RAC_CONNECTIVITY_WARNING,
CANCEL_VALUE);
}
@Test
public void dialogAction_buttonCancel_intentResetESIMS_metricsLogged() {
mRacDialogFragment.onCancel(mDialogInterface);
verify(mFeatureFactory.metricsFeatureProvider)
.action(
mRacDialogFragment.getActivity(),
SettingsEnums.ACTION_RESET_ESIMS_RAC_CONNECTIVITY_WARNING,
CANCEL_VALUE);
}
}