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

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

Merge "development: Add dev toggle to enable verbose logs for printing" into main

parents 46dcfcf8 06395d61
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -7,3 +7,10 @@ flag {
  description: "Feature flag for deprecating ListActivity in Settings"
  bug: "299195099"
}

flag {
  name: "enable_print_debug_option"
  namespace: "printing"
  description: "Feature flag for developer option that enables printing debug logs"
  bug: "397418860"
}
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -2143,6 +2143,10 @@
    <!-- Title of item to let user know the bluetooth key is missing [CHAR LIMIT=NONE]-->
    <string name="device_details_key_missing_title">Try restarting <xliff:g id="device_name">%1$s</xliff:g>. If that doesn’t work, forget the device. For your security, only pair it again when you aren’t in a public space.\n\nIf this device isn’t nearby, you don’t need to do anything.</string>
    <!-- Title for a toggle that enables additional logs for printing [CHAR LIMIT=NONE]-->
    <string name="verbose_printer_logging_title">Verbose print logging</string>
    <!-- Summary for a toggle that enables additional logs for printing [CHAR LIMIT=NONE]-->
    <string name="verbose_printer_logging_summary">Additional debug logs, including Internet Printing Protocol (IPP) that may contain private information.</string>
    <!--  Bluetooth device details. In the confirmation dialog for unpairing a paired device, this is the label on the button that will complete the unpairing action. -->
    <string name="bluetooth_unpair_dialog_forget_confirm_button">Forget device</string>
+5 −0
Original line number Diff line number Diff line
@@ -217,6 +217,11 @@
            android:title="@string/enable_verbose_vendor_logging"
            android:summary="@string/enable_verbose_vendor_logging_summary" />

        <SwitchPreferenceCompat
            android:key="verbose_printer_logging"
            android:summary="@string/verbose_printer_logging_summary"
            android:title="@string/verbose_printer_logging_title" />

        <SwitchPreferenceCompat
            android:key="automatic_system_server_heap_dumps"
            android:title="@string/automatic_system_heap_dump_title"
+1 −0
Original line number Diff line number Diff line
@@ -824,6 +824,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new AutofillCategoryController(context, lifecycle));
        controllers.add(new AutofillLoggingLevelPreferenceController(context, lifecycle));
        controllers.add(new AutofillResetOptionsPreferenceController(context));
        controllers.add(new PrintVerboseLoggingController(context));
        controllers.add(
                new BluetoothCodecListPreferenceController(
                        context, lifecycle, bluetoothA2dpConfigStore, fragment));
+78 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.os.SystemProperties
import android.util.Log
import androidx.annotation.VisibleForTesting
import androidx.preference.Preference
import androidx.preference.TwoStatePreference
import com.android.settings.core.PreferenceControllerMixin
import com.android.settingslib.development.DeveloperOptionsPreferenceController

class PrintVerboseLoggingController(val context: Context) :
    DeveloperOptionsPreferenceController(context),
    Preference.OnPreferenceChangeListener,
    PreferenceControllerMixin {

    private val TAG = "PrintVerboseLoggingController"

    companion object {
        @VisibleForTesting val PRINT_DEBUG_LOG_PROP = "debug.printing.logs.enabled"

        @VisibleForTesting val PRINT_DEBUG_LOG_PROP_ENABLED = "true"

        @VisibleForTesting val PRINT_DEBUG_LOG_PROP_DISABLED = "false"
    }

    override fun getPreferenceKey(): String = "verbose_printer_logging"

    override fun onPreferenceChange(pref: Preference, newValue: Any): Boolean {
        if (newValue !is Boolean) {
            Log.e(TAG, "Given non bool newValue: " + newValue)
            return false
        }
        if (newValue) {
            SystemProperties.set(PRINT_DEBUG_LOG_PROP, PRINT_DEBUG_LOG_PROP_ENABLED)
        } else {
            SystemProperties.set(PRINT_DEBUG_LOG_PROP, PRINT_DEBUG_LOG_PROP_DISABLED)
        }
        return true
    }

    override fun updateState(preference: Preference) {
        super.updateState(preference)
        if (preference !is TwoStatePreference) {
            // This should never happen.
            Log.e(TAG, "Given non TwoStatePreference: " + preference)
            return
        }
        preference.setChecked(
            PRINT_DEBUG_LOG_PROP_ENABLED.equals(SystemProperties.get(PRINT_DEBUG_LOG_PROP))
        )
    }

    override public fun onDeveloperOptionsSwitchDisabled() {
        super.onDeveloperOptionsSwitchDisabled()
        SystemProperties.set(PRINT_DEBUG_LOG_PROP, PRINT_DEBUG_LOG_PROP_DISABLED)
    }

    override fun isAvailable(): Boolean {
        return Flags.enablePrintDebugOption()
    }
}
Loading