| package android.security.cts.CVE_2021_0921; |
| |
| import android.content.ActivityNotFoundException; |
| import android.content.ComponentName; |
| import android.content.Context; |
| import android.content.Intent; |
| import android.content.pm.ApplicationInfo; |
| import android.content.pm.PackageManager; |
| import android.net.Uri; |
| import android.util.Log; |
| |
| import java.io.File; |
| |
| public class Trigger { |
| private static final String TAG = "TAG_2021_0921.Trigger"; |
| private Context mContext; |
| |
| public Trigger(Context context) { |
| mContext = context; |
| } |
| |
| private static boolean isCar(Context context) { |
| PackageManager pm = context.getPackageManager(); |
| return pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); |
| } |
| |
| private static boolean isWear(Context context) { |
| PackageManager pm = context.getPackageManager(); |
| return pm.hasSystemFeature(PackageManager.FEATURE_WATCH); |
| } |
| |
| private static boolean isTv(Context context) { |
| PackageManager pm = context.getPackageManager(); |
| return pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION); |
| } |
| |
| public void accountSettings() { |
| Log.d(TAG, "accountSettings() start"); |
| String exitMessage = "accountSettings() end"; |
| |
| //replaces intent.setAction(Intent.ACTION_REBOOT) in original Poc |
| Intent arbitraryIntent = new Intent(mContext, TestActivity.class); |
| |
| //Patched device is not supposed to process that intent |
| Authenticator.mIntent = arbitraryIntent; |
| |
| Intent intent = new Intent(); |
| String pkg = "com.android.settings"; |
| if (isCar(mContext)) { |
| pkg = "com.android.car.settings"; |
| intent.setComponent(new ComponentName(pkg, pkg + ".accounts.AddAccountActivity")); |
| } else if (isTv(mContext)) { |
| pkg = "com.android.tv.settings"; |
| intent.setComponent(new ComponentName(pkg, pkg + ".accounts.AddAccountWithTypeActivity")); |
| } else if (isWear(mContext)) { |
| pkg = "com.google.android.clockwork.home"; |
| intent.setComponent(new ComponentName(pkg, pkg + ".accounts.SetupAccountReceiver")); |
| } else { |
| intent.setComponent(new ComponentName(pkg, pkg + ".accounts.AddAccountSettings")); |
| } |
| intent.setAction(Intent.ACTION_RUN); |
| intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| String authTypes[] = {"android.security.cts"}; |
| |
| intent.putExtra("account_types", authTypes); |
| |
| try { |
| mContext.startActivity(intent); |
| } catch (ActivityNotFoundException e) { |
| // activity does not exist on this device |
| exitMessage = "accountSettings() failure: activity does not exist on this device"; |
| } |
| Log.d(TAG, exitMessage); |
| } |
| } |