Merge "Warnings at top of per-app settings page" into tm-dev
diff --git a/res/drawable/ic_error_outline.xml b/res/drawable/ic_error_outline.xml
new file mode 100644
index 0000000..2ddc6d4
--- /dev/null
+++ b/res/drawable/ic_error_outline.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * Copyright (C) 2022 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.
+ */
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:pathData="M11,15h2v2h-2v-2zM11,7h2v6h-2L11,7zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"
+ android:fillColor="?android:attr/colorError"
+ android:fillType="evenOdd"/>
+</vector>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c371a04..3b59ce4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -500,6 +500,15 @@
<!-- Title for the App's locale picker activity. [CHAR LIMIT=50]-->
<string name="app_locale_picker_title">App Language</string>
+ <!-- Title for the warning message of the locale picker activity. [CHAR LIMIT=50]-->
+ <string name="warnings_title">Update the app</string>
+
+ <!-- Summary for the warning message of the locale picker activity. [CHAR LIMIT=70]-->
+ <string name="warnings_summary">You need to update the app for the latest available languages</string>
+
+ <!-- Button text on warning message [CHAR LIMIT=20]-->
+ <string name="warnings_button_update">Update now</string>
+
<!-- Category for the suggested app's locales. [CHAR LIMIT=50]-->
<string name="suggested_app_locales_title">Suggested languages</string>
diff --git a/res/xml/app_locale_details.xml b/res/xml/app_locale_details.xml
index 05e72ee..7ded8d7 100644
--- a/res/xml/app_locale_details.xml
+++ b/res/xml/app_locale_details.xml
@@ -19,6 +19,12 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/app_locale_picker_title">
+ <com.android.settingslib.widget.BannerMessagePreference
+ android:key="key_warnings"
+ android:icon="@drawable/ic_error_outline"
+ android:title="@string/warnings_title"
+ android:summary="@string/warnings_summary"/>
+
<com.android.settingslib.widget.LayoutPreference
android:key="app_locale_description"
android:layout="@layout/app_locale_details_description"
diff --git a/src/com/android/settings/applications/appinfo/AppLocaleDetails.java b/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
index 3042694..70383d1 100644
--- a/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
+++ b/src/com/android/settings/applications/appinfo/AppLocaleDetails.java
@@ -22,14 +22,19 @@
import android.app.LocaleManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.ApplicationInfo;
+import android.content.pm.InstallSourceInfo;
import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.net.Uri;
import android.os.Bundle;
import android.os.LocaleList;
import android.os.UserHandle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
@@ -42,6 +47,8 @@
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
+import com.android.settingslib.widget.BannerMessagePreference;
+import com.android.settingslib.widget.BannerMessagePreference.AttentionLevel;
import com.android.settingslib.widget.LayoutPreference;
import java.util.Locale;
@@ -54,10 +61,12 @@
private static final String TAG = "AppLocaleDetails";
private static final String KEY_APP_DESCRIPTION = "app_locale_description";
+ private static final String KEY_WARNINGS = "key_warnings";
private boolean mCreated = false;
private String mPackageName;
private LayoutPreference mPrefOfDescription;
+ private ApplicationInfo mApplicationInfo;
/**
* Create a instance of AppLocaleDetails.
@@ -80,9 +89,10 @@
Log.d(TAG, "No package name.");
finish();
}
-
addPreferencesFromResource(R.xml.app_locale_details);
mPrefOfDescription = getPreferenceScreen().findPreference(KEY_APP_DESCRIPTION);
+ mApplicationInfo = getApplicationInfo(mPackageName, getContext().getUserId());
+ setWarningMessage();
}
// Override here so we don't have an empty screen
@@ -104,13 +114,8 @@
}
private void refreshUi() {
- int res = getAppDescription();
- if (res != -1) {
- mPrefOfDescription.setVisible(true);
- TextView description = (TextView) mPrefOfDescription.findViewById(R.id.description);
- description.setText(getContext().getString(res));
- return;
- }
+ setWarningMessage();
+ setDescription();
}
@Override
@@ -131,22 +136,62 @@
}
// Creates a head icon button of app on this page.
final Activity activity = getActivity();
- ApplicationInfo applicationInfo =
- getApplicationInfo(mPackageName, getContext().getUserId());
final Preference pref = EntityHeaderController
.newInstance(activity, this, null /* header */)
.setRecyclerView(getListView(), getSettingsLifecycle())
- .setIcon(Utils.getBadgedIcon(getContext(), applicationInfo))
- .setLabel(applicationInfo.loadLabel(getContext().getPackageManager()))
- .setIsInstantApp(AppUtils.isInstant(applicationInfo))
+ .setIcon(Utils.getBadgedIcon(getContext(), mApplicationInfo))
+ .setLabel(mApplicationInfo.loadLabel(getContext().getPackageManager()))
+ .setIsInstantApp(AppUtils.isInstant(mApplicationInfo))
.setPackageName(mPackageName)
- .setUid(applicationInfo.uid)
+ .setUid(mApplicationInfo.uid)
.setHasAppInfoLink(true)
.setButtonActions(ActionType.ACTION_NONE, ActionType.ACTION_NONE)
.done(activity, getPrefContext());
getPreferenceScreen().addPreference(pref);
}
+ private void setWarningMessage() {
+ BannerMessagePreference warningPreference =
+ (BannerMessagePreference) getPreferenceScreen().findPreference(KEY_WARNINGS);
+ try {
+ InstallSourceInfo installSourceInfo =
+ getContext().getPackageManager().getInstallSourceInfo(mPackageName);
+ if (mApplicationInfo.isSystemApp()
+ && installSourceInfo.getInstallingPackageName() == null) {
+ warningPreference.setAttentionLevel(AttentionLevel.MEDIUM);
+ warningPreference.setPositiveButtonOnClickListener(mBannerButtonClickListener);
+ warningPreference.setPositiveButtonText(R.string.warnings_button_update);
+ warningPreference.setVisible(true);
+ } else {
+ warningPreference.setVisible(false);
+ }
+ } catch (NameNotFoundException e) {
+ Log.e(TAG, "Exception while retrieving the package installer of " + mPackageName, e);
+ }
+ }
+
+ private void setDescription() {
+ int res = getAppDescription();
+ if (res != -1) {
+ mPrefOfDescription.setVisible(true);
+ TextView description = (TextView) mPrefOfDescription.findViewById(R.id.description);
+ description.setText(getContext().getString(res));
+ }
+ }
+
+ private OnClickListener mBannerButtonClickListener = new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startActivity(getAppSearchIntent(mPackageName));
+ }
+ };
+
+ private static Intent getAppSearchIntent(String pkg) {
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setData(Uri.parse("market://details?id=" + pkg));
+ return intent;
+ }
+
private ApplicationInfo getApplicationInfo(String packageName, int userId) {
ApplicationInfo applicationInfo;
try {