Add the screen to be displayed in Settings
Bug: 279616148
Test: build & test locally
Change-Id: I503b932285b5fa0f5c13558c3ab0ec80a399a5df
diff --git a/DeviceLockController/Android.bp b/DeviceLockController/Android.bp
index 86e182e..6e72cf7 100644
--- a/DeviceLockController/Android.bp
+++ b/DeviceLockController/Android.bp
@@ -104,6 +104,7 @@
"androidx.annotation_annotation",
"androidx.collection_collection",
"androidx.lifecycle_lifecycle-extensions",
+ "androidx.preference_preference",
"androidx.work_work-runtime",
"devicelockcontroller-grpc-interface-lib",
"devicelockcontroller-interface",
@@ -112,6 +113,8 @@
"guava",
"jsr330",
"dagger2",
+ "SettingsLibCollapsingToolbarBaseActivity",
+ "SettingsLibTopIntroPreference",
],
manifest: "AndroidManifestBase.xml",
apex_available: [
diff --git a/DeviceLockController/AndroidManifestBase.xml b/DeviceLockController/AndroidManifestBase.xml
index 131dc45..474a68e 100644
--- a/DeviceLockController/AndroidManifestBase.xml
+++ b/DeviceLockController/AndroidManifestBase.xml
@@ -143,8 +143,16 @@
</intent-filter>
</activity-alias>
- <!-- b/267355744: Disable the default initializer used by WorkManager, so that we can ensure
- WorkManager is initialized when needed. -->
+ <activity
+ android:name="com.android.devicelockcontroller.activities.DeviceLockSettingsActivity"
+ android:theme="@style/Theme.Materialu"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="com.android.devicelockcontroller.action.DEVICE_INFO_SETTINGS"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ </activity>
+
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
diff --git a/DeviceLockController/res/values/strings.xml b/DeviceLockController/res/values/strings.xml
index 925d106..b3cf9d5 100644
--- a/DeviceLockController/res/values/strings.xml
+++ b/DeviceLockController/res/values/strings.xml
@@ -150,39 +150,75 @@
<!-- Button text of the banner in Settings. This tells the user they can tap the button get more information. [CHAT_LIMIT=20]-->
<string name="settings_banner_button">Learn more</string>
<!-- Top introduction on the Settings screen, summarizing the changes a device provider can make to this device. [CHAR LIMIT=NONE] -->
- <string name="settings_intro"><xliff:g id="provider name">%1$s</xliff:g> can change settings and install the <xliff:g id="creditor_app">%2$s</xliff:g> app on this device.\n\nIf you miss a payment, <xliff:g id="provider name">%1$s</xliff:g> can restrict your device and change device settings.\n\nTo learn more, contact <xliff:g id="provider name">%1$s</xliff:g>.</string>
+ <string name="settings_intro"><xliff:g id="provider name">%1$s</xliff:g> can change settings and install the Kiosk app on this device.\n\nIf you miss a payment, <xliff:g id="provider name">%1$s</xliff:g> can restrict your device and change device settings.\n\nTo learn more, contact <xliff:g id="provider name">%1$s</xliff:g>.</string>
+ <!-- Key of the settings_intro Preference. translatable="false" -->
+ <string name="settings_intro_preference_key">settings_intro_preference_key</string>
<!-- Section header. This section shows what restrictions will be enforced on the device when it is financed / subsidized. [CHAR LIMIT=60] -->
<string name="settings_restrictions_category">Until you\u2019ve paid for your device, you can\u2019t:</string>
+ <!-- Key of the settings_restrictions_category Preference. translatable="false" -->
+ <string name="settings_restrictions_category_preference_key">settings_restrictions_category_preference_key</string>
<!-- Label explaining that installing apps from unknown sources beyond Play Store. [CHAR LIMIT=60]-->
<string name="settings_install_apps">Install apps from outside the Play Store</string>
+ <!-- Key of the settings_install_apps Preference. translatable="false" -->
+ <string name="settings_install_apps_preference_key">settings_install_apps_preference_key</string>
<!-- Label explaining that rebooting the device into safe mode. [CHAR LIMIT=60]-->
<string name="settings_safe_mode">Reboot your device into safe mode</string>
+ <!-- Key of the settings_safe_mode Preference. translatable="false" -->
+ <string name="settings_safe_mode_preference_key">settings_safe_mode_preference_key</string>
<!-- Label explaining that updating the date and time on the device. [CHAR LIMIT=60] -->
<string name="settings_config_date_time">Change date, time, and time zones</string>
+ <!-- Key of the settings_config_date_time Preference. translatable="false" -->
+ <string name="settings_config_date_time_preference_key">settings_config_date_time_preference_key</string>
<!-- Label explaining that turning on the developer options on the device. [CHAR LIMIT=40]-->
<string name="settings_developer_options">Use developer options</string>
+ <!-- Key of the settings_developer_options Preference. translatable="false" -->
+ <string name="settings_developer_options_preference_key">settings_developer_options_preference_key</string>
<!-- Section header. This section shows how device provider would control the device. [CHAR LIMIT=40]-->
<string name="settings_credit_provider_capabilities_category">If something goes wrong with your device, <xliff:g id="provider name">%1$s</xliff:g> can:</string>
+ <!-- Key of the settings_credit_provider_capabilities_category Preference. translatable="false" -->
+ <string name="settings_credit_provider_capabilities_category_preference_key">settings_credit_provider_capabilities_category_preference_key</string>
<!-- Label explaining that IMEI can be access by the credit provider. [CHAR LIMIT=40] -->
<string name="settings_IMEI">Access your IMEI number</string>
+ <!-- Key of the settings_IMEI Preference. translatable="false" -->
+ <string name="settings_IMEI_preference_key">settings_IMEI_preference_key</string>
<!-- Label explaining that device can be reset and data can be deleted. [CHAR LIMIT=80]-->
<string name="settings_factory_reset">Factory reset your device</string>
+ <!-- Key of the settings_factory_reset Preference. translatable="false" -->
+ <string name="settings_factory_reset_preference_key">settings_factory_reset_preference_key</string>
<!-- Section header. This section shows what the user can do if the device is restricted by the device provider. [CHAR LIMIT=100] -->
<string name="settings_locked_mode_category">If your device is restricted, you can only use it to:</string>
+ <!-- Key of the settings_locked_mode_category Preference. translatable="false" -->
+ <string name="settings_locked_mode_category_preference_key">settings_locked_mode_category_preference_key</string>
<!-- Label explaining that calling emergency numbers. [CHAR LIMIT=40]-->
<string name="settings_emergency_calls">Make calls to emergency numbers</string>
+ <!-- Key of the settings_emergency_calls Preference. translatable="false" -->
+ <string name="settings_emergency_calls_preference_key">settings_emergency_calls_preference_key</string>
<!-- Label explaining that access basic system level data including date, time, network status, and battery info. [CHAR LIMIT=100]-->
<string name="settings_system_info">View system info like date, time, network status, and battery</string>
+ <!-- Key of the settings_system_info Preference. translatable="false" -->
+ <string name="settings_system_info_preference_key">settings_system_info_preference_key</string>
<!-- Label explaining that powering on or off the device. [CHAR LIMIT=60]-->
<string name="settings_turn_on_off_device">Turn your device on or off</string>
+ <!-- Key of the settings_turn_on_off_device Preference. translatable="false" -->
+ <string name="settings_turn_on_off_device_preference_key">settings_turn_on_off_device_preference_key</string>
<!-- Label explaining that accessing notifications and text messages. [CHAR LIMIT=60]-->
<string name="settings_notifications">View notifications and text messages</string>
+ <!-- Key of the settings_notifications Preference. translatable="false" -->
+ <string name="settings_notifications_preference_key">settings_notifications_preference_key</string>
<!-- Label explaining that using apps that are allowed to be used by the device provider when the device is restricted. [CHAR LIMIT=100]-->
<string name="settings_allowlisted_apps">Access apps that are allowed by <xliff:g id="provider name">%1$s</xliff:g></string>
+ <!-- Key of the settings_allowlisted_apps Preference. translatable="false" -->
+ <string name="settings_allowlisted_apps_preference_key">settings_allowlisted_apps_preference_key</string>
<!-- Section header. This sections shows what would happen if the device is fully paid. [CHAR LIMIT=60] -->
<string name="settings_fully_paid_category">Once you pay the full amount:</string>
+ <!-- Key of the settings_fully_paid_category Preference. translatable="false" -->
+ <string name="settings_fully_paid_category_preference_key">settings_fully_paid_category_preference_key</string>
<!-- Label explaining that all previously restrictions enforce by the device provider will be revoked. [CHAR LIMIT=100]-->
<string name="settings_restrictions_removed"><xliff:g id="provider name">%1$s</xliff:g> can\u2019t restrict your device or change device settings</string>
+ <!-- Key of the settings_restrictions_removed Preference. translatable="false" -->
+ <string name="settings_restrictions_removed_preference_key">settings_restrictions_removed_preference_key</string>
<!-- Label explaining that the app installed by device provider can be uninstalled. [CHAR LIMIT=60]-->
- <string name="settings_uninstall_creditor_app">You can uninstall the <xliff:g id="creditor_app">%1$s</xliff:g> app</string>
+ <string name="settings_uninstall_kiosk_app">You can uninstall the <xliff:g id="kiosk_app">%1$s</xliff:g> app</string>
+ <!-- Key of the settings_uninstall_kiosk_app Preference. translatable="false" -->
+ <string name="settings_uninstall_kiosk_app_preference_key">settings_uninstall_kiosk_app_preference_key</string>
</resources>
diff --git a/DeviceLockController/res/xml/device_info_settings.xml b/DeviceLockController/res/xml/device_info_settings.xml
new file mode 100644
index 0000000..2f8b13b
--- /dev/null
+++ b/DeviceLockController/res/xml/device_info_settings.xml
@@ -0,0 +1,112 @@
+<!--
+ ~ Copyright (C) 2023 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.
+ -->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/device_provided_by_creditor">
+
+ <com.android.settingslib.widget.TopIntroPreference
+ android:key="@string/settings_intro_preference_key"
+ android:title="@string/settings_intro"/>
+
+ <PreferenceCategory android:key="@string/settings_restrictions_category_preference_key"
+ android:order="100"
+ android:title="@string/settings_restrictions_category"
+ android:contentDescription="@string/settings_restrictions_category">
+ <Preference android:key="@string/settings_install_apps_preference_key"
+ android:order="110"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_install_apps"
+ android:selectable="false" />
+ <Preference android:key="@string/settings_safe_mode_preference_key"
+ android:order="120"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_safe_mode"
+ android:selectable="false" />
+ <Preference android:key="@string/settings_config_date_time_preference_key"
+ android:order="130"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_config_date_time"
+ android:selectable="false" />
+ <Preference android:key="@string/settings_developer_options_preference_key"
+ android:order="140"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_developer_options"
+ android:selectable="false" />
+ </PreferenceCategory>
+
+ <PreferenceCategory android:key="@string/settings_credit_provider_capabilities_category_preference_key"
+ android:order="200"
+ android:title="@string/settings_credit_provider_capabilities_category"
+ android:contentDescription="@string/settings_credit_provider_capabilities_category">
+ <Preference android:key="@string/settings_IMEI_preference_key"
+ android:order="210"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_IMEI"
+ android:selectable="false" />
+ <Preference android:key="@string/settings_factory_reset_preference_key"
+ android:order="220"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_factory_reset"
+ android:selectable="false" />
+ </PreferenceCategory>
+
+ <PreferenceCategory android:key="@string/settings_locked_mode_category_preference_key"
+ android:order="300"
+ android:title="@string/settings_locked_mode_category"
+ android:contentDescription="@string/settings_locked_mode_category">
+ <Preference android:key="@string/settings_emergency_calls_preference_key"
+ android:order="310"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_emergency_calls"
+ android:selectable="false" />
+ <Preference android:key="@string/settings_system_info_preference_key"
+ android:order="320"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_system_info"
+ android:selectable="false" />
+ <Preference android:key="@string/settings_turn_on_off_device_preference_key"
+ android:order="330"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_turn_on_off_device"
+ android:selectable="false" />
+ <Preference android:key="@string/settings_notifications_preference_key"
+ android:order="340"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_notifications"
+ android:selectable="false" />
+ <Preference android:key="@string/settings_allowlisted_apps_preference_key"
+ android:order="350"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_allowlisted_apps"
+ android:selectable="false" />
+ </PreferenceCategory>
+
+ <PreferenceCategory android:key="@string/settings_fully_paid_category_preference_key"
+ android:order="400"
+ android:title="@string/settings_fully_paid_category"
+ android:contentDescription="@string/settings_fully_paid_category">
+ <Preference android:key="@string/settings_restrictions_removed_preference_key"
+ android:order="410"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_restrictions_removed"
+ android:selectable="false" />
+ <Preference android:key="@string/settings_uninstall_kiosk_app_preference_key"
+ android:order="420"
+ android:layout_height="wrap_content"
+ android:title="@string/settings_uninstall_kiosk_app"
+ android:selectable="false" />
+ </PreferenceCategory>
+</PreferenceScreen>
diff --git a/DeviceLockController/src/com/android/devicelockcontroller/activities/DeviceInfoSettingsFragment.java b/DeviceLockController/src/com/android/devicelockcontroller/activities/DeviceInfoSettingsFragment.java
new file mode 100644
index 0000000..6c96338
--- /dev/null
+++ b/DeviceLockController/src/com/android/devicelockcontroller/activities/DeviceInfoSettingsFragment.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2023 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.devicelockcontroller.activities;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import android.os.Bundle;
+import android.util.Pair;
+import android.view.View;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.lifecycle.ViewModelProvider;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.PreferenceManager;
+
+import com.android.devicelockcontroller.R;
+
+/**
+ * The screen which provides info about Device Lock in Settings' style.
+ */
+public final class DeviceInfoSettingsFragment extends PreferenceFragmentCompat {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ setPreferencesFromResource(R.xml.device_info_settings, rootKey);
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+
+ DeviceInfoSettingsViewModel viewModel = new ViewModelProvider(this).get(
+ DeviceInfoSettingsViewModel.class);
+ viewModel.mProviderNameLiveData.observe(getViewLifecycleOwner(), providerName -> {
+ PreferenceManager preferenceManager = getPreferenceManager();
+ for (Pair<Integer, Integer> keyTitlePair : viewModel.mPreferenceKeyTitlePairs) {
+ Preference preference = preferenceManager.findPreference(
+ getString(keyTitlePair.first));
+ checkNotNull(preference);
+ preference.setTitle(getString(keyTitlePair.second, providerName));
+ }
+ });
+ }
+}
diff --git a/DeviceLockController/src/com/android/devicelockcontroller/activities/DeviceInfoSettingsViewModel.java b/DeviceLockController/src/com/android/devicelockcontroller/activities/DeviceInfoSettingsViewModel.java
new file mode 100644
index 0000000..6110c72
--- /dev/null
+++ b/DeviceLockController/src/com/android/devicelockcontroller/activities/DeviceInfoSettingsViewModel.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2023 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.devicelockcontroller.activities;
+
+import android.text.TextUtils;
+import android.util.Pair;
+
+import androidx.lifecycle.MutableLiveData;
+import androidx.lifecycle.ViewModel;
+
+import com.android.devicelockcontroller.R;
+import com.android.devicelockcontroller.storage.SetupParametersClient;
+import com.android.devicelockcontroller.util.LogUtil;
+
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * ViewModel class which provides data for the {@link DeviceInfoSettingsFragment}.
+ */
+public final class DeviceInfoSettingsViewModel extends ViewModel {
+
+ private static final String TAG = "DeviceInfoSettingsViewModel";
+
+ // Preferences that need to be updated with provider name
+ private static final List<Pair<Integer, Integer>> PREFERENCE_KEY_TITLE_PAIRS = Arrays.asList(
+ new Pair<>(R.string.settings_intro_preference_key,
+ R.string.settings_intro),
+ new Pair<>(R.string.settings_credit_provider_capabilities_category_preference_key,
+ R.string.settings_credit_provider_capabilities_category),
+ new Pair<>(R.string.settings_allowlisted_apps_preference_key,
+ R.string.settings_allowlisted_apps),
+ new Pair<>(R.string.settings_restrictions_removed_preference_key,
+ R.string.settings_restrictions_removed),
+ new Pair<>(R.string.settings_uninstall_kiosk_app_preference_key,
+ R.string.settings_uninstall_kiosk_app));
+
+ final List<Pair<Integer, Integer>> mPreferenceKeyTitlePairs;
+
+ final MutableLiveData<String> mProviderNameLiveData;
+
+ public DeviceInfoSettingsViewModel() {
+ mPreferenceKeyTitlePairs = PREFERENCE_KEY_TITLE_PAIRS;
+ mProviderNameLiveData = new MutableLiveData<>();
+
+ Futures.addCallback(
+ SetupParametersClient.getInstance().getKioskAppProviderName(),
+ new FutureCallback<>() {
+ @Override
+ public void onSuccess(String providerName) {
+ if (TextUtils.isEmpty(providerName)) {
+ LogUtil.e(TAG, "Device provider name is empty, should not reach here.");
+ return;
+ }
+ mProviderNameLiveData.postValue(providerName);
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ LogUtil.e(TAG, "Failed to get Kiosk app provider name", t);
+ }
+ }, MoreExecutors.directExecutor());
+ }
+
+
+}
diff --git a/DeviceLockController/src/com/android/devicelockcontroller/activities/DeviceLockSettingsActivity.java b/DeviceLockController/src/com/android/devicelockcontroller/activities/DeviceLockSettingsActivity.java
new file mode 100644
index 0000000..42f873b
--- /dev/null
+++ b/DeviceLockController/src/com/android/devicelockcontroller/activities/DeviceLockSettingsActivity.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2023 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.devicelockcontroller.activities;
+
+import android.os.Bundle;
+
+import com.android.devicelockcontroller.R;
+import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
+
+/**
+ * Activity used in Settings.
+ */
+public final class DeviceLockSettingsActivity extends CollapsingToolbarBaseActivity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (savedInstanceState == null) {
+ getSupportFragmentManager()
+ .beginTransaction()
+ .add(R.id.content_frame, new DeviceInfoSettingsFragment())
+ .commitNow();
+ }
+ }
+}