[automerger skipped] Merge Android 12L am: 810578896e -s ours am: d4cc9ab2e5 -s ours am: 39f406f8a0 -s ours
am skip reason: Merged-In Iea002572895dfdb74f72b5d6fe7a1efbd4139cac with SHA-1 6454ff57c1 is already in history
Original change: https://android-review.googlesource.com/c/platform/packages/inputmethods/LatinIME/+/2013416
Change-Id: I043e801e312f24aa88bc0d318b5a3f7989e51409
diff --git a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
index 0517bc8..bdea3e9 100644
--- a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
+++ b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java
@@ -19,9 +19,6 @@
import android.app.DownloadManager;
import android.app.DownloadManager.Query;
import android.app.DownloadManager.Request;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
@@ -36,10 +33,7 @@
import android.text.TextUtils;
import android.util.Log;
-import com.android.inputmethod.compat.ConnectivityManagerCompatUtils;
-import com.android.inputmethod.compat.NotificationCompatUtils;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.common.LocaleUtils;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.utils.ApplicationUtils;
import com.android.inputmethod.latin.utils.DebugLogUtils;
@@ -844,54 +838,6 @@
}
/**
- * Shows the notification that informs the user a dictionary is available.
- *
- * When this notification is clicked, the dialog for downloading the dictionary
- * over a metered connection is shown.
- */
- private static void showDictionaryAvailableNotification(final Context context,
- final String clientId, final ContentValues installCandidate) {
- final String localeString = installCandidate.getAsString(MetadataDbHelper.LOCALE_COLUMN);
- final Intent intent = new Intent();
- intent.setClass(context, DownloadOverMeteredDialog.class);
- intent.putExtra(DownloadOverMeteredDialog.CLIENT_ID_KEY, clientId);
- intent.putExtra(DownloadOverMeteredDialog.WORDLIST_TO_DOWNLOAD_KEY,
- installCandidate.getAsString(MetadataDbHelper.WORDLISTID_COLUMN));
- intent.putExtra(DownloadOverMeteredDialog.SIZE_KEY,
- installCandidate.getAsInteger(MetadataDbHelper.FILESIZE_COLUMN));
- intent.putExtra(DownloadOverMeteredDialog.LOCALE_KEY, localeString);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
- final PendingIntent notificationIntent = PendingIntent.getActivity(context,
- 0 /* requestCode */, intent,
- PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
- final NotificationManager notificationManager =
- (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- // None of those are expected to happen, but just in case...
- if (null == notificationIntent || null == notificationManager) return;
-
- final String language = (null == localeString) ? ""
- : LocaleUtils.constructLocaleFromString(localeString).getDisplayLanguage();
- final String titleFormat = context.getString(R.string.dict_available_notification_title);
- final String notificationTitle = String.format(titleFormat, language);
- final Notification.Builder builder = new Notification.Builder(context)
- .setAutoCancel(true)
- .setContentIntent(notificationIntent)
- .setContentTitle(notificationTitle)
- .setContentText(context.getString(R.string.dict_available_notification_description))
- .setTicker(notificationTitle)
- .setOngoing(false)
- .setOnlyAlertOnce(true)
- .setSmallIcon(R.drawable.ic_notify_dictionary);
- NotificationCompatUtils.setColor(builder,
- context.getResources().getColor(R.color.notification_accent_color));
- NotificationCompatUtils.setPriorityToLow(builder);
- NotificationCompatUtils.setVisibilityToSecret(builder);
- NotificationCompatUtils.setCategoryToRecommendation(builder);
- final Notification notification = NotificationCompatUtils.build(builder);
- notificationManager.notify(DICT_AVAILABLE_NOTIFICATION_ID, notification);
- }
-
- /**
* Installs a word list if it has never been requested.
*
* This is called when a word list is requested, and is available but not installed. It checks
diff --git a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
index 60d2573..5e6e4ab 100644
--- a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
+++ b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
@@ -119,8 +119,7 @@
// Go ahead with the system default
if (viewToPerformHapticFeedbackOn != null) {
viewToPerformHapticFeedbackOn.performHapticFeedback(
- HapticFeedbackConstants.KEYBOARD_TAP,
- HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
+ HapticFeedbackConstants.KEYBOARD_TAP);
}
}
diff --git a/tools/EditTextVariations/AndroidManifest.xml b/tools/EditTextVariations/AndroidManifest.xml
index b5a27b9..ecfe764 100644
--- a/tools/EditTextVariations/AndroidManifest.xml
+++ b/tools/EditTextVariations/AndroidManifest.xml
@@ -18,9 +18,11 @@
package="com.android.inputmethod.tools.edittextvariations"
android:versionName="0.67"
android:versionCode="67">
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<supports-screens android:resizeable="true"/>
<uses-sdk android:targetSdkVersion="27"
android:minSdkVersion="11"/>
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<application android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:allowBackup="false">
@@ -34,6 +36,10 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
+ <activity android:name=".EditorActivity"
+ android:windowSoftInputMode="stateHidden|adjustPan"
+ android:theme="@style/defaultActivityTheme"
+ android:label="@string/app_name"/>
<receiver android:name=".NotificationBroadcastReceiver"
android:exported="false"/>
</application>
diff --git a/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/EditTextVariations.java b/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/EditTextVariations.java
index 6eb85a5..31a0025 100644
--- a/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/EditTextVariations.java
+++ b/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/EditTextVariations.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.tools.edittextvariations;
+import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
@@ -24,6 +25,7 @@
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Bundle;
@@ -45,7 +47,9 @@
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.TextView;
+import android.widget.Toast;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
@@ -64,6 +68,7 @@
private static final String PREF_THEME = "theme";
private static final String PREF_NAVIGATE = "navigate";
private static final String PREF_SOFTINPUT = "softinput";
+ private static final int NOTIFICATION_PERMISSION_REQUEST_CODE = 0;
private SharedPreferences prefs;
private View[] fields;
@@ -199,12 +204,36 @@
saveSoftInputMode(itemId == MENU_SOFTINPUT_VISIBLE);
restartActivity();
} else if (itemId == MENU_DIRECT_REPLY) {
- NotificationUtils.sendDirectReplyNotification(this);
+ final boolean needPermissionCheck = isNeedNotificationPermission()
+ && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) !=
+ PackageManager.PERMISSION_GRANTED;
+ if (needPermissionCheck) {
+ requestPermissions(new String[] { Manifest.permission.POST_NOTIFICATIONS },
+ NOTIFICATION_PERMISSION_REQUEST_CODE);
+ } else {
+ NotificationUtils.sendDirectReplyNotification(this);
+ }
}
return true;
}
@Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ int[] grantResults) {
+ if (requestCode == NOTIFICATION_PERMISSION_REQUEST_CODE) {
+ if (grantResults.length == 1 &&
+ grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ // Permission is granted. Continue to send the notification.
+ NotificationUtils.sendDirectReplyNotification(this);
+ } else {
+ Log.d(TAG, "POST_NOTIFICATIONS Permissions denied.");
+ Toast.makeText(this, "Required permission has denied",
+ Toast.LENGTH_LONG).show();
+ }
+ }
+ }
+
+ @Override
public void onClick(final DialogInterface dialog, final int which) {
saveTheme(ThemeItem.THEME_LIST.get(which));
restartActivity();
@@ -476,4 +505,14 @@
}
return text;
}
+
+ private static boolean isNeedNotificationPermission() {
+ for(Field field : Manifest.permission.class.getFields()) {
+ if (field.getName().equals("POST_NOTIFICATIONS")) {
+ Log.d(TAG, "Need notification permission.");
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/EditorActivity.java b/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/EditorActivity.java
new file mode 100644
index 0000000..4fc947b
--- /dev/null
+++ b/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/EditorActivity.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2021 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.inputmethod.tools.edittextvariations;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+
+public final class EditorActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ LinearLayout layout = new LinearLayout(this);
+ layout.setOrientation(LinearLayout.VERTICAL);
+ EditText editText = new EditText(this);
+ editText.setHint("reply the message");
+ layout.addView(editText);
+ setContentView(layout);
+ }
+}
diff --git a/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/NotificationUtils.java b/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/NotificationUtils.java
index a9b7132..78d52bb 100644
--- a/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/NotificationUtils.java
+++ b/tools/EditTextVariations/src/com/android/inputmethod/tools/edittextvariations/NotificationUtils.java
@@ -57,7 +57,7 @@
synchronized (sLock) {
if (!sNotificationChannelInitialized) {
final NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
- CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
+ CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
channel.setDescription(CHANNEL_DESCRIPTION);
context.getSystemService(NotificationManager.class)
.createNotificationChannel(channel);
@@ -79,12 +79,15 @@
final int notificationId = sNextNotificationId.getAndIncrement();
final PendingIntent pendingIntent = getReplyPendingIntent(context, notificationId);
+ final PendingIntent activityIntent = PendingIntent.getActivity(context, 0,
+ new Intent(context, EditorActivity.class), 0);
final Notification.Action action =
new Notification.Action.Builder(null, "Direct Reply Test", pendingIntent)
.addRemoteInput(remoteInput)
.build();
final Notification notification = createNotificationBuilder(context)
.setContentText("Content Title")
+ .setContentIntent(activityIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setContentText("Message from " + UserHandle.getUserHandleForUid(Process.myUid()))
.setShowWhen(true)