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

Commit 60ab063e authored by jeffreyhuang's avatar jeffreyhuang
Browse files

Introduce LogPersistPreferenceControllerV2

 - Create new LogPersistPreferenceControllerV2
 - Deprecate LogPersistPreferenceController
 - Add DisableLogPersistWarningDialog
 - Create controller inside the DashboardFragment
 - Port logic from DevelopmentSettings into the controller

Bug: 34203528
Test: make RunSettingsRoboTests -j40
Change-Id: I8ff49ec4ece15cad2d0c60bd21488e3f5d55ee98
parent cafce68b
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ import java.util.List;

public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFragment
        implements SwitchBar.OnSwitchChangeListener, OemUnlockDialogHost, AdbDialogHost,
        AdbClearKeysDialogHost {
        AdbClearKeysDialogHost, LogPersistDialogHost {

    private static final String TAG = "DevSettingsDashboard";

@@ -179,6 +179,20 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controller.onClearAdbKeysConfirmed();
    }

    @Override
    public void onDisableLogPersistDialogConfirmed() {
        final LogPersistPreferenceControllerV2 controller = getDevelopmentOptionsController(
                LogPersistPreferenceControllerV2.class);
        controller.onDisableLogPersistDialogConfirmed();
    }

    @Override
    public void onDisableLogPersistDialogRejected() {
        final LogPersistPreferenceControllerV2 controller = getDevelopmentOptionsController(
                LogPersistPreferenceControllerV2.class);
        controller.onDisableLogPersistDialogRejected();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        boolean handledResult = false;
@@ -270,7 +284,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new WaitForDebuggerPreferenceController(context));
        controllers.add(new VerifyAppsOverUsbPreferenceControllerV2(context));
        controllers.add(new LogdSizePreferenceControllerV2(context));
        // store logger data persistently on device
        controllers.add(new LogPersistPreferenceControllerV2(context, fragment, lifecycle));
        controllers.add(new ConnectivityMonitorPreferenceControllerV2(context));
        controllers.add(new CameraLaserSensorPreferenceControllerV2(context));
        controllers.add(new CameraHalHdrPlusPreferenceControllerV2(context));
+76 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.development;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.DialogInterface;
import android.os.Bundle;

import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;

public class DisableLogPersistWarningDialog extends InstrumentedDialogFragment implements
        DialogInterface.OnClickListener, DialogInterface.OnDismissListener {

    public static final String TAG = "DisableLogPersistDlg";

    public static void show(LogPersistDialogHost host) {
        if (!(host instanceof Fragment)) {
            return;
        }
        final Fragment hostFragment = (Fragment) host;
        final FragmentManager manager = hostFragment.getActivity().getFragmentManager();
        if (manager.findFragmentByTag(TAG) == null) {
            final DisableLogPersistWarningDialog dialog =
                    new DisableLogPersistWarningDialog();
            dialog.setTargetFragment(hostFragment, 0 /* requestCode */);
            dialog.show(manager, TAG);
        }
    }

    @Override
    public int getMetricsCategory() {
        return MetricsProto.MetricsEvent.DIALOG_LOG_PERSIST;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new AlertDialog.Builder(getActivity())
                .setTitle(R.string.dev_logpersist_clear_warning_title)
                .setMessage(R.string.dev_logpersist_clear_warning_message)
                .setPositiveButton(android.R.string.yes, this /* onClickListener */)
                .setNegativeButton(android.R.string.no, this /* onClickListener */)
                .create();
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        final LogPersistDialogHost host = (LogPersistDialogHost) getTargetFragment();
        if (host == null) {
            return;
        }
        if (which == DialogInterface.BUTTON_POSITIVE) {
            host.onDisableLogPersistDialogConfirmed();
        } else {
            host.onDisableLogPersistDialogRejected();
        }
    }
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.development;

/**
 * Interface for LogPersistDialogFragment callbacks.
 */
public interface LogPersistDialogHost {

    /**
     * Called when the user presses yes on the warning dialog.
     */
    void onDisableLogPersistDialogConfirmed();

    /**
     * Called when the user presses no on the warning dialog.
     */
    void onDisableLogPersistDialogRejected();
}
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.development;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;

import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.development.AbstractLogpersistPreferenceController;

public class LogPersistPreferenceControllerV2 extends
        AbstractLogpersistPreferenceController implements PreferenceControllerMixin {

    private final DevelopmentSettingsDashboardFragment mFragment;
    private ListPreference mPreference;


    public LogPersistPreferenceControllerV2(Context context,
            DevelopmentSettingsDashboardFragment fragment, Lifecycle lifecycle) {
        super(context, lifecycle);

        mFragment = fragment;
    }

    @Override
    public void showConfirmationDialog(@Nullable Preference preference) {
        DisableLogPersistWarningDialog.show(mFragment);
    }

    @Override
    public void dismissConfirmationDialog() {
        // intentional no-op
    }

    @Override
    public boolean isConfirmationDialogShowing() {
        return false;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);

        mPreference = (ListPreference) screen.findPreference(getPreferenceKey());
    }

    @Override
    public void updateState(Preference preference) {
        updateLogpersistValues();
    }

    @Override
    protected void onDeveloperOptionsSwitchEnabled() {
        mPreference.setEnabled(true);
    }

    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        writeLogpersistOption(null /* new value */, true);
        mPreference.setEnabled(false);
    }

    public void onDisableLogPersistDialogConfirmed() {
        setLogpersistOff(true);
        updateLogpersistValues();
    }

    public void onDisableLogPersistDialogRejected() {
        updateLogpersistValues();
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,10 @@ import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.development.AbstractLogpersistPreferenceController;

/**
 * depreacted in favor of {@link LogdSizePreferenceControllerV2}
 */
@Deprecated
public class LogpersistPreferenceController extends AbstractLogpersistPreferenceController
        implements PreferenceControllerMixin {

Loading