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

Commit 917cc515 authored by LuK1337's avatar LuK1337
Browse files

LineageParts: Add device controls global action

Change-Id: I67ac94740b4d0acbc8dd9ae98123e5c0f8aaf0bb
parent 98142f4b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -264,6 +264,7 @@
    <string name="power_menu_bug_report_devoptions_unavailable">Bug reporting is disabled as development settings aren\'t enabled</string>
    <string name="power_menu_bug_report_unavailable_for_user">Bug reporting is disabled for non-primary users.</string>
    <string name="power_menu_emergency_title">Emergency</string>
    <string name="power_menu_devicecontrols_title">Device controls</string>
    <string name="power_menu_advanced_restart_title">Advanced restart</string>
    <string name="power_menu_advanced_restart_summary">When unlocked, include options in the power menu for restarting into recovery or bootloader</string>

+6 −0
Original line number Diff line number Diff line
@@ -49,6 +49,12 @@
            android:title="@string/power_menu_emergency_title"
            android:defaultValue="false" />

        <CheckBoxPreference
            android:key="devicecontrols"
            android:title="@string/power_menu_devicecontrols_title"
            android:defaultValue="false"
            android:enabled="false" />

    </PreferenceCategory>

    <PreferenceCategory
+27 −0
Original line number Diff line number Diff line
@@ -17,18 +17,21 @@

package org.lineageos.lineageparts.input;

import android.Manifest;
import android.content.Context;
import android.content.pm.UserInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.service.controls.ControlsProviderService;

import androidx.preference.CheckBoxPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;

import com.android.internal.widget.LockPatternUtils;
import com.android.settingslib.applications.ServiceListing;

import org.lineageos.internal.util.PowerMenuConstants;
import org.lineageos.lineageparts.R;
@@ -55,6 +58,7 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
    private CheckBoxPreference mUsersPref;
    private CheckBoxPreference mBugReportPref;
    private CheckBoxPreference mEmergencyPref;
    private CheckBoxPreference mDeviceControlsPref;

    private LineageGlobalActions mLineageGlobalActions;

@@ -87,6 +91,8 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
                mBugReportPref = findPreference(GLOBAL_ACTION_KEY_BUGREPORT);
            } else if (action.equals(GLOBAL_ACTION_KEY_EMERGENCY)) {
                mEmergencyPref = findPreference(GLOBAL_ACTION_KEY_EMERGENCY);
            } else if (action.equals(GLOBAL_ACTION_KEY_DEVICECONTROLS)) {
                mDeviceControlsPref = findPreference(GLOBAL_ACTION_KEY_DEVICECONTROLS);
            }
        }

@@ -135,6 +141,23 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
                    GLOBAL_ACTION_KEY_EMERGENCY));
        }

        if (mDeviceControlsPref != null) {
            mDeviceControlsPref.setChecked(mLineageGlobalActions.userConfigContains(
                    GLOBAL_ACTION_KEY_DEVICECONTROLS));

            // Enable preference if any device control app is installed
            ServiceListing serviceListing = new ServiceListing.Builder(mContext)
                    .setIntentAction(ControlsProviderService.SERVICE_CONTROLS)
                    .setPermission(Manifest.permission.BIND_CONTROLS)
                    .setNoun("Controls Provider")
                    .setSetting("controls_providers")
                    .setTag("controls_providers")
                    .build();
            serviceListing.addCallback(
                    services -> mDeviceControlsPref.setEnabled(!services.isEmpty()));
            serviceListing.reload();
        }

        updatePreferences();
    }

@@ -170,6 +193,10 @@ public class PowerMenuActions extends SettingsPreferenceFragment {
            value = mEmergencyPref.isChecked();
            mLineageGlobalActions.updateUserConfig(value, GLOBAL_ACTION_KEY_EMERGENCY);

        } else if (preference == mDeviceControlsPref) {
            value = mDeviceControlsPref.isChecked();
            mLineageGlobalActions.updateUserConfig(value, GLOBAL_ACTION_KEY_DEVICECONTROLS);

        } else {
            return super.onPreferenceTreeClick(preference);
        }