<[组件名]android:exported = false>组件名>
Android平台定义了一系列用于保护系统服务和app组件的默认权限,可以对权限进行调整和定制
<string name= "custom_permission_label">Custom Permissionstring>
在AndroidManifest.xml中
"android.permission.CUSTOM_PERMISSION"
android:protextionLevel = "normal"
android:description = "My custom permission"
android:label = "@string/custom_permission_label"
>
android:permission = "android.permission.CUSTOM_PERMISSION">
android:permission = "android.permission.CUSTOM_PERMISSION">
android:permission = "android.permission.CUSTOM_PERMISSION">
<uses-permission android:name="android.permission.CUSTOM_PERMISSION"/>
<string name = "my_permissions_group_label">Personal Data Accessstring>
2.在AndroidManifest.xml中添加
android:name = "android.permissions.personal_data_access_group"
android:label ="@string/my_permissions_group_label"
android:description = "Permissions that allow access to personaldata"
>
...
android:permissionGroup = "android.permission.personal_data_acess_group"/>
"true" android:exported = "true" android:authorities = "com.android.myAuthority android:name = "com.myapp.provider"
android:permission="[permission name]"
>
可以要求提供读写权限
"[write permission name]"
android:readPermission = "[read permission name]"
>
<provider...>
<path-permission android:path = "/[path name]"
android:permission = "[read/write permission name]"
</provider>
<provider...>
<grant-uri-permission android:path="[path name]"/>
provider>
INSERT VALUES INTO [table name](?,?,?,?,....)
*通过获取keytool工具签名时的证书指纹 SHA1,与app中读取出来的指纹进行比较。
* 获取当前运行的app的指纹代码:
public String getCertificateSHA1Fingerprint(Context context) {
//获取包管理器
PackageManager pm = context.getPackageManager();
//获取当前要获取 SHA1 值的包名,也可以用其他的包名,但需要注意,
//在用其他包名的前提是,此方法传递的参数 Context 应该是对应包的上下文。
String packageName = context.getPackageName();
//返回包括在包中的签名信息
int flags = PackageManager.GET_SIGNATURES;
PackageInfo packageInfo = null;
try {
//获得包的所有内容信息类
packageInfo = pm.getPackageInfo(packageName, flags);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
//签名信息
Signature[] signatures = packageInfo.signatures;
byte[] cert = signatures[0].toByteArray();
//将签名转换为字节数组流
InputStream input = new ByteArrayInputStream(cert);
//证书工厂类,这个类实现了出厂合格证算法的功能
CertificateFactory cf = null;
try {
cf = CertificateFactory.getInstance("X509");
} catch (Exception e) {
e.printStackTrace();
}
//X509 证书,X.509 是一种非常通用的证书格式
X509Certificate c = null;
try {
c = (X509Certificate) cf.generateCertificate(input);
} catch (Exception e) {
e.printStackTrace();
}
String hexString = null;
try {
//加密算法的类,这里的参数可以使 MD4,MD5 等加密算法
MessageDigest md = MessageDigest.getInstance("SHA1");
//获得公钥
byte[] publicKey = md.digest(c.getEncoded());
//字节到十六进制的格式转换
hexString = byte2HexFormatted(publicKey);
} catch (NoSuchAlgorithmException e1) {
e1.printStackTrace();
} catch (CertificateEncodingException e) {
e.printStackTrace();
}
return hexString;
}
//这里是将获取到得编码进行16 进制转换
private String byte2HexFormatted(byte[] arr) {
StringBuilder str = new StringBuilder(arr.length * 2);
for (int i = 0; i < arr.length; i++) {
String h = Integer.toHexString(arr[i]);
int l = h.length();
if (l == 1)
h = "0" + h;
if (l > 2)
h = h.substring(l - 2, l);
str.append(h.toUpperCase());
if (i < (arr.length - 1))
str.append(':');
}
return str.toString();
}
minifyEnabled true
proguardFile file('proguard-rules.pro')
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
GexGuard要比ProGuard的可维护性和可测试性更多,编译和输出则是经过优化和加固的。使用GexGuard可以获得更多的安全性,同时,它还具有:API隐藏和字符串加密的特性
DexGuard是收费的,但是对于一个公司来说是可以承受的