আচরণের পরিবর্তন: Android 14 বা উচ্চতরকে লক্ষ্য করে এমন অ্যাপ

পূর্ববর্তী রিলিজের মতো, Android 14-এ এমন আচরণের পরিবর্তন অন্তর্ভুক্ত রয়েছে যা আপনার অ্যাপকে প্রভাবিত করতে পারে। নিম্নলিখিত আচরণ পরিবর্তনগুলি শুধুমাত্র Android 14 (API স্তর 34) বা উচ্চতরকে লক্ষ্য করে এমন অ্যাপগুলিতে প্রযোজ্য। যদি আপনার অ্যাপটি Android 14 বা তার বেশির দিকে লক্ষ্য করে থাকে, তাহলে প্রযোজ্য ক্ষেত্রে এই আচরণগুলিকে সঠিকভাবে সমর্থন করার জন্য আপনার অ্যাপটি সংশোধন করা উচিত।

অ্যাপ্লিকেশানের targetSdkVersion নির্বিশেষে Android 14 এ চলমান সমস্ত অ্যাপ্লিকেশানকে প্রভাবিত করে এমন আচরণের পরিবর্তনগুলির তালিকাটিও পর্যালোচনা করতে ভুলবেন না।

মূল কার্যকারিতা

ফোরগ্রাউন্ড পরিষেবার প্রকারগুলি প্রয়োজন৷

如果您的应用以 Android 14(API 级别 34)或更高版本为目标平台,则必须为应用中的每个前台服务至少指定一项前台服务类型。您应选择一个能代表应用用例的前台服务类型。系统需要特定类型的前台服务满足特定用例。

如果应用中的用例与这些类型均不相关,强烈建议您迁移逻辑以使用 WorkManager用户发起的数据传输作业

BluetoothAdapter-এ BLUETOOTH_CONNECT অনুমতির প্রয়োগ৷

对于以 Android 14(API 级别 34)或更高版本为目标平台的应用,在调用 BluetoothAdapter getProfileConnectionState() 方法时,Android 14 会强制执行 BLUETOOTH_CONNECT 权限。

此方法已需要 BLUETOOTH_CONNECT 权限,但未强制执行。确保您的应用在应用的 AndroidManifest.xml 文件中声明 BLUETOOTH_CONNECT,如以下代码段所示,并在调用 getProfileConnectionState 之前检查用户是否已授予相应权限

<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

OpenJDK 17 আপডেট

Android 14 continues the work of refreshing Android's core libraries to align with the features in the latest OpenJDK LTS releases, including both library updates and Java 17 language support for app and platform developers.

A few of these changes can affect app compatibility:

  • Changes to regular expressions: Invalid group references are now disallowed to more closely follow the semantics of OpenJDK. You might see new cases where an IllegalArgumentException is thrown by the java.util.regex.Matcher class, so make sure to test your app for areas that use regular expressions. To enable or disable this change while testing, toggle the DISALLOW_INVALID_GROUP_REFERENCE flag using the compatibility framework tools.
  • UUID handling: The java.util.UUID.fromString() method now does more strict checks when validating the input argument, so you might see an IllegalArgumentException during deserialization. To enable or disable this change while testing, toggle the ENABLE_STRICT_VALIDATION flag using the compatibility framework tools.
  • ProGuard issues: In some cases, the addition of the java.lang.ClassValue class causes an issue if you try to shrink, obfuscate, and optimize your app using ProGuard. The problem originates with a Kotlin library that changes runtime behaviour based on whether Class.forName("java.lang.ClassValue") returns a class or not. If your app was developed against an older version of the runtime without the java.lang.ClassValue class available, then these optimizations might remove the computeValue method from classes derived from java.lang.ClassValue.

JobScheduler কলব্যাক এবং নেটওয়ার্ক আচরণকে শক্তিশালী করে

Since its introduction, JobScheduler expects your app to return from onStartJob or onStopJob within a few seconds. Prior to Android 14, if a job runs too long, the job is stopped and fails silently. If your app targets Android 14 (API level 34) or higher and exceeds the granted time on the main thread, the app triggers an ANR with the error message "No response to onStartJob" or "No response to onStopJob".

This ANR may be a result of 2 scenarios: 1. There is work blocking the main thread, preventing the callbacks onStartJob or onStopJob from executing and completing within the expected time limit. 2. The developer is running blocking work within the JobScheduler callback onStartJob or onStopJob, preventing the callback from completing within the expected time limit.

To address #1, you will need to further debug what is blocking the main thread when the ANR occurs, you can do this using ApplicationExitInfo#getTraceInputStream() to get the tombstone trace when the ANR occurs. If you're able to manually reproduce the ANR, you can record a system trace and inspect the trace using either Android Studio or Perfetto to better understand what is running on the main thread when the ANR occurs. Note that this can happen when using JobScheduler API directly or using the androidx library WorkManager.

