Marking test receiver as exported.

In order to follow the new dynamic receiver paradigm introduced in T, receivers will have to be specifically marked as exported or not exported when registering dynamically. Since this is in a test only, and the test says that it needs the broadcast to be in a different process, mark as exported.

Bug: 161145287
Change-Id: I112d56962e3a6c3043240f8dfab058dc5a728ba9
Test: atest HostsideRestrictBackgroundNetworkTests#testAppIdle_toast
This commit is contained in:
Jacob Hobbie 2022-02-03 18:01:25 +00:00 • committed by Michael Groover
commit 4c06b3885d
2 changed files with 12 additions and 4 deletions

View file

@ -22,7 +22,10 @@ android_test_helper_app {
name: "CtsHostsideNetworkTestsApp2",
defaults: ["cts_support_defaults"],
sdk_version: "test_current",
static_libs: ["CtsHostsideNetworkTestsAidl"],
static_libs: [
"CtsHostsideNetworkTestsAidl",
"NetworkStackApiStableShims",
],
srcs: ["src/**/*.java"],
// Tag this module as a cts test artifact
test_suites: [

View file

@ -21,6 +21,7 @@ import static com.android.cts.net.hostside.app2.Common.ACTION_RECEIVER_READY;
import static com.android.cts.net.hostside.app2.Common.ACTION_SNOOZE_WARNING;
import static com.android.cts.net.hostside.app2.Common.DYNAMIC_RECEIVER;
import static com.android.cts.net.hostside.app2.Common.TAG;
import static com.android.networkstack.apishim.ConstantsShim.RECEIVER_EXPORTED;
import android.app.NotificationChannel;
import android.app.NotificationManager;
@ -40,6 +41,7 @@ import android.util.Log;
import com.android.cts.net.hostside.IMyService;
import com.android.cts.net.hostside.INetworkCallback;
import com.android.modules.utils.build.SdkLevel;
/**
* Service used to dynamically register a broadcast receiver.
@ -64,11 +66,14 @@ public class MyService extends Service {
return;
}
final Context context = getApplicationContext();
final int flags = SdkLevel.isAtLeastT() ? RECEIVER_EXPORTED : 0;
mReceiver = new MyBroadcastReceiver(DYNAMIC_RECEIVER);
context.registerReceiver(mReceiver, new IntentFilter(ACTION_RECEIVER_READY));
context.registerReceiver(mReceiver,
new IntentFilter(ACTION_RESTRICT_BACKGROUND_CHANGED));
context.registerReceiver(mReceiver, new IntentFilter(ACTION_SNOOZE_WARNING));
new IntentFilter(ACTION_RECEIVER_READY), flags);
context.registerReceiver(mReceiver,
new IntentFilter(ACTION_RESTRICT_BACKGROUND_CHANGED), flags);
context.registerReceiver(mReceiver,
new IntentFilter(ACTION_SNOOZE_WARNING), flags);
Log.d(TAG, "receiver registered");
}