Revision 6dd86be3
trustedintents/src/info/guardianproject/trustedintents/TrustedIntents.java | ||
---|---|---|
92 | 92 |
return true; |
93 | 93 |
} |
94 | 94 |
|
95 |
public Intent getIntentFromTrustedSender(Activity activity) |
|
96 |
throws NameNotFoundException, CertificateException { |
|
97 |
Intent intent = activity.getIntent(); |
|
98 |
if (!isIntentSane(intent)) |
|
99 |
throw new NameNotFoundException( |
|
100 |
"Intent incomplete or was sent using startActivity() instead of startActivityWithResult()"); |
|
95 |
/** |
|
96 |
* Check if an {@link Intent} is from a trusted sender. |
|
97 |
* |
|
98 |
* @param intent the {@code Intent} to check |
|
99 |
* @return boolean whether {@code intent} is from a trusted sender |
|
100 |
* @see #addTrustedSigner(Class) |
|
101 |
*/ |
|
102 |
public boolean isIntentFromTrustedSender(Intent intent) { |
|
103 |
if (!isIntentSane(intent)) { |
|
104 |
return false; |
|
105 |
} |
|
101 | 106 |
String packageName = intent.getPackage(); |
102 | 107 |
if (TextUtils.isEmpty(packageName)) { |
103 | 108 |
packageName = intent.getComponent().getPackageName(); |
104 | 109 |
} |
105 |
if (TextUtils.isEmpty(packageName)) |
|
106 |
throw new NameNotFoundException(packageName); |
|
107 |
checkTrustedSigner(packageName); |
|
108 |
return intent; |
|
110 |
if (TextUtils.isEmpty(packageName)) { |
|
111 |
return false; |
|
112 |
} |
|
113 |
return isPackageNameTrusted(packageName); |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* Returns an {@link Intent} if the sending app is signed by one of |
|
118 |
* the trusted signing keys as set in {@link #addTrustedSigner(Class)}. |
|
119 |
* |
|
120 |
* @returns {@code null} if there is no {@code Intent} or if the |
|
121 |
* sender is not trusted. |
|
122 |
* @see #addTrustedSigner(Class) |
|
123 |
*/ |
|
124 |
public Intent getIntentFromTrustedSender(Activity activity) { |
|
125 |
Intent intent = activity.getIntent(); |
|
126 |
if (isIntentFromTrustedSender(intent)) { |
|
127 |
return intent; |
|
128 |
} |
|
129 |
return null; |
|
109 | 130 |
} |
110 | 131 |
|
111 | 132 |
private boolean isIntentSane(Intent intent) { |
Also available in: Unified diff