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

Commit c506eaaa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adding a fragment to launch the OngoingPrivacy dialog." into qt-dev

parents d4178f82 5ce9fcba
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;

import com.android.packageinstaller.DeviceUtils;
import com.android.packageinstaller.permission.ui.auto.ReviewOngoingUsageAutoFragment;
import com.android.packageinstaller.permission.ui.handheld.ReviewOngoingUsageFragment;

/**
@@ -43,9 +44,14 @@ public final class ReviewOngoingUsageActivity extends FragmentActivity {
        getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);

        long numMillis = getIntent().getLongExtra(Intent.EXTRA_DURATION_MILLIS, DEFAULT_MILLIS);
        if (DeviceUtils.isAuto(this)) {
            getSupportFragmentManager().beginTransaction().replace(android.R.id.content,
                    ReviewOngoingUsageAutoFragment.newInstance(numMillis)).commit();
        } else {
            getSupportFragmentManager().beginTransaction().replace(android.R.id.content,
                    ReviewOngoingUsageFragment.newInstance(numMillis)).commit();
        }
    }


    @Override
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.packageinstaller.permission.ui.auto;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;

import com.android.packageinstaller.permission.ui.handheld.ReviewOngoingUsageFragment;

/**
 * A dialog listing the currently uses of camera, microphone, and location.
 */
public class ReviewOngoingUsageAutoFragment extends ReviewOngoingUsageFragment {

    /**
     * @return A new {@link ReviewOngoingUsageAutoFragment}
     */
    public static ReviewOngoingUsageAutoFragment newInstance(long numMillis) {
        ReviewOngoingUsageAutoFragment fragment = new ReviewOngoingUsageAutoFragment();
        Bundle arguments = new Bundle();
        arguments.putLong(Intent.EXTRA_DURATION_MILLIS, numMillis);
        fragment.setArguments(arguments);
        return fragment;
    }

    @Override
    protected void setNeutralButton(AlertDialog.Builder builder) {
        // do nothing
    }
}
+15 −10
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ import java.util.concurrent.TimeUnit;
/**
 * A dialog listing the currently uses of camera, microphone, and location.
 */
public final class ReviewOngoingUsageFragment extends PreferenceFragmentCompat {
public class ReviewOngoingUsageFragment extends PreferenceFragmentCompat {

    private @NonNull PermissionUsages mPermissionUsages;
    private @Nullable AlertDialog mDialog;
@@ -142,19 +142,24 @@ public final class ReviewOngoingUsageFragment extends PreferenceFragmentCompat {
    }

    private void showDialog(@NonNull List<Pair<AppPermissionUsage, List<GroupUsage>>> usages) {
        mDialog = new AlertDialog.Builder(getActivity())
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
                .setView(createDialogView(usages))
                .setPositiveButton(R.string.ongoing_usage_dialog_ok, (dialog, which) ->
                        PermissionControllerStatsLog.write(PRIVACY_INDICATORS_INTERACTED,
                                PRIVACY_INDICATORS_INTERACTED__TYPE__DIALOG_DISMISS, null))
                .setNeutralButton(R.string.ongoing_usage_dialog_open_settings, (dialog, which) -> {
                .setOnDismissListener((dialog) -> getActivity().finish());
        setNeutralButton(builder);
        mDialog = builder.create();
        mDialog.show();
    }

    protected void setNeutralButton(AlertDialog.Builder builder) {
        builder.setNeutralButton(R.string.ongoing_usage_dialog_open_settings, (dialog, which) -> {
            PermissionControllerStatsLog.write(PRIVACY_INDICATORS_INTERACTED,
                    PRIVACY_INDICATORS_INTERACTED__TYPE__DIALOG_PRIVACY_SETTINGS, null);
            startActivity(new Intent(Settings.ACTION_PRIVACY_SETTINGS).putExtra(
                            Intent.EXTRA_DURATION_MILLIS, TimeUnit.MINUTES.toMillis(1))); })
                .setOnDismissListener((dialog) -> getActivity().finish())
                .create();
        mDialog.show();
                    Intent.EXTRA_DURATION_MILLIS, TimeUnit.MINUTES.toMillis(1)));
        });
    }

    private @NonNull View createDialogView(