diff options
author | Aaron Whyte <awhyte@google.com> | 2014-04-16 23:56:07 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-04-16 23:56:07 +0000 |
commit | 8aa68921a577e1b665fe61cb40d3c929054a0a94 (patch) | |
tree | c827d9b0e4b759c7ff969c00f8257d3f3306c04e /services/usb/java/com | |
parent | 3d295988f2d7011db3cec69ba0d80736a568ab15 (diff) | |
parent | ee5d512d624c15fa0c7e179ace24c7055a9f539d (diff) | |
download | frameworks_base-8aa68921a577e1b665fe61cb40d3c929054a0a94.zip frameworks_base-8aa68921a577e1b665fe61cb40d3c929054a0a94.tar.gz frameworks_base-8aa68921a577e1b665fe61cb40d3c929054a0a94.tar.bz2 |
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 'ee5d512d624c15fa0c7e179ace24c7055a9f539d':
Allowed custom secure-adb confirmation via Activity or Service. It used to only be available via an Activity.
Diffstat (limited to 'services/usb/java/com')
-rw-r--r-- | services/usb/java/com/android/server/usb/UsbDebuggingManager.java | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/services/usb/java/com/android/server/usb/UsbDebuggingManager.java b/services/usb/java/com/android/server/usb/UsbDebuggingManager.java index f73d425..0946c5a 100644 --- a/services/usb/java/com/android/server/usb/UsbDebuggingManager.java +++ b/services/usb/java/com/android/server/usb/UsbDebuggingManager.java @@ -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 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 { - mContext.startActivity(intent); - } catch (ActivityNotFoundException e) { - Slog.e(TAG, "unable to start UsbDebuggingActivity"); + 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() { |