Revision 35897639
src/info/guardianproject/trustedintents/TrustedIntents.java | ||
---|---|---|
1 | 1 |
|
2 | 2 |
package info.guardianproject.trustedintents; |
3 | 3 |
|
4 |
import android.app.Activity; |
|
5 |
import android.content.ActivityNotFoundException; |
|
4 | 6 |
import android.content.Context; |
5 | 7 |
import android.content.Intent; |
6 | 8 |
import android.content.pm.PackageInfo; |
... | ... | |
33 | 35 |
} |
34 | 36 |
|
35 | 37 |
public boolean isReceiverTrusted(Intent intent) { |
36 |
if (intent == null)
|
|
38 |
if (!isIntentSane(intent))
|
|
37 | 39 |
return false; |
38 | 40 |
String packageName = intent.getPackage(); |
39 |
if (TextUtils.isEmpty(packageName)) |
|
40 |
return false; |
|
41 | 41 |
try { |
42 | 42 |
checkTrustedSigner(packageName); |
43 | 43 |
} catch (NameNotFoundException e) { |
44 | 44 |
e.printStackTrace(); |
45 | 45 |
return false; |
46 | 46 |
} catch (CertificateException e) { |
47 |
e.printStackTrace(); |
|
48 | 47 |
return false; |
49 | 48 |
} |
50 | 49 |
return true; |
51 | 50 |
} |
52 | 51 |
|
52 |
private boolean isIntentSane(Intent intent) { |
|
53 |
if (intent == null) |
|
54 |
return false; |
|
55 |
String packageName = intent.getPackage(); |
|
56 |
if (TextUtils.isEmpty(packageName)) |
|
57 |
return false; |
|
58 |
|
|
59 |
return true; |
|
60 |
} |
|
61 |
|
|
53 | 62 |
/** |
54 | 63 |
* Add an APK signature that is always trusted for any packageName. |
55 | 64 |
* |
... | ... | |
101 | 110 |
return false; |
102 | 111 |
return true; |
103 | 112 |
} |
113 |
|
|
114 |
public void startActivity(Activity activity, Intent intent) throws CertificateException { |
|
115 |
if (!isIntentSane(intent)) |
|
116 |
throw new ActivityNotFoundException("The intent was null or empty!"); |
|
117 |
String packageName = intent.getPackage(); |
|
118 |
try { |
|
119 |
checkTrustedSigner(packageName); |
|
120 |
} catch (NameNotFoundException e) { |
|
121 |
e.printStackTrace(); |
|
122 |
throw new ActivityNotFoundException(e.getLocalizedMessage()); |
|
123 |
} |
|
124 |
activity.startActivity(intent); |
|
125 |
} |
|
104 | 126 |
} |
Also available in: Unified diff