To address #2, consider migrating to WorkManager, which provides support for wrapping any processing in onStartJob or onStopJob in an asynchronous thread.

JobScheduler also introduces a requirement to declare the ACCESS_NETWORK_STATE permission if using setRequiredNetworkType or setRequiredNetwork constraint. If your app does not declare the ACCESS_NETWORK_STATE permission when scheduling the job and is targeting Android 14 or higher, it will result in a SecurityException.

টাইলস লঞ্চ API

14 এবং উচ্চতর টার্গেট করা অ্যাপ্লিকেশানগুলির জন্য, TileService#startActivityAndCollapse(Intent) বাতিল করা হয়েছে এবং এখন কল করার সময় একটি ব্যতিক্রম থ্রো করে৷ যদি আপনার অ্যাপটি টাইলস থেকে ক্রিয়াকলাপ চালু করে, তাহলে পরিবর্তে TileService#startActivityAndCollapse(PendingIntent) ব্যবহার করুন।

গোপনীয়তা

ফটো এবং ভিডিও আংশিক অ্যাক্সেস

অ্যান্ড্রয়েড 14 নির্বাচিত ফটো অ্যাক্সেস প্রবর্তন করে, যা ব্যবহারকারীদের একটি প্রদত্ত ধরণের সমস্ত মিডিয়াতে অ্যাক্সেস দেওয়ার পরিবর্তে তাদের লাইব্রেরিতে নির্দিষ্ট চিত্র এবং ভিডিওগুলিতে অ্যাপ্লিকেশনগুলিকে অ্যাক্সেস দেওয়ার অনুমতি দেয়।

আপনার অ্যাপটি Android 14 (API লেভেল 34) বা উচ্চতরকে লক্ষ্য করলেই এই পরিবর্তনটি সক্ষম হবে। আপনি যদি এখনও ফটো পিকার ব্যবহার না করেন, তাহলে আমরা কোনও স্টোরেজ অনুমতির অনুরোধ না করেই ব্যবহারকারীর গোপনীয়তা বাড়ায় এমন ছবি এবং ভিডিও নির্বাচন করার জন্য একটি সামঞ্জস্যপূর্ণ অভিজ্ঞতা প্রদানের জন্য এটিকে আপনার অ্যাপে প্রয়োগ করার পরামর্শ দিই।

আপনি যদি স্টোরেজ অনুমতিগুলি ব্যবহার করে আপনার নিজস্ব গ্যালারি পিকার বজায় রাখেন এবং আপনার বাস্তবায়নের উপর সম্পূর্ণ নিয়ন্ত্রণ বজায় রাখতে চান, তাহলে নতুন READ_MEDIA_VISUAL_USER_SELECTED অনুমতি ব্যবহার করতে আপনার বাস্তবায়ন মানিয়ে নিন । যদি আপনার অ্যাপটি নতুন অনুমতি ব্যবহার না করে, তাহলে সিস্টেমটি আপনার অ্যাপটিকে একটি সামঞ্জস্যপূর্ণ মোডে চালায়।

ব্যবহারকারীর অভিজ্ঞতা

পূর্ণ-স্ক্রীন ইন্টেন্ট বিজ্ঞপ্তিগুলি সুরক্ষিত করুন

在 Android 11(API 级别 30)中,任何应用都可以在手机处于锁定状态时使用 Notification.Builder.setFullScreenIntent 发送全屏 intent。您可以通过在 AndroidManifest 中声明 USE_FULL_SCREEN_INTENT 权限,在应用安装时自动授予此权限。

全屏 intent 通知适用于需要用户立即注意的极高优先级通知,例如用户来电或用户配置的闹钟设置。对于以 Android 14(API 级别 34)或更高版本为目标平台的应用,获准使用此权限的应用仅限于提供通话和闹钟的应用。对于不适合此情况的任何应用,Google Play 商店会撤消其默认的 USE_FULL_SCREEN_INTENT 权限。这些政策变更的截止日期为 2024 年 5 月 31 日

在用户更新到 Android 14 之前,在手机上安装的应用仍拥有此权限。用户可以开启和关闭此权限。

您可以使用新 API NotificationManager.canUseFullScreenIntent 检查应用是否具有该权限;如果没有,应用可以使用新 intent ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT 启动设置页面,在该页面中,用户可以授予权限。

নিরাপত্তা

অন্তর্নিহিত এবং মুলতুবি অভিপ্রায়ে সীমাবদ্ধতা

For apps targeting Android 14 (API level 34) or higher, Android restricts apps from sending implicit intents to internal app components in the following ways:

  • Implicit intents are only delivered to exported components. Apps must either use an explicit intent to deliver to unexported components, or mark the component as exported.
  • If an app creates a mutable pending intent with an intent that doesn't specify a component or package, the system throws an exception.

