Files
rr3-apk/decompiled/sources/androidx/browser/trusted/TrustedWebActivityService.java
Daniel Elliott f9d20bb3fc Add decompiled APK source code (JADX)
- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-18 14:52:23 -08:00

220 lines
9.4 KiB
Java

package androidx.browser.trusted;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.BitmapFactory;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcelable;
import android.support.customtabs.trusted.ITrustedWebActivityService;
import androidx.annotation.BinderThread;
import androidx.annotation.CallSuper;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresPermission;
import androidx.annotation.RestrictTo;
import androidx.browser.trusted.TrustedWebActivityServiceConnection;
import androidx.core.app.NotificationManagerCompat;
import java.util.Locale;
/* loaded from: classes.dex */
public abstract class TrustedWebActivityService extends Service {
@SuppressLint({"ActionValue", "ServiceName"})
public static final String ACTION_TRUSTED_WEB_ACTIVITY_SERVICE = "android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE";
public static final String KEY_SMALL_ICON_BITMAP = "android.support.customtabs.trusted.SMALL_ICON_BITMAP";
public static final String KEY_SUCCESS = "androidx.browser.trusted.SUCCESS";
public static final String META_DATA_NAME_SMALL_ICON = "android.support.customtabs.trusted.SMALL_ICON";
public static final int SMALL_ICON_NOT_SET = -1;
private NotificationManager mNotificationManager;
int mVerifiedUid = -1;
private final ITrustedWebActivityService.Stub mBinder = new ITrustedWebActivityService.Stub() { // from class: androidx.browser.trusted.TrustedWebActivityService.1
@Override // android.support.customtabs.trusted.ITrustedWebActivityService
public Bundle areNotificationsEnabled(Bundle bundle) {
checkCaller();
return new TrustedWebActivityServiceConnection.ResultArgs(TrustedWebActivityService.this.onAreNotificationsEnabled(TrustedWebActivityServiceConnection.NotificationsEnabledArgs.fromBundle(bundle).channelName)).toBundle();
}
@Override // android.support.customtabs.trusted.ITrustedWebActivityService
@RequiresPermission("android.permission.POST_NOTIFICATIONS")
public Bundle notifyNotificationWithChannel(Bundle bundle) {
checkCaller();
TrustedWebActivityServiceConnection.NotifyNotificationArgs fromBundle = TrustedWebActivityServiceConnection.NotifyNotificationArgs.fromBundle(bundle);
return new TrustedWebActivityServiceConnection.ResultArgs(TrustedWebActivityService.this.onNotifyNotificationWithChannel(fromBundle.platformTag, fromBundle.platformId, fromBundle.notification, fromBundle.channelName)).toBundle();
}
@Override // android.support.customtabs.trusted.ITrustedWebActivityService
public void cancelNotification(Bundle bundle) {
checkCaller();
TrustedWebActivityServiceConnection.CancelNotificationArgs fromBundle = TrustedWebActivityServiceConnection.CancelNotificationArgs.fromBundle(bundle);
TrustedWebActivityService.this.onCancelNotification(fromBundle.platformTag, fromBundle.platformId);
}
@Override // android.support.customtabs.trusted.ITrustedWebActivityService
public Bundle getActiveNotifications() {
checkCaller();
return new TrustedWebActivityServiceConnection.ActiveNotificationsArgs(TrustedWebActivityService.this.onGetActiveNotifications()).toBundle();
}
@Override // android.support.customtabs.trusted.ITrustedWebActivityService
public int getSmallIconId() {
checkCaller();
return TrustedWebActivityService.this.onGetSmallIconId();
}
@Override // android.support.customtabs.trusted.ITrustedWebActivityService
public Bundle getSmallIconBitmap() {
checkCaller();
return TrustedWebActivityService.this.onGetSmallIconBitmap();
}
@Override // android.support.customtabs.trusted.ITrustedWebActivityService
public Bundle extraCommand(String str, Bundle bundle, IBinder iBinder) {
checkCaller();
return TrustedWebActivityService.this.onExtraCommand(str, bundle, TrustedWebActivityCallbackRemote.fromBinder(iBinder));
}
private void checkCaller() {
TrustedWebActivityService trustedWebActivityService = TrustedWebActivityService.this;
if (trustedWebActivityService.mVerifiedUid == -1) {
String[] packagesForUid = trustedWebActivityService.getPackageManager().getPackagesForUid(Binder.getCallingUid());
int i = 0;
if (packagesForUid == null) {
packagesForUid = new String[0];
}
Token load = TrustedWebActivityService.this.getTokenStore().load();
PackageManager packageManager = TrustedWebActivityService.this.getPackageManager();
if (load != null) {
int length = packagesForUid.length;
while (true) {
if (i >= length) {
break;
}
if (load.matches(packagesForUid[i], packageManager)) {
TrustedWebActivityService.this.mVerifiedUid = Binder.getCallingUid();
break;
}
i++;
}
}
}
if (TrustedWebActivityService.this.mVerifiedUid != Binder.getCallingUid()) {
throw new SecurityException("Caller is not verified as Trusted Web Activity provider.");
}
}
};
@NonNull
@BinderThread
public abstract TokenStore getTokenStore();
@Override // android.app.Service
@Nullable
@MainThread
public final IBinder onBind(@Nullable Intent intent) {
return this.mBinder;
}
@Nullable
@BinderThread
public Bundle onExtraCommand(@NonNull String str, @NonNull Bundle bundle, @Nullable TrustedWebActivityCallbackRemote trustedWebActivityCallbackRemote) {
return null;
}
@Override // android.app.Service
@CallSuper
@MainThread
public void onCreate() {
super.onCreate();
this.mNotificationManager = (NotificationManager) getSystemService("notification");
}
@BinderThread
public boolean onAreNotificationsEnabled(@NonNull String str) {
ensureOnCreateCalled();
if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
return NotificationApiHelperForO.isChannelEnabled(this.mNotificationManager, channelNameToId(str));
}
return false;
}
@BinderThread
@RequiresPermission("android.permission.POST_NOTIFICATIONS")
public boolean onNotifyNotificationWithChannel(@NonNull String str, int i, @NonNull Notification notification, @NonNull String str2) {
ensureOnCreateCalled();
if (!NotificationManagerCompat.from(this).areNotificationsEnabled()) {
return false;
}
String channelNameToId = channelNameToId(str2);
Notification copyNotificationOntoChannel = NotificationApiHelperForO.copyNotificationOntoChannel(this, this.mNotificationManager, notification, channelNameToId, str2);
if (!NotificationApiHelperForO.isChannelEnabled(this.mNotificationManager, channelNameToId)) {
return false;
}
this.mNotificationManager.notify(str, i, copyNotificationOntoChannel);
return true;
}
@BinderThread
public void onCancelNotification(@NonNull String str, int i) {
ensureOnCreateCalled();
this.mNotificationManager.cancel(str, i);
}
@NonNull
@BinderThread
@RestrictTo({RestrictTo.Scope.LIBRARY})
public Parcelable[] onGetActiveNotifications() {
ensureOnCreateCalled();
return NotificationApiHelperForM.getActiveNotifications(this.mNotificationManager);
}
@NonNull
@BinderThread
public Bundle onGetSmallIconBitmap() {
int onGetSmallIconId = onGetSmallIconId();
Bundle bundle = new Bundle();
if (onGetSmallIconId == -1) {
return bundle;
}
bundle.putParcelable(KEY_SMALL_ICON_BITMAP, BitmapFactory.decodeResource(getResources(), onGetSmallIconId));
return bundle;
}
@BinderThread
public int onGetSmallIconId() {
try {
Bundle bundle = getPackageManager().getServiceInfo(new ComponentName(this, getClass()), 128).metaData;
if (bundle == null) {
return -1;
}
return bundle.getInt(META_DATA_NAME_SMALL_ICON, -1);
} catch (PackageManager.NameNotFoundException unused) {
return -1;
}
}
@Override // android.app.Service
@MainThread
public final boolean onUnbind(@Nullable Intent intent) {
this.mVerifiedUid = -1;
return super.onUnbind(intent);
}
private static String channelNameToId(String str) {
return str.toLowerCase(Locale.ROOT).replace(' ', '_') + "_channel_id";
}
private void ensureOnCreateCalled() {
if (this.mNotificationManager == null) {
throw new IllegalStateException("TrustedWebActivityService has not been properly initialized. Did onCreate() call super.onCreate()?");
}
}
}