diff options
Diffstat (limited to 'src/com')
5 files changed, 218 insertions, 2 deletions
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java index 39e3d03eb7..41c177b2d5 100644 --- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java @@ -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"; @@ -180,6 +180,20 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra } @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; for (AbstractPreferenceController controller : mPreferenceControllers) { @@ -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)); diff --git a/src/com/android/settings/development/DisableLogPersistWarningDialog.java b/src/com/android/settings/development/DisableLogPersistWarningDialog.java new file mode 100644 index 0000000000..1ab3a92a69 --- /dev/null +++ b/src/com/android/settings/development/DisableLogPersistWarningDialog.java @@ -0,0 +1,76 @@ +/* + * 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(); + } + } +} diff --git a/src/com/android/settings/development/LogPersistDialogHost.java b/src/com/android/settings/development/LogPersistDialogHost.java new file mode 100644 index 0000000000..0187e0370a --- /dev/null +++ b/src/com/android/settings/development/LogPersistDialogHost.java @@ -0,0 +1,33 @@ +/* + * 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(); +} diff --git a/src/com/android/settings/development/LogPersistPreferenceControllerV2.java b/src/com/android/settings/development/LogPersistPreferenceControllerV2.java new file mode 100644 index 0000000000..537b71bbc5 --- /dev/null +++ b/src/com/android/settings/development/LogPersistPreferenceControllerV2.java @@ -0,0 +1,89 @@ +/* + * 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(); + } +} diff --git a/src/com/android/settings/development/LogpersistPreferenceController.java b/src/com/android/settings/development/LogpersistPreferenceController.java index a1ca186cca..26ab878452 100644 --- a/src/com/android/settings/development/LogpersistPreferenceController.java +++ b/src/com/android/settings/development/LogpersistPreferenceController.java @@ -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 { |