These changes prevent malicious apps from intercepting implicit intents that are intended for use by an app's internal components.

For example, here is an intent filter that could be declared in your app's manifest file:

<activity
    android:name=".AppActivity"
    android:exported="false">
    <intent-filter>
        <action android:name="com.example.action.APP_ACTION" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

If your app tried to launch this activity using an implicit intent, an ActivityNotFoundException exception would be thrown:

Kotlin

// Throws an ActivityNotFoundException exception when targeting Android 14.
context.startActivity(Intent("com.example.action.APP_ACTION"))

Java

// Throws an ActivityNotFoundException exception when targeting Android 14.
context.startActivity(new Intent("com.example.action.APP_ACTION"));

To launch the non-exported activity, your app should use an explicit intent instead:

Kotlin

// This makes the intent explicit.
val explicitIntent =
        Intent("com.example.action.APP_ACTION")
explicitIntent.apply {
    package = context.packageName
}
context.startActivity(explicitIntent)

Java

// This makes the intent explicit.
Intent explicitIntent =
        new Intent("com.example.action.APP_ACTION")
explicitIntent.setPackage(context.getPackageName());
context.startActivity(explicitIntent);

রানটাইম-নিবন্ধিত ব্রডকাস্ট রিসিভারদের অবশ্যই রপ্তানি আচরণ নির্দিষ্ট করতে হবে

অ্যাপ্লিকেশান এবং পরিষেবাগুলি যেগুলি Android 14 (API স্তর 34) বা উচ্চতরকে লক্ষ্য করে এবং প্রসঙ্গ-নিবন্ধিত রিসিভারগুলি ব্যবহার করে তা নির্দেশ করার জন্য একটি পতাকা নির্দিষ্ট করতে হবে যে রিসিভারটিকে ডিভাইসের অন্যান্য সমস্ত অ্যাপে রপ্তানি করা উচিত কিনা: যথাক্রমে RECEIVER_EXPORTED বা RECEIVER_NOT_EXPORTED . এই প্রয়োজনীয়তাটি Android 13-এ প্রবর্তিত এই রিসিভারগুলির জন্য বৈশিষ্ট্যগুলি ব্যবহার করে সুরক্ষা দুর্বলতা থেকে অ্যাপগুলিকে রক্ষা করতে সহায়তা করে৷

শুধুমাত্র সিস্টেম সম্প্রচার গ্রহণকারী রিসিভারদের জন্য ব্যতিক্রম

আপনার অ্যাপ যদি Context#registerReceiver Context#registerReceiver() এর মতো সিস্টেম সম্প্রচারের জন্য শুধুমাত্র একটি রিসিভার নিবন্ধন করে থাকে, তাহলে রিসিভার নিবন্ধন করার সময় এটি একটি পতাকা নির্দিষ্ট করবে না।

নিরাপদ ডায়নামিক কোড লোড হচ্ছে

যদি আপনার অ্যাপটি Android 14 (API লেভেল 34) বা উচ্চতরকে টার্গেট করে এবং ডায়নামিক কোড লোডিং (DCL) ব্যবহার করে, তবে সমস্ত গতিশীল-লোড করা ফাইলগুলিকে শুধুমাত্র পঠনযোগ্য হিসাবে চিহ্নিত করতে হবে। অন্যথায়, সিস্টেম একটি ব্যতিক্রম নিক্ষেপ. আমরা সুপারিশ করি যে যখনই সম্ভব অ্যাপগুলিকে গতিশীলভাবে কোড লোড করা এড়িয়ে চলুন , কারণ এটি করার ফলে কোড ইনজেকশন বা কোড টেম্পারিং দ্বারা একটি অ্যাপের সাথে আপস করা হওয়ার ঝুঁকি অনেক বেড়ে যায়।

যদি আপনাকে গতিশীলভাবে কোড লোড করতে হয়, ফাইলটি খোলার সাথে সাথে এবং কোনো বিষয়বস্তু লেখার আগে গতিশীলভাবে লোড করা ফাইল (যেমন একটি DEX, JAR বা APK ফাইল) শুধুমাত্র পঠনযোগ্য হিসাবে সেট করতে নিম্নলিখিত পদ্ধতিটি ব্যবহার করুন:

কোটলিন

val jar = File("DYNAMICALLY_LOADED_FILE.jar")
val os = FileOutputStream(jar)
os.use {
    // Set the file to read-only first to prevent race conditions
    jar.setReadOnly()
    // Then write the actual file content
}
val cl = PathClassLoader(jar, parentClassLoader)

জাভা

