<commit_before>package com.afwsamples.testdpc;

import android.annotation.TargetApi;
import android.app.Fragment;
import android.content.ComponentName;
import android.content.pm.crossprofile.CrossProfileApps;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.afwsamples.testdpc.common.ReflectionUtil;

import java.util.List;

// TODO: Replace it with P.
@TargetApi(28)
public class CrossProfileAppsFragment extends Fragment {
    private static final String TAG = "CrossProfileAppsFragmen";

    private View mInflatedView;
    private TextView mSwitchProfileTextView;
    private TextView mDescriptionTextView;
    private ImageView mSwitchProfileImageView;
    private CrossProfileApps mCrossProfileApps;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        mInflatedView = inflater.inflate(R.layout.cross_profile_apps, container, false);
        mSwitchProfileTextView = mInflatedView.findViewById(R.id.cross_profile_app_label);
        mSwitchProfileImageView = mInflatedView.findViewById(R.id.cross_profile_app_icon);
        mDescriptionTextView = mInflatedView.findViewById(R.id.cross_profile_app_description);
        return mInflatedView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mCrossProfileApps = getActivity().getSystemService(CrossProfileApps.class);
    }

    @Override
    public void onResume() {
        super.onResume();
        refreshUi();
    }

    private void refreshUi() {
        List<UserHandle> targetUserProfiles = mCrossProfileApps.getTargetUserProfiles();
        if (targetUserProfiles.isEmpty()) {
            showNoTargetUserUi();
        } else {
            showHasTargetUserUi(targetUserProfiles.get(0));
        }
    }

    private void showNoTargetUserUi() {
        mDescriptionTextView.setText(R.string.cross_profile_apps_not_available);
        mSwitchProfileTextView.setText("");
        mSwitchProfileImageView.setImageDrawable(null);
        mSwitchProfileImageView.setOnClickListener(null);
    }

    private void showHasTargetUserUi(UserHandle userHandle) {
        mSwitchProfileTextView.setText(mCrossProfileApps.getProfileSwitchingLabel(userHandle));
        mSwitchProfileImageView.setImageDrawable(
                mCrossProfileApps.getProfileSwitchingIcon(userHandle));
        mDescriptionTextView.setText(R.string.cross_profile_apps_available);
        mSwitchProfileImageView.setOnClickListener(
                view -> mCrossProfileApps.startMainActivity(
                        new ComponentName(getActivity(),
                            PolicyManagementActivity.class),
                            userHandle));
    }
}
<commit_msg>Change according to the API change<commit_after>package com.afwsamples.testdpc;

import android.annotation.TargetApi;
import android.app.Fragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.crossprofile.CrossProfileApps;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.UserHandle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.afwsamples.testdpc.common.ReflectionUtil;

import java.util.List;

// TODO: Replace it with P.
@TargetApi(28)
public class CrossProfileAppsFragment extends Fragment {
    private static final String TAG = "CrossProfileAppsFragmen";

    private View mInflatedView;
    private TextView mSwitchProfileTextView;
    private TextView mDescriptionTextView;
    private ImageView mSwitchProfileImageView;
    private Object mCrossProfileApps;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        mInflatedView = inflater.inflate(R.layout.cross_profile_apps, container, false);
        mSwitchProfileTextView = mInflatedView.findViewById(R.id.cross_profile_app_label);
        mSwitchProfileImageView = mInflatedView.findViewById(R.id.cross_profile_app_icon);
        mDescriptionTextView = mInflatedView.findViewById(R.id.cross_profile_app_description);
        return mInflatedView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mCrossProfileApps = getActivity().getSystemService(Context.CROSS_PROFILE_APPS_SERVICE);
    }

    @Override
    public void onResume() {
        super.onResume();
        refreshUi();
    }

    private void refreshUi() {
        try {
            List<UserHandle> targetUserProfiles =
                    (List<UserHandle>) ReflectionUtil.invoke(
                            mCrossProfileApps,
                            "getTargetUserProfiles");
            if (targetUserProfiles.isEmpty()) {
                showNoTargetUserUi();
            } else {
                showHasTargetUserUi(targetUserProfiles.get(0));
            }
        } catch (ReflectionUtil.ReflectionIsTemporaryException ex) {
            Log.e(TAG, "Failed to call CrossProfileApps API: ", ex);
        }
    }

    private void showNoTargetUserUi() {
        mDescriptionTextView.setText(R.string.cross_profile_apps_not_available);
        mSwitchProfileTextView.setText("");
        mSwitchProfileImageView.setImageDrawable(null);
        mSwitchProfileImageView.setOnClickListener(null);
    }

    private void showHasTargetUserUi(UserHandle userHandle)
            throws ReflectionUtil.ReflectionIsTemporaryException {
        mSwitchProfileTextView.setText((String)
                ReflectionUtil.invoke(
                        mCrossProfileApps, "getProfileSwitchingLabel", userHandle));
        mSwitchProfileImageView.setImageDrawable((Drawable) ReflectionUtil.invoke(
                mCrossProfileApps, "getProfileSwitchingIconDrawable", userHandle));
        mDescriptionTextView.setText(R.string.cross_profile_apps_available);
        mSwitchProfileImageView.setOnClickListener(
                view -> {
                    try {
                        ReflectionUtil.invoke(
                                mCrossProfileApps, "startMainActivity",
                                new ComponentName(getActivity(), PolicyManagementActivity.class),
                                userHandle);
                    } catch (ReflectionUtil.ReflectionIsTemporaryException e) {
                        e.printStackTrace();
                    }
                });
    }
}

{'fraction_non_alphanumeric': 0.0763258130676824, 'fraction_numerical': 0.0008789920890711983, 'mean_word_length': 3.08557749850389, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6962066', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1713, 'n_words': 299}