- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
483 lines
19 KiB
Java
483 lines
19 KiB
Java
package androidx.core.content;
|
|
|
|
import android.accounts.AccountManager;
|
|
import android.annotation.SuppressLint;
|
|
import android.app.ActivityManager;
|
|
import android.app.AlarmManager;
|
|
import android.app.AppOpsManager;
|
|
import android.app.DownloadManager;
|
|
import android.app.KeyguardManager;
|
|
import android.app.NotificationManager;
|
|
import android.app.SearchManager;
|
|
import android.app.UiModeManager;
|
|
import android.app.WallpaperManager;
|
|
import android.app.admin.DevicePolicyManager;
|
|
import android.app.job.JobScheduler;
|
|
import android.app.usage.UsageStatsManager;
|
|
import android.appwidget.AppWidgetManager;
|
|
import android.bluetooth.BluetoothManager;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.ClipboardManager;
|
|
import android.content.ComponentName;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
import android.content.RestrictionsManager;
|
|
import android.content.pm.LauncherApps;
|
|
import android.content.res.ColorStateList;
|
|
import android.content.res.Configuration;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.hardware.ConsumerIrManager;
|
|
import android.hardware.SensorManager;
|
|
import android.hardware.camera2.CameraManager;
|
|
import android.hardware.display.DisplayManager;
|
|
import android.hardware.input.InputManager;
|
|
import android.hardware.usb.UsbManager;
|
|
import android.location.LocationManager;
|
|
import android.media.AudioManager;
|
|
import android.media.MediaRouter;
|
|
import android.media.projection.MediaProjectionManager;
|
|
import android.media.session.MediaSessionManager;
|
|
import android.media.tv.TvInputManager;
|
|
import android.net.ConnectivityManager;
|
|
import android.net.nsd.NsdManager;
|
|
import android.net.wifi.WifiManager;
|
|
import android.net.wifi.p2p.WifiP2pManager;
|
|
import android.nfc.NfcManager;
|
|
import android.os.BatteryManager;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.DropBoxManager;
|
|
import android.os.Handler;
|
|
import android.os.PowerManager;
|
|
import android.os.Process;
|
|
import android.os.UserManager;
|
|
import android.os.Vibrator;
|
|
import android.os.storage.StorageManager;
|
|
import android.print.PrintManager;
|
|
import android.telecom.TelecomManager;
|
|
import android.telephony.SubscriptionManager;
|
|
import android.telephony.TelephonyManager;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import android.view.Display;
|
|
import android.view.LayoutInflater;
|
|
import android.view.WindowManager;
|
|
import android.view.accessibility.AccessibilityManager;
|
|
import android.view.accessibility.CaptioningManager;
|
|
import android.view.inputmethod.InputMethodManager;
|
|
import android.view.textservice.TextServicesManager;
|
|
import androidx.annotation.ColorInt;
|
|
import androidx.annotation.ColorRes;
|
|
import androidx.annotation.DrawableRes;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.ReplaceWith;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.core.app.LocaleManagerCompat;
|
|
import androidx.core.app.NotificationCompat;
|
|
import androidx.core.app.NotificationManagerCompat;
|
|
import androidx.core.content.res.ResourcesCompat;
|
|
import androidx.core.os.ConfigurationCompat;
|
|
import androidx.core.os.ExecutorCompat;
|
|
import androidx.core.os.LocaleListCompat;
|
|
import androidx.core.util.ObjectsCompat;
|
|
import com.applovin.sdk.AppLovinEventTypes;
|
|
import com.ironsource.r8;
|
|
import com.ironsource.v8;
|
|
import com.vungle.ads.internal.presenter.NativeAdPresenter;
|
|
import java.io.File;
|
|
import java.lang.annotation.Retention;
|
|
import java.lang.annotation.RetentionPolicy;
|
|
import java.util.HashMap;
|
|
import java.util.concurrent.Executor;
|
|
|
|
@SuppressLint({"PrivateConstructorForUtilityClass"})
|
|
/* loaded from: classes.dex */
|
|
public class ContextCompat {
|
|
private static final String DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION_SUFFIX = ".DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION";
|
|
public static final int RECEIVER_EXPORTED = 2;
|
|
public static final int RECEIVER_NOT_EXPORTED = 4;
|
|
public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 1;
|
|
private static final String TAG = "ContextCompat";
|
|
private static final Object sSync = new Object();
|
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY})
|
|
public @interface RegisterReceiverFlags {
|
|
}
|
|
|
|
public static boolean startActivities(@NonNull Context context, @NonNull Intent[] intentArr) {
|
|
return startActivities(context, intentArr, null);
|
|
}
|
|
|
|
public static boolean startActivities(@NonNull Context context, @NonNull Intent[] intentArr, @Nullable Bundle bundle) {
|
|
context.startActivities(intentArr, bundle);
|
|
return true;
|
|
}
|
|
|
|
@ReplaceWith(expression = "context.startActivity(intent, options)")
|
|
@Deprecated
|
|
public static void startActivity(@NonNull Context context, @NonNull Intent intent, @Nullable Bundle bundle) {
|
|
context.startActivity(intent, bundle);
|
|
}
|
|
|
|
@Nullable
|
|
public static File getDataDir(@NonNull Context context) {
|
|
return Api24Impl.getDataDir(context);
|
|
}
|
|
|
|
@NonNull
|
|
@ReplaceWith(expression = "context.getObbDirs()")
|
|
@Deprecated
|
|
public static File[] getObbDirs(@NonNull Context context) {
|
|
return context.getObbDirs();
|
|
}
|
|
|
|
@NonNull
|
|
@ReplaceWith(expression = "context.getExternalFilesDirs(type)")
|
|
@Deprecated
|
|
public static File[] getExternalFilesDirs(@NonNull Context context, @Nullable String str) {
|
|
return context.getExternalFilesDirs(str);
|
|
}
|
|
|
|
@NonNull
|
|
@ReplaceWith(expression = "context.getExternalCacheDirs()")
|
|
@Deprecated
|
|
public static File[] getExternalCacheDirs(@NonNull Context context) {
|
|
return context.getExternalCacheDirs();
|
|
}
|
|
|
|
@Nullable
|
|
public static Drawable getDrawable(@NonNull Context context, @DrawableRes int i) {
|
|
return Api21Impl.getDrawable(context, i);
|
|
}
|
|
|
|
@Nullable
|
|
public static ColorStateList getColorStateList(@NonNull Context context, @ColorRes int i) {
|
|
return ResourcesCompat.getColorStateList(context.getResources(), i, context.getTheme());
|
|
}
|
|
|
|
@ColorInt
|
|
public static int getColor(@NonNull Context context, @ColorRes int i) {
|
|
return Api23Impl.getColor(context, i);
|
|
}
|
|
|
|
public static int checkSelfPermission(@NonNull Context context, @NonNull String str) {
|
|
ObjectsCompat.requireNonNull(str, "permission must be non-null");
|
|
if (Build.VERSION.SDK_INT >= 33 || !TextUtils.equals("android.permission.POST_NOTIFICATIONS", str)) {
|
|
return context.checkPermission(str, Process.myPid(), Process.myUid());
|
|
}
|
|
return NotificationManagerCompat.from(context).areNotificationsEnabled() ? 0 : -1;
|
|
}
|
|
|
|
@Nullable
|
|
public static File getNoBackupFilesDir(@NonNull Context context) {
|
|
return Api21Impl.getNoBackupFilesDir(context);
|
|
}
|
|
|
|
@NonNull
|
|
public static File getCodeCacheDir(@NonNull Context context) {
|
|
return Api21Impl.getCodeCacheDir(context);
|
|
}
|
|
|
|
private static File createFilesDir(File file) {
|
|
synchronized (sSync) {
|
|
try {
|
|
if (!file.exists()) {
|
|
if (file.mkdirs()) {
|
|
return file;
|
|
}
|
|
Log.w(TAG, "Unable to create files subdir " + file.getPath());
|
|
}
|
|
return file;
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Nullable
|
|
public static Context createDeviceProtectedStorageContext(@NonNull Context context) {
|
|
return Api24Impl.createDeviceProtectedStorageContext(context);
|
|
}
|
|
|
|
public static boolean isDeviceProtectedStorage(@NonNull Context context) {
|
|
return Api24Impl.isDeviceProtectedStorage(context);
|
|
}
|
|
|
|
@NonNull
|
|
public static Executor getMainExecutor(@NonNull Context context) {
|
|
if (Build.VERSION.SDK_INT >= 28) {
|
|
return Api28Impl.getMainExecutor(context);
|
|
}
|
|
return ExecutorCompat.create(new Handler(context.getMainLooper()));
|
|
}
|
|
|
|
public static void startForegroundService(@NonNull Context context, @NonNull Intent intent) {
|
|
Api26Impl.startForegroundService(context, intent);
|
|
}
|
|
|
|
@NonNull
|
|
public static Display getDisplayOrDefault(@NonNull Context context) {
|
|
if (Build.VERSION.SDK_INT >= 30) {
|
|
return Api30Impl.getDisplayOrDefault(context);
|
|
}
|
|
return ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
|
|
}
|
|
|
|
@Nullable
|
|
public static <T> T getSystemService(@NonNull Context context, @NonNull Class<T> cls) {
|
|
return (T) Api23Impl.getSystemService(context, cls);
|
|
}
|
|
|
|
@Nullable
|
|
public static Intent registerReceiver(@NonNull Context context, @Nullable BroadcastReceiver broadcastReceiver, @NonNull IntentFilter intentFilter, int i) {
|
|
return registerReceiver(context, broadcastReceiver, intentFilter, null, null, i);
|
|
}
|
|
|
|
@Nullable
|
|
public static Intent registerReceiver(@NonNull Context context, @Nullable BroadcastReceiver broadcastReceiver, @NonNull IntentFilter intentFilter, @Nullable String str, @Nullable Handler handler, int i) {
|
|
int i2 = i & 1;
|
|
if (i2 != 0 && (i & 4) != 0) {
|
|
throw new IllegalArgumentException("Cannot specify both RECEIVER_VISIBLE_TO_INSTANT_APPS and RECEIVER_NOT_EXPORTED");
|
|
}
|
|
if (i2 != 0) {
|
|
i |= 2;
|
|
}
|
|
int i3 = i;
|
|
int i4 = i3 & 2;
|
|
if (i4 == 0 && (i3 & 4) == 0) {
|
|
throw new IllegalArgumentException("One of either RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED is required");
|
|
}
|
|
if (i4 != 0 && (i3 & 4) != 0) {
|
|
throw new IllegalArgumentException("Cannot specify both RECEIVER_EXPORTED and RECEIVER_NOT_EXPORTED");
|
|
}
|
|
if (Build.VERSION.SDK_INT >= 33) {
|
|
return Api33Impl.registerReceiver(context, broadcastReceiver, intentFilter, str, handler, i3);
|
|
}
|
|
return Api26Impl.registerReceiver(context, broadcastReceiver, intentFilter, str, handler, i3);
|
|
}
|
|
|
|
@Nullable
|
|
public static String getSystemServiceName(@NonNull Context context, @NonNull Class<?> cls) {
|
|
return Api23Impl.getSystemServiceName(context, cls);
|
|
}
|
|
|
|
@NonNull
|
|
public static String getString(@NonNull Context context, int i) {
|
|
return getContextForLanguage(context).getString(i);
|
|
}
|
|
|
|
@NonNull
|
|
public static Context getContextForLanguage(@NonNull Context context) {
|
|
LocaleListCompat applicationLocales = LocaleManagerCompat.getApplicationLocales(context);
|
|
if (Build.VERSION.SDK_INT > 32 || applicationLocales.isEmpty()) {
|
|
return context;
|
|
}
|
|
Configuration configuration = new Configuration(context.getResources().getConfiguration());
|
|
ConfigurationCompat.setLocales(configuration, applicationLocales);
|
|
return context.createConfigurationContext(configuration);
|
|
}
|
|
|
|
@Nullable
|
|
public static String getAttributionTag(@NonNull Context context) {
|
|
if (Build.VERSION.SDK_INT >= 30) {
|
|
return Api30Impl.getAttributionTag(context);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@NonNull
|
|
public static Context createAttributionContext(@NonNull Context context, @Nullable String str) {
|
|
return Build.VERSION.SDK_INT >= 30 ? Api30Impl.createAttributionContext(context, str) : context;
|
|
}
|
|
|
|
public static String obtainAndCheckReceiverPermission(Context context) {
|
|
String str = context.getPackageName() + DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION_SUFFIX;
|
|
if (PermissionChecker.checkSelfPermission(context, str) == 0) {
|
|
return str;
|
|
}
|
|
throw new RuntimeException("Permission " + str + " is required by your application to receive broadcasts, please add it to your manifest");
|
|
}
|
|
|
|
public static final class LegacyServiceMapHolder {
|
|
static final HashMap<Class<?>, String> SERVICES;
|
|
|
|
private LegacyServiceMapHolder() {
|
|
}
|
|
|
|
static {
|
|
HashMap<Class<?>, String> hashMap = new HashMap<>();
|
|
SERVICES = hashMap;
|
|
hashMap.put(SubscriptionManager.class, "telephony_subscription_service");
|
|
hashMap.put(UsageStatsManager.class, "usagestats");
|
|
hashMap.put(AppWidgetManager.class, "appwidget");
|
|
hashMap.put(BatteryManager.class, "batterymanager");
|
|
hashMap.put(CameraManager.class, "camera");
|
|
hashMap.put(JobScheduler.class, "jobscheduler");
|
|
hashMap.put(LauncherApps.class, "launcherapps");
|
|
hashMap.put(MediaProjectionManager.class, "media_projection");
|
|
hashMap.put(MediaSessionManager.class, "media_session");
|
|
hashMap.put(RestrictionsManager.class, "restrictions");
|
|
hashMap.put(TelecomManager.class, "telecom");
|
|
hashMap.put(TvInputManager.class, "tv_input");
|
|
hashMap.put(AppOpsManager.class, "appops");
|
|
hashMap.put(CaptioningManager.class, "captioning");
|
|
hashMap.put(ConsumerIrManager.class, "consumer_ir");
|
|
hashMap.put(PrintManager.class, "print");
|
|
hashMap.put(BluetoothManager.class, r8.d);
|
|
hashMap.put(DisplayManager.class, "display");
|
|
hashMap.put(UserManager.class, "user");
|
|
hashMap.put(InputManager.class, "input");
|
|
hashMap.put(MediaRouter.class, "media_router");
|
|
hashMap.put(NsdManager.class, "servicediscovery");
|
|
hashMap.put(AccessibilityManager.class, "accessibility");
|
|
hashMap.put(AccountManager.class, "account");
|
|
hashMap.put(ActivityManager.class, "activity");
|
|
hashMap.put(AlarmManager.class, NotificationCompat.CATEGORY_ALARM);
|
|
hashMap.put(AudioManager.class, "audio");
|
|
hashMap.put(ClipboardManager.class, "clipboard");
|
|
hashMap.put(ConnectivityManager.class, "connectivity");
|
|
hashMap.put(DevicePolicyManager.class, "device_policy");
|
|
hashMap.put(DownloadManager.class, NativeAdPresenter.DOWNLOAD);
|
|
hashMap.put(DropBoxManager.class, "dropbox");
|
|
hashMap.put(InputMethodManager.class, "input_method");
|
|
hashMap.put(KeyguardManager.class, "keyguard");
|
|
hashMap.put(LayoutInflater.class, "layout_inflater");
|
|
hashMap.put(LocationManager.class, "location");
|
|
hashMap.put(NfcManager.class, "nfc");
|
|
hashMap.put(NotificationManager.class, "notification");
|
|
hashMap.put(PowerManager.class, "power");
|
|
hashMap.put(SearchManager.class, AppLovinEventTypes.USER_EXECUTED_SEARCH);
|
|
hashMap.put(SensorManager.class, "sensor");
|
|
hashMap.put(StorageManager.class, v8.a.j);
|
|
hashMap.put(TelephonyManager.class, "phone");
|
|
hashMap.put(TextServicesManager.class, "textservices");
|
|
hashMap.put(UiModeManager.class, "uimode");
|
|
hashMap.put(UsbManager.class, "usb");
|
|
hashMap.put(Vibrator.class, "vibrator");
|
|
hashMap.put(WallpaperManager.class, "wallpaper");
|
|
hashMap.put(WifiP2pManager.class, "wifip2p");
|
|
hashMap.put(WifiManager.class, "wifi");
|
|
hashMap.put(WindowManager.class, "window");
|
|
}
|
|
}
|
|
|
|
@RequiresApi(21)
|
|
public static class Api21Impl {
|
|
private Api21Impl() {
|
|
}
|
|
|
|
public static Drawable getDrawable(Context context, int i) {
|
|
return context.getDrawable(i);
|
|
}
|
|
|
|
public static File getNoBackupFilesDir(Context context) {
|
|
return context.getNoBackupFilesDir();
|
|
}
|
|
|
|
public static File getCodeCacheDir(Context context) {
|
|
return context.getCodeCacheDir();
|
|
}
|
|
}
|
|
|
|
@RequiresApi(23)
|
|
public static class Api23Impl {
|
|
private Api23Impl() {
|
|
}
|
|
|
|
public static int getColor(Context context, int i) {
|
|
return context.getColor(i);
|
|
}
|
|
|
|
public static <T> T getSystemService(Context context, Class<T> cls) {
|
|
return (T) context.getSystemService(cls);
|
|
}
|
|
|
|
public static String getSystemServiceName(Context context, Class<?> cls) {
|
|
return context.getSystemServiceName(cls);
|
|
}
|
|
}
|
|
|
|
@RequiresApi(24)
|
|
public static class Api24Impl {
|
|
private Api24Impl() {
|
|
}
|
|
|
|
public static File getDataDir(Context context) {
|
|
return context.getDataDir();
|
|
}
|
|
|
|
public static Context createDeviceProtectedStorageContext(Context context) {
|
|
return context.createDeviceProtectedStorageContext();
|
|
}
|
|
|
|
public static boolean isDeviceProtectedStorage(Context context) {
|
|
return context.isDeviceProtectedStorage();
|
|
}
|
|
}
|
|
|
|
@RequiresApi(26)
|
|
public static class Api26Impl {
|
|
private Api26Impl() {
|
|
}
|
|
|
|
public static Intent registerReceiver(Context context, @Nullable BroadcastReceiver broadcastReceiver, IntentFilter intentFilter, String str, Handler handler, int i) {
|
|
if ((i & 4) != 0 && str == null) {
|
|
return context.registerReceiver(broadcastReceiver, intentFilter, ContextCompat.obtainAndCheckReceiverPermission(context), handler);
|
|
}
|
|
return context.registerReceiver(broadcastReceiver, intentFilter, str, handler, i & 1);
|
|
}
|
|
|
|
public static ComponentName startForegroundService(Context context, Intent intent) {
|
|
return context.startForegroundService(intent);
|
|
}
|
|
}
|
|
|
|
@RequiresApi(28)
|
|
public static class Api28Impl {
|
|
private Api28Impl() {
|
|
}
|
|
|
|
public static Executor getMainExecutor(Context context) {
|
|
return context.getMainExecutor();
|
|
}
|
|
}
|
|
|
|
@RequiresApi(30)
|
|
public static class Api30Impl {
|
|
private Api30Impl() {
|
|
}
|
|
|
|
public static String getAttributionTag(Context context) {
|
|
return context.getAttributionTag();
|
|
}
|
|
|
|
public static Display getDisplayOrDefault(Context context) {
|
|
try {
|
|
return context.getDisplay();
|
|
} catch (UnsupportedOperationException unused) {
|
|
Log.w(ContextCompat.TAG, "The context:" + context + " is not associated with any display. Return a fallback display instead.");
|
|
return ((DisplayManager) context.getSystemService(DisplayManager.class)).getDisplay(0);
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
public static Context createAttributionContext(@NonNull Context context, @Nullable String str) {
|
|
return context.createAttributionContext(str);
|
|
}
|
|
}
|
|
|
|
@RequiresApi(33)
|
|
public static class Api33Impl {
|
|
private Api33Impl() {
|
|
}
|
|
|
|
public static Intent registerReceiver(Context context, @Nullable BroadcastReceiver broadcastReceiver, IntentFilter intentFilter, String str, Handler handler, int i) {
|
|
return context.registerReceiver(broadcastReceiver, intentFilter, str, handler, i);
|
|
}
|
|
}
|
|
}
|