Merge "Use POWER_MENU_LOCKED_SHOW_CONTENT in wallet" into rvc-dev am: 2b49f81e7e am: 6fd18c094a am: d6cd810b72

Change-Id: Ic7659dfe3a8a9a98f34bc1606f3a675d15cfdaa9
This commit is contained in:
TreeHugger Robot
2020-04-29 18:57:12 +00:00
committed by Automerger Merge Worker
2 changed files with 59 additions and 16 deletions

View File

@@ -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.
*/

View File

@@ -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