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

Commit 41cb8496 authored by Jonathan Klee's avatar Jonathan Klee Committed by Nishith Khanna
Browse files

Write telemetry system settings

parent 960445fd
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -30,6 +30,12 @@
    <string name="use_ota_staging_popup_title">You are about to connect to /e/ OS test channel</string>
    <string name="use_ota_staging_popup_message">It will allow you to download and install test versions of /e/ OS. Those builds may be unstable, and should be used only for test purposes. Please accept only if you know what you are doing.</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>

    <!-- /e/ 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>
+4 −0
Original line number Diff line number Diff line
@@ -774,6 +774,10 @@
            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>

    <PreferenceCategory
+1 −0
Original line number Diff line number Diff line
@@ -777,6 +777,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new NfcVerboseVendorLogPreferenceController(context, fragment));
        controllers.add(new ShowTapsPreferenceController(context));
        controllers.add(new ChangeSourcePreferenceController(context));
        controllers.add(new EnableTelemetryPreferenceController(context));
        controllers.add(new PointerLocationPreferenceController(context));
        controllers.add(new ShowKeyPressesPreferenceController(context));
        controllers.add(new TouchpadVisualizerPreferenceController(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();
    }
}