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

Commit 19ae9aa2 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal Committed by Mohammed Althaf T
Browse files

Settings: Add /e/ legal



Signed-off-by: default avataralthafvly <althafvly@gmail.com>
parent 4827afab
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -17,4 +17,7 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- /e/ version -->
    <string name="e_version">/e/ OS version</string>

    <!-- /e/ legal. -->
    <string name="elicense_title">/e/ legal</string>
</resources>
+6 −0
Original line number Diff line number Diff line
@@ -35,6 +35,12 @@
        android:title="@string/license_title"
        settings:controller="com.android.settings.deviceinfo.legal.LicensePreferenceController" />

    <!-- e Foundation License information -->
    <Preference
        android:key="elicense"
        android:title="@string/elicense_title"
        settings:controller="com.android.settings.deviceinfo.legal.ELicensePreferenceController" />

    <!-- Terms and conditions -->
    <Preference
        android:key="terms"
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2026 The LineageOS 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.deviceinfo.legal

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.SystemProperties
import androidx.annotation.StringRes
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
import com.android.settingslib.metadata.PreferenceMetadata
import com.android.settingslib.metadata.PreferenceTitleProvider

class ELegalPreference(override val key: String, @StringRes val defaultTitle: Int = 0) :
    PreferenceMetadata, PreferenceTitleProvider, PreferenceAvailabilityProvider {

    private companion object {
        const val PROPERTY_E_LICENSE_URL = "ro.elegal.url"
    }

    private fun getLicenseUrl(): String = SystemProperties.get(PROPERTY_E_LICENSE_URL)

    override fun getTitle(context: Context): CharSequence? = context.getText(defaultTitle)

    override fun isAvailable(context: Context): Boolean {
        val url = getLicenseUrl()
        if (url.isNullOrBlank()) return false

        val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
        return intent.resolveActivity(context.packageManager) != null
    }

    override fun intent(context: Context): Intent? {
        val url = getLicenseUrl()
        return if (url.isNotBlank()) {
            Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        } else null
    }
}
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 E FOUNDATION
 *
 * 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.deviceinfo.legal;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.SystemProperties;

import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.settings.core.BasePreferenceController;

public class ELicensePreferenceController extends BasePreferenceController {

    private static final String PROPERTY_E_LICENSE_URL = "ro.elegal.url";

    public ELicensePreferenceController(Context context, String key) {
        super(context, key);
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);

        Preference preference = screen.findPreference(getPreferenceKey());
        if (preference != null) {
            preference.setOnPreferenceClickListener(pref -> {
                mContext.startActivity(getIntent());
                return true;
            });
        }
    }

    @Override
    public int getAvailabilityStatus() {
        if (getIntent().resolveActivity(mContext.getPackageManager()) != null) {
            return AVAILABLE;
        } else {
            return UNSUPPORTED_ON_DEVICE;
        }
    }

    private Intent getIntent() {
        return new Intent(Intent.ACTION_VIEW,
                Uri.parse(SystemProperties.get(PROPERTY_E_LICENSE_URL)));
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ open class LegalSettingsScreen : PreferenceScreenMixin {
        preferenceHierarchy(context) {
            +LegalPreference("copyright", R.string.copyright_title, "android.settings.COPYRIGHT")
            +LegalPreference("license", R.string.license_title, "android.settings.LICENSE")
            +ELegalPreference("e_license", R.string.elicense_title)
            +LineageLegalPreference("lineage_license", R.string.lineagelicense_title)
            +LegalPreference("terms", R.string.terms_title, "android.settings.TERMS")
            +ModuleLicensesScreen.KEY // Use screen key in case it is overlaid.