diff options
author | 2023-01-03 19:37:39 +0000 | |
---|---|---|
committer | 2023-01-06 19:19:42 +0000 | |
commit | 0583bf4ee809b05ce0e7e3cad730510f0db7ea6d (patch) | |
tree | 77041344b5062e2a25599ce7f9ba6809b07bdf1d | |
parent | f5920982961fdbb99f83d9d6a5ef0918995f091a (diff) |
Adding a manifest registered broadcast Receiver
to listen to updates in packages.
BUG:261660277
Test: Manual
Change-Id: I1929f23446d1c885f76b3bf4d3e353ff9a31d849
-rw-r--r-- | PermissionController/AndroidManifest.xml | 11 | ||||
-rw-r--r-- | PermissionController/src/com/android/permissioncontroller/safetylabel/SafetyLabelChangedBroadcastReceiver.kt | 63 |
2 files changed, 74 insertions, 0 deletions
diff --git a/PermissionController/AndroidManifest.xml b/PermissionController/AndroidManifest.xml index a155cba4d..090fd63a5 100644 --- a/PermissionController/AndroidManifest.xml +++ b/PermissionController/AndroidManifest.xml @@ -239,6 +239,17 @@ </intent-filter> </receiver> + <receiver + android:name="com.android.permissioncontroller.safetylabel.SafetyLabelChangedBroadcastReceiver" + android:enabled="@bool/is_at_least_u" + android:exported="true"> + <intent-filter> + <action android:name="android.intent.action.PACKAGE_REMOVED" /> + <action android:name="android.intent.action.PACKAGE_ADDED" /> + <data android:scheme="package" /> + </intent-filter> + </receiver> + <service android:name="com.android.permissioncontroller.privacysources.AccessibilityJobService" android:enabled="@bool/is_at_least_t" diff --git a/PermissionController/src/com/android/permissioncontroller/safetylabel/SafetyLabelChangedBroadcastReceiver.kt b/PermissionController/src/com/android/permissioncontroller/safetylabel/SafetyLabelChangedBroadcastReceiver.kt new file mode 100644 index 000000000..b09011687 --- /dev/null +++ b/PermissionController/src/com/android/permissioncontroller/safetylabel/SafetyLabelChangedBroadcastReceiver.kt @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.permissioncontroller.safetylabel + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.util.Log +import androidx.core.util.Preconditions +import com.android.permissioncontroller.permission.utils.KotlinUtils + +/** + * Listens for package additions, replacements, and removals. + */ +class SafetyLabelChangedBroadcastReceiver : BroadcastReceiver() { + + override fun onReceive(context: Context, intent: Intent) { + if (!KotlinUtils.isSafetyLabelChangeNotificationsEnabled()) { + return + } + + val data = Preconditions.checkNotNull(intent.data) + val action = Preconditions.checkNotNull(intent.action) + if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) { + if (action != Intent.ACTION_PACKAGE_ADDED) { + return + } + // TODO(b/261660881): Update Safety Label store when packages are added or updated. + if (DEBUG) { + Log.v(TAG, "Package ${data.schemeSpecificPart} replaced. Intent " + + "Action: ${action}\n") + } + } else if (action == Intent.ACTION_PACKAGE_ADDED) { + // TODO(b/261660881): Update Safety Label store when packages are added or updated. + if (DEBUG) { + Log.v(TAG, "Package ${data.schemeSpecificPart} added.") + } + } else if (action == Intent.ACTION_PACKAGE_REMOVED) { + // TODO(b/261661752): Update Safety Label store when packages are removed. + if (DEBUG) { + Log.v(TAG, "Package ${data.schemeSpecificPart} removed.") + } + } + } + companion object { + private const val TAG = "SafetyLabelChangedBroadcastReceiver" + private const val DEBUG = false + } +}
\ No newline at end of file |