1 /* 2 * Copyright (C) 2022 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.app.stubs; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.os.Binder; 22 import android.os.Bundle; 23 import android.os.IBinder; 24 import android.os.Parcel; 25 import android.os.RemoteException; 26 27 /** 28 * An empty helper activity. 29 */ 30 public final class RemoteActivity extends Activity { 31 32 /** Extras to the launching intent */ 33 public static final String EXTRA_CALLBACK = "callback"; 34 35 private final IBinder mStub = new Binder() { 36 @Override 37 protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) 38 throws RemoteException { 39 switch (code) { 40 case IBinder.FIRST_CALL_TRANSACTION: 41 finish(); 42 return true; 43 default: 44 return false; 45 } 46 } 47 }; 48 49 @Override onCreate(Bundle savedInstanceState)50 protected void onCreate(Bundle savedInstanceState) { 51 super.onCreate(savedInstanceState); 52 final Intent intent = getIntent(); 53 final IBinder callback = intent.getExtras().getBinder(EXTRA_CALLBACK); 54 final Parcel data = Parcel.obtain(); 55 try { 56 data.writeStrongBinder(mStub); 57 callback.transact(IBinder.FIRST_CALL_TRANSACTION, data, null, 0); 58 } catch (RemoteException e) { 59 } finally { 60 data.recycle(); 61 } 62 } 63 } 64