(SHIFT) deviceinfo: add ShiftOS legal

Change-Id: I96e75ba922203a1d79c09fac43a9d9b88aa71b2f
Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
diff --git a/res/values-de/shiftos_strings.xml b/res/values-de/shiftos_strings.xml
new file mode 100644
index 0000000..6e3e454
--- /dev/null
+++ b/res/values-de/shiftos_strings.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2022 SHIFT GmbH
+
+     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.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="shiftos_version">ShiftOS-Version</string>
+    <string name="shiftos_license_title">Rechtliche Hinweise zu ShiftOS</string>
+</resources>
diff --git a/res/values/shiftos_config.xml b/res/values/shiftos_config.xml
index 7903b55..a8408b1 100644
--- a/res/values/shiftos_config.xml
+++ b/res/values/shiftos_config.xml
@@ -15,6 +15,9 @@
      limitations under the License.
 -->
 <resources>
+    <!-- URL to privacy policy / tos  -->
+    <string name="shiftos_license_url">"https://shift.eco/legal/"</string>
+
     <!-- Packages, which should be kept enabled -->
     <string-array name="config_shiftos_keep_enabled_packages" translatable="false">
         <!-- EEA GMS requirement: do not allow disabling search engine selector -->
diff --git a/res/values/shiftos_strings.xml b/res/values/shiftos_strings.xml
index 2b047ea..1c3e7c8 100644
--- a/res/values/shiftos_strings.xml
+++ b/res/values/shiftos_strings.xml
@@ -16,4 +16,5 @@
 -->
 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <string name="shiftos_version">ShiftOS version</string>
+    <string name="shiftos_license_title">ShiftOS legal</string>
 </resources>
diff --git a/res/xml/about_legal.xml b/res/xml/about_legal.xml
index 7c43509..29d2386 100644
--- a/res/xml/about_legal.xml
+++ b/res/xml/about_legal.xml
@@ -43,6 +43,12 @@
         settings:controller="com.android.settings.deviceinfo.legal.LineageLicensePreferenceController" />
 -->
 
+    <!-- ShiftOS License information -->
+    <Preference
+        android:key="shiftos_license"
+        android:title="@string/shiftos_license_title"
+        settings:controller="com.android.settings.deviceinfo.legal.ShiftOsLicensePreferenceController" />
+
     <!-- Terms and conditions -->
     <Preference
         android:key="terms"
diff --git a/src/com/android/settings/deviceinfo/legal/ShiftOsLicensePreferenceController.java b/src/com/android/settings/deviceinfo/legal/ShiftOsLicensePreferenceController.java
new file mode 100644
index 0000000..afda55a
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/legal/ShiftOsLicensePreferenceController.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2021 The LineageOS Project
+ * Copyright (C) 2022 SHIFT GmbH
+ *
+ * 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.R;
+import com.android.settings.core.BasePreferenceController;
+
+public class ShiftOsLicensePreferenceController extends BasePreferenceController {
+
+    public ShiftOsLicensePreferenceController(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(mContext.getString(R.string.shiftos_license_url)));
+    }
+}