Migrate the Legal Info page to Catalyst
Test: atest LegalPreferenceTest Test: atest LegalSettingsScreenTest Test: atest WallpaperAttributionsPreferenceTest Bug: 360061554 Flag: com.android.settings.flags.catalyst_legal_information Change-Id: Ic15384e853584b72a847e1a10713a0c3c29273a7
This commit is contained in:
@@ -17,8 +17,13 @@
|
||||
package com.android.settings;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.deviceinfo.legal.LegalSettingsScreen;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
@@ -44,4 +49,10 @@ public class LegalSettings extends DashboardFragment {
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.about_legal);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPreferenceScreenBindingKey(@NonNull Context context) {
|
||||
return LegalSettingsScreen.KEY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.android.settings.deviceinfo.legal;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
// LINT.IfChange
|
||||
public class CopyrightPreferenceController extends LegalPreferenceController {
|
||||
|
||||
private static final Intent INTENT = new Intent("android.settings.COPYRIGHT");
|
||||
@@ -30,3 +31,4 @@ public class CopyrightPreferenceController extends LegalPreferenceController {
|
||||
return INTENT;
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(LegalPreference.kt)
|
||||
|
||||
58
src/com/android/settings/deviceinfo/legal/LegalPreference.kt
Normal file
58
src/com/android/settings/deviceinfo/legal/LegalPreference.kt
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source 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.content.pm.ApplicationInfo
|
||||
import android.content.pm.ResolveInfo
|
||||
import androidx.annotation.StringRes
|
||||
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
|
||||
import com.android.settingslib.metadata.PreferenceMetadata
|
||||
import com.android.settingslib.metadata.PreferenceTitleProvider
|
||||
|
||||
// LINT.IfChange
|
||||
class LegalPreference(
|
||||
override val key: String,
|
||||
@StringRes val defaultTitle: Int = 0,
|
||||
val intentAction: String,
|
||||
) : PreferenceMetadata, PreferenceTitleProvider, PreferenceAvailabilityProvider {
|
||||
|
||||
override fun getTitle(context: Context): CharSequence? {
|
||||
val resolveInfo =
|
||||
findMatchingSpecificActivity(context) ?: return context.getText(defaultTitle)
|
||||
return resolveInfo.loadLabel(context.packageManager)
|
||||
}
|
||||
|
||||
override fun isAvailable(context: Context) = (findMatchingSpecificActivity(context) != null)
|
||||
|
||||
override fun intent(context: Context) =
|
||||
findMatchingSpecificActivity(context)?.let {
|
||||
Intent()
|
||||
.setClassName(it.activityInfo.packageName, it.activityInfo.name)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
|
||||
private fun findMatchingSpecificActivity(context: Context): ResolveInfo? {
|
||||
val intent = Intent(intentAction)
|
||||
// Find the activity that is in the system image
|
||||
val list: List<ResolveInfo> = context.packageManager.queryIntentActivities(intent, 0)
|
||||
return list.firstOrNull {
|
||||
(it.activityInfo.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0
|
||||
}
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(LegalPreferenceController.java)
|
||||
@@ -27,6 +27,7 @@ import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// LINT.IfChange
|
||||
public abstract class LegalPreferenceController extends BasePreferenceController {
|
||||
private final PackageManager mPackageManager;
|
||||
private Preference mPreference;
|
||||
@@ -94,3 +95,4 @@ public abstract class LegalPreferenceController extends BasePreferenceController
|
||||
mPreference.setTitle(resolveInfo.loadLabel(mPackageManager));
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(LegalPreference.kt)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source 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 com.android.settings.LegalSettings
|
||||
import com.android.settings.R
|
||||
import com.android.settings.flags.Flags
|
||||
import com.android.settingslib.metadata.ProvidePreferenceScreen
|
||||
import com.android.settingslib.metadata.preferenceHierarchy
|
||||
import com.android.settingslib.preference.PreferenceScreenCreator
|
||||
|
||||
@ProvidePreferenceScreen
|
||||
open class LegalSettingsScreen : PreferenceScreenCreator {
|
||||
override val key: String
|
||||
get() = KEY
|
||||
|
||||
override val title: Int
|
||||
get() = R.string.legal_information
|
||||
|
||||
override fun isFlagEnabled(context: Context) = Flags.catalystLegalInformation()
|
||||
|
||||
override fun fragmentClass() = LegalSettings::class.java
|
||||
|
||||
override fun getPreferenceHierarchy(context: Context) =
|
||||
preferenceHierarchy(this) {
|
||||
+LegalPreference("copyright", R.string.copyright_title, "android.settings.COPYRIGHT")
|
||||
+LegalPreference("license", R.string.license_title, "android.settings.LICENSE")
|
||||
+LegalPreference("terms", R.string.terms_title, "android.settings.TERMS")
|
||||
+ModuleLicensesScreen.KEY // Use screen key in case it is overlaid.
|
||||
+LegalPreference(
|
||||
"webview_license",
|
||||
R.string.webview_license_title,
|
||||
"android.settings.WEBVIEW_LICENSE",
|
||||
)
|
||||
+WallpaperAttributionsPreference()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KEY = "legal_information"
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ package com.android.settings.deviceinfo.legal;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
// LINT.IfChange
|
||||
public class LicensePreferenceController extends LegalPreferenceController {
|
||||
|
||||
private static final Intent INTENT = new Intent("android.settings.LICENSE");
|
||||
@@ -30,3 +31,4 @@ public class LicensePreferenceController extends LegalPreferenceController {
|
||||
return INTENT;
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(LegalPreference.kt)
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// LINT.IfChange
|
||||
public class ModuleLicensesListPreferenceController extends BasePreferenceController {
|
||||
public ModuleLicensesListPreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
@@ -39,3 +40,4 @@ public class ModuleLicensesListPreferenceController extends BasePreferenceContro
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(ModuleLicensesScreen.kt)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source 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 com.android.settings.R
|
||||
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
|
||||
import com.android.settingslib.metadata.ProvidePreferenceScreen
|
||||
import com.android.settingslib.metadata.preferenceHierarchy
|
||||
import com.android.settingslib.preference.PreferenceScreenCreator
|
||||
|
||||
// LINT.IfChange
|
||||
@ProvidePreferenceScreen
|
||||
class ModuleLicensesScreen : PreferenceScreenCreator, PreferenceAvailabilityProvider {
|
||||
override val key: String
|
||||
get() = KEY
|
||||
|
||||
override val title: Int
|
||||
get() = R.string.module_license_title
|
||||
|
||||
// We need to avoid directly assign fragment attribute in the bind() API. So we need to create
|
||||
// a screen and provide it to its parent screen LegalSettingsScreen.
|
||||
// By the way, we also need to set the isFlagEnabled() as false. Let system render the legacy
|
||||
// UI. The hierarchy will be added while migrating this page.
|
||||
override fun isFlagEnabled(context: Context) = false
|
||||
|
||||
override fun fragmentClass() = ModuleLicensesDashboard::class.java
|
||||
|
||||
override fun getPreferenceHierarchy(context: Context) = preferenceHierarchy(this) {}
|
||||
|
||||
override fun isAvailable(context: Context): Boolean {
|
||||
val modules = context.packageManager.getInstalledModules(/* flags= */ 0)
|
||||
return modules.any {
|
||||
try {
|
||||
ModuleLicenseProvider.getPackageAssetManager(context.packageManager, it.packageName)
|
||||
.list("")
|
||||
?.contains(ModuleLicenseProvider.GZIPPED_LICENSE_FILE_NAME) == true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KEY = "module_license"
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(ModuleLicensesListPreferenceController.java)
|
||||
@@ -17,6 +17,7 @@ package com.android.settings.deviceinfo.legal;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
// LINT.IfChange
|
||||
public class TermsPreferenceController extends LegalPreferenceController {
|
||||
|
||||
private static final Intent INTENT = new Intent("android.settings.TERMS");
|
||||
@@ -30,3 +31,4 @@ public class TermsPreferenceController extends LegalPreferenceController {
|
||||
return INTENT;
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(LegalPreference.kt)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source 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 androidx.preference.Preference
|
||||
import com.android.settings.R
|
||||
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
|
||||
import com.android.settingslib.metadata.PreferenceMetadata
|
||||
import com.android.settingslib.preference.PreferenceBinding
|
||||
|
||||
// LINT.IfChange
|
||||
class WallpaperAttributionsPreference :
|
||||
PreferenceMetadata, PreferenceBinding, PreferenceAvailabilityProvider {
|
||||
override val key: String
|
||||
get() = KEY
|
||||
|
||||
override val title: Int
|
||||
get() = R.string.wallpaper_attributions
|
||||
|
||||
override val summary: Int
|
||||
get() = R.string.wallpaper_attributions_values
|
||||
|
||||
override fun bind(preference: Preference, metadata: PreferenceMetadata) {
|
||||
super.bind(preference, metadata)
|
||||
preference.isSelectable = false
|
||||
}
|
||||
|
||||
override fun isAvailable(context: Context) =
|
||||
context.resources.getBoolean(R.bool.config_show_wallpaper_attribution)
|
||||
|
||||
companion object {
|
||||
const val KEY = "wallpaper_attributions"
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(WallpaperAttributionsPreferenceController.java)
|
||||
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
// LINT.IfChange
|
||||
public class WallpaperAttributionsPreferenceController extends BasePreferenceController {
|
||||
|
||||
public WallpaperAttributionsPreferenceController(Context context, String key) {
|
||||
@@ -33,3 +34,4 @@ public class WallpaperAttributionsPreferenceController extends BasePreferenceCon
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(WallpaperAttributionsPreference.kt)
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.android.settings.deviceinfo.legal;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
// LINT.IfChange
|
||||
public class WebViewLicensePreferenceController extends LegalPreferenceController {
|
||||
|
||||
private static final Intent INTENT = new Intent("android.settings.WEBVIEW_LICENSE");
|
||||
@@ -30,3 +31,4 @@ public class WebViewLicensePreferenceController extends LegalPreferenceControlle
|
||||
return INTENT;
|
||||
}
|
||||
}
|
||||
// LINT.ThenChange(LegalPreference.kt)
|
||||
|
||||
Reference in New Issue
Block a user