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

Commit 614da2b9 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Revert "Revert "Write telemetry system settings""

This reverts commit 05a8dfea.
parent 77a4ad70
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -218,6 +218,12 @@
    <string name="fast_charging_title">Fast charging</string>
    <string name="fast_charging_summary">Disable to reduce the heat produced by the device while charging or to extend the lifespan of the battery</string>

    <!-- /e/ Telemetry -->
    <string name="enable_telemetry">Enable /e/OS Telemetry</string>
    <string name="telemetry_details">Enable automatic bug reporting</string>
    <string name="telemetry_dialog_title">You are about to enable /e/OS Telemetry</string>
    <string name="telemetry_dialog_message">It will allow automatic bug report when an application crash or when the application ends up in an unexpected state. Please reboot your device after changing this setting.</string>

    <!-- Advanced Privacy -->
    <string name="advanced_privacy_dashboard_title" translatable="false">Advanced Privacy</string>
    <string name="advanced_privacy_dashboard_summary">Manage trackers, fake location, hide IP address</string>
+5 −0
Original line number Diff line number Diff line
@@ -618,6 +618,11 @@
            android:key="change_update_source"
            android:title="@string/title_ota_server"
            android:summary="@string/use_ota_summary" />

        <SwitchPreference
            android:key="enable_telemetry"
            android:title="@string/enable_telemetry"
            android:summary="@string/telemetry_details" />
    </PreferenceCategory>

    <com.android.settings.development.autofill.AutofillPreferenceCategory
+1 −0
Original line number Diff line number Diff line
@@ -485,6 +485,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new BluetoothMaxConnectedAudioDevicesPreferenceController(context));
        controllers.add(new ShowTapsPreferenceController(context));
        controllers.add(new ChangeSourcePreferenceController(context));
        controllers.add(new EnableTelemetryPreferenceController(context));
        controllers.add(new PointerLocationPreferenceController(context));
        controllers.add(new ShowSurfaceUpdatesPreferenceController(context));
        controllers.add(new ShowLayoutBoundsPreferenceController(context));
+101 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 MURENA SAS
 *
 * 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.content.Context;
import android.content.DialogInterface;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;

import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

public class EnableTelemetryPreferenceController extends DeveloperOptionsPreferenceController implements
        Preference.OnPreferenceChangeListener, PreferenceControllerMixin {

    private static final String PREFERENCES_ENABLE_TELEMETRY_KEY = "enable_telemetry";
    private static final String TELEMETRY_KEY = "e_telemetry";
    private static final int TELEMETRY_ON = 1;
    private static final int TELEMETRY_OFF = 0;
    private String status;

    public EnableTelemetryPreferenceController(Context context) {
        super(context);
    }

    @Override
    public String getPreferenceKey(){
        return PREFERENCES_ENABLE_TELEMETRY_KEY;
    }

    public void enableTelemetry(Boolean enabled) {
        Settings.System.putInt(mContext.getContentResolver(), TELEMETRY_KEY, enabled ? TELEMETRY_ON : TELEMETRY_OFF);
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        final boolean isEnabled = (Boolean) newValue;
        ((SwitchPreference) mPreference).setChecked(isEnabled);

        if (!isEnabled) {
	    enableTelemetry(false);
	    return true;
	}

        new AlertDialog.Builder(mContext)
                .setTitle(R.string.telemetry_dialog_title)
                .setMessage(mContext.getResources().getString(R.string.telemetry_dialog_message))
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        ((SwitchPreference) mPreference).setChecked(true);
                        enableTelemetry(true);
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        ((SwitchPreference) mPreference).setChecked(false);
                        enableTelemetry(false);
                    }
                }).show();
        return true;
    }

    @Override
    public void updateState(Preference preference) {
	if (Settings.System.getInt(mContext.getContentResolver(), TELEMETRY_KEY, 0) == TELEMETRY_ON) {
            ((SwitchPreference) mPreference).setChecked(true);
	} else {
            ((SwitchPreference) mPreference).setChecked(false);
	}
    }

    @Override
    protected void onDeveloperOptionsSwitchDisabled() {
        super.onDeveloperOptionsSwitchDisabled();
        ((SwitchPreference) mPreference).setChecked(false);
        enableTelemetry(false);
    }

    @Override
    protected void onDeveloperOptionsSwitchEnabled() {
        super.onDeveloperOptionsSwitchEnabled();
    }
}