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

Commit 11a38b81 authored by Haijie Hong's avatar Haijie Hong
Browse files

Add logging action when opening bluetooth device details

Bug: 419204440
Test: local tested
Flag: EXEMPT minor change
Change-Id: Idd676226f965114ed644c3b665ca5a5df3edc26c
parent cce6ef49
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.bluetooth.ui.model.FragmentTypeModel;
import com.android.settings.connecteddevice.stylus.StylusDevicesController;
import com.android.settings.flags.Flags;
@@ -61,6 +62,9 @@ import com.android.settingslib.core.lifecycle.Lifecycle;

import com.google.common.collect.ImmutableList;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
@@ -166,6 +170,9 @@ public class BluetoothDeviceDetailsFragment extends BluetoothDetailsConfigurable
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        String callingAppPackageName =
                ((SettingsActivity) getActivity()).getInitialCallingPackage();
        logPageEntrypoint(context, callingAppPackageName, getIntent());
        localBluetoothManager = getLocalBluetoothManager(context);
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        mUserManager = getUserManager();
@@ -473,4 +480,22 @@ public class BluetoothDeviceDetailsFragment extends BluetoothDetailsConfigurable
            getActivity().setTitle(getContext().getString(R.string.stylus_device_details_title));
        }
    }

    private void logPageEntrypoint(
            @NonNull Context context,
            @Nullable String callingAppPackageName,
            @Nullable Intent intent) {
        String action = intent != null ? intent.getAction() : "";
        JSONObject formattedLogging = new JSONObject();
        try {
            formattedLogging.put("calling_package", callingAppPackageName);
            formattedLogging.put("intent_action", action);
            mMetricsFeatureProvider.action(
                    context,
                    SettingsEnums.ACTION_OPEN_SETTINGS_DEVICE_DETAILS,
                    formattedLogging.toString());
        } catch (JSONException e) {
            Log.w(TAG, "Error happened when logging entrypoint");
        }
    }
}