1 /*
2  * Copyright (C) 2017 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 com.android.test.cantsavestate1;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.os.IBinder;
23 import android.os.Parcel;
24 import android.os.RemoteException;
25 
26 public class CantSave1Activity extends Activity {
27 
28     public static final String ACTION_FINISH = "com.android.test.action.FINISH";
29     public static final String EXTRA_CALLBACK = "android.app.stubs.extra.callback";
30 
31     private IBinder mCallback;
32 
33     @Override
onCreate(Bundle savedInstanceState)34     public void onCreate(Bundle savedInstanceState) {
35         super.onCreate(savedInstanceState);
36         setContentView(R.layout.cant_save_1_activity);
37         getWindow().getDecorView().requestFocus();
38         final Intent intent = getIntent();
39         final Bundle extras = intent.getExtras();
40         if (extras != null) {
41             mCallback = extras.getBinder(EXTRA_CALLBACK);
42         }
43     }
44 
45     @Override
onTrimMemory(int level)46     public void onTrimMemory(int level) {
47         if (mCallback != null) {
48             final Parcel data = Parcel.obtain();
49             final Parcel reply = Parcel.obtain();
50             data.writeInt(level);
51             try {
52                 mCallback.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
53             } catch (RemoteException e) {
54             } finally {
55                 data.recycle();
56                 reply.recycle();
57             }
58         }
59     }
60 
61     @Override
onNewIntent(Intent intent)62     protected void onNewIntent(Intent intent) {
63         if (ACTION_FINISH.equals(intent.getAction())) {
64             finish();
65         }
66     }
67 }
68