Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8aa68921 authored by Aaron Whyte's avatar Aaron Whyte Committed by Android Git Automerger
Browse files

am ee5d512d: am 4980996b: Merge "Allowed custom secure-adb confirmation via...

am ee5d512d: am 4980996b: Merge "Allowed custom secure-adb confirmation via Activity or Service. It used to only be available via an Activity." into klp-modular-dev

* commit 'ee5d512d':
  Allowed custom secure-adb confirmation via Activity or Service. It used to only be available via an Activity.
parents 3d295988 ee5d512d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1340,10 +1340,10 @@
         Example: com.google.android.myapp/.resolver.MyResolverActivity  -->
    <string name="config_customResolverActivity"></string>

    <!-- Name of the activity that prompts the user to reject, accept, or whitelist
    <!-- Name of the activity or service that prompts the user to reject, accept, or whitelist
         an adb host's public key, when an unwhitelisted host connects to the local adbd.
         Can be customized for other product types -->
    <string name="config_customAdbPublicKeyActivity"
    <string name="config_customAdbPublicKeyConfirmationComponent"
            >com.android.systemui/com.android.systemui.usb.UsbDebuggingActivity</string>

    <!-- Apps that are authorized to access shared accounts, overridden by product overlays -->
+1 −1
Original line number Diff line number Diff line
@@ -1623,7 +1623,7 @@
  <java-symbol type="string" name="enable_explore_by_touch_warning_message" />
  <java-symbol type="bool" name="config_powerDecoupleAutoSuspendModeFromDisplay" />
  <java-symbol type="bool" name="config_powerDecoupleInteractiveModeFromDisplay" />
  <java-symbol type="string" name="config_customAdbPublicKeyActivity" />
  <java-symbol type="string" name="config_customAdbPublicKeyConfirmationComponent" />

  <java-symbol type="layout" name="resolver_list" />
  <java-symbol type="id" name="resolver_list" />
+53 −13
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
@@ -210,7 +212,7 @@ public class UsbDebuggingManager implements Runnable {
                case MESSAGE_ADB_CONFIRM: {
                    String key = (String)msg.obj;
                    mFingerprints = getFingerprints(key);
                    showConfirmationDialog(key, mFingerprints);
                    startConfirmation(key, mFingerprints);
                    break;
                }

@@ -245,22 +247,60 @@ public class UsbDebuggingManager implements Runnable {
        return sb.toString();
    }

    private void showConfirmationDialog(String key, String fingerprints) {
        Intent intent = new Intent();
    private void startConfirmation(String key, String fingerprints) {
        String nameString = Resources.getSystem().getString(
                com.android.internal.R.string.config_customAdbPublicKeyConfirmationComponent);
        ComponentName componentName = ComponentName.unflattenFromString(nameString);
        if (startConfirmationActivity(componentName, key, fingerprints)
                || startConfirmationService(componentName, key, fingerprints)) {
            return;
        }
        Slog.e(TAG, "unable to start customAdbPublicKeyConfirmationComponent "
                + nameString + " as an Activity or a Service");
    }

        ComponentName componentName = ComponentName.unflattenFromString(
                Resources.getSystem().getString(
                        com.android.internal.R.string.config_customAdbPublicKeyActivity));
        intent.setClassName(componentName.getPackageName(),
                componentName.getClassName());
    /**
     * @returns true if the componentName led to an Activity that was started.
     */
    private boolean startConfirmationActivity(ComponentName componentName, String key,
            String fingerprints) {
        PackageManager packageManager = mContext.getPackageManager();
        Intent intent = createConfirmationIntent(componentName, key, fingerprints);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("key", key);
        intent.putExtra("fingerprints", fingerprints);
        if (packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
            try {
                mContext.startActivity(intent);
                return true;
            } catch (ActivityNotFoundException e) {
            Slog.e(TAG, "unable to start UsbDebuggingActivity");
                Slog.e(TAG, "unable to start adb whitelist activity: " + componentName, e);
            }
        }
        return false;
    }

    /**
     * @returns true if the componentName led to a Service that was started.
     */
    private boolean startConfirmationService(ComponentName componentName, String key,
            String fingerprints) {
        Intent intent = createConfirmationIntent(componentName, key, fingerprints);
        try {
            if (mContext.startService(intent) != null) {
                return true;
            }
        } catch (SecurityException e) {
            Slog.e(TAG, "unable to start adb whitelist service: " + componentName, e);
        }
        return false;
    }

    private Intent createConfirmationIntent(ComponentName componentName, String key,
            String fingerprints) {
        Intent intent = new Intent();
        intent.setClassName(componentName.getPackageName(), componentName.getClassName());
        intent.putExtra("key", key);
        intent.putExtra("fingerprints", fingerprints);
        return intent;
    }

    private File getUserKeyFile() {