File jar = new File("DYNAMICALLY_LOADED_FILE.jar");
try (FileOutputStream os = new FileOutputStream(jar)) {
    // Set the file to read-only first to prevent race conditions
    jar.setReadOnly();
    // Then write the actual file content
} catch (IOException e) { ... }
PathClassLoader cl = new PathClassLoader(jar, parentClassLoader);

গতিশীল-লোড করা ফাইলগুলি পরিচালনা করুন যা ইতিমধ্যেই বিদ্যমান

বিদ্যমান গতিশীলভাবে লোড করা ফাইলগুলির জন্য ব্যতিক্রমগুলি ছুঁড়ে ফেলা থেকে প্রতিরোধ করার জন্য, আমরা আপনার অ্যাপে আবার গতিশীলভাবে লোড করার চেষ্টা করার আগে ফাইলগুলি মুছে ফেলা এবং পুনরায় তৈরি করার পরামর্শ দিই৷ আপনি ফাইলগুলি পুনরায় তৈরি করার সময়, লেখার সময় ফাইলগুলিকে শুধুমাত্র পঠনযোগ্য চিহ্নিত করার জন্য পূর্ববর্তী নির্দেশিকা অনুসরণ করুন। বিকল্পভাবে, আপনি বিদ্যমান ফাইলগুলিকে শুধুমাত্র-পঠন হিসাবে পুনরায় লেবেল করতে পারেন, তবে এই ক্ষেত্রে, আমরা দৃঢ়ভাবে সুপারিশ করি যে আপনি প্রথমে ফাইলগুলির অখণ্ডতা যাচাই করুন (উদাহরণস্বরূপ, একটি বিশ্বস্ত মানের বিপরীতে ফাইলের স্বাক্ষর চেক করে), সুরক্ষায় সহায়তা করতে দূষিত কর্ম থেকে আপনার অ্যাপ্লিকেশন.

ব্যাকগ্রাউন্ড থেকে কার্যক্রম শুরু করার অতিরিক্ত বিধিনিষেধ

For apps targeting Android 14 (API level 34) or higher, the system further restricts when apps are allowed to start activities from the background:

These changes expand the existing set of restrictions to protect users by preventing malicious apps from abusing APIs to start disruptive activities from the background.

জিপ পাথ ট্রাভার্সাল

For apps targeting Android 14 (API level 34) or higher, Android prevents the Zip Path Traversal Vulnerability in the following way: ZipFile(String) and ZipInputStream.getNextEntry() throws a ZipException if zip file entry names contain ".." or start with "/".

Apps can opt-out from this validation by calling dalvik.system.ZipPathValidator.clearCallback().

对于以 Android 14(API 级别 34)或更高版本为目标平台的应用,在以下任一情况下,MediaProjection#createVirtualDisplay 都会抛出 SecurityException

您的应用必须在每次捕获会话之前征求用户同意。单次捕获会话是对 MediaProjection#createVirtualDisplay 的单次调用,并且每个 MediaProjection 实例只能使用一次。

处理配置变更

如果您的应用需要调用 MediaProjection#createVirtualDisplay 来处理配置更改(例如屏幕方向或屏幕大小更改),您可以按照以下步骤更新现有 MediaProjection 实例的 VirtualDisplay

  1. 使用新的宽度和高度调用 VirtualDisplay#resize
  2. VirtualDisplay#setSurface 提供新的 Surface,并为其指定新的宽度和高度。

注册回调

您的应用应注册回调,以处理用户不同意继续拍摄会话的情况。为此,请实现 Callback#onStop,并让应用释放所有相关资源(例如 VirtualDisplaySurface)。

如果您的应用未注册此回调,当您的应用调用它时,MediaProjection#createVirtualDisplay 会抛出 IllegalStateException

নন-SDK সীমাবদ্ধতা আপডেট করা হয়েছে

Android 14 包含更新后的受限非 SDK 接口列表(基于与 Android 开发者之间的协作以及最新的内部测试)。在限制使用非 SDK 接口之前,我们会尽可能确保有可用的公开替代方案。

如果您的应用并非以 Android 14 为目标平台,其中一些变更可能不会立即对您产生影响。然而,虽然您目前仍可以使用一些非 SDK 接口(具体取决于应用的目标 API 级别),但只要您使用任何非 SDK 方法或字段,终归存在导致应用出问题的显著风险。

如果您不确定自己的应用是否使用了非 SDK 接口,则可以测试您的应用来进行确认。如果您的应用依赖于非 SDK 接口,您应该开始计划迁移到 SDK 替代方案。然而,我们知道某些应用具有使用非 SDK 接口的有效用例。如果您无法为应用中的某项功能找到使用非 SDK 接口的替代方案,应请求新的公共 API

To learn more about the changes in this release of Android, see Updates to non-SDK interface restrictions in Android 14. To learn more about non-SDK interfaces generally, see Restrictions on non-SDK interfaces.