1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.attributionsource.cts.blamed 18 19 import android.app.Activity 20 import android.content.AttributionSource 21 import android.content.ContextParams 22 import android.content.Intent 23 import android.os.Bundle 24 import android.os.RemoteCallback 25 26 class BringToForegroundActivity : Activity() { 27 onCreatenull28 override fun onCreate(savedInstanceState: Bundle?) { 29 super.onCreate(savedInstanceState) 30 val callback = intent.getParcelableExtra<RemoteCallback>(REMOTE_CALLBACK) 31 32 val attributionContext = createContext( 33 ContextParams.Builder() 34 .setAttributionTag(RECEIVER_ATTRIBUTION_TAG) 35 .setNextAttributionSource(AttributionSource.Builder( 36 packageManager.getPackageUid(RECEIVER2_PACKAGE_NAME, 0)) 37 .setPackageName(RECEIVER2_PACKAGE_NAME) 38 .setAttributionTag(RECEIVER2_ATTRIBUTION_TAG) 39 .build()) 40 .build()) 41 42 val result = Bundle() 43 result.putParcelable(ATTRIBUTION_SOURCE, attributionContext.attributionSource) 44 callback?.sendResult(result) 45 } 46 onNewIntentnull47 override fun onNewIntent(intent: Intent?) { 48 super.onNewIntent(intent) 49 finish() 50 } 51 52 companion object { 53 val REMOTE_CALLBACK = "remote_callback" 54 val ATTRIBUTION_SOURCE = "attribution_source" 55 val RECEIVER2_PACKAGE_NAME = "android.attributionsource.cts.blamed2" 56 val RECEIVER_ATTRIBUTION_TAG = "receiver_attribution_tag" 57 val RECEIVER2_ATTRIBUTION_TAG = "receiver2_attribution_tag" 58 } 59 } 60