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

Verified Commit ecf17846 authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Rework settings bits

parent 9d2d56ab
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -14,6 +14,6 @@
        <activity
            android:name=".MPermissionHelperActivity"
            android:exported="true"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
            android:theme="@style/HiddenActivity"/>
    </application>
</manifest>
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public abstract class HelperLocationBackendService extends LocationBackendServic
                perms.addAll(Arrays.asList(helper.getRequiredPermissions()));
            }
            // Request background location permission if needed as we are likely to run in background
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q && (perms.contains(ACCESS_COARSE_LOCATION) || perms.contains(ACCESS_FINE_LOCATION))) {
            if (Build.VERSION.SDK_INT >= 29 && (perms.contains(ACCESS_COARSE_LOCATION) || perms.contains(ACCESS_FINE_LOCATION))) {
                perms.add(ACCESS_BACKGROUND_LOCATION);
            }
            for (Iterator<String> iterator = perms.iterator(); iterator.hasNext(); ) {
+15 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ SPDX-FileCopyrightText: 2020, microG Project Team
  ~ SPDX-License-Identifier: Apache-2.0
  -->

<resources>

    <style name="HiddenActivity" parent="android:Theme.Translucent.NoTitleBar">
        <item name="android:windowAnimationStyle">@null</item>
        <item name="android:windowDisablePreview">true</item>
        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
    </style>
</resources>
 No newline at end of file
+1 −5
Original line number Diff line number Diff line
@@ -66,15 +66,11 @@ abstract class AbstractBackendHelper(private val TAG: String, private val contex
    fun bind() {
        if (!bound) {
            Log.d(TAG, "Binding to: $serviceIntent sig: $signatureDigest")
            if (signatureDigest == null) {
                Log.w(TAG, "No signature digest provided. Aborting.")
                return
            }
            if (serviceIntent.getPackage() == null) {
                Log.w(TAG, "Intent is not properly resolved, can't verify signature. Aborting.")
                return
            }
            if (signatureDigest != firstSignatureDigest(context, serviceIntent.getPackage())) {
            if (signatureDigest != null && signatureDigest != firstSignatureDigest(context, serviceIntent.getPackage())) {
                Log.w(TAG, "Target signature does not match selected package (" + signatureDigest + " = " + firstSignatureDigest(context, serviceIntent.getPackage()) + "). Aborting.")
                return
            }
+39 −14
Original line number Diff line number Diff line
@@ -7,32 +7,57 @@ package org.microg.nlp.service

import android.content.Context
import android.content.SharedPreferences
import android.os.Build


class Preferences(private val context: Context) {

    private val sharedPreferences: SharedPreferences
        get() = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE)

    var locationBackends: Array<String>
        get() = splitBackendString(sharedPreferences.getString(PREF_LOCATION_BACKENDS, null))
    private fun SharedPreferences.getStringSetCompat(key: String, defValues: Set<String>? = null): Set<String>? {
        if (Build.VERSION.SDK_INT >= 11) {
            try {
                val res = getStringSet(key, null)
                if (res != null) return res.filter { it.isNotEmpty() }.toSet()
            } catch (ignored: Exception) {
                // Ignore
            }
        }
        try {
            val str = getString(key, null)
            if (str != null) return str.split("\\|".toRegex()).filter { it.isNotEmpty() }.toSet()
        } catch (ignored: Exception) {
            // Ignore
        }
        return defValues
    }

    private fun SharedPreferences.Editor.putStringSetCompat(key: String, values: Set<String>): SharedPreferences.Editor {
        return if (Build.VERSION.SDK_INT >= 11) {
            putStringSet(key, values.filter { it.isNotEmpty() }.toSet())
        } else {
            putString(key, values.filter { it.isNotEmpty() }.joinToString("|"))
        }
    }

    var locationBackends: Set<String>
        get() =
            sharedPreferences.getStringSetCompat(PREF_LOCATION_BACKENDS) ?: emptySet()
        set(backends) {
            sharedPreferences.edit().putString(PREF_LOCATION_BACKENDS, backends.joinToString("|")).apply()
            sharedPreferences.edit().putStringSetCompat(PREF_LOCATION_BACKENDS, backends).apply()
        }

    var geocoderBackends: Array<String>
        get() = splitBackendString(sharedPreferences.getString(PREF_GEOCODER_BACKENDS, null))
    var geocoderBackends: Set<String>
        get() =
            sharedPreferences.getStringSetCompat(PREF_GEOCODER_BACKENDS) ?: emptySet()
        set(backends) {
            sharedPreferences.edit().putString(PREF_GEOCODER_BACKENDS, backends.joinToString("|")).apply()
            sharedPreferences.edit().putStringSetCompat(PREF_GEOCODER_BACKENDS, backends).apply()
        }

    companion object {
        private val PREFERENCES_NAME = "unified_nlp"
        private val PREF_LOCATION_BACKENDS = "location_backends"
        private val PREF_GEOCODER_BACKENDS = "geocoder_backends"

        private fun splitBackendString(backendString: String?): Array<String> {
            return backendString?.split("\\|".toRegex())?.dropLastWhile(String::isEmpty)?.toTypedArray()
                    ?: emptyArray()
        }
        private const val PREFERENCES_NAME = "unified_nlp"
        private const val PREF_LOCATION_BACKENDS = "location_backends"
        private const val PREF_GEOCODER_BACKENDS = "geocoder_backends"
    }
}
Loading