summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2020-04-29 18:08:23 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-04-29 18:08:23 +0000
commit2b49f81e7ec30cea92167c2352d45c568fdcf24f (patch)
treea8d4f017bebf1da50306831a8cbd22a84f93f99d
parent66bf0f533c404cb7ef870c6cc18bb1a125886bdb (diff)
parentd3cfe6204ec27a6a9c7d5e1fd401a2ae7c2633f4 (diff)
Merge "Use POWER_MENU_LOCKED_SHOW_CONTENT in wallet" into rvc-dev
-rwxr-xr-xcore/java/android/provider/Settings.java3
-rw-r--r--core/java/android/service/quickaccesswallet/QuickAccessWalletClientImpl.java72
2 files changed, 59 insertions, 16 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 20bc792d2c77..78b0910ad01a 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2020,8 +2020,7 @@ public final class Settings {
* In some cases, a matching Activity may not exist, so ensure you
* safeguard against this.
* <p>
- * Input: The Intent's data URI specifies the application package name
- * to be shown, with the "package" scheme. That is "package:com.my.app".
+ * Input: Nothing.
* <p>
* Output: Nothing.
*/
diff --git a/core/java/android/service/quickaccesswallet/QuickAccessWalletClientImpl.java b/core/java/android/service/quickaccesswallet/QuickAccessWalletClientImpl.java
index 31a085d15a34..9d0b582dddc4 100644
--- a/core/java/android/service/quickaccesswallet/QuickAccessWalletClientImpl.java
+++ b/core/java/android/service/quickaccesswallet/QuickAccessWalletClientImpl.java
@@ -16,6 +16,8 @@
package android.service.quickaccesswallet;
+import static android.service.quickaccesswallet.QuickAccessWalletService.ACTION_VIEW_WALLET;
+import static android.service.quickaccesswallet.QuickAccessWalletService.ACTION_VIEW_WALLET_SETTINGS;
import static android.service.quickaccesswallet.QuickAccessWalletService.SERVICE_INTERFACE;
import android.annotation.CallbackExecutor;
@@ -26,6 +28,9 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.IBinder;
@@ -97,8 +102,7 @@ public class QuickAccessWalletClientImpl implements QuickAccessWalletClient, Ser
@Override
public boolean isWalletFeatureAvailableWhenDeviceLocked() {
- return checkSecureSetting(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS)
- && checkSecureSetting(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS);
+ return checkSecureSetting(Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT);
}
@Override
@@ -234,27 +238,67 @@ public class QuickAccessWalletClientImpl implements QuickAccessWalletClient, Ser
@Override
@Nullable
public Intent createWalletIntent() {
- if (mServiceInfo == null || TextUtils.isEmpty(mServiceInfo.getWalletActivity())) {
+ if (mServiceInfo == null) {
return null;
}
- return new Intent(QuickAccessWalletService.ACTION_VIEW_WALLET)
- .setComponent(
- new ComponentName(
- mServiceInfo.getComponentName().getPackageName(),
- mServiceInfo.getWalletActivity()));
+ String packageName = mServiceInfo.getComponentName().getPackageName();
+ String walletActivity = mServiceInfo.getWalletActivity();
+ return createIntent(walletActivity, packageName, ACTION_VIEW_WALLET);
}
@Override
@Nullable
public Intent createWalletSettingsIntent() {
- if (mServiceInfo == null || TextUtils.isEmpty(mServiceInfo.getSettingsActivity())) {
+ if (mServiceInfo == null) {
return null;
}
- return new Intent(QuickAccessWalletService.ACTION_VIEW_WALLET_SETTINGS)
- .setComponent(
- new ComponentName(
- mServiceInfo.getComponentName().getPackageName(),
- mServiceInfo.getSettingsActivity()));
+ String packageName = mServiceInfo.getComponentName().getPackageName();
+ String settingsActivity = mServiceInfo.getSettingsActivity();
+ return createIntent(settingsActivity, packageName, ACTION_VIEW_WALLET_SETTINGS);
+ }
+
+ @Nullable
+ private Intent createIntent(@Nullable String activityName, String packageName, String action) {
+ PackageManager pm = mContext.getPackageManager();
+ if (TextUtils.isEmpty(activityName)) {
+ activityName = queryActivityForAction(pm, packageName, action);
+ }
+ if (TextUtils.isEmpty(activityName)) {
+ return null;
+ }
+ ComponentName component = new ComponentName(packageName, activityName);
+ if (!isActivityEnabled(pm, component)) {
+ return null;
+ }
+ return new Intent(action).setComponent(component);
+ }
+
+ @Nullable
+ private static String queryActivityForAction(PackageManager pm, String packageName,
+ String action) {
+ Intent intent = new Intent(action).setPackage(packageName);
+ ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
+ if (resolveInfo == null
+ || resolveInfo.activityInfo == null
+ || !resolveInfo.activityInfo.exported) {
+ return null;
+ }
+ return resolveInfo.activityInfo.name;
+ }
+
+ private static boolean isActivityEnabled(PackageManager pm, ComponentName component) {
+ int setting = pm.getComponentEnabledSetting(component);
+ if (setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
+ return true;
+ }
+ if (setting != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
+ return false;
+ }
+ try {
+ return pm.getActivityInfo(component, 0).isEnabled();
+ } catch (NameNotFoundException e) {
+ return false;
+ }
}
@Override